Skip to main content
Version: 3.1

Observation

Technical reference for the Observation module in Care EMR. For the plain-language view, see the Observation concept.

Source:

An observation is one recorded result about a patient in an encounter: a value or a coded answer for one code at one effective time.

The Django model is the storage layer. It keeps the codes, the value, the reference ranges, the interpretation and the components as JSON fields.

The Pydantic resource specs give those fields their shape. They also define the enums, the bound value sets, and the separate read and write schemas.

Three paths write observations: questionnaire submission, test results on a diagnostic report (upsert_observations), and direct create on the observation API. Each path sets different fields. See "Methods & save behaviour".

The observation API has no update. A DELETE does not remove the record: it marks the observation entered in error.

Models​

ModelPurpose
ObservationOne recorded result about a patient, linked to one encounter: a value or coded answer for one code at one effective time

Observation extends EMRBaseModel. Through it, each observation also has history and meta JSON fields and created_by / updated_by user links.

The API identifies an observation by its external_id, which read responses return as id.

Observation fields​

Status and grouping​

FieldStorageAPI and write paths
statusCharField(255)ObservationStatus. Required in the shared spec. Direct create accepts only final, which is also its default. Values and the paths that set them are listed under "Enum values"
is_groupBooleanField, default FalseNo code sets it. A group observation is marked by value_type group instead

Codes​

FieldStorageAPI and write paths
main_codeJSONField, default {}Coding. Required on direct create, and not checked against a value set there. Questionnaire: the question's code, which must be in the "Observation" value set. Test results: the observation definition's code
categoryJSONField, default {}Coding, optional on direct create. Questionnaires never set it, because a stored question has no category. Test results: the observation definition's category
alternate_codingJSONField, default []CodeableConcept, optional on direct create. The storage default is a list, while the spec type is one object

Subject and context​

FieldStorageAPI and write paths
subject_typeCharField(255)SubjectType, default encounter in the shared spec. Direct create and test results set encounter. Questionnaires set the questionnaire's subject type, and only submissions with an encounter store observations
subject_idUUIDFieldNot in the create spec. Direct create: the encounter's ID. Questionnaire: the submission's resource ID, which the Care frontend sets to the encounter's ID
patientFK → emr.Patient, CASCADESet by Care: from the encounter (direct create), from the report (test results), or from the questionnaire submission
encounterFK → emr.Encounter, CASCADE, requiredUUID4, required on direct create. The encounter must belong to the patient in the URL. Read responses return null
effective_datetimeDateTimeField, nullableTimezone-aware datetime, required on direct create. Optional in ObservationUpdateSpec. Questionnaire: the moment of submission. Test results from the Care frontend: the moment of saving

Author and performer​

FieldStorageAPI and write paths
data_entered_byFK → users.User, CASCADE, nullableDirect create rejects data_entered_by_id and records the signed-in user. Questionnaire: the submitting user. Test results: not set. Read responses include it as a user object when it is set
performerJSONField, default {}Performer, optional on direct create

Value​

FieldStorageAPI and write paths
value_typeCharField(255)QuestionType, required on direct create. Questionnaire: the question's type. Test results from the Care frontend: the definition's data type, or decimal when it has none
valueJSONField, no default, not nullableQuestionnaireSubmitResultValue, required on direct create. Optional in ObservationUpdateSpec. Shape and the way each path fills it are under "Nested JSON shapes"
noteTextFieldOptional on direct create. Questionnaires copy the note of the answer

Qualifiers​

FieldStorageAPI and write paths
body_siteJSONField, default {}Coding bound to the "Body Site" value set (system-body-site-observation), optional. Questionnaires never store it
methodJSONField, default {}Coding bound to the "Observation Method" value set (system-collection-method), optional. Questionnaires never store it

Interpretation and ranges​

