Backend

Backend responsibilities, models, views, serializers, and API reference for Microbiology.

👤 Mohammad Ashfaque Alam📅 Updated: May 22, 2026📁 Microbiology

Backend

What Backend Owns

ConcernBackend responsibility
Master data persistenceOrganism, Antibiotic, OrganismAntibiotics, MolecularOrganismAntibiotics models, validation, and lifecycle hooks
CachingOrganism and antibiotic records are cached individually and in collections using ReportingCacheBase to avoid repeated DB queries
ValidationMandatory field checks, duplicate prevention, RIS range pattern validation, and logic purity for all master data operations
API endpointsCRUD for organisms and antibiotics, enable/disable flows, and linked-entity queries (which organisms use an antibiotic and vice versa)
Report submissionMicrobiology report data is persisted as part of the generic report-entry submission flow; microbiology-specific parsing handled by MicrobiologyComponent
Authorizationaccess_admin decorator on all write endpoints; reporting_read decorator on all read endpoints

Backend Repos

  • livehealthapp: Contains model definitions, serializers, views, and URL configurations for Organism, Antibiotic, OrganismAntibiotics, and MolecularOrganismAntibiotics.
  • 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

ColumnTypeDescription
idAutoFieldPrimary key
nameCharField(150)Organism name; unique per lab
labFK → labsThe lab owning the organism; null for system defaults
categoryCharField(150)Free-text grouping (e.g. Bacteria, Fungi)
codeCharField(25)Short identifier
is_disabledBooleanFieldControls visibility
sample_typeCharField(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

ColumnTypeDescription
idAutoFieldPrimary key
nameCharField(150)Antibiotic name
labFK → labsThe lab owning the antibiotic
categoryCharField(150)Free-text grouping
codeCharField(25)Short identifier
is_disabledBooleanFieldControls visibility
sample_typeCharField(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

ColumnTypeDescription
idAutoFieldPrimary key
organismFK → OrganismThe parent organism
antibioticFK → AntibioticThe mapped antibiotic
resistance_diameter_upper / _lowerFloatFieldDisk diffusion ranges for Resistant
intermediate_diameter_upper / _lowerFloatFieldDisk diffusion ranges for Intermediate
sensitive_diameter_upper / _lowerFloatFieldDisk diffusion ranges for Sensitive
resistance_mic_upper / _lowerFloatFieldMIC ranges for Resistant
intermediate_mic_upper / _lowerFloatFieldMIC ranges for Intermediate
sensitive_mic_upper / _lowerFloatFieldMIC ranges for Sensitive

Bulk create (OrganismAntibiotics.bulk_create):

  • Deletes all existing mappings matching the filters dict (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

ColumnTypeDescription
idAutoFieldPrimary key
organismFK → OrganismThe parent organism
antibioticFK → AntibioticThe mapped antibiotic
sequenceIntegerFieldDetermines display order in the grid
is_activeBooleanFieldWhether 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

MethodEndpointDescription
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

MethodEndpointDescription
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

  1. Report entry values are submitted via the standard report submission API.
  2. The payload contains an array of distinct objects for each organism and its matched antibiotics under the MICROBIOLOGY parameter type.
  3. The MicrobiologyComponent proxy evaluates these records, builds the result, and stores it in the ReportData payload using standard structure.
  4. 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

AreaFileDescription
Organism modelreporting/models/organism.pyCore organism entity, RIS mapping management, caching, activity logging
OrganismAntibiotics modelreporting/models/organism_antibiotics.pyThrough-table for organism ↔ antibiotic RIS breakpoints
MolecularOrganismAntibiotics modelreporting/models/molecular_organism_antibiotics.pyThrough-table for Molecular mapping tab
Organism viewreporting/views/organism.pyHTTP handlers for organism CRUD
Organism serializerreporting/serializers/organism.pySerializes organism data including nested mappings
Organism component proxyreporting/proxies/report_format/organism_component.pyReport-format proxy for the ORGANISM component type

On this page