Skip to main content
Version: 3.1

Detected Issue

A DetectedIssue records a clinical risk found during an encounter — a drug interaction, a dose problem, a duplicate therapy, or a care gap. It maps to the FHIR DetectedIssue resource. Each issue points at the clinical records that caused it, and carries the notes that describe how staff mitigated it.

Source:

A detected issue lives across two layers. The Django models are storage: code and metadata are opaque JSONFields, and status, category, and severity are plain CharFields. The Pydantic resource specs are the API layer. They supply the enums, the read and write schemas, and the validation.

Models​

ModelPurpose
DetectedIssueA clinical risk detected for a patient during an encounter
DetectedIssueMitigationA note that records the action taken against an issue
DetectedIssueResourceA link from an issue to the clinical record that caused it

All three extend EMRBaseModel, the shared Care EMR base that gives external_id, created_date/modified_date, created_by/updated_by, soft-delete through deleted, and history/meta JSON.

DetectedIssue fields​

FieldTypeNotes
statusCharField(25)Lifecycle state. Spec binds it to DetectedIssueStatusOptions; required on create
categoryCharField(25)Kind of risk. Spec binds it to DetectedIssueCategoryOptions; required on create
severityCharField(25)How serious the risk is. Spec binds it to DetectedIssueSeverityOptions; required on create
codeJSONField, nullableCoded detail of the issue. No current spec reads or writes it — storage only
encounterFK → Encounter, on_delete=PROTECTThe encounter the issue belongs to. Required on create as a UUID; the server resolves it
patientFK → Patient, on_delete=PROTECT, not nullSubject of the issue. Taken from the URL, never from the body (__exclude__)

Enums​

Every enum is a str, Enum in care/emr/resources/detected_issue/constants.py. The value stored and serialized is the string in the table.

DetectedIssueStatusOptions values​

ValueMeaning
draftIssue is not yet published
activeIssue is open
inactiveIssue no longer applies
not_doneIssue was not acted on
entered_in_errorIssue was recorded by mistake

DetectedIssueSeverityOptions values​

Value
high
moderate
low

DetectedIssueMitigationStatusOptions values​

ValueMeaning
activeMitigation applies. Model default
entered_in_errorMitigation was recorded by mistake

DetectedIssueCategoryOptions values​