FieldStorageAPI and write paths
reference_rangeJSONField, default []List of ReferenceRange. Not accepted on direct create. Test results linked to a definition: computed by Care. Questionnaire: never set
interpretationJSONField, default {}A free object (dict, default {}) in the shared spec. Not accepted on direct create. Test results linked to a definition: computed by Care. Questionnaire: never set
interpretation_oldCharField(255), nullableLegacy text column
FieldStorageAPI and write paths
parentUUIDField, nullable, not a foreign keyOptional UUID4 in the shared spec. Rejected on direct create. Questionnaire: each child of an ordinary group points to the group observation
componentJSONField, default []List of Component, default []. Allowed on direct create. Questionnaire: filled from a component group. Test results: each matching component gets its own interpretation
questionnaire_responseFK → emr.QuestionnaireResponse, CASCADE, nullableOptional UUID4 in the shared spec. Rejected on direct create. Set by questionnaire submission. Read responses return null
diagnostic_reportFK → emr.DiagnosticReport, CASCADE, nullableRejected on direct create. Set by upsert_observations
observation_definitionFK → emr.ObservationDefinition, CASCADE, nullableNot accepted on direct create. Set by upsert_observations when the item names a definition. Retrieve returns it

Enum values​

ObservationStatus values​

ValueLabel in the locale fileSet by
finalFinalDirect create (the only value it accepts), questionnaire submission, and new test results created from a definition
amendedNone: the locale file has no key for itNo backend code sets it, and the Care frontend never sends it. An API client can store it by sending it to upsert_observations for an existing test result
entered_in_errorEntered in ErrorDELETE on a random observation, marking the questionnaire response entered in error, or upsert_observations

QuestionType values (value_type)​

value_type uses the question types of the questionnaire module.

ValueLabel in the locale file
groupGroup
booleanBoolean
decimalDecimal
integerInteger
stringString
textText
displayDisplay
dateDate
dateTimeDate Time
timeTime
choiceChoice
urlURL
quantityQuantity
structuredStructured
  • ignore_group=true on the list leaves out observations with value_type group.
  • For test results, the Care frontend sends the observation definition's data type as value_type, and decimal when the definition has none.

SubjectType values (subject_type)​

Value
patient
encounter: the shared spec default, and the value that direct create and test results set
referral
location
device
facility

PerformerType values (performer.type)​

Value
related_person
user

Value sets​

