Skip to main content
Version: 3.1

Condition

Technical reference for the Condition module in Care EMR. For what a condition is, see the Condition concept.

A Condition row records one symptom or one diagnosis for a patient. Care serves the same table through two APIs under the patient: the symptom API and the diagnosis API.

Source:

The Django model stores the data. Its code, body_site, onset and abatement fields are JSON fields.

The Pydantic resource specs define the shape of code, onset and abatement. The specs also define the enums, the value set bindings, the validation and the read and write schemas.

Models​

ModelPurpose
ConditionOne symptom or one diagnosis recorded for a patient

Condition extends EMRBaseModel. That reference page describes the inherited fields. The "Inherited fields" table below lists the ones that the condition APIs use.

Condition fields​

Each table gives the storage type from the Django model and the API shape from the specs.

Status and classification​

FieldStorage typeAPI shapeNotes
clinical_statusCharField(100), nullableClinicalStatusChoices on write, str on readOptional on create and update
verification_statusCharField(100), nullableVerificationStatusChoices on write, str on readRequired on create and update
categoryCharField(100), nullableCategoryChoices on create, str on readRequired on create by both APIs. The symptom API then saves problem_list_item, whatever the request sends. The update specs do not take it
severityCharField(100), nullableSeverityChoices on write, str on readOptional on create and update

Coded concepts​

FieldStorage typeAPI shapeNotes
codeJSONField (default=dict), not nullWrite: ValueSetBoundCoding, bound to system-condition-code (diagnosis API) or system-symptom-code (symptom API). Read: CodingRequired on create and update. The name list filter searches its display
body_siteJSONField (default=dict), not nullNot in ConditionReadSpec or the update specsThe read and update schemas do not return or change it

Timing​

FieldStorage typeAPI shapeNotes
onsetJSONField (default=dict)ConditionOnSetSpecAccepted on create and update, returned on read. Shape below
abatementJSONField (default=dict)ConditionAbatementSpecAccepted on create and update, returned on read. Shape below
recorded_dateDateTimeField, nullableNot in ConditionReadSpec or the update specsThe read and update schemas do not return or change it

Context and note​

FieldStorage typeAPI shapeNotes
patientFK → emr.Patient (CASCADE), requiredNot in ConditionReadSpecSet on create from the encounter's patient. The client does not choose it
encounterFK → emr.Encounter (CASCADE), nullableUUID4: required on create, returned on read, not in the update specsMust exist, else "Encounter not found". Must belong to the patient in the URL, else "Patient external ID mismatch with encounter's patient"
noteTextField, nullablestr | NoneOptional

Inherited fields​

FieldAPI shapeNotes
external_idReturned as id (UUID4) in the read schemaAn upsert datapoint with this id updates the record
created_datedatetime, in the read schemaA list ordering field
modified_datedatetime, in the read schemaA list ordering field
created_bydict | None, in the read schemaReturned on read
updated_bydict | None, in the read schemaReturned on read
deletedNot in the read schemaDELETE sets it to True (soft delete)

Enum values​

Every enum is a str, Enum in care/emr/resources/condition/spec.py. The model stores the string value, and the read schema returns it as a str.

ClinicalStatusChoices values​

Value
active
recurrence
relapse
inactive
remission
resolved
unknown

Care's frontend form offers six of these values. It does not offer unknown.

VerificationStatusChoices values​

Value
unconfirmed
provisional
differential
confirmed
refuted
entered_in_error

Care's frontend form offers entered_in_error only on a record that is already saved. To retract a record, the frontend sets verification_status to entered_in_error. It never sends DELETE.

CategoryChoices values​

ValueSet by
problem_list_itemThe symptom API, on every create
encounter_diagnosisCare's Diagnosis form, on every new diagnosis
chronic_conditionNo screen in Care's frontend. The frontend only reads this category

Both create specs require category. The symptom API then overwrites it with problem_list_item, whatever the request sends.

SeverityChoices values​

Value
mild
moderate
severe

Nested JSON shapes​

onset (ConditionOnSetSpec)​