The category codes come from the FHIR DetectedIssue category value set (http://hl7.org/fhir/ValueSet/detectedissue-category), with codes from http://terminology.hl7.org/CodeSystem/v3-ActCode. The abstract grouping codes of v3-ActCode (the notSelectable codes with a _ prefix) are not included.

GroupValues
Product and interaction alertsFOOD, TPROD, DRG, NHP, NONRX, OBSA
Age alertsAGE, ADALRT, DOSEHINDA, DOSELINDA, GEALRT, PEALRT
Condition alertsCOND, HGHT, LACT, PREG, WGHT
Reaction and allergy alertsCREACT, GEN, GEND, LAB, REACT, ALGY, INT, RREACT, RALG, RAR, RINT
Compliance alertsPREVINEF, COMPLY, DUPTHPY, DUPTHPCLS, DUPTHPGEN, ABUSE, FRAUD, PLYDOC, PLYPHRM
Dose alertsDACT, DOSE, DOSECOND, DOSEDUR, DOSEDURH, DOSEDURHIND, DOSEDURL, DOSEDURLIND, DOSEH, DOSEHIND, DOSEHINDSA, DOSEHINDW, DOSEIVL, DOSEIVLIND, DOSEL, DOSELIND, DOSELINDSA, DOSELINDW, MDOSE
Timing alertsTIME, ALRTENDLATE, ALRTSTRTLATE, ENDLATE, STRTLATE, TIMING, INTERVAL, MINFREQ, HELD, TOOLATE, TOOSOON
Fulfilment alertsALLDONE, FULFIL, NOTACTN, NOTEQUIV, NOTEQUIVGEN, NOTEQUIVTHER
OtherHISTORIC, PATPREF, PATPREFALT, CAREGAP, CODINGGAP

DetectedIssueResourceType values​

The record types an issue can point at. Each value maps to a handler in care/emr/utils/resource_reference.py, which does the read authorization and the rendering.

Value
diagnostic_report
observation
condition
allergy_intolerance
service_request
specimen
questionnaire_response
file_upload
immunization
medication_request

DetectedIssueMitigation​

Records what staff did about an issue. A mitigation is append-only: the note cannot change after creation, and the only update allowed sets the status to entered_in_error.

FieldTypeNotes
detected_issueFK → DetectedIssue (CASCADE)related_name="mitigation". Set from the URL
noteTextFieldRequired. Stripped of outer whitespace and must not be empty
statusCharField(25), default "active"One of DetectedIssueMitigationStatusOptions
entered_in_error_byFK → users.User (PROTECT), nullableSet by the server when the status changes to entered_in_error
entered_in_error_atDateTimeField, nullableSet by the server at the same time

DetectedIssueResource​

Links an issue to the clinical record that caused it.

FieldTypeNotes
detected_issueFK → DetectedIssue (CASCADE)related_name="resources". Set from the URL
resource_typeCharField(100)One of DetectedIssueResourceType
resource_idUUIDFieldThe external_id of the linked record
metadataJSONField, default {}Free-form client metadata about the link

A partial UniqueConstraint named unique_detected_issue_resource covers resource_type, resource_id, and detected_issue where deleted=False. A duplicate link returns a validation error ("Resource is already attached to this detected issue"). The resource columns lead the index, so the same index also serves the reverse lookup that finds issues for a set of records.

Relationships​

DetectedIssue.patient → FK Patient (PROTECT, from the URL)
DetectedIssue.encounter → FK Encounter (PROTECT, required on create)
DetectedIssueMitigation.detected_issue → FK DetectedIssue (CASCADE, related_name="mitigation")
DetectedIssueResource.detected_issue → FK DetectedIssue (CASCADE, related_name="resources")

Resource specs (API schema)​

Every spec extends EMRResource (base.py) unless the table says otherwise. DetectedIssueBaseSpec sets __model__ = DetectedIssue and __exclude__ = ["patient", "encounter", "resources"], so none of the three is read from the generic field loop.

Spec classRoleExposes / behaviour
DetectedIssueBaseSpecshared baseid, status, category, severity
DetectedIssueCreateSpecwrite · createBase + encounter (UUID4, required) and resources (list[DetectedIssueResourceCreateSpec], default []). Resolves the encounter and holds the resource list for the viewset
DetectedIssueUpdateSpecwrite · updatestatus, category, severity, each MISSING by default. A field left out keeps its stored value. encounter, patient, and resources cannot change
DetectedIssueListSpecread · listBase + patient (UUID4), encounter (UUID4), created_date, modified_date, created_by?, updated_by?
DetectedIssueRetrieveSpecread · detailList spec + resources (DetectedIssueResourceReadSpec[]) and mitigation (DetectedIssueMitigationReadSpec[])
DetectedIssueResourceCreateSpecwrite · createresource_type, resource_id (UUID4), metadata (default {})
DetectedIssueResourceReadSpecreadCreate spec + id, detected_issue (UUID4), created_date, modified_date, created_by?, updated_by?
DetectedIssueMitigationCreateSpecwrite · createnote only (extra="forbid", whitespace stripped, min_length=1)
DetectedIssueMitigationUpdateSpecwrite · updatePlain BaseModel, extra="forbid". status is a Literal["entered_in_error"] — the only allowed update
DetectedIssueMitigationReadSpecreadid, detected_issue, note, status, entered_in_error_by?, entered_in_error_at?, audit fields
DetectedIssueResolvedResourceSpecread (action)resource_type and the rendered resource dict, returned by the resolve action
DetectedIssueResourceLookupRequestwrite (action body)encounter (UUID4), resource_type, resource_ids (1–100 UUID4s). extra="forbid"
DetectedIssueResourceLookupResponseread (action)results: a list of DetectedIssueRetrieveSpec

Validation & server-maintained behaviour​

  • patient comes from the URL. On create the viewset checks that the supplied encounter belongs to that patient, else "Patient does not match the encounter patient".
  • resources sent inside the create body are saved in the same transaction as the issue, through the same validation as the standalone resource endpoint.
  • A linked record must belong to the issue's patient, and the caller must be able to read it. For a file_upload, the file must be uploaded and not archived, and its owning record (patient, encounter, diagnostic_report, service_request, referral, or consent) must resolve to the same patient.
  • Updating a mitigation takes a row lock and only writes when the status really changes. It then stamps entered_in_error_by, entered_in_error_at, and updated_by.
  • The list endpoint requires an encounter query parameter — detected issues are always listed per encounter. status, category, and severity are the supported filters, and created_date / modified_date are the ordering fields.

Permissions​

Detected issues are authorized at the encounter level. Both checks run through the encounter's facility organizations (and the organizations of its current location).

PermissionAllowsDefault roles
can_read_detected_issueRead issues, their resources, and their mitigationsFacility Admin, Administrator, Admin, Staff, Doctor, Nurse, Volunteer, Pharmacist
can_write_detected_issueCreate and update issues, with their resources and mitigationsFacility Admin, Admin, Doctor, Nurse

Write access is also refused when the encounter is already in a completed state.

API integration notes​

  • Endpoints are nested under the patient: /patient/{patient_external_id}/detected_issue/, with resources/ and mitigations/ nested under an issue.
  • POST .../detected_issue/by_resources/ returns the issues of one encounter that reference a given set of records. Send encounter, resource_type, and 1–100 resource_ids.
  • GET .../resources/{external_id}/resolve/ returns the linked record itself, rendered with that resource type's read spec, after a fresh read-permission check.
  • Create and update return the full DetectedIssueRetrieveSpec, so the resources and mitigations come back in the same response.
  • Do not send patient, external_id, audit fields, or deleted — the server owns them.