Questionnaire Response Template
A QuestionnaireResponseTemplate is a clinician's saved "favourite" or order set: a reusable, shareable bundle that pre-fills a questionnaire response along with its medication requests and activity definitions. Reach for it when building authoring shortcuts that seed several clinical resources from one named template.
The Django model stores the template; the Pydantic resource specs define the template_data payload, its validation, and the read/write API schemas.
Source:
Models
| Model | Purpose |
|---|---|
QuestionnaireResponseTemplate | A named template bundling pre-filled questionnaire answers, medication requests, and activity definitions, scoped to a facility/users/organizations |
QuestionnaireResponseTemplate extends EMRBaseModel, the shared Care EMR base that provides external_id, audit fields, soft-delete, and history/meta JSON.
QuestionnaireResponseTemplate fields
| Field | Type | Notes |
|---|---|---|
name | CharField(255) | Display name shown when picking a template |
description | TextField | default="" |
template_data | JSONField | default=dict. The structured payload; shape defined by TemplateData (see shape) |
facility | FK → Facility | CASCADE, nullable. Owning facility; instance-wide when null |
questionnaire | FK → Questionnaire | CASCADE, nullable, default=None. The questionnaire the template targets, if any |
facility_organizations | ArrayField[int] | default=list. Facility-organization ids the template is shared with |
users | ArrayField[int] | default=list. User ids the template is shared with |
available_keys | ArrayField[CharField(255)] | default=list. Platform-maintained: the populated top-level keys of template_data, recomputed on every write. Don't set it directly |
TemplateData shape
template_data is an opaque JSONField on the model; the spec (resources/questionnaire_response_template/spec.py) gives it this structure. Every section is optional, and available_keys records which ones a given template carries.
TemplateData {
medication_request: list[MedicationRequestTemplateSpec] | None
questionnaire: list[QuestionnaireAnswer] | None
activity_definition: list[ActivityDefinitionTemplateSpec] | None
meta: dict | None
}
QuestionnaireAnswer { question_id: str, answer: dict, meta: dict }
MedicationRequestTemplateSpec # extends the medication request write spec
+ requested_product: str | None # validated against ProductKnowledge.slug
ActivityDefinitionTemplateSpec {
slug: str # validated against ActivityDefinition.slug
service_request: ServiceRequestUpdateSpec
}
See Medication Request, Activity Definition, and Service Request for the embedded specs.
Resource specs (API schema)
All specs extend EMRResource (resources/base.py).
| Spec class | Role | Notes |
|---|---|---|
QuestionnaireResponseTemplateBaseSpec | shared | __model__ = QuestionnaireResponseTemplate; id (UUID4?), template_data (TemplateData), name, description (= "") |
QuestionnaireResponseTemplateCreateSpec | write · create | Adds questionnaire (slug str?), facility (UUID4?), users (list[str]), facility_organizations (list[UUID4]). Requires a facility whenever facility_organizations are given; resolves the questionnaire by slug and the facility by external id; recomputes available_keys |
QuestionnaireResponseTemplateUpdateSpec | write · update | users, facility_organizations; recomputes available_keys. Cannot change facility/questionnaire |
QuestionnaireResponseTemplateReadSpec | read · list | Adds created_date/modified_date |
QuestionnaireResponseTemplateRetrieveSpec | read · detail | Expands users (UserSpec via cache) and facility_organizations (FacilityOrganizationReadSpec), plus created_by/updated_by |
Validation and server-maintained behaviour
validate_facility(model_validator(after)on create) rejects facility organizations that have no facility.perform_extra_deserializationderivesavailable_keyson every create and update from thetemplate_datakeys whose value is non-empty. Clients don't set it.- Before save, the embedded
requested_productand activity-definitionslugare checked to exist againstProductKnowledgeandActivityDefinition.
API integration notes
- This is a Care-specific authoring convenience, not a FHIR resource, so it has no FHIR mapping.
facility,facility_organizations, anduserscontrol sharing. Leavefacilitynull for instance-wide templates.- Read
available_keysto learn which sections a template carries without parsingtemplate_data.
Related
- Reference: Questionnaire Response — what a template helps pre-fill
- Reference: Questionnaire
- Reference: Medication Request · Activity Definition · Service Request
- Source: questionnaire.py on GitHub