NameSlugContentUsed by
Observationsystem-observationAll LOINC codes (http://loinc.org)The code of a questionnaire question, and so the main_code of questionnaire observations
Body Sitesystem-body-site-observationSNOMED CT concepts that are a 442083009body_site
Observation Methodsystem-collection-methodSNOMED CT descendants of 272394005, 129264002 and 386053000method
UCUM Unitssystem-ucum-unitsAll UCUM units (http://unitsofmeasure.org)The unit of a questionnaire question
Normal Coded Value Setsystem-normal-coded-valuesetHL7 interpretation codes N Normal, ND Not detected, NEG NegativeDefined in the observation module
Critical Coded Value Setsystem-critical-coded-valuesetC Critical, CC Critical high, CL Critical low, CV Critical valueDefined in the observation module
Abnormal Coded Value Setsystem-abnormal-coded-valuesetA, AA, H, HH, L, LL, POS, DETDefined in the observation module
  • A body_site or method code outside its value set is rejected with "Code does not exist in the valueset".
  • On direct create, main_code is a plain Coding. Care does not check it against a value set.

Nested JSON shapes​

Coding​

main_code, category, body_site, method, value.unit, value.coding and component[].code are codings. Care rejects any key that is not listed.

Coding {
system: str | null
version: str | null
code: str required
display: str | null
}

code has no minimum length, so an empty code ("") is accepted.

alternate_coding: CodeableConcept​

The text key must be present, but it may be null. Care rejects any key that is not listed.

CodeableConcept {
id: str | null
coding: Coding[] | null
text: str | null key required
}

value: QuestionnaireSubmitResultValue​

All three parts are optional. value is text, unit is the coding of a quantity's unit, and coding is the coding of a coded answer.

QuestionnaireSubmitResultValue {
value: str | null
unit: Coding | null
coding: Coding | null
}

How each write path fills value:

  • Questionnaire, choice answer with a coding: coding holds the answer's coding.
  • Questionnaire, quantity answer with a coding: unit is the question's unit, value the entered number, and coding the answer's coding.
  • The Care frontend sends the unit picked in the questionnaire as the answer's coding. So the picked unit is kept only in value.coding, and value.unit is always the question's unit.
  • Questionnaire, any other answer: value holds the entered value, plus the question's unit when the question has one.
  • Questionnaire, group: an empty object.
  • Questionnaire, answer with several values: one observation, with the last value only.
  • Test results from the Care frontend: the unit is the observation definition's unit.

performer: Performer​

Performer {
type: PerformerType related_person | user
id: str
}

A performer has a type and an id.

reference_range[]: ReferenceRange​

The spec types a reference range as follows.

ReferenceRange {
min: float | null
max: float | null
unit: str | null
interpretation: str required
value: str | null
}

The reference ranges that Care computes for test results are the numeric ranges of the matching qualified range. Each stored entry therefore carries an interpretation object, not text.

interpretation: computed interpretation object​

The shared spec types interpretation as a free object. The interpretation that Care computes from an observation definition has this shape.

Interpretation {
display: str required
icon: optional
color: optional
highlight: bool | null default false
code: optional
}

The built-in coded interpretations are {"display": "Normal"}, {"display": "Critical"} and {"display": "Abnormal"}.

component[]: Component​

Component {
value: QuestionnaireSubmitResultValue required
interpretation: str | dict default {}
reference_range: ReferenceRange[] default []
code: Coding | null default null
note: str default ""
}

The spec defines a component as above. A questionnaire component holds the sub-question's code, value and note.

Observation links to other models as follows. parent points to another observation and is not a foreign key. Deleting the patient row deletes its observations (CASCADE).

Observation
patient → FK emr.Patient (CASCADE)
encounter → FK emr.Encounter (CASCADE, required)
data_entered_by → FK users.User (CASCADE, nullable)
questionnaire_response → FK emr.QuestionnaireResponse (CASCADE, nullable)
diagnostic_report → FK emr.DiagnosticReport (CASCADE, nullable)
observation_definition → FK emr.ObservationDefinition (CASCADE, nullable)
parent → UUIDField: id of another Observation (not a foreign key)

Observations about locations, devices and facilities are a separate model, FacilityResourceObservation, tied to a facility. This page does not cover it.

Resource specs (API schema)​

ObservationCreateSpec extends EMRResource directly. ObservationUpdateSpec, ObservationSpec and ObservationReadSpec extend the shared BaseObservationSpec, and ObservationRetrieveSpec extends ObservationReadSpec.

SpecRoleNotes
BaseObservationSpecshared basestatus required. subject_type default encounter. body_site and method bound to value sets. interpretation a free object, default {}. parent and questionnaire_response optional UUIDs. component default []
ObservationCreateSpecwrite · create (POST)"An observation entered independently of a questionnaire or diagnostic report". Rejects any field it does not list
ObservationUpdateSpecwrite · upsert_observationsThe shared spec with effective_datetime and value optional. status stays required
ObservationSpecinternal · questionnaire submissionAdds data_entered_by_id, created_by_id and updated_by_id, and keeps the observation ID generated during submission
ObservationReadSpecread · listAdds is_random, created_by, updated_by and data_entered_by
ObservationRetrieveSpecread · detailExtends the read spec with observation_definition, when one is linked

Create: ObservationCreateSpec​

The body of POST /api/v1/patient/{patient_id}/observation/.

{
"encounter": UUID, required
"status": "final", optional; default "final"; no other value
"main_code": Coding, required; not bound to a value set
"effective_datetime": datetime with timezone, required
"value_type": QuestionType, required
"value": QuestionnaireSubmitResultValue, required
"category": Coding | null, optional
"alternate_coding": CodeableConcept, optional
"performer": Performer, optional
"note": str, optional
"body_site": Coding in system-body-site-observation, optional
"method": Coding in system-collection-method, optional
"component": Component[], optional; default []
}
  • Any other field is rejected with HTTP 400. This includes id, questionnaire_response, diagnostic_report, parent, created_by_id, data_entered_by_id, is_random and meta.
  • The create spec has no reference_range, interpretation or observation_definition.
  • Care takes the patient from the encounter, sets subject_type to encounter, and sets subject_id to the encounter's ID.
  • Care sets data_entered_by, created_by and updated_by to the signed-in user.
  • The response is the full saved observation.

Read: ObservationReadSpec and ObservationRetrieveSpec​

  • id is the observation's external_id.
  • is_random tells whether the observation was entered on its own, not through a questionnaire or a diagnostic report.
  • created_by and updated_by are user objects. data_entered_by is a user object when it is set.
  • encounter and questionnaire_response are always null in read responses, to avoid extra queries.
  • Retrieve also returns the linked observation definition as observation_definition.

Deserialization​

Generic deserialization never writes a foreign key, id or external_id from a request body. Care sets those fields itself on each path.

Methods & save behaviour​

is_random​

is_random is a model property. It is true when the observation has neither a questionnaire response nor a diagnostic report. Only random observations can be marked entered in error with DELETE.

Write path 1: questionnaire submission​

Questionnaire answers are submitted with POST /api/v1/questionnaire/{questionnaire_id}/submit/. Care builds the observations with the internal ObservationSpec.

  • Observations are stored only when the submission has an encounter. A patient questionnaire saves the questionnaire response and no observations.
  • A question that is not a group produces an observation only if the question has a code.
  • Each observation has status final and takes value_type from the question type.
  • main_code is the question's code. A stored question has no category key, so questionnaire observations have no category.
  • effective_datetime is the moment of submission. A time taken on the answer is not stored.
  • The note of the answer is copied. Body site and method are not stored.
  • subject_type is the questionnaire's subject type. The submitting user is recorded as data_entered_by, created_by and updated_by.
  • Each observation is linked to the questionnaire response, the patient and the encounter. subject_id is the submission's resource ID.
  • No observation definition, reference range or interpretation is set.
  • A group question gives a group observation: value_type group, an empty value, and the submission time.
  • In an ordinary group, each answer inside gives a separate observation whose parent is the group observation's ID. Care keeps the group observation only if it has at least one child.
  • A group marked as component gives one observation, with the answers as its components. A repeating group gives one such observation per repetition.
  • Marking the questionnaire response entered in error marks every observation created from it entered in error.

Write path 2: test results on a diagnostic report (upsert_observations)​

Results are written with POST /api/v1/patient/{patient_id}/diagnostic_report/{id}/upsert_observations/. It creates observations from an observation definition or from scratch, or updates existing ones.

Each item has an observation body (ObservationUpdateSpec, status required). It also names an observation definition by slug (observation_definition), an existing observation (observation_id), or neither for a new observation.

  • The call is refused on a final report: "Cannot update observations for a final diagnostic report".
  • After that check, Care runs the diagnostic-report write check. It does not check the encounter's status or the service request's status.
  • With a definition slug, Care looks up the definition in the report's facility and links it to the new observation. The new observation starts as final, with the definition's category and code.
  • With observation_id, the observation must belong to that report. The fields sent, status included, overwrite the stored ones.
  • So this path can set an existing observation to amended or entered_in_error.
  • Every observation saved here gets the report's encounter and patient, the report link, and subject_type encounter. Care sets updated_by; it does not set data_entered_by.
  • When the observation is linked to a definition, Care computes its interpretation and reference ranges before saving. See "Interpretation and reference ranges" below.
  • ObservationUpdateSpec makes value optional, but the value column has no default and is not nullable.
  • Opening the report returns all its observations in any status, entered_in_error included, each with its definition.

The Care frontend sends each result with status final, or entered_in_error when the user removes it. It never sends amended. It sends the moment of saving as effective_datetime.

Each Save Results sends every saved result of the report again, changed or not. So each one gets the new save time as its effective time.

Write path 3: direct create​

POST /api/v1/patient/{patient_id}/observation/ creates an observation from ObservationCreateSpec. See "Create: ObservationCreateSpec" above for the body and the fields that Care sets.

No screen of the Care frontend creates an observation directly or sends DELETE. Its observation API has only list, analyse and upsert_observations.

Interpretation and reference ranges​

Care computes these only for test results linked to an observation definition. Questionnaire observations and direct creates get none.

  • Care evaluates the definition's qualified ranges in the context of the observation's patient and encounter.
  • The result sets interpretation and reference_range. When nothing matches, Care clears both.
  • Care uses the first qualified range whose conditions all hold. Conditions can test Patient Age, Patient Gender, Patient Tag, Encounter Class and Encounter Tag.
  • Numeric value: it must be between min and max, both included; a missing bound is open. Care uses the matching range's interpretation and stores all the rule's ranges as the reference range.
  • A coded value against numeric ranges raises "Coding not supported".
  • Coded value: Care checks the coding against the rule's normal, then critical, then abnormal value set, which give "Normal", "Critical" or "Abnormal". Then it checks each custom value set interpretation.
  • If no range or value set matches, Care uses the rule's default interpretation when it has one.
  • Each component whose code matches a component of the definition gets its own interpretation and reference ranges.

Marking entered in error​

  • DELETE sets status to entered_in_error and records the user as updated_by. It does not remove or soft-delete the observation.
  • The value, the author and the data-entry user stay. Repeating the request still returns HTTP 204.
  • Only random observations can be marked this way. Others fail with "Only random observations can be marked as entered in error".
  • Questionnaire observations: mark the questionnaire response entered in error, which marks all its observations. By default this is possible for 120 minutes after the response is created.
  • Test results: send the observation with status entered_in_error to upsert_observations.
  • The observation API has no hard delete and no update.

API integration notes​

Routes​

All routes are under /api/v1/. Observation routes are nested under the patient. Every request needs a signed-in user.

ActionMethod and pathBodyResponse
ListGET /api/v1/patient/{patient_id}/observation/Nonecount and results
RetrieveGET /api/v1/patient/{patient_id}/observation/{id}/NoneThe observation, with its observation definition when one is linked
CreatePOST /api/v1/patient/{patient_id}/observation/ObservationCreateSpecThe saved observation
UpdatePUT or PATCH /api/v1/patient/{patient_id}/observation/{id}/NoneHTTP 405
Mark entered in errorDELETE /api/v1/patient/{patient_id}/observation/{id}/NoneHTTP 204, no body
AnalysePOST /api/v1/patient/{patient_id}/observation/analyse/codes, page_sizeresults: one entry per code
Test resultsPOST /api/v1/patient/{patient_id}/diagnostic_report/{id}/upsert_observations/Items as described aboveSee "Write path 2"
Questionnaire submissionPOST /api/v1/questionnaire/{questionnaire_id}/submit/The questionnaire answersSee "Write path 1"

{id} is the observation's id as read responses return it.

List filters, ordering and pages​

Query parameterEffect
encounterEncounter external ID. Returns only that encounter's observations. Without patient-level access, the list needs it (see "Authorization")
codesComma-separated codes. Matches the code of main_code, not its system. An empty value applies no filter
ignore_grouptrue leaves out observations whose value_type is group
statusComma-separated statuses. Without it, the list returns every status, entered_in_error included
limitRecords per page: 14 by default, at most 200
offsetRecords to skip
  • The list has no ordering parameter and no date-range filter.
  • Results are always the most recently modified first, and only for the patient in the URL.

analyse​

analyse returns the most recently modified observations of several codes in one call.

POST /api/v1/patient/{patient_id}/observation/analyse/
{
"codes": Coding[], 1 to 20 codings
"page_size": int default 10, at most 30
}
  • For each coding, Care returns up to page_size of the patient's most recently modified observations with that code and system.
  • The list's query filters apply first: encounter, status, codes and ignore_group.
  • The response has results, a list with one entry for each requested code. Each entry has the code and its results.

Authorization​

The table uses these terms.

  • "Closed encounter": the encounter's status is completed, cancelled, entered_in_error or discontinued.
  • "A role on the patient": a role in a facility organization of an open encounter of the patient, or of its current location. It can also come from the patient's geographic organizations, or a direct patient–user association.
  • "An organization of the encounter": one of the encounter's facility organizations (its departments), or an organization of its current location.
  • The encounter's facility organizations include the organizations it is assigned to, their parents, and the facility's root organization "Administration".
  • Where the "Held where" column names organizations, the user must hold a role that carries the permission in one of them.
ActionPermission (display name, slug)Held whereConditions and refusal
Retrieve"Can view clinical data about patients" (can_view_clinical_data)A role on the patientRefusal: "Permission denied to user"
List, analyse"Can view clinical data about patients" (can_view_clinical_data)A role on the patientIf this check fails, Care tries the next row
List, analyse, with ?encounter="Can Read encounter related clinical data" (can_read_encounter_clinical_data)An organization of the encounter named in encounterOpen and closed encounters alike. Without encounter, a user with only this permission gets HTTP 403. Refusal: "Permission denied to user"
Create"Update Encounter related clinical data" (can_write_encounter_clinical_data)An organization of the encounter in the bodyRefused for a closed encounter (HTTP 403). Refusal: "You do not have permission to update encounter"
Mark entered in error (DELETE)"Update Encounter related clinical data" (can_write_encounter_clinical_data)An organization of the observation's encounterRefused for a closed encounter. The observation must be random and belong to the patient in the URL. No read check runs
Questionnaire submission (encounter questionnaire)"Can submit questionnaire about patient encounters" (can_submit_encounter_questionnaire)An organization of the encounterRefused for a closed encounter: "Permission Denied to submit encounter questionnaire". The encounter must belong to the patient ("Encounter is required for this questionnaire"), and to the questionnaire's facility for a facility questionnaire ("Encounter facility does not match questionnaire facility"). The questionnaire must be active ("Questionnaire is inactive") and the latest revision; an empty submission fails ("Empty Questionnaire cannot be submitted")
Mark a questionnaire response entered in error"Can submit questionnaire about patient encounters" (can_submit_encounter_questionnaire)An organization of the encounterFirst, the response must be readable: "Can view clinical data about patients" through a role on the patient, or "Can Read encounter related clinical data" in an organization of the encounter; else "You do not have permission to view questionnaire responses". Refused for a closed encounter: "Permission Denied to update encounter questionnaire". Refused when the response is already entered in error, or after the edit window (120 minutes by default): "Questionnaire Response cannot be edited"
upsert_observations"Can Create Diagnostic Report on Facility" (can_write_diagnostic_report)An organization of the service request's encounter, or of one of the service request's locationsThe report is not final. The encounter's status is not checked. Refusal: HTTP 403, "You do not have permission to write this diagnostic report"
Read test results (open the diagnostic report)"Can Read Diagnostic Report" (can_read_diagnostic_report)The same places as the write checkRefusal: "You do not have permission to read this diagnostic report"

Default roles per permission:

Permission (display name)SlugDefault roles
Can view clinical data about patientscan_view_clinical_dataStaff, Doctor, Nurse, Facility Admin
Can Read encounter related clinical datacan_read_encounter_clinical_dataDoctor, Nurse, Facility Admin
Update Encounter related clinical datacan_write_encounter_clinical_dataDoctor, Nurse, Facility Admin
Can submit questionnaire about patient encounterscan_submit_encounter_questionnaireStaff, Doctor, Nurse, Facility Admin
Can Create Diagnostic Report on Facilitycan_write_diagnostic_reportFacility Admin, Doctor, Nurse
Can Read Diagnostic Reportcan_read_diagnostic_reportFacility Admin, Administrator, Staff, Doctor, Nurse, Volunteer
  • The permission definitions also name an Admin role. Roles are matched by name, and the only role named Admin in the database is for role organizations, which the facility screens do not offer. The lists above leave it out.
  • Staff does not hold "Can Read encounter related clinical data" or "Update Encounter related clinical data". Staff reads observations only through a role on the patient.
  • These role lists are the defaults in code. The roles of an installation can be changed.

Errors​

  • A create body with a field that the create spec does not list: HTTP 400.
  • An encounter of another patient: "Patient external ID mismatch with encounter's patient". An unknown encounter: not found.
  • A body_site or method code outside its value set: "Code does not exist in the valueset".
  • A create in a closed encounter: HTTP 403.
  • PUT or PATCH on an observation: HTTP 405.
  • A request without a signed-in user: HTTP 403.

Other places observations appear​

  • Referrals: an observation can be attached to a referral as a resource of type observation.
  • Reading it there needs the patient-level read check ("Can view clinical data about patients"), or the encounter-level read check on the observation's encounter. Otherwise: "Permission denied to read this resource".
  • Report templates: a diagnostic report's template can include its observations, with title, value, components, status, effective date and time, interpretation and reference ranges.
  • Resource observations (/api/v1/resource_observation/) come from location, device and facility questionnaires and need "Can View Resource Responses"; no staff screen reads them.