A distributed client-server application engineered to calculate the statistical probability of Adverse Drug Reactions (ADRs) by analyzing unstructured Electronic Health Records (EHR) against multiple pharmacological APIs and vectorized datasets. It employs a Node.js/Express backend, a React frontend, and a MongoDB NoSQL database cluster for persistent state management.
The backend exposes specific RESTful API endpoints that handle complex data transformation protocols.
graph TD
A([Client: /predict Payload]) -->|EHR String + Prescriptions| B(GPT-3.5 Normalization)
B -->|Delimited Med Strings| C{RxNav Tokenization}
C -->|Array of RxCUIs| D[NIH Interaction API]
D -->|ONCHigh Severities| E
B -->|Patient Demographics| E{FAISS Vector Search}
E -->|K-NN Embeddings| F[(FAERS Dataset)]
F -->|Top 5 Matches| G[Generative Synthesis Prompt]
G -->|Update Arrays| H[(MongoDB: patients)]
| Route Endpoint | Method | Operational Scope |
|---|---|---|
/upload |
POST | Parses PDF via wget subprocess. Executes text extraction. Injects payload into MongoDB patients schema. |
/predict |
POST | Orchestrates sequential LLM normalization, RxNav API tokenization, and FAISS vector similarity extraction. Mutates patient arrays. |
/adr |
PUT | Compares predicted ADRs against client-submitted observed arrays. Triggers MongoDB upsert to increment integer tallies. |
/stats |
GET | Aggregates side-effect integer tallies, calculating relative frequency percentages for frontend rendering. |
-
LLM String Normalization
The raw prescription string is concatenated with the extracted EHR text and dispatched via the OpenAI API (GPT-3.5). The LLM is prompted via few-shot learning techniques to output a rigid delimiter-separated string:Medications||Demographics, Conditions||Allergies||. -
RxNav Tokenization
The extracted medication strings are formatted into HTTP GET requests targetinghttps://rxnav.nlm.nih.gov/REST/drugs.json. This maps arbitrary brand names to absolute unique numerical identifiers (RxCUIs). -
Interaction Assessment
A subsequent request is dispatched tohttps://rxnav.nlm.nih.gov/REST/interaction/list.jsonpassing the array of RxCUIs. The JSON response is parsed to extract ONCHigh severity mappings and DrugBank description strings. -
Vector Similarity Search
The system implements a FAISS (Facebook AI Similarity Search) index over the FAERS (FDA Adverse Event Reporting System) dataset (contained indata.csv). It computes embeddings for the patient's demographic/condition profile and runs a K-Nearest Neighbors (KNN) search to isolate the 5 most statistically analogous historical cases. -
Generative Synthesis
The extracted interactions, the FAERS case histories, and the RxCUI data are compiled into a final GPT prompt. The LLM generates a predictive matrix classifying the interactions with Risk Levels (High, Medium, Low) and predicted Side Effects.
-
Clone the Repository Ensure you have Node.js and Python installed before cloning.
-
Server Initialization Navigate to the
Serverdirectory. Install the required Python packages and execute the backend server instance:cd Server pip install -r requirement.txt python server.py -
Client Initialization Navigate to the
Clientdirectory. Download dependencies and start the React frontend:cd Client npm install npm start
Caution
The root .env file must strictly define MONGO_URI and OPENAI_API_KEY for the server instances to execute correctly.