Skip to main content
Version: 3.0

Detected Issue

A DetectedIssue records a clinical risk found against an encounter — a drug interaction, a dose problem, an allergy conflict, or a care gap. It maps to the FHIR DetectedIssue resource. Each issue points at the clinical records that caused it, and carries the mitigations that clinicians record against it.

Source:

A DetectedIssue lives across two layers:

  • The Django model (care/emr/models/detected_issue.py) is storage. status, category, and severity are plain CharFields, and code is an opaque JSONField.
  • The Pydantic resource specs (care/emr/resources/detected_issue/spec.py) are the API. They define the enums, the read and write schemas, and the rules that bind an issue to its encounter, its attached resources, and its mitigations.

Models​

ModelPurpose
DetectedIssueA clinical risk detected for a patient within an encounter
DetectedIssueMitigationA recorded action or note that answers an issue
DetectedIssueResourceA link from an issue to a clinical record that caused it

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

DetectedIssue fields​

FieldModel typeSpec typeNotes
statusCharField(25)DetectedIssueStatusOptionsLifecycle state. Required on create. See status values
categoryCharField(25)DetectedIssueCategoryOptionsThe kind of risk, as a FHIR v3 ActCode. Required on create. See category values
severityCharField(25)DetectedIssueSeverityOptionsHow serious the issue is. Required on create. See severity values
codeJSONField, nullable(not in any spec)Exists on the model, but no current spec reads or writes it — storage only
encounterFK → emr.Encounter (PROTECT)UUID4 (create only)Encounter the issue belongs to. Required on create, then immutable. An encounter with a detected issue cannot be deleted
patientFK → emr.Patient (PROTECT, not null)(derived)Subject of the issue. Set server-side from the URL, never read from the client

The spec base sets __exclude__ = ["patient", "encounter", "resources"], so the client never maps those fields directly.

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
draftThe issue is being drafted
activeThe issue is open and needs attention
inactiveThe issue no longer applies
not_doneNo action was taken on the issue
entered_in_errorThe issue was recorded in error

DetectedIssueSeverityOptions values​

Value
high
moderate
low

DetectedIssueMitigationStatusOptions values​

ValueMeaning
activeThe mitigation stands. Model default
entered_in_errorThe mitigation was recorded in error

DetectedIssueCategoryOptions values​

category holds a code from the FHIR detectedissue-category value set, system http://terminology.hl7.org/CodeSystem/v3-ActCode. The abstract grouping codes of that code system (the notSelectable ones, prefixed with _) are left out.

GroupValues
Product & interaction alertsFOOD, TPROD, DRG, NHP, NONRX
Patient-context alertsOBSA, AGE, ADALRT, DOSEHINDA, DOSELINDA, GEALRT, PEALRT, COND, HGHT, LACT, PREG, WGHT, GEN, GEND, LAB
Reaction, allergy & intolerance alertsCREACT, REACT, ALGY, INT, RREACT, RALG, RAR, RINT, PREVINEF
Compliance & duplicate-therapy alertsCOMPLY, DUPTHPY, DUPTHPCLS, DUPTHPGEN, ABUSE, FRAUD, PLYDOC, PLYPHRM
Dosage 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 & equivalence alertsALLDONE, FULFIL, NOTACTN, NOTEQUIV, NOTEQUIVGEN, NOTEQUIVTHER
Record & preference alertsHISTORIC, PATPREF, PATPREFALT, CAREGAP, CODINGGAP

DetectedIssueResourceType values​

The kinds of record an issue can point at. Each value has a handler in the resource-reference registry that supplies the model, the read spec, and the read-authorization rule.

ValueModelRead specRead check
diagnostic_reportDiagnosticReportDiagnosticReportSpecBasecan_read_diagnostic_report on the linked service request; a report with no service request is never readable
observationObservationObservationReadSpecClinical-data access on the patient, or on the encounter
conditionConditionConditionReadSpecClinical-data access on the patient, or on the encounter
allergy_intoleranceAllergyIntoleranceAllergyIntoleranceReadSpecClinical-data access on the patient, or on the encounter
service_requestServiceRequestBaseServiceRequestSpeccan_read_service_request
specimenSpecimenBaseSpecimenSpeccan_read_specimen on the linked service request
questionnaire_responseQuestionnaireResponseQuestionnaireResponseReadSpecClinical-data access; a response with no encounter falls back to can_view_patient_questionnaire_responses
file_uploadFileUploadFileUploadRetrieveSpecfile_authorizer on the file type and its associated record
immunizationImmunizationImmunizationListSpecClinical-data access on the patient, or on the encounter
medication_requestMedicationRequestMedicationRequestReadSpecClinical-data access, or can_view_as_pharmacist on the encounter facility
DetectedIssue
encounter → FK Encounter (PROTECT)
patient → FK Patient (PROTECT)
mitigation ← DetectedIssueMitigation (CASCADE, related_name "mitigation")
resources ← DetectedIssueResource (CASCADE, related_name "resources")

DetectedIssueMitigation​

The action a clinician took, or the reason the issue was accepted.

