# abhijeetk597/medical-data-extraction architecture

> Architecture diagram of the GitHub repository abhijeetk597/medical-data-extraction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhijeetk597/medical-data-extraction
- Repository: https://github.com/abhijeetk597/medical-data-extraction

## Overview

Medical Data Extraction is a Streamlit-to-FastAPI application for extracting patient-record and prescription fields from PDFs, reviewing them, and saving verified values. The main workflow uploads a selected document type, rasterizes and preprocesses its pages, runs OCR, dispatches text to a type-specific parser, then returns extracted fields for review. Submission takes a separate API route to MySQL persistence. README documents these capabilities; the graph follows sampled calls and documented UI/API wiring, without assuming details of unsampled database schema or OCR internals.

Main entry points: [`backend/src/extractor.py`](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py) (Extraction orchestrator), [`frontend/app.py`](https://github.com/abhijeetk597/medical-data-extraction/blob/main/frontend/app.py) (Upload and review), [`backend/src/main.py`](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/main.py) (Extraction route), [`backend/src/parser_patient_details.py`](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_patient_details.py) (Patient parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_streamlit["Upload and review<br/>[app.py]"]
end

subgraph group_api["Backend API"]
  node_extract_api["Extraction route<br/>[main.py]"]
  node_save_api["Save routes<br/>[main.py]"]
end

subgraph group_extraction["Document extraction"]
  node_extractor["Extraction orchestrator<br/>[extractor.py]"]
  node_pdf_render["PDF rasterization<br/>[extractor.py]"]
  node_preprocess["Image preprocessing<br/>[utils.py]"]
  node_dispatch["Document-type dispatch<br/>[extractor.py]"]
  node_patient_parser["Patient parser"]
  node_prescription_parser["Prescription parser"]
  node_parser_base["Parser base<br/>[parser_generic.py]"]
end

subgraph group_persistence["Data persistence"]
  node_db_utility["Database utility<br/>[db_utils.py]"]
end

node_user(("Reviewer"))
node_tesseract["Tesseract OCR"]
node_mysql[("MySQL database")]

node_user -->|"uploads and reviews"| node_streamlit
node_streamlit -->|"requests extraction"| node_extract_api
node_extract_api -->|"calls extraction"| node_extractor
node_extractor -->|"rasterizes PDF"| node_pdf_render
node_extractor -->|"preprocesses pages"| node_preprocess
node_extractor -->|"extracts text"| node_tesseract
node_extractor -->|"selects parser"| node_dispatch
node_dispatch -->|"parses patient fields"| node_patient_parser
node_dispatch -->|"parses prescription fields"| node_prescription_parser
node_patient_parser -->|"extends"| node_parser_base
node_prescription_parser -->|"extends"| node_parser_base
node_extract_api -->|"returns extracted fields"| node_streamlit
node_user -->|"submits verified fields"| node_streamlit
node_streamlit -->|"posts reviewed values"| node_save_api
node_save_api -->|"updates table"| node_db_utility
node_db_utility -->|"calls stored procedures"| node_mysql

click node_streamlit "https://github.com/abhijeetk597/medical-data-extraction/blob/main/frontend/app.py"
click node_extract_api "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/main.py"
click node_save_api "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/main.py"
click node_extractor "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py"
click node_pdf_render "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py"
click node_preprocess "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/utils.py"
click node_dispatch "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py"
click node_patient_parser "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_patient_details.py"
click node_prescription_parser "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_prescription.py"
click node_parser_base "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_generic.py"
click node_db_utility "https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/db_utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_streamlit,node_user toneBlue
class node_extract_api,node_save_api,node_mysql toneAmber
class node_extractor,node_pdf_render,node_preprocess,node_dispatch,node_patient_parser,node_prescription_parser,node_parser_base toneMint
class node_db_utility toneRose
class node_tesseract toneIndigo
```

## Components

### User interface

- [Upload and review](https://github.com/abhijeetk597/medical-data-extraction/blob/main/frontend/app.py): `frontend/app.py`

### Backend API

- [Extraction route](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/main.py): `backend/src/main.py`
- [Save routes](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/main.py): `backend/src/main.py`

### Document extraction

- [Extraction orchestrator](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py): `backend/src/extractor.py`
- [PDF rasterization](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py): `backend/src/extractor.py`
- [Image preprocessing](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/utils.py): `backend/src/utils.py`
- [Document-type dispatch](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/extractor.py): `backend/src/extractor.py`
- [Patient parser](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_patient_details.py): `backend/src/parser_patient_details.py`
- [Prescription parser](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_prescription.py): `backend/src/parser_prescription.py`
- [Parser base](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/parser_generic.py): `backend/src/parser_generic.py`

### Data persistence

- [Database utility](https://github.com/abhijeetk597/medical-data-extraction/blob/main/backend/src/db_utils.py): `backend/src/db_utils.py`

### Other components

- **Reviewer**
- **Tesseract OCR**
- **MySQL database**

## Connections

- Reviewer → Upload and review: uploads and reviews (evidence: `README.md`)
- Upload and review → Extraction route: requests extraction (evidence: `frontend/app.py`)
- Extraction route → Extraction orchestrator: calls extraction (evidence: `backend/src/main.py`)
- Extraction orchestrator → PDF rasterization: rasterizes PDF (evidence: `backend/src/extractor.py`)
- Extraction orchestrator → Image preprocessing: preprocesses pages (evidence: `backend/src/extractor.py`)
- Extraction orchestrator → Tesseract OCR: extracts text (evidence: `backend/src/extractor.py`)
- Extraction orchestrator → Document-type dispatch: selects parser (evidence: `backend/src/extractor.py`)
- Document-type dispatch → Patient parser: parses patient fields (evidence: `backend/src/extractor.py`)
- Document-type dispatch → Prescription parser: parses prescription fields (evidence: `backend/src/extractor.py`)
- Patient parser → Parser base: extends (evidence: `backend/src/parser_patient_details.py`)
- Prescription parser → Parser base: extends (evidence: `backend/src/parser_prescription.py`)
- Extraction route → Upload and review: returns extracted fields (evidence: `frontend/app.py`)
- Reviewer → Upload and review: submits verified fields (evidence: `frontend/app.py`)
- Upload and review → Save routes: posts reviewed values (evidence: `frontend/app.py`)
- Save routes → Database utility: updates table (evidence: `backend/src/main.py`)
- Database utility → MySQL database: calls stored procedures (evidence: `backend/src/db_utils.py`)
