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.pyreport/models/lab_report_relation.pyreport/models/critical_callout.py
Schema
Three entities are involved in tracking critical callout state:
| Entity | Field | Design |
|---|---|---|
CriticalCallout | bill | FK → finance.Billing (on_delete=SET_NULL). Ties each callout audit record to an order, independent of individual reports |
CriticalCallout | lab_report | Nullable. For bill-level drafts (is_draft=True), a single record is stored with lab_report=None; completed callouts set this to the specific report |
LabReportRelation | criticalValues | Integer 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 # newThis enum is the single source of truth for callout status. It is used in:
LabReportRelation.criticalValuesfield choicesBulkCriticalCalloutManagerstate transitions- Frontend constants (
CRITICAL_CALLOUT_PENDING/DONE/ATTEMPTED) - Elasticsearch
patient_reportsindex 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
| Field | Contents |
|---|---|
critical_callout_meta | communication_methods, notify_to_others, already_notified, log_message, callout_for (draft only) |
critical_values_meta | List 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:
| kwarg | Type | Role |
|---|---|---|
is_draft | bool | Controls whether lab_report is None and status becomes ATTEMPTED |
do_save | bool | When False, returns unsaved instance for deferred bulk_create |
sendEmail / sendFax | bool | Appended to communication_methods list in meta |
other | dict | notify_to_others block — name, email, faxNumber, contactNumber |
notified_by_call / notified_by_fax | dict | already_notified block — recorded call/fax details |
report_params | list | Stored as critical_values_meta JSON |
session | dict | Resolves performed_by_user_id and performed_by_doctor_id |