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:
- 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 - Resource reference registry:
care/emr/utils/resource_reference.py - Permissions:
care/security/permissions/detected_issue.py
A DetectedIssue lives across two layers:
- The Django model (
care/emr/models/detected_issue.py) is storage.status,category, andseverityare plainCharFields, andcodeis an opaqueJSONField. - 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
| Model | Purpose |
|---|---|
DetectedIssue | A clinical risk detected for a patient within an encounter |
DetectedIssueMitigation | A recorded action or note that answers an issue |
DetectedIssueResource | A 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
| Field | Model type | Spec type | Notes |
|---|---|---|---|
status | CharField(25) | DetectedIssueStatusOptions | Lifecycle state. Required on create. See status values |
category | CharField(25) | DetectedIssueCategoryOptions | The kind of risk, as a FHIR v3 ActCode. Required on create. See category values |
severity | CharField(25) | DetectedIssueSeverityOptions | How serious the issue is. Required on create. See severity values |
code | JSONField, nullable | (not in any spec) | Exists on the model, but no current spec reads or writes it — storage only |
encounter | FK → 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 |
patient | FK → 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
| Value | Meaning |
|---|---|
draft | The issue is being drafted |
active | The issue is open and needs attention |
inactive | The issue no longer applies |
not_done | No action was taken on the issue |
entered_in_error | The issue was recorded in error |
DetectedIssueSeverityOptions values
| Value |
|---|
high |
moderate |
low |
DetectedIssueMitigationStatusOptions values
| Value | Meaning |
|---|---|
active | The mitigation stands. Model default |
entered_in_error | The 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.
| Group | Values |
|---|---|
| Product & interaction alerts | FOOD, TPROD, DRG, NHP, NONRX |
| Patient-context alerts | OBSA, AGE, ADALRT, DOSEHINDA, DOSELINDA, GEALRT, PEALRT, COND, HGHT, LACT, PREG, WGHT, GEN, GEND, LAB |
| Reaction, allergy & intolerance alerts | CREACT, REACT, ALGY, INT, RREACT, RALG, RAR, RINT, PREVINEF |
| Compliance & duplicate-therapy alerts | COMPLY, DUPTHPY, DUPTHPCLS, DUPTHPGEN, ABUSE, FRAUD, PLYDOC, PLYPHRM |
| Dosage 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 & equivalence alerts | ALLDONE, FULFIL, NOTACTN, NOTEQUIV, NOTEQUIVGEN, NOTEQUIVTHER |
| Record & preference alerts | HISTORIC, 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.
| Value | Model | Read spec | Read check |
|---|---|---|---|
diagnostic_report | DiagnosticReport | DiagnosticReportSpecBase | can_read_diagnostic_report on the linked service request; a report with no service request is never readable |
observation | Observation | ObservationReadSpec | Clinical-data access on the patient, or on the encounter |
condition | Condition | ConditionReadSpec | Clinical-data access on the patient, or on the encounter |
allergy_intolerance | AllergyIntolerance | AllergyIntoleranceReadSpec | Clinical-data access on the patient, or on the encounter |
service_request | ServiceRequest | BaseServiceRequestSpec | can_read_service_request |
specimen | Specimen | BaseSpecimenSpec | can_read_specimen on the linked service request |
questionnaire_response | QuestionnaireResponse | QuestionnaireResponseReadSpec | Clinical-data access; a response with no encounter falls back to can_view_patient_questionnaire_responses |
file_upload | FileUpload | FileUploadRetrieveSpec | file_authorizer on the file type and its associated record |
immunization | Immunization | ImmunizationListSpec | Clinical-data access on the patient, or on the encounter |
medication_request | MedicationRequest | MedicationRequestReadSpec | Clinical-data access, or can_view_as_pharmacist on the encounter facility |
Related models
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.
| Field | Model type | Spec type | Notes |
|---|---|---|---|
detected_issue | FK DetectedIssue (CASCADE) | UUID4 (read) | Set server-side from the URL |
note | TextField | str | Required. Whitespace is stripped and the value must not be empty |
status | CharField(25), default "active" | DetectedIssueMitigationStatusOptions (read) | Write accepts only entered_in_error. See below |
entered_in_error_by | FK users.User (PROTECT), nullable | dict | None (read) | Set server-side when the status moves to entered_in_error. Read returns a cached UserSpec dict |
entered_in_error_at | DateTimeField, nullable | datetime | None (read) | Set server-side at the same time |
DetectedIssueResource
A link from an issue to one clinical record.
| Field | Model type | Spec type | Notes |
|---|---|---|---|
detected_issue | FK DetectedIssue (CASCADE) | UUID4 (read) | Set server-side from the URL |
resource_type | CharField(100) | DetectedIssueResourceType | The kind of record. Required |
resource_id | UUIDField | UUID4 | The external_id of the record. Required |
metadata | JSONField, default dict | dict | Free-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.
| Spec | Role | Exposes / behaviour |
|---|---|---|
DetectedIssueBaseSpec | shared | id, status, category, severity. __exclude__ = ["patient", "encounter", "resources"] |
DetectedIssueCreateSpec | write · create | Adds encounter: UUID4 and resources: list[DetectedIssueResourceCreateSpec] (default []). On create, resolves the encounter and stashes the resource list for the viewset to save |
DetectedIssueUpdateSpec | write · update | status, category, severity, each defaulting to the MISSING sentinel, so an omitted field is left unchanged. Does not accept encounter or resources |
DetectedIssueListSpec | read · list | Base fields plus patient, encounter (both external_id), created_date, modified_date, created_by, updated_by |
DetectedIssueRetrieveSpec | read · detail | Extends the list spec with resources (DetectedIssueResourceReadSpec[]) and mitigation (DetectedIssueMitigationReadSpec[]) |
DetectedIssueMitigationCreateSpec | write · create | note only (stripped, min length 1). extra="forbid" |
DetectedIssueMitigationUpdateSpec | write · update | status: Literal["entered_in_error"] only. extra="forbid" |
DetectedIssueMitigationReadSpec | read | id, detected_issue, note, status, entered_in_error_by, entered_in_error_at, audit fields |
DetectedIssueResourceCreateSpec | write · create | resource_type, resource_id, metadata |
DetectedIssueResourceReadSpec | read | Extends the create spec with id, detected_issue, and audit fields |
DetectedIssueResolvedResourceSpec | read (action body) | { resource_type, resource } — the response of the resolve action |
DetectedIssueResourceLookupRequest | write (action body) | encounter, resource_type, resource_ids (1–100 UUIDs). extra="forbid" |
DetectedIssueResourceLookupResponse | read (action body) | { results: DetectedIssueRetrieveSpec[] } |
Server-maintained behaviour
- Patient comes from the URL. Every endpoint is nested under a patient.
perform_createsetspatientfrom 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
resourceslist are saved in one transaction, through the same validation as the standalone resource endpoint. - List is per encounter. The list endpoint needs an
encounterquery parameter. Without it, the request fails with "Detected issues are listed per encounter". Results are also scoped to the patient in the URL. - Filters.
statusaccepts several values at once (MultiSelectFilter);categoryandseverityeach accept one value. Results can be ordered bycreated_dateormodified_date. The resource endpoint filters onresource_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.
| Permission | Grants | Default roles |
|---|---|---|
can_read_detected_issue | Read the detected issues of an encounter | Facility Admin, Administrator, Admin, Staff, Doctor, Nurse, Volunteer, Pharmacist |
can_write_detected_issue | Create and update detected issues of an encounter, with their resources and mitigations | Facility 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
resourcesandmitigationunder an issue. POST .../detected_issue/by_resources/takes an encounter, oneresource_type, and up to 100resource_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.patientis always server-derived.encounteris set once on create and cannot be changed afterwards.codeis on the model but outside the API surface. Usecategoryfor the kind of risk.
Related
- Reference: Encounter
- Reference: Patient
- Reference: Condition
- Reference: Allergy Intolerance
- Reference: Medication Request
- Base: Base model
- Source: model · spec · constants · viewsets