Backend
Backend responsibilities, models, views, serializers, and API reference for Microbiology.
Backend
What Backend Owns
| Concern | Backend responsibility |
|---|---|
| Master data persistence | Organism, Antibiotic, OrganismAntibiotics, MolecularOrganismAntibiotics models, validation, and lifecycle hooks |
| Caching | Organism and antibiotic records are cached individually and in collections using ReportingCacheBase to avoid repeated DB queries |
| Validation | Mandatory field checks, duplicate prevention, RIS range pattern validation, and logic purity for all master data operations |
| API endpoints | CRUD for organisms and antibiotics, enable/disable flows, and linked-entity queries (which organisms use an antibiotic and vice versa) |
| Report submission | Microbiology report data is persisted as part of the generic report-entry submission flow; microbiology-specific parsing handled by MicrobiologyComponent |
| Authorization | access_admin decorator on all write endpoints; reporting_read decorator on all read endpoints |
Backend Repos
livehealthapp: Contains model definitions, serializers, views, and URL configurations forOrganism,Antibiotic,OrganismAntibiotics, andMolecularOrganismAntibiotics.crelio-app: Shares the core logic for report submission, organism/antibiotic caching, and microbiology report component processing for multi-centre use cases.
Core Backend Models
Organism
Table: Organism
Source: livehealthapp/reporting/models/organism.py
| Column | Type | Description |
|---|---|---|
id | AutoField | Primary key |
name | CharField(150) | Organism name; unique per lab |
lab | FK → labs | The lab owning the organism; null for system defaults |
category | CharField(150) | Free-text grouping (e.g. Bacteria, Fungi) |
code | CharField(25) | Short identifier |
is_disabled | BooleanField | Controls visibility |
sample_type | CharField(150) | Associated sample type |
After save: Clears caches for the specific organism and the organism list.
Model hooks: save_molecular_antibiotic_mappings handles the ordered Molecular tabs list on organism save.
Antibiotic
Table: Antibiotic
Source: livehealthapp/reporting/models/antibiotic.py
| Column | Type | Description |
|---|---|---|
id | AutoField | Primary key |
name | CharField(150) | Antibiotic name |
lab | FK → labs | The lab owning the antibiotic |
category | CharField(150) | Free-text grouping |
code | CharField(25) | Short identifier |
is_disabled | BooleanField | Controls visibility |
sample_type | CharField(150) | Associated sample type |
After save: Clears caches for the specific antibiotic and the list.
OrganismAntibiotics
Table: OrganismAntibiotics
Source: livehealthapp/reporting/models/organism_antibiotics.py
| Column | Type | Description |
|---|---|---|
id | AutoField | Primary key |
organism | FK → Organism | The parent organism |
antibiotic | FK → Antibiotic | The mapped antibiotic |
resistance_diameter_upper / _lower | FloatField | Disk diffusion ranges for Resistant |
intermediate_diameter_upper / _lower | FloatField | Disk diffusion ranges for Intermediate |
sensitive_diameter_upper / _lower | FloatField | Disk diffusion ranges for Sensitive |
resistance_mic_upper / _lower | FloatField | MIC ranges for Resistant |
intermediate_mic_upper / _lower | FloatField | MIC ranges for Intermediate |
sensitive_mic_upper / _lower | FloatField | MIC ranges for Sensitive |
Bulk create (OrganismAntibiotics.bulk_create):
- Deletes all existing mappings matching the
filtersdict (e.g.\{"organism_id": self.pk\}). - Re-creates all passed instances; validates each before save.
- Used during
Organism.after_save(...)to replace the full antibiogram in a single atomic block.
MolecularOrganismAntibiotics
Table: MolecularOrganismAntibiotics
Source: livehealthapp/reporting/models/molecular_organism_antibiotics.py
| Column | Type | Description |
|---|---|---|
id | AutoField | Primary key |
organism | FK → Organism | The parent organism |
antibiotic | FK → Antibiotic | The mapped antibiotic |
sequence | IntegerField | Determines display order in the grid |
is_active | BooleanField | Whether it is actively used in the report |
Payload Reference
Organism Create/Update Payload
When creating or updating an organism, the frontend sends the mapping lists inside the organism payload:
{
"name": "Escherichia coli",
"category": "Bacteria",
"code": "ECOLI",
"sample_type": "blood",
"antibiotic_mappings": [
{
"antibiotic_id": 42,
"antibiotic_name": "Ciprofloxacin",
"resistance_diameter_upper": 12,
"resistance_diameter_lower": 0,
"intermediate_diameter_upper": 19,
"intermediate_diameter_lower": 13,
"sensitive_diameter_upper": 40,
"sensitive_diameter_lower": 20,
"resistance_mic_upper": 8,
"resistance_mic_lower": 0,
"intermediate_mic_upper": 4,
"intermediate_mic_lower": 2,
"sensitive_mic_upper": 1,
"sensitive_mic_lower": 0
}
],
"molecular_organism_antibiotics": [
{
"antibiotic_id": 42,
"sequence": 1,
"is_active": true
}
]
}API Endpoints
Organism Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /reporting/organisms/ | List all organisms; supports is_disabled, name, lab_ids query params |
GET | /reporting/organisms/\{organism_id\} | Fetch a single organism by ID |
POST | /reporting/organisms/new/ | Create a new organism |
POST | /reporting/organisms/\{organism_id\}/update/ | Update an existing organism |
POST | /reporting/organisms/\{instance_id\}/disable/ | Disable an organism |
POST | /reporting/organisms/\{instance_id\}/enable/ | Re-enable a disabled organism |
GET | /reporting/organisms/\{instance_id\}/antibiotics/ | List antibiotics mapped to an organism |
GET | /reporting/antibiotics/\{instance_id\}/organisms/ | List organisms mapped to an antibiotic |
Antibiotic Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /reporting/antibiotics/ | List all antibiotics; supports is_disabled, name, lab_ids query params |
GET | /reporting/antibiotics/\{antibiotic_id\} | Fetch a single antibiotic by ID |
POST | /reporting/antibiotics/new/ | Create a new antibiotic |
POST | /reporting/antibiotics/\{antibiotic_id\}/update/ | Update an existing antibiotic |
POST | /reporting/antibiotics/\{instance_id\}/disable/ | Disable an antibiotic |
POST | /reporting/antibiotics/\{instance_id\}/enable/ | Re-enable a disabled antibiotic |
Backend Data Flow for Microbiology Report Entry
- Report entry values are submitted via the standard report submission API.
- The payload contains an array of distinct objects for each organism and its matched antibiotics under the
MICROBIOLOGYparameter type. - The
MicrobiologyComponentproxy evaluates these records, builds the result, and stores it in theReportDatapayload using standard structure. - The frontend performs all the intermediate/sensitive/resistant text derivation on the client side, then submits the final calculated values in the text fields (
result_2).
Source File Reference
| Area | File | Description |
|---|---|---|
| Organism model | reporting/models/organism.py | Core organism entity, RIS mapping management, caching, activity logging |
| OrganismAntibiotics model | reporting/models/organism_antibiotics.py | Through-table for organism ↔ antibiotic RIS breakpoints |
| MolecularOrganismAntibiotics model | reporting/models/molecular_organism_antibiotics.py | Through-table for Molecular mapping tab |
| Organism view | reporting/views/organism.py | HTTP handlers for organism CRUD |
| Organism serializer | reporting/serializers/organism.py | Serializes organism data including nested mappings |
| Organism component proxy | reporting/proxies/report_format/organism_component.py | Report-format proxy for the ORGANISM component type |