Skip to main content
Version: 3.1

Patient

Technical reference for the Patient module in Care EMR. For a product-oriented overview, see the Patient concept.

Source: care/emr/models/patient.py

Models

ModelPurpose
PatientCore patient record
PatientOrganizationLinks a patient to an Organization
PatientUserGrants a User access to a patient with a RoleModel
PatientIdentifierConfigDefines identifier types (instance-wide or per-facility)
PatientIdentifierStores an identifier value for a patient

All models extend EMRBaseModel (shared Care EMR base with external_id, audit fields, and soft-delete semantics).

Patient fields

Demographics

FieldTypeNotes
nameCharField(200)Display name
genderCharField(35)Administrative gender
date_of_birthDateFieldNullable; preferred when known
year_of_birthIntegerFieldMin 1900; used when full DOB is unknown. Auto-set from date_of_birth on save
deceased_datetimeDateTimeFieldSet when patient is marked deceased; affects age calculation
blood_groupCharField(16)

Contact & address

FieldTypeNotes
phone_numberCharField(14)Validated with mobile_or_landline_number_validator
emergency_phone_numberCharField(14)Same validator
addressTextFieldCurrent address
permanent_addressTextField
pincodeIntegerFieldNullable

Organization & access caches

These are denormalized caches rebuilt on every Patient.save() for fast filtering without deep joins.

FieldTypeRebuilt by
geo_organizationFK → OrganizationGeographic/administrative org assignment
organization_cacheArrayField[int]rebuild_organization_cache() — includes geo_organization parent chain and all linked PatientOrganization orgs
users_cacheArrayField[int]rebuild_users_cache() — user IDs from PatientUser rows

Identifiers & tags

FieldTypeNotes
instance_identifiersJSONFieldList of {config, value} built from PatientIdentifier rows (instance-scoped configs)
facility_identifiersJSONFieldDict keyed by facility_id → list of {config, value}
instance_tagsArrayField[int]Instance-level tag IDs
facility_tagsJSONFieldDict keyed by facility → tag IDs
extensionsJSONFieldOpen extension bag for deployment-specific metadata

Identifier values live in PatientIdentifier and are materialized into the JSON caches via build_instance_identifiers() and build_facility_identifiers(facility_id).

PatientOrganization

patient → FK Patient
organization → FK Organization

Saving a PatientOrganization triggers patient.save(), which rebuilds organization_cache.

PatientUser

Grants a Care user access to a patient record.

user → FK User
patient → FK Patient
role → FK RoleModel (PROTECT)

Saving a PatientUser triggers patient.save(), which rebuilds users_cache.

PatientIdentifier / PatientIdentifierConfig

PatientIdentifierConfig defines what identifiers exist (status, optional facility scope, JSON config). PatientIdentifier stores the actual value:

patient → FK Patient
config → FK PatientIdentifierConfig
facility → FK Facility (nullable)
value → CharField(1024), indexed

PatientIdentifierConfigCache provides in-process caching for configs (get_instance_config(), get_facility_config(facility_id)).

Methods & save behaviour

Age

  • get_age() → str — human-readable age (years, months, days) relative to deceased_datetime or now
  • age → int — whole years only

Both use date_of_birth when present, otherwise year_of_birth (January 1).

save() side effects

On every save:

  1. If date_of_birth is set and year_of_birth is empty → year_of_birth is derived
  2. rebuild_organization_cache() runs
  3. rebuild_users_cache() runs
  4. A second save(update_fields=["organization_cache", "users_cache"]) persists the caches

Integrators should expect two write passes when creating or updating patients through the ORM.

API integration notes

  • Patient records are exposed through Care's REST API and FHIR Patient resources; field names in API payloads may differ from Django model names.
  • Use instance_identifiers / facility_identifiers JSON for read-optimized identifier lookup; write through PatientIdentifier for consistency.
  • extensions is the supported place for custom key-value data without schema migrations.
  • users_cache and organization_cache are maintained by the platform — do not set them directly from clients.