KeyTypeDefaultMeaning and validation
onset_datetimedatetime | NoneNoneDate and time of onset. Cannot be in the future: "Onset date cannot be in the future"
onset_ageint | NoneNoneAge at onset
onset_stringstr | NoneNoneFree-text description of the onset
notestr | NoneNoneNote about the onset

abatement (ConditionAbatementSpec)​

ConditionAbatementSpec extends EMRResource.

KeyTypeDefaultMeaning and validation
abatement_datetimedatetime | NoneNoneDate and time of abatement. No future-date check
abatement_ageint | NoneNoneAge at abatement
abatement_stringstr | NoneNoneFree-text description of the abatement
notestr | NoneNoneNote about the abatement

code​

On write, code is a ValueSetBoundCoding. Care checks the coding against the bound value set (see "Bound value sets").

On read, ConditionReadSpec types code as a plain Coding, not as a bound coding. For the Coding keys, see common/coding.py.

Condition has two foreign keys to clinical records.

patient → FK emr.Patient (CASCADE, required)
encounter → FK emr.Encounter (CASCADE, nullable; both create specs require it)

Each create and update through either API also writes a questionnaire response for the condition's patient and encounter. See "Methods & save behaviour".

Resource specs (API schema)​

The diagnosis API writes with the Condition* specs, which bind code to the Condition value set. The symptom API writes with the Symptom* specs, which bind code to the Symptom value set.

Both APIs read with ConditionReadSpec.

