PharmaX: Smart Geolocation & Conversational AI for On-Call Pharmacies
Project History, Engineering Pipeline, Mathematical Modeling & Key Learnings
The Inspiration: Field Insights
It all started with a personal experience, one shared by thousands of families in Lomé, Togo. It is 11:00 PM, a loved one falls ill with a sudden fever, and an on-call pharmacy must be found urgently. The information exists (published officially by INAM and ONPT), but it is severely fragmented: a blurry image shared on WhatsApp, a static table on a website, or a lost post on social media.
I realized that the core problem was not an absence of data, but the inability to make it queryable at the crucial moment. The user is forced to perform the machine's task: cross-referencing addresses, guessing distances, and switching applications to calculate a route. From this fragmented healthcare journey arose the drive to create PharmaX: a single, conversational, geolocated Progressive Web Application (PWA) designed to eliminate friction and save vital time.
Building the Project: From Data to Application
The construction of PharmaX followed a rigorous engineering methodology structured around a complete end-to-end pipeline.
1. Data Collection and Processing (ETL Pipeline)
To make the AI system functional and reliable, clean data was mandatory. I built an automated Python scraper to extract official on-call lists from INAM. The main challenge was matching extracted pharmacy names against my own geospatial dataset. I implemented the Jaccard Similarity Index to calculate text alignment:
$$J(A,B) = \frac{|A \cap B|}{|A \cup B|}$$
(where $A$ and $B$ represent the sets of word n-grams forming the pharmacy names).
2. Frugal Artificial Intelligence & NLP
Rather than relying on expensive, internet-dependent Large Language Models (LLMs), I opted for a frugal AI architecture. I trained a lightweight LinearSVC (TF-IDF) model on a domain-specific corpus of 5,000 utterances. To evaluate its classification performance under class imbalance, I used the $\text{F1-macro}$ metric:
$$\text{F1-macro} = \frac{1}{K} \sum_{i=1}^{K} \frac{2 \cdot \text{Precision}_i \cdot \text{Recall}_i}{\text{Precision}_i + \text{Recall}_i}$$
3. Geolocation & Spatial Navigation
For initial route guidance, the system computes geodesic distances ($d$) across the Earth's surface (radius $R \approx 6371 \text{ km}$) using the Haversine formula:
$$a = \sin^2\left(\frac{\Delta \varphi}{2}\right) + \cos(\varphi_1)\cos(\varphi_2)\sin^2\left(\frac{\Delta \lambda}{2}\right)$$
$$d = 2R \cdot \arctan2\left(\sqrt{a}, \sqrt{1-a}\right)$$
The complete stack integrates a lightweight Flask backend (Python), SQLite, Leaflet.js, OpenStreetMap, and the OSRM routing engine for real-time navigation.
Challenges Encountered & Solutions
- Severe Data Imbalance: Emergency intent (emergency) accounted for less than 3% of incoming queries. A standard model would have overlooked these critical cases. I applied targeted oversampling techniques to force the AI model to accurately identify emergency scenarios.
- Source Fragility (Human-in-the-Loop): Structure changes on source websites could break standard scrapers. I designed a hybrid verification architecture: 100% automated matching for high-confidence scores, with low-confidence matches flagged for administrator validation via a dedicated back-office.
- Hardware Constraints: Optimizing for constrained execution environments (without dedicated high-end GPUs) led to continuous codebase efficiency, resulting in 90.7% overall accuracy while maintaining a 99% emergency detection rate.
- User Usability Validation: Conducting System Usability Scale (SUS) benchmarks with real users was logistically demanding, yet essential to validate real-world impact—reducing emergency search durations from 18 minutes down to 20 seconds.
Key Learnings
- AI is only as good as its underlying data: The most complex phase was not training the model, but data cleaning, ETL pipeline stability, and validation (Garbage in, garbage out).
- Frugal AI is a necessity and a strength: Complex LLMs are not always required to solve critical local problems. Lightweight, self-contained models offer superior reliability and speed under fluctuating network connectivity.
- Human oversight is essential in digital health: AI should not operate as an opaque black box. Blending fast automated matching with human administration builds sustainable user trust.
PharmaX is more than just a technical prototype. It demonstrates that tailored technological innovation can—and must—deliver a direct, measurable social impact.