Skip to content

Repository files navigation

SafeMeds

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.


Algorithmic Pipeline & Endpoints

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)]
Loading

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.

Predictive Pipeline Breakdown (/predict)

  1. 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||.

  2. RxNav Tokenization
    The extracted medication strings are formatted into HTTP GET requests targeting https://rxnav.nlm.nih.gov/REST/drugs.json. This maps arbitrary brand names to absolute unique numerical identifiers (RxCUIs).

  3. Interaction Assessment
    A subsequent request is dispatched to https://rxnav.nlm.nih.gov/REST/interaction/list.json passing the array of RxCUIs. The JSON response is parsed to extract ONCHigh severity mappings and DrugBank description strings.

  4. Vector Similarity Search
    The system implements a FAISS (Facebook AI Similarity Search) index over the FAERS (FDA Adverse Event Reporting System) dataset (contained in data.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.

  5. 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.



Setup & Run Instructions

  1. Clone the Repository Ensure you have Node.js and Python installed before cloning.

  2. Server Initialization Navigate to the Server directory. Install the required Python packages and execute the backend server instance:

    cd Server
    pip install -r requirement.txt
    python server.py
  3. Client Initialization Navigate to the Client directory. Download dependencies and start the React frontend:

    cd Client
    npm install
    npm start

Environment Configuration

Caution

The root .env file must strictly define MONGO_URI and OPENAI_API_KEY for the server instances to execute correctly.

About

A distributed client-server application to calculate the statistical probability of ADRs by analyzing unstructured EHR against multiple pharmacological APIs and vectorized datasets.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages