# panushri25/emrqa architecture

> Architecture diagram of the GitHub repository panushri25/emrqa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/panushri25/emrqa
- Repository: https://github.com/panushri25/emrqa

## Overview

#### Purpose and Runtime

emrQA is an offline, Python 2.7 data-generation pipeline for creating clinical question-answer (QA) and question–logical-form (QL) corpora from licensed i2b2/N2C2 challenge annotations. It is not a serving application. The primary entry point is `main.py`; its outputs are generated JSON/CSV files under an `output/` directory.

#### Inputs and External Boundary

The pipeline combines expert-authored templates with externally downloaded, license-controlled i2b2 clinical notes and annotations. The template contract is a tabular row containing dataset selector, paraphrased question templates, logical-form template, answer type, and sub-answer type.

- Template source: `templates/templates-all.csv`
- Pipeline launcher/path configuration: `main.py`
- External dependency manifest: `requirements.txt`

The required `i2b2/` input tree is deliberately absent from the repo because it contains controlled clinical datasets.

#### Orchestration and Dataset Routing

`main.py` coordinates generation across five source challenge families, dispatching templates and i2b2 annotations to specialized generators. Each generator produces challenge-specific QA and QL artifacts; a final aggregation stage emits corpus-level files. Dataset identity in the template CSV is the routing boundary: medications, relations, risk, smoking, or obesity.

- Orchestrator: `main.py`
- Final aggregation: `generation/combine_data/combine_answers.py`
- Templates: `templates/templates-all.csv`

#### Annotation-to-QA Generation Stages

The architecture is organized by materially different i2b2 annotation formats rather than a uniform parser. Each stage reads its challenge’s notes/annotations, resolves template placeholders from annotated entities or labels, constructs questions and logical forms, and attaches context/evidence/answer metadata.

- Medication extraction QA: `generation/i2b2_medications/medication-answers.py`
- Relation/concept/assertion QA: `generation/i2b2_relations/relations-answers.py`
- Heart-disease risk-factor QA: `generation/i2b2_heart_disease_risk/risk-answers.py`
- Smoking classification QA: `generation/i2b2_smoking/smoking-answers.py`
- Obesity/comorbidity classification QA: `generation/i2b2_obesity/obesity-answers.py`

#### Important Data Semantics

Generated QA JSON is organized by dataset title, then clinical-note paragraphs, then QAs. For span-oriented sources, answers carry entity text, line/token location, and evidence line; answer type distinguishes `single`, `empty`, and `complex` answers. Smoking and obesity are classification-oriented: their class label is the answer and the full note serves as context/evidence. Heart-risk contexts combine multiple chronologically ordered notes for a patient, unlike the generally one-note-per-patient sources.

Relations generation also relies on repository-local normalization/matching assets:

- `generation/i2b2_relations/problem_classfiers.py`
- `generation/i2b2_relations/common_names.txt`
- `generation/i2b2_relations/matching_notes.csv`

#### Consolidation and Deliverables

Per-challenge generators create intermediate QA JSON and QL CSV outputs. `combine_answers.py` merges them into the primary deliverables: `data.json` for reading-comprehension-style QA and `data-ql.csv` for question/logical-form learning. This cleanly separates source-specific parsing from cross-corpus packaging.

- Combiner: `generation/combine_data/combine_answers.py`
- Source-specific generators: `generation/i2b2_relations/relations-answers.py`, `generation/i2b2_medications/medication-answers.py`

#### Post-generation Analysis

Independent analysis scripts consume generated outputs or the template corpus; they are downstream and do not alter generation. They calculate corpus statistics, paraphrase similarity/diversity, and logical-form-template properties.

- Output statistics: `evaluation/basic-stats.py`
- Paraphrase analysis: `evaluation/paraphrase-analysis.py`
- Template/logical-form analysis: `evaluation/template-analysis.py`

Main entry points: [`main.py`](https://github.com/panushri25/emrqa/blob/master/main.py) (Pipeline orchestrator), [`templates/templates-all.csv`](https://github.com/panushri25/emrqa/blob/master/templates/templates-all.csv) (QA/QL templates), [`generation/combine_data/combine_answers.py`](https://github.com/panushri25/emrqa/blob/master/generation/combine_data/combine_answers.py) (Corpus combiner), [`generation/i2b2_relations/relations-answers.py`](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_relations/relations-answers.py) (Relation QA generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs &amp; contracts"]
  node_templates["QA/QL templates<br/>Template CSV<br/>[templates-all.csv]"]
  node_i2b2[("Licensed i2b2 inputs<br/>External clinical data")]
  node_requirements["Python dependencies<br/>Dependency manifest<br/>[requirements.txt]"]
end

subgraph group_generation["Source-specific generation"]
  node_medications["Medication QA generator<br/>Challenge generator"]
  node_relations["Relation QA generator<br/>Challenge generator"]
  node_risk["Heart-risk QA generator<br/>Challenge generator<br/>[risk-answers.py]"]
  node_smoking["Smoking QA generator<br/>Challenge generator<br/>[smoking-answers.py]"]
  node_obesity["Obesity QA generator<br/>Challenge generator<br/>[obesity-answers.py]"]
  node_relation_assets["Relation matching assets<br/>Normalization assets"]
  node_intermediate[("Per-challenge artifacts")]
end

subgraph group_outputs["Corpus packaging &amp; analysis"]
  node_combiner["Corpus combiner<br/>Aggregation script<br/>[combine_answers.py]"]
  node_data_json["data.json<br/>QA corpus"]
  node_data_ql["data-ql.csv<br/>QL corpus"]
  node_basic_stats["Output statistics<br/>Analysis script<br/>[basic-stats.py]"]
  node_paraphrase_analysis["Paraphrase analysis<br/>Analysis script"]
  node_template_analysis["Template/LF analysis<br/>Analysis script"]
end

node_main{{"Pipeline orchestrator<br/>Python entry point<br/>[main.py]"}}

node_requirements -.->|"runtime dependencies"| node_main
node_templates -->|"dataset routing"| node_main
node_i2b2 -->|"notes and annotations"| node_main
node_main -->|"medications templates/input"| node_medications
node_main -->|"relations templates/input"| node_relations
node_main -->|"risk templates/input"| node_risk
node_main -->|"smoking templates/input"| node_smoking
node_main -->|"obesity templates/input"| node_obesity
node_relation_assets -->|"normalization and matching"| node_relations
node_medications -->|"QA JSON and QL CSV"| node_intermediate
node_relations -->|"QA JSON and QL CSV"| node_intermediate
node_risk -->|"QA JSON and QL CSV"| node_intermediate
node_smoking -->|"QA JSON and QL CSV"| node_intermediate
node_obesity -->|"QA JSON and QL CSV"| node_intermediate
node_intermediate -->|"source artifacts"| node_combiner
node_combiner -->|"merged QA corpus"| node_data_json
node_combiner -->|"merged QL corpus"| node_data_ql
node_data_json -.->|"corpus metrics"| node_basic_stats
node_templates -.->|"template diversity"| node_paraphrase_analysis
node_templates -.->|"template/LF properties"| node_template_analysis

click node_main "https://github.com/panushri25/emrqa/blob/master/main.py"
click node_templates "https://github.com/panushri25/emrqa/blob/master/templates/templates-all.csv"
click node_requirements "https://github.com/panushri25/emrqa/blob/master/requirements.txt"
click node_medications "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_medications/medication-answers.py"
click node_relations "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_relations/relations-answers.py"
click node_risk "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_heart_disease_risk/risk-answers.py"
click node_smoking "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_smoking/smoking-answers.py"
click node_obesity "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_obesity/obesity-answers.py"
click node_relation_assets "https://github.com/panushri25/emrqa/blob/master/generation/i2b2_relations/problem_classfiers.py"
click node_combiner "https://github.com/panushri25/emrqa/blob/master/generation/combine_data/combine_answers.py"
click node_basic_stats "https://github.com/panushri25/emrqa/blob/master/evaluation/basic-stats.py"
click node_paraphrase_analysis "https://github.com/panushri25/emrqa/blob/master/evaluation/paraphrase-analysis.py"
click node_template_analysis "https://github.com/panushri25/emrqa/blob/master/evaluation/template-analysis.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_templates,node_i2b2,node_requirements toneBlue
class node_medications,node_relations,node_risk,node_smoking,node_obesity,node_relation_assets,node_intermediate toneAmber
class node_combiner,node_data_json,node_data_ql,node_basic_stats,node_paraphrase_analysis,node_template_analysis toneMint
class node_main toneNeutral
```

## Components

### Inputs & contracts

- [QA/QL templates](https://github.com/panushri25/emrqa/blob/master/templates/templates-all.csv): Template CSV · Dataset selector and question, logical-form, and answer-type templates. · `templates/templates-all.csv`
- **Licensed i2b2 inputs**: External clinical data · Controlled notes and annotations are intentionally absent from the repository.
- [Python dependencies](https://github.com/panushri25/emrqa/blob/master/requirements.txt): Dependency manifest · `requirements.txt`

### Source-specific generation

Each generator parses its challenge annotations and emits QA JSON plus QL CSV.

- [Medication QA generator](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_medications/medication-answers.py): Challenge generator · Builds span-oriented medication QA and QL artifacts. · `generation/i2b2_medications/medication-answers.py`
- [Relation QA generator](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_relations/relations-answers.py): Challenge generator · Builds concept, relation, and assertion QA and QL artifacts. · `generation/i2b2_relations/relations-answers.py`
- [Heart-risk QA generator](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_heart_disease_risk/risk-answers.py): Challenge generator · Combines chronologically ordered notes per patient for risk-factor QA. · `generation/i2b2_heart_disease_risk/risk-answers.py`
- [Smoking QA generator](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_smoking/smoking-answers.py): Challenge generator · Uses smoking class labels with full-note evidence. · `generation/i2b2_smoking/smoking-answers.py`
- [Obesity QA generator](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_obesity/obesity-answers.py): Challenge generator · Uses obesity/comorbidity class labels with full-note evidence. · `generation/i2b2_obesity/obesity-answers.py`
- [Relation matching assets](https://github.com/panushri25/emrqa/blob/master/generation/i2b2_relations/problem_classfiers.py): Normalization assets · Problem classifiers, common names, and note matching support relation generation. · `generation/i2b2_relations/problem_classfiers.py`
- **Per-challenge artifacts**: Intermediate QA JSON + QL CSV · Challenge-specific generated QA and logical-form outputs.

### Corpus packaging & analysis

- [Corpus combiner](https://github.com/panushri25/emrqa/blob/master/generation/combine_data/combine_answers.py): Aggregation script · Merges all challenge artifacts into corpus-level deliverables. · `generation/combine_data/combine_answers.py`
- **data.json**: QA corpus · Reading-comprehension QA organized by dataset, paragraphs, and QAs.
- **data-ql.csv**: QL corpus · Question and logical-form training corpus.
- [Output statistics](https://github.com/panushri25/emrqa/blob/master/evaluation/basic-stats.py): Analysis script · `evaluation/basic-stats.py`
- [Paraphrase analysis](https://github.com/panushri25/emrqa/blob/master/evaluation/paraphrase-analysis.py): Analysis script · `evaluation/paraphrase-analysis.py`
- [Template/LF analysis](https://github.com/panushri25/emrqa/blob/master/evaluation/template-analysis.py): Analysis script · `evaluation/template-analysis.py`

### Other components

- [Pipeline orchestrator](https://github.com/panushri25/emrqa/blob/master/main.py): Python entry point · Routes templates and controlled annotations across challenge families. · `main.py`

## Connections

- Python dependencies → Pipeline orchestrator: runtime dependencies
- QA/QL templates → Pipeline orchestrator: dataset routing
- Licensed i2b2 inputs → Pipeline orchestrator: notes and annotations
- Pipeline orchestrator → Medication QA generator: medications templates/input
- Pipeline orchestrator → Relation QA generator: relations templates/input
- Pipeline orchestrator → Heart-risk QA generator: risk templates/input
- Pipeline orchestrator → Smoking QA generator: smoking templates/input
- Pipeline orchestrator → Obesity QA generator: obesity templates/input
- Relation matching assets → Relation QA generator: normalization and matching
- Medication QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Relation QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Heart-risk QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Smoking QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Obesity QA generator → Per-challenge artifacts: QA JSON and QL CSV
- Per-challenge artifacts → Corpus combiner: source artifacts
- Corpus combiner → data.json: merged QA corpus
- Corpus combiner → data-ql.csv: merged QL corpus
- data.json → Output statistics: corpus metrics
- QA/QL templates → Paraphrase analysis: template diversity
- QA/QL templates → Template/LF analysis: template/LF properties
