Skip to main content
Version: 3.1

Diagnostic Report

Technical reference for the DiagnosticReport module in Care EMR. For what a diagnostic report is and how Care's screens use it, see the Diagnostic Report concept.

A diagnostic report holds the outcome of one service request for one patient and one encounter. Its results are not fields of the report: they are Observation rows that point to it.

Source:

The Django model is the storage layer. It stores status as free text, category and code as nullable JSON fields, and note and conclusion as nullable text.

The Pydantic resource specs give these fields their shape: the status enum, the Coding structure, the bound value sets, and separate read and write schemas.

The viewset adds the routes, the list filters, the upsert_observations action that saves results, and the authorization checks.

Models​

ModelPurpose
DiagnosticReportThe outcome of one service request for one patient and one encounter. Its results are Observation rows linked to it

DiagnosticReport extends EMRBaseModel. Through it, each report has external_id, created_date, modified_date, the soft-delete flag deleted, created_by, updated_by, history and meta.

DiagnosticReport fields​

Classification​

FieldModel typeSpec typeNotes
statusCharField(max_length=255)DiagnosticReportStatusChoicesRequired on create. Optional on update: when it is left out, the stored value stays. Free text in the database; the spec accepts only the enum values below
categoryJSONField(null=True, blank=True)Coding bound to system-diagnostic-service-sections-codeRequired on create and on every update
codeJSONField(null=True, blank=True)Coding bound to system-observationOptional. What the report is for. An update cannot clear it by sending null

Narrative​

FieldModel typeSpec typeNotes
noteTextField(null=True, blank=True)str | NoneOptional free text. The Care frontend has no input for it. An update cannot clear it by sending null
conclusionTextField(null=True, blank=True)str | NoneOptional free text. The Care frontend edits it in a rich text editor. An update cannot clear it by sending null

Relationships​

FieldTypeSet byNotes
facilityFK → facility.Facility, PROTECT, nullable, default NoneCare, from the encounter of the service requestA facility that has reports cannot be hard-deleted
patientFK → emr.Patient, CASCADECare, from the patient in the URLMust be the patient of the service request; otherwise create fails with "Invalid Request"
encounterFK → emr.Encounter, CASCADECare, from the service requestNot in any write spec
service_requestFK → emr.ServiceRequest, CASCADEThe client, on create onlySent on create as the service request's external_id. __exclude__ keeps it out of the generic field mapping. List and detail reads return it as an embedded object. The update spec has no such field, so it cannot change

Inherited from EMRBaseModel​

FieldTypeNotes
external_idUUIDField(default=uuid4, unique=True, db_index=True)The report's public ID. Reads return it as id, and the report routes look the report up by it. The report's files use it as associating_id
created_date, modified_dateDateTimeFieldSet automatically. Returned in list and detail reads. The list can be ordered by either
deletedBooleanField(default=False, db_index=True)Soft-delete flag. The API has no delete action
created_by, updated_byForeign keys to the userOn create, both are the requesting user. Every update sets updated_by. The detail read returns both as user objects
history, metaJSONField(default=dict)Shared JSON fields of every EMR model

Coding shape​

category and code each hold one Coding. Care rejects any key that is not in this table.

KeyRequiredNotes
systemNostr | None
versionNostr | None
codeYesstr. Must be in the bound value set
displayNostr | None

Enum values​

DiagnosticReportStatusChoices values​

The spec accepts only these four values on write. The second column is the label that the Care frontend shows for the value.

ValueLabel in the Care frontendUse in the Care frontend
registeredRegisteredNo screen sets it
partialPartialNo screen sets it
preliminaryPreliminaryEvery report created in the Care frontend starts with this status. Results are saved while the report has it
finalFinalSet by Approve Results. On the service request page, the report's results, conclusion and files are then read-only
  • The Care frontend never sets registered or partial. It creates every report as Preliminary and sets Final only by approval.
  • In the Care frontend, Save Results and Approve Results are shown only for a Preliminary report.
  • The value modified is commented out of the backend enum, so the API rejects it.
  • The status list of the Care frontend still has modified, with the label Modified. No screen sends it.
  • The API enforces no order of statuses. An update can set any of the four values from any status, final included. See "Update" under "Methods & save behaviour".
  • Report templates print the status as "Registered", "Partial", "Preliminary" or "Final".