Spec classRoleFields and behaviour
ConditionSpecDiagnosis API: create, and upsert datapoints without idRequired: verification_status, code (Condition value set), encounter (UUID4), category. Optional fields include clinical_status, severity, onset, abatement and note. Checks that the encounter exists. On create, sets encounter and takes patient from it
SymptomSpecSymptom API: create, and upsert datapoints without idExtends ConditionSpec and binds code to the Symptom value set. The API then saves category as problem_list_item
ConditionUpdateSpecDiagnosis API: update, and upsert datapoints with idExtends BaseConditionSpec. Required: verification_status, code (Condition value set). Optional: clinical_status, severity, onset, abatement, note. Does not take encounter or category
SymptomUpdateSpecSymptom API: update, and upsert datapoints with idExtends ConditionUpdateSpec and binds code to the Symptom value set
ChronicConditionUpdateSpecNot usedExtends ConditionUpdateSpec and adds encounter (UUID4). No viewset uses it
ConditionReadSpecBoth APIs: readid (the record's external_id), clinical_status, verification_status, category, severity (each str), code (Coding), encounter (UUID4), onset, abatement, created_by, updated_by, note, created_date, modified_date. It has no criticality field
ConditionOnSetSpecNested: shape of onsetonset_datetime, onset_age, onset_string, note
ConditionAbatementSpecNested: shape of abatementabatement_datetime, abatement_age, abatement_string, note

Bound value sets​

SpecsValue setConstantSlugDefault composition
ConditionSpec, ConditionUpdateSpec, ChronicConditionUpdateSpecConditionCARE_CODITION_CODE_VALUESETsystem-condition-codeSNOMED CT concepts is-a 64572001
SymptomSpec, SymptomUpdateSpecSymptomCARE_SYMPTOM_CODE_VALUESETsystem-symptom-codeSNOMED CT concepts that match the constraint < 404684003 MINUS << 64572001

The Symptom constraint takes the descendants of 404684003 that are not 64572001 or a descendant of 64572001. So, by default, no code is in both value sets.

Both value sets have the status active and register as system value sets.

The Symptom value set, and the is-a 64572001 rule of the Condition value set, are new in Care 3.1.

Validation reads the stored value set by slug and takes the first match. If no value set has the slug, the request fails with "Valueset does not exist in care, Resync valuesets".

A code outside the value set fails with "Code does not exist in the valueset". A Condition value set code sent to the symptom API fails this way.

Care's frontend searches the same value sets. The symptom search uses system-symptom-code, and the diagnosis search uses system-condition-code.

Validation​

  • verification_status, code, encounter and category are required on create, by both APIs.
  • verification_status and code are required on update.
  • code must hold a code from the bound value set, on create and on update.
  • The encounter in the request must exist. Otherwise the request fails with "Encounter not found".
  • The condition's encounter must belong to the patient in the URL. Otherwise the request fails with "Patient external ID mismatch with encounter's patient".
  • onset.onset_datetime cannot be in the future: "Onset date cannot be in the future". abatement.abatement_datetime has no such check.
  • The update specs do not take encounter or category.

Server-side behaviour​

  • Create: Care sets encounter from the request and takes patient from that encounter.
  • Symptom create: Care saves category as problem_list_item, whatever the request sends.
  • Read, symptom API: Care returns only the patient's records of category problem_list_item.
  • Read, diagnosis API: Care returns the patient's records of every category, symptoms included.

Methods & save behaviour​

  • SymptomViewSet.perform_create sets category to problem_list_item before the save.
  • Delete is a soft delete. Care sets deleted = True and keeps the row.
  • Each create and update through either API also writes a QuestionnaireResponse for the condition's patient and encounter.
  • The questionnaire response has structured_response_type set to symptom (symptom API) or diagnosis (diagnosis API). Its submit type is CREATE on create and UPDATE on update.
  • Care's frontend shows these questionnaire responses in the encounter's responses, titled "Symptom" or "Diagnosis".
  • patient and encounter use on_delete=CASCADE.

API integration notes​

Endpoints​

Both APIs sit on the patient router. The base paths are /api/v1/patient/{patient_id}/symptom/ and /api/v1/patient/{patient_id}/diagnosis/, where {patient_id} is the patient's external_id.

ActionSymptom APIDiagnosis API
list and retrieveOnly the patient's problem_list_item records, as ConditionReadSpecThe patient's records of every category, as ConditionReadSpec
createSymptomSpec. Requires category, then saves problem_list_itemConditionSpec. Requires category
updateSymptomUpdateSpecConditionUpdateSpec
delete (DELETE)Soft deleteSoft delete
upsert (POST upsert/)A datapoints list, through the specs aboveThe same

Neither list leaves out records entered in error by default.

The diagnosis list also returns symptoms. To list diagnoses only, send category=encounter_diagnosis,chronic_condition, as Care's frontend does.

Upsert​

  • The body has a datapoints list.
  • An empty list fails with "No datapoints provided". More than MAX_DATAPOINTS_PER_UPSERT datapoints (default 100) fail with "Too many datapoints provided".
  • A datapoint with id (the id that the read schema returns) updates that record through the API's update spec. A datapoint without id creates a record through the API's create spec.
  • Each datapoint goes through the create or update authorization check (see "Authorization").
  • Each created or updated datapoint writes its own questionnaire response.
  • The upsert is all-or-nothing. If one datapoint fails, Care saves none of them.
  • Care's Diagnosis form sends only new or changed rows, with the form's encounter on each row, as one upsert.
  • Care's Symptom form sends every row it holds, changed or not, as one upsert.

Filters and ordering​

ParameterBehaviour
encounterAn encounter external_id. Returns only that encounter's records. With it, the read check can also pass through the encounter (see "Authorization")
clinical_status, exclude_clinical_statusOne or more clinical statuses, comma-separated, to include or to leave out
verification_status, exclude_verification_statusOne or more verification statuses, comma-separated, to include or to leave out
severityOne severity
nameRecords whose code.display contains the text
categoryOne or more categories, comma-separated
orderingcreated_date or modified_date. A leading - sorts in descending order

Authorization​

The viewsets check clinical-data permissions for each action, as the table shows.

ActionCare checksPermission (slug)Refusal
list and retrieve, both APIsPatient clinical-data read on the patient in the URL. If that fails and the request has ?encounter=, encounter clinical-data read on that encounter"Can view clinical data about patients" (can_view_clinical_data), through a role on the patient. Or "Can Read encounter related clinical data" (can_read_encounter_clinical_data), in the encounter"Permission denied to user"
create, both APIscan_update_encounter_clinical_data on the encounter in the request"Update Encounter related clinical data" (can_write_encounter_clinical_data), in the encounter. The encounter must not be closed"You do not have permission to update encounter"
update, symptom APIThe same check, on the record's encounterAs for createAs for create
update, diagnosis API, category chronic_conditionPatient clinical-data read on the record's patient only"Can view clinical data about patients" (can_view_clinical_data), through a role on the patient"You do not have permission to update chronic condition"
update, diagnosis API, other categoriesThe create check, on the record's encounterAs for createAs for create
delete, both APIsThe create check, on the record's encounterAs for createAs for create
upsert, both APIsThe create or update check, for each datapointAs for create and updateAs for create and update
  • "In the encounter" means a role in one of the encounter's facility organizations or in a facility organization of its current location.
  • The encounter's facility organizations are its departments, the parents of each department, and the facility's root department, "Administration".
  • A user's roles on the patient come from three places. These are the facility organizations of the patient's open encounters and their current locations, the patient's organizations, and a direct patient link.
  • An encounter is closed when its status is completed, cancelled, entered_in_error or discontinued. On a closed encounter, create, update and delete fail with "You do not have permission to update encounter".
  • The exception is a diagnosis of category chronic_condition: its update checks only the patient permission, with no encounter status check.
  • A read with ?encounter= passes when the user holds "Can Read encounter related clinical data" in that encounter. No role on the patient is needed.
  • After an encounter closes, roles held only through that encounter stop counting as roles on the patient.
  • The encounter clinical-data read check has no status condition. So such a user can still read that encounter's conditions with ?encounter=, through "Can Read encounter related clinical data" in the encounter.
  • By default, Doctor, Nurse and Facility Admin hold "Update Encounter related clinical data" and "Can Read encounter related clinical data".
  • By default, Staff, Doctor, Nurse and Facility Admin hold "Can view clinical data about patients".
  • So, by default, Staff can read conditions but cannot create, update or delete them. The exception is the update of a chronic_condition diagnosis, which needs only "Can view clinical data about patients".
  • role.py defines an Admin role with the facility context, but no Admin role can be given in a facility department. Roles sync by name, and the role-organization Admin syncs after the facility Admin and replaces its contexts.
  • So only one Admin role exists, for role organizations only. In a facility, the default roles that can write conditions are Doctor, Nurse and Facility Admin.
  • These role lists are defaults. Roles are editable.
  • The value set search that picks a code needs no other permission. Every signed-in user can read instance-level value sets.
  • Care's frontend does not check "Update Encounter related clinical data" before it shows the Symptom and Diagnosis forms. The backend checks it when the form saves, except for the update of a chronic_condition diagnosis.

Errors​

MessageCause
"Encounter not found"The encounter in a create request does not exist
"Patient external ID mismatch with encounter's patient"The condition's encounter belongs to another patient than the one in the URL
"Onset date cannot be in the future"onset.onset_datetime is in the future
"Valueset does not exist in care, Resync valuesets"No stored value set has the bound slug
"Code does not exist in the valueset"code is not in the bound value set
"No datapoints provided"An upsert with no datapoints
"Too many datapoints provided"An upsert with more than MAX_DATAPOINTS_PER_UPSERT datapoints
"Permission denied to user"The read check fails
"You do not have permission to update encounter"The write check fails, or the encounter is closed
"You do not have permission to update chronic condition"An update of a chronic_condition diagnosis without "Can view clinical data about patients"

Other notes​

  • The symptom API registers as an internal questionnaire of type symptom, titled "Symptom", with subject type patient.
  • The diagnosis API registers as an internal questionnaire of type diagnosis, titled "Diagnosis", with subject type patient.
  • In the form builder, the structured question types Symptom and Diagnosis are offered for encounter questionnaires. So a facility's own encounter forms can record conditions.
  • Care's frontend creates every new diagnosis as encounter_diagnosis. No screen creates a chronic_condition record.
  • Print templates: the report data for an encounter includes its encounter_diagnosis records as diagnoses and its problem_list_item records as symptoms.
  • These print data points do not filter on verification status, so they include records entered in error.
  • Send code as a coding from the bound value set, not as free text. Do not send patient: Care takes it from the encounter.