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:
- Model:
care/emr/models/detected_issue.py - Resource spec:
care/emr/resources/detected_issue/spec.py - Constants:
care/emr/resources/detected_issue/constants.py - Viewsets:
care/emr/api/viewsets/detected_issue.py - Permissions:
care/security/permissions/detected_issue.py
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
| Model | Purpose |
|---|---|
DetectedIssue | A clinical risk detected for a patient during an encounter |
DetectedIssueMitigation | A note that records the action taken against an issue |
DetectedIssueResource | A 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
| Field | Type | Notes |
|---|---|---|
status | CharField(25) | Lifecycle state. Spec binds it to DetectedIssueStatusOptions; required on create |
category | CharField(25) | Kind of risk. Spec binds it to DetectedIssueCategoryOptions; required on create |
severity | CharField(25) | How serious the risk is. Spec binds it to DetectedIssueSeverityOptions; required on create |
code | JSONField, nullable | Coded detail of the issue. No current spec reads or writes it — storage only |
encounter | FK → Encounter, on_delete=PROTECT | The encounter the issue belongs to. Required on create as a UUID; the server resolves it |
patient | FK → Patient, on_delete=PROTECT, not null | Subject 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
| Value | Meaning |
|---|---|
draft | Issue is not yet published |
active | Issue is open |
inactive | Issue no longer applies |
not_done | Issue was not acted on |
entered_in_error | Issue was recorded by mistake |
DetectedIssueSeverityOptions values
| Value |
|---|
high |
moderate |
low |
DetectedIssueMitigationStatusOptions values
| Value | Meaning |
|---|---|
active | Mitigation applies. Model default |
entered_in_error | Mitigation 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.
| Group | Values |
|---|---|
| Product and interaction alerts | FOOD, TPROD, DRG, NHP, NONRX, OBSA |
| Age alerts | AGE, ADALRT, DOSEHINDA, DOSELINDA, GEALRT, PEALRT |
| Condition alerts | COND, HGHT, LACT, PREG, WGHT |
| Reaction and allergy alerts | CREACT, GEN, GEND, LAB, REACT, ALGY, INT, RREACT, RALG, RAR, RINT |
| Compliance alerts | PREVINEF, COMPLY, DUPTHPY, DUPTHPCLS, DUPTHPGEN, ABUSE, FRAUD, PLYDOC, PLYPHRM |
| Dose alerts | DACT, DOSE, DOSECOND, DOSEDUR, DOSEDURH, DOSEDURHIND, DOSEDURL, DOSEDURLIND, DOSEH, DOSEHIND, DOSEHINDSA, DOSEHINDW, DOSEIVL, DOSEIVLIND, DOSEL, DOSELIND, DOSELINDSA, DOSELINDW, MDOSE |
| Timing alerts | TIME, ALRTENDLATE, ALRTSTRTLATE, ENDLATE, STRTLATE, TIMING, INTERVAL, MINFREQ, HELD, TOOLATE, TOOSOON |
| Fulfilment alerts | ALLDONE, FULFIL, NOTACTN, NOTEQUIV, NOTEQUIVGEN, NOTEQUIVTHER |
| Other | HISTORIC, 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 |
Related models
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.
| Field | Type | Notes |
|---|---|---|
detected_issue | FK → DetectedIssue (CASCADE) | related_name="mitigation". Set from the URL |
note | TextField | Required. Stripped of outer whitespace and must not be empty |
status | CharField(25), default "active" | One of DetectedIssueMitigationStatusOptions |
entered_in_error_by | FK → users.User (PROTECT), nullable | Set by the server when the status changes to entered_in_error |
entered_in_error_at | DateTimeField, nullable | Set by the server at the same time |
DetectedIssueResource
Links an issue to the clinical record that caused it.
| Field | Type | Notes |
|---|---|---|
detected_issue | FK → DetectedIssue (CASCADE) | related_name="resources". Set from the URL |
resource_type | CharField(100) | One of DetectedIssueResourceType |
resource_id | UUIDField | The external_id of the linked record |
metadata | JSONField, 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 class | Role | Exposes / behaviour |
|---|---|---|
DetectedIssueBaseSpec | shared base | id, status, category, severity |
DetectedIssueCreateSpec | write · create | Base + encounter (UUID4, required) and resources (list[DetectedIssueResourceCreateSpec], default []). Resolves the encounter and holds the resource list for the viewset |
DetectedIssueUpdateSpec | write · update | status, category, severity, each MISSING by default. A field left out keeps its stored value. encounter, patient, and resources cannot change |
DetectedIssueListSpec | read · list | Base + patient (UUID4), encounter (UUID4), created_date, modified_date, created_by?, updated_by? |
DetectedIssueRetrieveSpec | read · detail | List spec + resources (DetectedIssueResourceReadSpec[]) and mitigation (DetectedIssueMitigationReadSpec[]) |
DetectedIssueResourceCreateSpec | write · create | resource_type, resource_id (UUID4), metadata (default {}) |
DetectedIssueResourceReadSpec | read | Create spec + id, detected_issue (UUID4), created_date, modified_date, created_by?, updated_by? |
DetectedIssueMitigationCreateSpec | write · create | note only (extra="forbid", whitespace stripped, min_length=1) |
DetectedIssueMitigationUpdateSpec | write · update | Plain BaseModel, extra="forbid". status is a Literal["entered_in_error"] — the only allowed update |
DetectedIssueMitigationReadSpec | read | id, detected_issue, note, status, entered_in_error_by?, entered_in_error_at?, audit fields |
DetectedIssueResolvedResourceSpec | read (action) | resource_type and the rendered resource dict, returned by the resolve action |
DetectedIssueResourceLookupRequest | write (action body) | encounter (UUID4), resource_type, resource_ids (1–100 UUID4s). extra="forbid" |
DetectedIssueResourceLookupResponse | read (action) | results: a list of DetectedIssueRetrieveSpec |
Validation & server-maintained behaviour
patientcomes from the URL. On create the viewset checks that the suppliedencounterbelongs to that patient, else "Patient does not match the encounter patient".resourcessent 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, orconsent) 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, andupdated_by. - The list endpoint requires an
encounterquery parameter — detected issues are always listed per encounter.status,category, andseverityare the supported filters, andcreated_date/modified_dateare 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).
| Permission | Allows | Default roles |
|---|---|---|
can_read_detected_issue | Read issues, their resources, and their mitigations | Facility Admin, Administrator, Admin, Staff, Doctor, Nurse, Volunteer, Pharmacist |
can_write_detected_issue | Create and update issues, with their resources and mitigations | Facility 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/, withresources/andmitigations/nested under an issue. POST .../detected_issue/by_resources/returns the issues of one encounter that reference a given set of records. Sendencounter,resource_type, and 1–100resource_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, ordeleted— the server owns them.
Related
- Reference: Patient
- Reference: Encounter
- Reference: Condition
- Reference: Allergy intolerance
- Reference: Medication request
- Reference: Base model
- Source: detected_issue.py · spec.py · constants.py