FieldModel typeSpec typeNotes
detected_issueFK DetectedIssue (CASCADE)UUID4 (read)Set server-side from the URL
noteTextFieldstrRequired. Whitespace is stripped and the value must not be empty
statusCharField(25), default "active"DetectedIssueMitigationStatusOptions (read)Write accepts only entered_in_error. See below
entered_in_error_byFK users.User (PROTECT), nullabledict | None (read)Set server-side when the status moves to entered_in_error. Read returns a cached UserSpec dict
entered_in_error_atDateTimeField, nullabledatetime | None (read)Set server-side at the same time

DetectedIssueResource​

A link from an issue to one clinical record.

FieldModel typeSpec typeNotes
detected_issueFK DetectedIssue (CASCADE)UUID4 (read)Set server-side from the URL
resource_typeCharField(100)DetectedIssueResourceTypeThe kind of record. Required
resource_idUUIDFieldUUID4The external_id of the record. Required
metadataJSONField, default dictdictFree-form payload about the link. Defaults to {}

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

Resource specs (API schema)​

Every spec extends EMRResource (base.py), except the plain BaseModel request and response bodies.

SpecRoleExposes / behaviour
DetectedIssueBaseSpecsharedid, status, category, severity. __exclude__ = ["patient", "encounter", "resources"]
DetectedIssueCreateSpecwrite · createAdds encounter: UUID4 and resources: list[DetectedIssueResourceCreateSpec] (default []). On create, resolves the encounter and stashes the resource list for the viewset to save
DetectedIssueUpdateSpecwrite · updatestatus, category, severity, each defaulting to the MISSING sentinel, so an omitted field is left unchanged. Does not accept encounter or resources
DetectedIssueListSpecread · listBase fields plus patient, encounter (both external_id), created_date, modified_date, created_by, updated_by
DetectedIssueRetrieveSpecread · detailExtends the list spec with resources (DetectedIssueResourceReadSpec[]) and mitigation (DetectedIssueMitigationReadSpec[])
DetectedIssueMitigationCreateSpecwrite · createnote only (stripped, min length 1). extra="forbid"
DetectedIssueMitigationUpdateSpecwrite · updatestatus: Literal["entered_in_error"] only. extra="forbid"
DetectedIssueMitigationReadSpecreadid, detected_issue, note, status, entered_in_error_by, entered_in_error_at, audit fields
DetectedIssueResourceCreateSpecwrite · createresource_type, resource_id, metadata
DetectedIssueResourceReadSpecreadExtends the create spec with id, detected_issue, and audit fields
DetectedIssueResolvedResourceSpecread (action body){ resource_type, resource } — the response of the resolve action
DetectedIssueResourceLookupRequestwrite (action body)encounter, resource_type, resource_ids (1–100 UUIDs). extra="forbid"
DetectedIssueResourceLookupResponseread (action body){ results: DetectedIssueRetrieveSpec[] }

Server-maintained behaviour​

  • Patient comes from the URL. Every endpoint is nested under a patient. perform_create sets patient from the URL, and the create call is rejected when the encounter belongs to a different patient.
  • Create is atomic. The issue and each entry of its resources list are saved in one transaction, through the same validation as the standalone resource endpoint.
  • List is per encounter. The list endpoint needs an encounter query parameter. Without it, the request fails with "Detected issues are listed per encounter". Results are also scoped to the patient in the URL.
  • Filters. status accepts several values at once (MultiSelectFilter); category and severity each accept one value. Results can be ordered by created_date or modified_date. The resource endpoint filters on resource_type.
  • Attached records are checked twice. On attach, the record must resolve through the registry, must belong to the issue's patient, and the caller must be able to read it. A file must also be upload-complete, not archived, and associated with the same patient, encounter, diagnostic report, service request, referral, or consent.

Mitigations are append-only​

A mitigation is created with a note and nothing else. The only update allowed is to set status to entered_in_error. That update takes a row lock, and when the status changes, the server also records entered_in_error_by, entered_in_error_at, and updated_by. A mitigation is never deleted and its note is never edited.

Authorization​

Detected issues are encounter-level only. Every check runs against the facility organizations of the issue's encounter, through EncounterAccess.check_permission_in_encounter.

PermissionGrantsDefault roles
can_read_detected_issueRead the detected issues of an encounterFacility Admin, Administrator, Admin, Staff, Doctor, Nurse, Volunteer, Pharmacist
can_write_detected_issueCreate and update detected issues of an encounter, with their resources and mitigationsFacility Admin, Admin, Doctor, Nurse

Write access is also refused when the encounter is in a completed state, so a closed encounter cannot gain new issues, resources, or mitigations.

API integration notes​

  • Endpoints are nested under a patient: the issue list and detail, then resources and mitigation under an issue.
  • POST .../detected_issue/by_resources/ takes an encounter, one resource_type, and up to 100 resource_ids, and returns the full issues that reference any of them. Use it to show risk flags beside a list of records.
  • GET .../resources/{id}/resolve/ returns the attached record itself, serialized with that resource type's read spec, after it re-checks read access.
  • patient is always server-derived. encounter is set once on create and cannot be changed afterwards.
  • code is on the model but outside the API surface. Use category for the kind of risk.