Product EngineeringFeaturesCritical CalloutBackend

Data Model

Finalized schema — CriticalValuesEnum, CriticalCallout model, LabReportRelation, and the save_critical_callout factory method.

👤 Sachin Sharma📅 Updated: Apr 29, 2026🏷️ feature🏷️ backend🏷️ data-model

Data Model

Files:

  • report/migrations/0055_criticalcallout_bill_and_more.py
  • report/models/lab_report_relation.py
  • report/models/critical_callout.py

Schema

Three entities are involved in tracking critical callout state:

EntityFieldDesign
CriticalCalloutbillFK → finance.Billing (on_delete=SET_NULL). Ties each callout audit record to an order, independent of individual reports
CriticalCalloutlab_reportNullable. For bill-level drafts (is_draft=True), a single record is stored with lab_report=None; completed callouts set this to the specific report
LabReportRelationcriticalValuesInteger field with five states: 0 NORMAL · 1 CALLOUT_PENDING · 2 CALLOUT_DONE · 3 ABNORMAL · 4 CALLOUT_ATTEMPTED

CriticalValuesEnum

File: report/models/lab_report_relation.py

class CriticalValuesEnum(BaseEnum):
    NORMAL            = 0
    CALLOUT_PENDING   = 1
    CALLOUT_DONE      = 2
    ABNORMAL          = 3
    CALLOUT_ATTEMPTED = 4  # new

This enum is the single source of truth for callout status. It is used in:

  • LabReportRelation.criticalValues field choices
  • BulkCriticalCalloutManager state transitions
  • Frontend constants (CRITICAL_CALLOUT_PENDING/DONE/ATTEMPTED)
  • Elasticsearch patient_reports index field

CriticalCallout model

File: report/models/critical_callout.py

The CriticalCallout table is an audit table — every callout action (draft or done) creates one or more rows. It does not replace LabReportRelation.criticalValues; it supplements it with the who/when/how detail.

DB table: CriticalCallout
Indexes:  (lab, lab_report)

JSON fields

FieldContents
critical_callout_metacommunication_methods, notify_to_others, already_notified, log_message, callout_for (draft only)
critical_values_metaList of critical parameter objects per report (value, parameter_name, reference_range, bounds)

save_critical_callout factory

CriticalCallout.save_critical_callout(lab_report, **kwargs) is the single place that builds and persists callout records.

Key kwargs:

kwargTypeRole
is_draftboolControls whether lab_report is None and status becomes ATTEMPTED
do_saveboolWhen False, returns unsaved instance for deferred bulk_create
sendEmail / sendFaxboolAppended to communication_methods list in meta
otherdictnotify_to_others block — name, email, faxNumber, contactNumber
notified_by_call / notified_by_faxdictalready_notified block — recorded call/fax details
report_paramslistStored as critical_values_meta JSON
sessiondictResolves performed_by_user_id and performed_by_doctor_id

On this page