Skip to main content

Define extension fields

Extension fields are extra fields that a deployment adds to some Care records, such as patients, accounts and supply deliveries. You describe them on the backend with JSON Schema, and the frontend shows the fields on the matching screens.

Staff see these fields as additional fields. For the user view, see Additional fields.

There is no screen for defining them. Use one of these two ways:

  • Set CORE_EXTENSIONS_<RESOURCE>_WRITE, and if needed _READ and _RETRIEVE, in the backend environment.
  • Install a backend plug that registers a PlugExtension.

Resources that take extension fields​

Nine resources take extension fields, and each of their models stores the values in an extensions JSON field. The Care 3.1 frontend knows only seven of them: it does not know facility and resource_request.

ResourceVariable prefixScreens in 3.1
patientCORE_EXTENSIONS_PATIENT_Registration and edit form, patient profile, appointment token card (printed only), appointment print
accountCORE_EXTENSIONS_ACCOUNT_Account sheet
payment_reconciliationCORE_EXTENSIONS_PAYMENT_RECONCILIATION_Payment sheet
supply_delivery_orderCORE_EXTENSIONS_SUPPLY_DELIVERY_ORDER_Delivery order form, delivery order page, delivery order print
supply_deliveryCORE_EXTENSIONS_SUPPLY_DELIVERY_Add supply delivery form, supply deliveries table
encounterCORE_EXTENSIONS_ENCOUNTER_None
productCORE_EXTENSIONS_PRODUCT_None
facilityCORE_EXTENSIONS_FACILITY_None
resource_requestCORE_EXTENSIONS_RESOURCE_REQUEST_None

Set the environment variables​

Care registers a core extension for every resource, so every resource can get fields from the environment.

The core extension reads its schemas from CORE_EXTENSIONS_<RESOURCE>_<ACTION>, with the resource name in upper case and ACTION one of WRITE, READ or RETRIEVE. For example, CORE_EXTENSIONS_PATIENT_WRITE.

VariableWhat it is forIf it is not set
..._WRITECare validates submitted values against it. The patient registration and edit form builds its fields from it.The schema is empty.
..._READPublished as read_schema. The supply deliveries table uses it.Care uses the WRITE schema.
..._RETRIEVEPublished as retrieve_schema. The patient profile and the delivery order page use it.Care uses the READ schema, and so the WRITE schema if READ is not set.

The schemas apply to the whole instance. Nothing in them is per facility.

warning

Each value must be valid JSON. If it is not, Care raises "Invalid JSON" each time it reads that schema. Check the JSON before you set the variable.

Example​

This minimal example is for illustration only. It adds one optional text field, employer, to patients. The field uses the textarea control and is left off the printed appointment token card and the appointment print.

CORE_EXTENSIONS_PATIENT_WRITE='{"type": "object", "properties": {"employer": {"type": "string", "x-ui": {"control": "textarea", "render_blacklist": ["appointment_print"]}}}}'

With CORE_EXTENSIONS_PATIENT_READ and CORE_EXTENSIONS_PATIENT_RETRIEVE not set, Care uses this schema for both. Care stores the value at extensions.core.employer.

How values are validated and stored​

The core extension validates submitted values against the WRITE schema with jsonschema. If the values do not match, Care rejects the request with "Invalid extensions".

Care stores values under the name of the extension that owns them: extensions.core.<field> for fields from the environment, and extensions.<extension name>.<field> for fields from a plug.

Top-level keys under extensions that match no registered extension are dropped without an error.

An update that sends extensions: {} does not erase stored values, because the backend skips fields that equal their default when it writes.

Add UI hints with x-ui​

A field can carry an x-ui object with hints for the frontend: control, render_blacklist and placement.after.

control​

x-ui.control accepts these values: page, section, grid, table, list, textbox, textarea, dropdown, radio, checkbox, switch, date, datetime and autocomplete.

ValuesWhat the frontend does
section, grid, table (for arrays), autocomplete, switch, radio, textarea, checkbox, date, datetimeRenders the field with that control
Any other valueFalls back to the JSON type. A field with enum or titled oneOf options is a drop-down, and a string is a text box.
page, listNo special rendering

render_blacklist​

x-ui.render_blacklist lists the contexts where the field must not show. A field with no list shows in every context. Fields with const and hidden fields ignore the list.

ContextScreen
registrationPatient registration and edit form, at the end of section "2: Additional Details" (WRITE schema)
patient_editNo screen uses it
appointment_printAppointment token card (printed copy only) and appointment print ("Appointment Details")
patient_summaryPatient profile, section "Additional Details" (RETRIEVE schema)
account_formAccount sheet ("Create Account" and "Edit Account")
payment_reconciliation_formPayment sheet ("Collect Payment" or "Record Credit Note")
supply_delivery_order_formDelivery order form
supply_delivery_order_summaryDelivery order page details card, and delivery order print (RETRIEVE schema)
supply_delivery_formAdd supply delivery form, items table
supply_delivery_tableSupply deliveries table on the delivery order page (READ schema)
caution

The patient form passes registration both when it registers a patient and when it edits one. If you hide a field from registration, it is hidden on edit too.

placement.after​

x-ui.placement.after places a field right after a named element of the screen. Anchors exist only for supply_delivery: product, batch, expiry, category, requested_quantity, pack_size, pack_quantity, quantity, date, sale, purchase, tax, discount, status and condition. Fields without placement stay in the screen's default block.

Where the fields show in 3.1​

ResourceScreenWhere the fields show
patientPatient registration and edit formAt the end of section "2: Additional Details"
patientPatient profileIn a section headed "Additional Details", which holds only extension values and shows only when at least one value is filled
patientAppointment token cardOnly on the printed card, not on screen
patientAppointment print ("Appointment Details")As rows right after the "Patient" row
accountAccount sheet ("Create Account" and "Edit Account")At the end of the form, filled in on edit
payment_reconciliationPayment sheet ("Collect Payment" or "Record Credit Note")At the end of the form, after "Notes"
supply_delivery_orderDelivery order formAfter "Tags"
supply_delivery_orderDelivery order pageFilled values, with their labels, in the details card
supply_delivery_orderDelivery order printFilled values in the details block at the top, alternating between the left and right columns
supply_deliveryAdd supply delivery formAs extra columns in the items table, after their anchor column or at the end. Required fields have a red asterisk.
supply_deliverySupply deliveries table on the delivery order pageAs extra columns, after their anchor or at the end. An empty value shows "-".

These resources have extension fields but no screen in 3.1: encounter, product, facility and resource_request. The product form always sends extensions: {}, which does not erase stored values. Medication returns also always send empty supply delivery extensions.

The facility and resource request APIs still take extension values on create and return them on list and detail.

Report templates can print patient and encounter extensions, as "Patient Extensions" and "Encounter Extensions".

Add fields from a plug​

A backend plug adds fields by subclassing PlugExtension, whose owner is "plug", and registering it with ExtensionRegistry.register. Registration needs a resource type and an extension name.

PlugExtension does no validation unless the plug overrides validate.

Care stores the plug's values under extensions.<extension name>.

For how to install a plug, see Install apps.

Check what Care loaded​

GET /api/v1/extensions/ returns, for each resource, the registered extensions with their name, owner, version, write_schema, read_schema and retrieve_schema. It is read-only.

Any signed-in user can call it.

The frontend reads this list once and keeps it for 24 hours. Production builds also keep it in the browser's local storage, which is cleared at staff sign-in and when a new frontend version is deployed.

So after you change a schema, users see the new fields when they sign in again, or within 24 hours.