Bound value sets​

Each coded field checks its code against a Care value set. A code outside the set fails with "Code does not exist in the valueset".

FieldValue setSlugDefault content
categoryDiagnostic Service Sectionssystem-diagnostic-service-sections-codeHL7 v2 table 0074 (http://terminology.hl7.org/CodeSystem/v2-0074)
codeObservationsystem-observationLOINC (http://loinc.org)
  • Both are system value sets. A management command writes them to the database, and admins can then edit them. A deployment's content can therefore differ from these defaults.
  • The Care frontend creates every report with the category Laboratory (code LAB, system v2-0074).
  • The diagnostic_report_codes of an activity definition use the same Observation value set as code.

DiagnosticReport is the only model in its file. It has no specimen, performer, reviewer, effective-date or issued-date field. Its foreign keys are:

DiagnosticReport
facility → FK facility.Facility (PROTECT, nullable)
patient → FK emr.Patient (CASCADE)
encounter → FK emr.Encounter (CASCADE)
service_request → FK emr.ServiceRequest (CASCADE)

A hard delete of a patient, encounter or service request also removes its reports. The shared BaseModel.delete() is a soft delete that sets deleted. The facility link is protected.

Other models that work with diagnostic reports:

ModelLinkNotes
Observationdiagnostic_report: nullable FK, CASCADE; at most one report per observationThe report's results. The detail read lists all of them, entered-in-error ones included
File Uploadfile_type diagnostic_report, associating_id = the report's external_idFiles attached to the report. See "Files" under "API integration notes"
ServiceRequestReverse of service_requestA service request can have several reports. Its detail embeds a summary of each one
ActivityDefinitiondiagnostic_report_codes: a list of Coding, default emptyEach entry is a report type. The Care frontend offers one report per report type, one at a time. With no entries, it offers one report per service request

Resource specs (API schema)​

DiagnosticReportSpecBase extends EMRResource. It sets __model__ = DiagnosticReport and __exclude__ = ["service_request"], so the create spec and the read specs handle service_request themselves.

SpecRoleFields and behaviour
DiagnosticReportSpecBaseshared baseid?, status (required), category (bound Coding, required), code? (bound Coding), note?, conclusion?
DiagnosticReportCreateSpecwrite · createBase + service_request: UUID4 (required). Resolves the service request with get_object_or_404
DiagnosticReportUpdateSpecwrite · updateBase with status optional. category stays required. No service_request field
DiagnosticReportListSpecread · listBase + created_date, modified_date, and service_request as an embedded BaseServiceRequestSpec object
DiagnosticReportRetrieveSpecread · detailThe list fields + observations, encounter, created_by, updated_by, requester
UpsertObservationRequestwrite · results itemOne item of an upsert_observations request: observation, observation_id?, observation_definition?

Create body: DiagnosticReportCreateSpec​

The body of POST /api/v1/patient/{patient_external_id}/diagnostic_report/.

FieldTypeRequiredNotes
service_requestUUID4YesThe service request's external_id. An unknown ID returns 404. A service request of another patient fails with "Invalid Request"
statusDiagnosticReportStatusChoicesYesThe Care frontend sends preliminary
categoryCodingYesIn system-diagnostic-service-sections-code
codeCoding | NoneNoIn system-observation
notestr | NoneNo
conclusionstr | NoneNo

Update body: DiagnosticReportUpdateSpec​

The body of PUT or PATCH /api/v1/patient/{patient_external_id}/diagnostic_report/{external_id}/.

FieldTypeRequiredNotes
statusDiagnosticReportStatusChoicesNoWhen left out, the stored value stays
categoryCodingYesMust be sent with every update
codeCoding | NoneNoSending null does not clear it
notestr | NoneNoSending null does not clear it
conclusionstr | NoneNoSending null does not clear it

Read payloads: DiagnosticReportListSpec and DiagnosticReportRetrieveSpec​

FieldListDetailNotes
idYesYesThe report's external_id (a UUID), not the database ID
status, category, code, note, conclusionYesYes
created_date, modified_dateYesYes
service_requestYesYesThe linked service request as an object (BaseServiceRequestSpec). It is serialized from obj.service_request, not through model_from_cache
observationsNoYesEvery observation linked to the report, with no status filter: entered-in-error observations are included
encounterNoYesEncounterListSpec, with patient inside it as PatientRetrieveSpec for the report's facility
created_by, updated_byNoYesUser objects from the user cache (model_from_cache)
requesterNoYesThe requester of the service request, from the user cache

The write specs accept none of the embedded objects.

Results body: upsert_observations​

The body of POST /api/v1/patient/{patient_external_id}/diagnostic_report/{external_id}/upsert_observations/.

FieldTypeNotes
observationslist of UpsertObservationRequestOne item per observation
observations[].observationObservationUpdateSpecThe observation's data
observations[].observation_idUUID4 | NoneAn existing observation to update. Used only when observation_definition is not set. It must belong to this report; otherwise the request returns 404
observations[].observation_definitionstr | NoneThe slug of an observation definition of the report's facility. An unknown slug returns 404

Methods & save behaviour​

Create​

  • Care sets patient from the URL, encounter from the service request, and facility from that encounter. A request body cannot set them.
  • If the service request belongs to another patient than the one in the URL, Care refuses the request with "Invalid Request".
  • Care sets created_by and updated_by to the requesting user.
  • Create checks the write permission and that the service request belongs to the patient. It does not check the service request's status, the number of reports the service request already has, or the encounter's status.
  • The backend does not check specimens on create. Only the Care frontend waits for the specimens to be collected.

Update​

  • Care writes only fields whose value differs from the field's default. A field that is left out or sent as null keeps its stored value.
  • So an update cannot clear code, note or conclusion, and an update without status keeps the stored status.
  • category must be sent with every update, PATCH included.
  • service_request is not in the update spec, so a report stays on its service request.
  • Update checks only the write permission. It does not look at the report's current status.
  • The API therefore accepts updates to a report with status final, and its status can be set to any of the four values.
  • Among the write actions, only upsert_observations refuses a final report.
  • After an update sets a final report back to preliminary, upsert_observations accepts results for it again.
  • On the service request page, the Care frontend shows the results, conclusion and files of a Final report read-only. Its approval dialog says "This action cannot be undone."
  • Care sets updated_by to the requesting user.
  • PATCH runs exactly like PUT: the partial flag does not reach validation, so the body is checked against the full update spec. The Care frontend uses PUT.

Entering results: upsert_observations​

  • An item with observation_definition creates a new observation from that definition, even when the item also has observation_id. Care then ignores the ID.
  • That new observation starts with status final and takes its category and code from the definition. Values in the request can override them.
  • An item with observation_id and no observation_definition updates that observation of the report.
  • An item with neither creates a new observation that is not linked to a definition.
  • Every saved observation gets the report's encounter and patient, the encounter as its subject, and a link to the report.
  • For an observation linked to an observation definition, Care computes the interpretation and the reference range from the definition's ranges on every save.
  • The computed values replace the stored ones. When no range matches, Care clears both.
  • An observation's status is final, amended or entered_in_error. The Care frontend removes a saved result by sending it with entered_in_error.
  • While the report's status is final, Care refuses the request with "Cannot update observations for a final diagnostic report".
  • This check runs before the permission check. A caller without the write permission gets this message, not a permission error, for a final report.
  • A successful request answers "Observations updated successfully".
  • The observation API has no update action. It marks an observation as entered in error only when the observation is not linked to a report or a questionnaire response.
  • A report's observations therefore change only through upsert_observations.

Approval​

  • There is no separate review or approval endpoint. Setting status to final with an update is the approval, and it needs the same permission as any update.
  • The report has no reviewer field. Care records the approving user only as updated_by.

No delete​

  • The viewset has no destroy action, so the API cannot delete a diagnostic report.

API integration notes​

Endpoints​

All routes are under /api/v1/, nested under the patient. Every action sees only the reports of the patient in the URL.

ActionMethod and pathBodyNotes
ListGET /api/v1/patient/{patient_external_id}/diagnostic_report/NoneItems in the list read shape. Filters below
CreatePOST /api/v1/patient/{patient_external_id}/diagnostic_report/DiagnosticReportCreateSpec
RetrieveGET /api/v1/patient/{patient_external_id}/diagnostic_report/{external_id}/NoneThe detail read shape
UpdatePUT or PATCH /api/v1/patient/{patient_external_id}/diagnostic_report/{external_id}/DiagnosticReportUpdateSpecApproval is an update with status final
Enter resultsPOST /api/v1/patient/{patient_external_id}/diagnostic_report/{external_id}/upsert_observations/observations listSee "Entering results" above
DeleteNoneNoneNo destroy action
  • Successful list, retrieve, create and update calls answer HTTP 200. Create answers 200 with the new report, not 201.
  • Invalid data answers 400 with an errors list. An unknown report, patient or service request answers 404 with the error type object_not_found.
  • A permission refusal answers 403 with the refusal message as detail.

List filters and ordering​

Query parameterEffect
statusCase-insensitive exact match on the status
encounterThe encounter's external_id. A caller without "Can view clinical data about patients" can then pass with "Can Read encounter related clinical data"; see "Authorization"
service_requestThe service request's external_id. The list then needs "Can Read Diagnostic Report" on that service request instead of the clinical-data permissions; see "Authorization"
orderingcreated_date or modified_date
limitReports per page. Default 14, at most 200
offsetReports to skip

The list body is count (the total) and results, with no next or previous links. Without ordering, the list returns the newest reports first.

Authorization​

The table uses these places:

  • "On the service request": a role with the permission in a facility organization of the service request's encounter, or of that encounter's current location. Failing that, a role in a facility organization of the location that the service request is for.
  • The encounter's facility organizations include its organizations, their parent organizations, and the facility's root organization "Administration".
  • "On the patient": roles from the facility organizations and current locations of the patient's open encounters. An encounter is closed when it is completed, cancelled, discontinued or entered in error. Roles from the patient's organizations, and a role given directly on the patient, also count.
  • "In the encounter": the encounter's facility organizations, or those of its current location.
ActionHandlerPermissionHeld whereRefusal message
Createcan_write_diagnostic_report"Can Create Diagnostic Report on Facility"On the service request named in the body"You do not have permission to write this diagnostic report"
Retrievecan_read_diagnostic_report"Can Read Diagnostic Report"On the report's service request"You do not have permission to read this diagnostic report"
Update (PUT, PATCH)can_write_diagnostic_report"Can Create Diagnostic Report on Facility"On the report's service request"You do not have permission to write this diagnostic report"
upsert_observationscan_write_diagnostic_report, after the final check"Can Create Diagnostic Report on Facility"On the report's service request"You do not have permission to write this diagnostic report"
List with service_requestcan_read_diagnostic_report"Can Read Diagnostic Report"On that service request"You do not have permission to read this diagnostic report for this service request"
List without service_requestcan_view_clinical_data"Can view clinical data about patients"On the patient"Permission denied to user" when the request has no encounter filter; with one, Care tries the next row
List without service_request, with encountercan_view_encounter_clinical_data"Can Read encounter related clinical data"In the encounter named in encounter"Permission denied to user" when neither this row nor the previous one passes
List or open a report's filescan_read_diagnostic_report"Can Read Diagnostic Report"On the report's service request"Cannot View File"
Upload, rename, mark upload complete or archive a report's filecan_write_diagnostic_report"Can Create Diagnostic Report on Facility"On the report's service request"Cannot View File"
Attach a report to a referralcan_read_diagnostic_report"Can Read Diagnostic Report"On the report's service request"Permission denied to read this resource"
  • A list without service_request does not use "Can Read Diagnostic Report". Without encounter, it passes only with "Can view clinical data about patients".
  • For retrieve, update and upsert_observations, finding the report adds no check of its own. Each action then runs its own check.
  • No write check looks at the encounter's status. A report can be created, updated and given results after its encounter is completed.
  • The file checks do not look at the report's status, so files can be uploaded to and archived from a final report.
  • A superuser passes every check. A list returns every report of the patient to a superuser without a check.
  • Opening a service request needs only "Can Read Service Request". Its detail embeds a summary of each report (status, category, code, note, conclusion). Care checks no diagnostic report permission for that summary.

Default roles per permission:

PermissionSlugDefault roles
"Can Create Diagnostic Report on Facility"can_write_diagnostic_reportFacility Admin, Doctor, Nurse
"Can Read Diagnostic Report"can_read_diagnostic_reportFacility Admin, Administrator, Staff, Doctor, Nurse, Volunteer
"Can view clinical data about patients"can_view_clinical_dataStaff, Doctor, Nurse, Facility Admin
"Can Read encounter related clinical data"can_read_encounter_clinical_dataDoctor, Nurse, Facility Admin
"Can Read Service Request"can_read_service_requestFacility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist
  • By default, Pharmacist holds neither diagnostic report permission.
  • 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.
  • These role lists are defaults. Care reads the links between roles and permissions from the database at run time.
  • A superuser can create and change roles through the role API. The sync command rebuilds the default links of system roles on every run.

Files​

  • A report's files are file uploads with file_type diagnostic_report and associating_id set to the report's external_id.
  • Routes: /api/v1/files/ (list, create), /api/v1/files/{id}/ (retrieve, update), /api/v1/files/{id}/mark_upload_completed/ and /api/v1/files/{id}/archive/.
  • A list needs file_type and associating_id; otherwise it fails with "Cannot filter files". It returns only files whose upload is complete.
  • A file is removed by archiving it, which needs an archive reason. Archived files are kept.

What the Care frontend sends​

The Care frontend makes only three kinds of report write.

Action in the Care frontendRequestContent
Create ReportPOST .../diagnostic_report/status preliminary, the category Laboratory (LAB), the service request, and the chosen report type as code when the activity definition has diagnostic_report_codes
Save ResultsPOST /api/v1/batch_requests/ that holds upsert_observations (when a result has a value or a saved result is removed) and a PUT on the reportupsert_observations resends every result that has a value, also results saved before, each with effective_datetime set to the time of the save. The PUT resends the stored status, category, code and note with the edited conclusion
Approve Results, then ApprovePUT .../diagnostic_report/{external_id}/status final and the conclusion shown in the review card
  • A batch request runs all its calls in one transaction. If one call fails, Care rolls all of them back.
  • When an inner call is refused, the whole batch answers 400 and returns the status code and body of each inner call.
  • Each call in a batch request is authorized as if it were sent on its own.
  • The Care frontend creates a report only after the specimens are collected; the backend does not check this. For every specimen requirement of the activity definition, the service request must have a specimen of that definition with status available.
  • No screen sets registered, partial or modified, edits the note, or changes the category or code after create.
  • The encounter's Diagnostic Reports tab lists reports with the encounter filter. The print preview for a whole service request lists only final reports, with service_request and status=final.
  • The service request page takes its reports from the service request detail, not from the report list.

Other integrations​

  • Service request detail: GET /api/v1/facility/{facility_external_id}/service_request/{external_id}/ embeds a summary of every report of the request.
  • Referrals: a report can be attached to a referral as a resource of type diagnostic_report. The Care frontend's referral picker lists the patient's reports with no filter.
  • A report of another patient is refused with "Resource does not belong to the referral patient". A report already attached is refused with "Resource is already attached to this referral".
  • Report templates: templates for an encounter reach its reports through the encounter field "Diagnostic Reports". The encounter-based report types are "Discharge Summary" and "Encounter Report".
  • No report-template type exists for a single diagnostic report.
  • The "Diagnostic Reports" field includes every report of the encounter, whatever its status, unless the template filters by status.
  • For each report, a template can show "Title", "Status", "Category", "Observations", "Conclusion", "Notes", "Service Request" and "Uploaded Files". "Title" is the display of the report's code, and "Service Request" is the title of the service request.
  • For each observation, a template can show "Observation Title", "Observation Value", "Observation Component", "Observation Status", "Effective DateTime", "Interpretation" and "Reference Range". The data point does not filter out entered-in-error observations.
  • For each file, a template can show "Filename" and "File URL". Archived files are left out.
  • Printing one report in the Care frontend happens in the browser and uses no backend report template.