References/Resource Request: Difference between revisions
More languages
More actions
OHC identity seed |
Add Navbox platform (via update-page on MediaWiki MCP Server) |
||
| Line 230: | Line 230: | ||
* Send <code>referring_facility_contact_number</code> in a format <code>mobile_or_landline_number_validator</code> accepts. |
* Send <code>referring_facility_contact_number</code> in a format <code>mobile_or_landline_number_validator</code> accepts. |
||
* <code>related_patient</code> cascades on patient deletion. <code>origin_facility</code> is <code>PROTECT</code>-ed, so it can't be deleted while requests reference it or changed once the request exists. |
* <code>related_patient</code> cascades on patient deletion. <code>origin_facility</code> is <code>PROTECT</code>-ed, so it can't be deleted while requests reference it or changed once the request exists. |
||
{{Navbox platform}} |
|||
{{Related}} |
{{Related}} |
||
Latest revision as of 09:54, 6 July 2026
ResourceRequest represents an inter-facility request for a resource (transfer, supply, or assistance) and tracks it from the originating facility through approval and assignment. You touch it whenever a facility needs something another facility can provide.
The Django model is only storage: status, category, and priority are open CharField/IntegerField columns with no model-level choices. The Pydantic resource specs give the fields their shape — pinning them to enums, running validation, resolving foreign keys, and splitting the read and write schemas.
Sources:
- Model: [https://github.com/ohcnetwork/care/blob/develop/care/emr/models/resource_request.py
care/emr/models/resource_request.py] - Spec: [https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/resource_request/spec.py
care/emr/resources/resource_request/spec.py]
Models
| Model | Purpose |
|---|---|
ResourceRequest
|
An inter-facility request for a resource (transfer, supply, or assistance), tracked from origin through approval and assignment |
ResourceRequestComment
|
A free-text comment thread entry attached to a ResourceRequest
|
Both extend EMRBaseModel, the shared Care EMR base that adds external_id, audit fields (created_by, updated_by, created_date, modified_date), and soft-delete semantics.
ResourceRequest fields
Facilities
| Field | Type | Notes |
|---|---|---|
origin_facility |
FK → Facility (PROTECT) |
Required. The facility raising the request. Set once on create (when is_update is false) and never reassigned. related_name="resource_requesting_facilities".
|
approving_facility |
FK → Facility (SET_NULL) |
Nullable. The facility responsible for approving. related_name="resource_approving_facilities".
|
assigned_facility |
FK → Facility (SET_NULL) |
Nullable. The facility the request is assigned to or fulfilled by. Required when assigned_to is set. related_name="resource_assigned_facilities".
|
Request details
| Field | Type | Required | Default | Notes |
|---|---|---|---|---|
emergency |
bool (BooleanField) |
Yes (spec) | ||
title |
str (CharField(255)) |
Yes | ||
reason |
str (TextField) |
Yes (spec) | ||
status |
StatusChoices enum (CharField(100)) |
Yes | ||
category |
CategoryChoices enum (CharField(100)) |
Yes | ||
priority |
int (IntegerField) |
Yes (spec) |
Referring contact
| Field | Type | Required | Default | Notes |
|---|---|---|---|---|
referring_facility_contact_name |
str (TextField) |
Yes (spec) | ||
referring_facility_contact_number |
str (CharField(14)) |
Yes (spec) |
Assignment & patient
| Field | Type | Notes |
|---|---|---|
is_assigned_to_user |
bool (BooleanField) |
Defaults to False; signals that a user-level assignment exists. The spec classes never expose it.
{{Field|model=ResourceRequest|section=Assignment & patient|name=assigned_to|type=FK → User (SET_NULL)|notes=Nullable. The user the request is assigned to. Requires |
related_patient |
FK → Patient (CASCADE) |
Nullable, defaults to None. Links the request to a patient where one applies. Set only on create.
|
Enum values
The spec layer pins status and category to string enums defined in spec.py. The Django columns are plain CharFields, so these values hold only through the API — anything written directly to the database bypasses them.
StatusChoices values
| Value |
|---|
pending
|
approved
|
rejected
|
cancelled
|
transportation_to_be_arranged
|
transfer_in_progress
|
completed
|
CategoryChoices values
| Value |
|---|
patient_care
|
comfort_devices
|
medicines
|
financial
|
supplies
|
other
|
Resource specs (API schema)
Every spec builds on EMRResource ([https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py base.py]), which supplies serialize (DB object → pydantic, the read path) and de_serialize (pydantic → DB object, the write path), plus the perform_extra_serialization / perform_extra_deserialization hooks. __exclude__ names the fields the base (de)serializer skips, leaving them to be handled by hand — FK resolution, for instance.
ResourceRequest specs
| Spec | Role | Fields beyond base |
|---|---|---|
ResourceRequestBaseSpec
|
shared | id, emergency, title, reason, referring_facility_contact_name, referring_facility_contact_number, status, category, priority. __exclude__s the five FK fields (origin_facility, approving_facility, assigned_facility, related_patient, assigned_to).
|
ResourceRequestCreateSpec
|
write · create & update | Adds the FKs as UUID4 external ids: origin_facility (required), approving_facility, assigned_facility, related_patient, assigned_to (all optional). Resolves each external id to a DB object in perform_extra_deserialization.
|
ResourceRequestListSpec
|
read · list | None, created_date, modified_date. Inlines origin_facility/assigned_facility via FacilityReadSpec.
|
ResourceRequestRetrieveSpec
|
read · detail | Everything in List plus approving_facility, related_patient (via PatientListSpec), assigned_to (via UserSpec, cache-backed), created_by, updated_by.
|
There is no separate UpdateSpec. ResourceRequestCreateSpec covers both create and update, branching on the is_update flag.
Validation
validate_assigned_to_user(model validator,mode="after"): onceassigned_tois set,assigned_facilitybecomes required, and the assigned user must be a member of that facility (checked viaFacilityOrganizationUser). Either gap raisesValueError.
Server-side behaviour (perform_extra_deserialization)
origin_facilityexternal id →Facilityobject, only on create (is_updatefalse). It is never reassigned on update.approving_facility,assigned_facility,assigned_toexternal ids → their DB objects whenever present, on create or update.related_patientexternal id →Patientobject, only on create.- Every lookup uses
get_object_or_404onexternal_id, so an unknown id returns 404.
Read serialization (perform_extra_serialization)
idis emitted as the stringexternal_id.origin_facility(andassigned_facility,approving_facilitywhere present) are inlined viaFacilityReadSpec.related_patientviaPatientListSpec;assigned_toviaUserSpec, resolved from cache (model_from_cachekeyed onassigned_to_id).created_by/updated_bycome fromserialize_audit_users.
ResourceRequestComment specs
| Spec | Role | Fields beyond base |
|---|---|---|
ResourceRequestCommentBaseSpec
|
shared | comment: str. __exclude__s request.
|
ResourceRequestCommentCreateSpec
|
write · create | No extra fields — the parent ResourceRequest is bound from the URL, not the body.
|
ResourceRequestCommentListSpec
|
read · list | Adds created_by, created_date; populates created_by via serialize_audit_users.
|
ResourceRequestCommentRetrieveSpec
|
read · detail | Subclasses ResourceRequestCommentListSpec with no changes.
|
Related models
ResourceRequestComment
A comment entry on a resource request. The FK uses PROTECT, so deleting a comment leaves the request untouched.
request → FK ResourceRequest (PROTECT, required)
comment → TextField (default "")
Methods & save behaviour
- Read path:
<Spec>.serialize(obj)copies model fields, runsperform_extra_serialization(FK inlining, audit users,idas string), and builds the pydantic instance without re-validation (model_construct). - Write path:
<Spec>.de_serialize()writes scalar fields onto the model (model_dump(exclude_defaults=True)), thenperform_extra_deserializationresolves FK external ids and enforces the create-only constraints onorigin_facility/related_patient. statusandcategorykeep nostatus_historyhere; a transition overwrites the column directly.
API integration notes
ResourceRequestandResourceRequestCommentare served through Care's REST API. Write bodies use theCreateSpecschema; reads useListSpec/RetrieveSpec.- Foreign keys travel as
external_idUUIDs in write payloads and come back as nested objects (FacilityReadSpec,PatientListSpec,UserSpec) in read payloads. - Only
StatusChoices/CategoryChoicesvalues clear validation forstatus/category, andprioritymust be an integer — even though all three columns are looser in the database. - Assigning to a user requires
assigned_facility, with the user a member of that facility. - Send
referring_facility_contact_numberin a formatmobile_or_landline_number_validatoraccepts. related_patientcascades on patient deletion.origin_facilityisPROTECT-ed, so it can't be deleted while requests reference it or changed once the request exists.
Related
- Reference: References/Base models & conventions