Product Knowledge
Technical reference for the ProductKnowledge module in Care EMR. For what Product Knowledge means to facility users, see the Product Knowledge concept.
ProductKnowledge is the reusable definition of a product: its coding, base unit, names, storage guidelines, and type-specific definition. Every Product references one ProductKnowledge record. A record is either instance-level (no facility) or scoped to one facility.
The Django model is only the storage layer: code, names, storage_guidelines, definitional, and base_unit are JSONFields whose structure lives in the Pydantic resource specs. The enums, nested shapes, and validation below come from those specs; the endpoints, scoping, and authorization come from the viewset.
Source:
- Model:
care/emr/models/product_knowledge.py - Spec:
care/emr/resources/inventory/product_knowledge/spec.py - Value sets:
care/emr/resources/inventory/product_knowledge/valueset.py - Viewset:
care/emr/api/viewsets/inventory/product_knowledge.py - Authorization:
care/security/authorization/product_knowledge.py - Permissions:
care/security/permissions/product_knowledge.py
Models
| Model | Purpose |
|---|---|
ProductKnowledge | Reusable definition of a product (medication, nutritional product, or consumable) |
ProductKnowledge extends SlugBaseModel, which extends EMRBaseModel. The shared base provides external_id, created_date, modified_date, and soft delete through deleted; EMRBaseModel adds created_by, updated_by, history, and meta.
SlugBaseModel sets FACILITY_SCOPED = True and adds the slug helpers calculate_slug_from_facility, calculate_slug_from_instance, and parse_slug. It defines no save(): the viewset prefixes the slug on create and update (see Slug prefixing).
ProductKnowledge fields
Identity & scope
| Field | Type | Notes |
|---|---|---|
facility | FK → facility.Facility | PROTECT, nullable. Null means instance-level; set means facility-scoped. In the spec base's __exclude__; only ProductKnowledgeWriteSpec (create) sets it, so an update cannot move a record to another facility. Surfaced on read as is_instance_level |
slug | CharField(255) | Stores the full prefixed slug: f-<facility external_id>-<slug_value> or i-<slug_value>. The viewset sets it from slug_value on create and update. The API's lookup field |
alternate_identifier | CharField(255), nullable | Secondary identifier. The UI labels it "HSN Code" |
status | CharField(255) | Spec-constrained to ProductKnowledgeStatusOptions (required) |
product_type | CharField(255) | Spec-constrained to ProductTypeOptions (required) |
category | FK → emr.ResourceCategory | PROTECT, nullable. Classifies the record into a resource category. Written as a category slug string; read returns the serialized category |
Naming
| Field | Type | Notes |
|---|---|---|
name | CharField(255) | Primary display name (required in spec) |
names | JSONField (list), nullable | list[ProductName] | None. See ProductName |
names_cache | CharField(2048), nullable | name plus every names[].name, space-joined, rebuilt on each save() by set_names_cache(). Searched by the alternate_names filter. In no spec; never set it from clients |
Coding & definition (JSON fields)
The model stores these as nullable JSONFields; the spec enforces the shapes below.
| Field | Model type | Spec type / shape | Notes |
|---|---|---|---|
code | JSONField (dict) | Coding | None | Optional product code as a Coding; not value-set bound at the spec layer. The UI searches system-medication for it |
base_unit | JSONField (dict) | ValueSetBoundCoding[CARE_UCUM_UNITS] | Required. Bound to the UCUM units value set (system-ucum-units). The UI offers a fixed list of eight units |
names | JSONField (list) | list[ProductName] | None | See ProductName |
storage_guidelines | JSONField (list) | list[StorageGuideline] | None | See StorageGuideline |
definitional | JSONField (dict) | ProductDefinitionSpec | None | See ProductDefinitionSpec. The spec does not tie its contents to product_type |
Enums
ProductTypeOptions (product_type)
| Value | UI label |
|---|---|
medication | Medication |
nutritional_product | Nutritional Product |
consumable | None: the locale files have no consumable key, so the UI shows the raw word "consumable" |
ProductKnowledgeStatusOptions (status)
| Value | Notes |
|---|---|
draft | Offered by the UI form as "Draft" |
active | Offered by the UI form as "Active"; the UI's default for new records. The UI's product knowledge pickers list only active records |
retired | Offered by the UI form as "Retired"; set by the UI's "Delete" action |
unknown | Accepted by the API; the UI form does not offer it |
ProductNameTypes (names[].name_type)
| Value | UI label |
|---|---|
trade_name | Trade Name (the UI's default) |
alias | Alias |
original_name | Original Name |
preferred | Preferred |
DrugCharacteristicCode (definitional.drug_characteristic[].code)
API only: the UI form has no field for drug characteristics.
| Value |
|---|
imprint_code |
size |
shape |
color |
coating |
scoring |
logo |
image |
Nested spec shapes
These are plain Pydantic BaseModels in spec.py. Every field listed as required has no default.
ProductName
names[]: alternate names for the product.
| Field | Type | Required | Notes |
|---|---|---|---|
name_type | ProductNameTypes | yes | Enum, see above |
name | str | yes |
StorageGuideline
storage_guidelines[]: a storage note paired with a stability duration.
| Field | Type | Required | Notes |
|---|---|---|---|
note | str | yes | |
stability_duration | DurationSpec = value: int, unit: Coding | yes | value is a whole number; unit is a free Coding. The UI offers minutes, hours, days, weeks, months, and years |
ProductDefinitionSpec
definitional: the dosage form, routes, ingredients, nutrients, and drug characteristics. The 3.1 UI form edits only dosage_form and intended_routes; the other three lists are set through the API only.
| Field | Type | Default | Notes |
|---|---|---|---|
dosage_form | ValueSetBoundCoding[MEDICATION_FORM_CODES] | None | required (nullable) | Bound to medication form codes (system-medication-form-codes, SNOMED is-a 736542009) |
intended_routes | list[Coding] | [] | Free Codings, not value-set bound. The UI picks them from system-route |
ingredients | list[ProductIngredient] | [] | See ProductIngredient |
nutrients | list[ProductNutrient] | [] | See ProductNutrient |
drug_characteristic | list[DrugCharacteristic] | [] | See DrugCharacteristic |
ProductIngredient
definitional.ingredients[].
| Field | Type | Required | Notes |
|---|---|---|---|
is_active | bool | yes | Active or inactive ingredient |
substance | ValueSetBoundCoding[CARE_SUBSTANCE_VALUSET] | yes | Bound to the substance value set (system-substance, SNOMED is-a 105590001) |
strength | ProductStrength | yes | See ProductStrength |
ProductNutrient
definitional.nutrients[].
| Field | Type | Required | Notes |
|---|---|---|---|
item | ValueSetBoundCoding[CARE_NUTRIENTS_VALUESET] | yes | Bound to the nutrients value set (system-nutrients, SNOMED is-a 226355009) |
amount | ProductStrength | yes | See ProductStrength |
ProductStrength
Shared by ProductIngredient.strength and ProductNutrient.amount.
| Field | Type | Required | Notes |
|---|---|---|---|
ratio | Ratio = numerator: Quantity, denominator: Quantity | yes | |
quantity | Quantity | yes | See Quantity |
DrugCharacteristic
definitional.drug_characteristic[].
| Field | Type | Required | Notes |
|---|---|---|---|
code | DrugCharacteristicCode | yes | Enum, see above |
value | str | yes |
Shared common types
Coding
From care/emr/resources/common/coding.py (extra="forbid").
| Field | Type | Required |
|---|---|---|
system | str | None | no |
version | str | None | no |
code | str | yes |
display | str | None | no |
A ValueSetBoundCoding[<slug>] is a Coding whose code is validated against the named value set on input.
Quantity
From care/emr/resources/common/quantity.py (extra="forbid").
| Field | Type | Notes |
|---|---|---|
value | Decimal | None | At most 20 digits, 6 decimal places |
unit | Coding | None | Human-readable form of the unit |
code | Coding | None | Computer-processable form of the unit |
meta | dict | None |
Ratio has numerator: Quantity and denominator: Quantity, both required.
Related models
| Model | Field | Relationship |
|---|---|---|
Product | product_knowledge | Required FK to ProductKnowledge, PROTECT. Every product references one record |
InventoryItem | product | Required FK to Product, PROTECT; reaches ProductKnowledge only through the product |
SupplyRequest | item | FK to ProductKnowledge, CASCADE |
MedicationRequest | requested_product | Optional FK to ProductKnowledge, SET_NULL |
MedicationAdministration | administered_product | Optional FK to ProductKnowledge, CASCADE |
Resource specs (API schema)
Every spec builds on EMRResource (care/emr/resources/base.py).
| Spec class | Role | Adds / behaviour |
|---|---|---|
BaseProductKnowledgeSpec | shared base | __exclude__ = ["facility"]. Fields: id, alternate_identifier, status, product_type, code, base_unit (required, UCUM-bound), name, names, storage_guidelines, definitional |
ProductKnowledgeUpdateSpec | write · update | Adds category: str | None (resource category slug) and slug_value: SlugType (required). On deserialize, resolves category with ResourceCategory.objects.get(slug=...) and sets obj.slug = slug_value |
ProductKnowledgeWriteSpec | write · create | Extends the update spec; adds facility: UUID4 | None. On deserialize, runs the update-spec logic, then resolves facility by external id |
ProductKnowledgeReadSpec | read · list and detail | Adds is_instance_level (true when there is no facility), category (serialized resource category), slug_config (the parsed slug: facility and slug_value, or slug_value only), and slug |
Validation & bound value sets
status,product_type,base_unit, andnameare required.base_unitis bound tosystem-ucum-units.definitional.dosage_formis bound tosystem-medication-form-codes,ingredients[].substancetosystem-substance, andnutrients[].itemtosystem-nutrients.codeandintended_routesstay freeCodings.slug_valueusesSlugType: 5–50 characters, starting and ending with a letter or digit, and containing only letters, digits,-, and_.- Create and update reject a slug that already exists in the same scope (the same facility, or instance level), compared without case, with the validation error "Slug already exists.".
- For a facility record, the viewset returns 404 for an unknown
categoryslug.
Server-maintained behaviour
facilityis set only on create, fromProductKnowledgeWriteSpec.facility.- The viewset prefixes
slugon create and update; the model rebuildsnames_cacheinsave(). is_instance_level,slug_config, and the serializedcategoryare computed on read; none of them is a stored column.
Methods & save behaviour
save() side effects
save() calls set_names_cache() before it writes the record:
names_cacheis reset to"<name> ".- The
nameof each entry innamesis appended, separated by spaces. super().save()writes the record.
names_cache is platform-maintained: write name and names instead.
Slug prefixing
ProductKnowledgeViewSet.recalculate_slug() runs in perform_create and perform_update. It stores f-<facility external_id>-<slug_value> for a facility record and i-<slug_value> for an instance-level record. SlugBaseModel has no save() of its own.
API integration notes
Endpoints
The API is registered at /api/v1/product_knowledge/, not nested under a facility. Records are addressed by slug, the full prefixed slug.
| Method and path | Action | Notes |
|---|---|---|
GET /api/v1/product_knowledge/ | list | See filters and scoping below |
POST /api/v1/product_knowledge/ | create | Body: ProductKnowledgeWriteSpec |
GET /api/v1/product_knowledge/<slug>/ | retrieve | Returns ProductKnowledgeReadSpec |
PUT /api/v1/product_knowledge/<slug>/ | update | Body: ProductKnowledgeUpdateSpec. The UI sends PUT |
POST /api/v1/product_knowledge/upsert/ | upsert | Body: a datapoints list. A datapoint with id (the slug) updates that record; one without id creates a record. If any datapoint fails, the batch is rolled back and the response is 400 with the per-datapoint results |
GET /api/v1/product_knowledge/favorite_lists/ | favorites | The caller's favorite list names |
POST /api/v1/product_knowledge/<slug>/add_favorite/ | favorites | Body: optional favorite_list |
POST /api/v1/product_knowledge/<slug>/remove_favorite/ | favorites | Body: optional favorite_list |
There is no delete endpoint. The UI's "Delete" action sends a PUT that sets status to retired.
Filters and ordering
| Parameter | Behaviour |
|---|---|
facility | Scopes the list to one facility. See scoping below |
include_instance | With facility: true adds instance-level records |
category | A category slug, looked up in the same facility. With include_children=true, records in descendant categories are also returned |
status, product_type, alternate_identifier | Exact match, case-insensitive |
name, alternate_names | Trigram similarity above 0.1 on name or names_cache, ordered by similarity |
facility_is_null | Null filter on facility |
ordering | created_date or modified_date |
Scoping and authorization
- List with
facility: requirescan_read_product_knowledgein any organization of that facility. Returns that facility's records, plus instance-level records wheninclude_instance=true. - List without
facility: returns only instance-level records, with no permission check. - Retrieve a facility record: requires
can_read_product_knowledgein any organization of its facility; otherwise 403 "Cannot read product knowledge". Retrieving an instance-level record has no permission check. - Create a facility record: requires
can_write_product_knowledgein the facility's root organization (named "Administration"); otherwise 403 "Cannot create product knowledge". A role holding the permission in another department of the facility is refused. - Update a facility record: requires
can_write_product_knowledgein the root organization of the record's facility; otherwise 403 "Cannot update product knowledge". - Instance-level records cannot be created or updated through facility permissions.
- Only facility-organization memberships count; governance-organization memberships are not consulted.
- The frontend's list calls send
include_instance=trueby default, so pickers that do not override it also list instance-level records.
| Permission | Display name | Checked in | Default roles |
|---|---|---|---|
can_write_product_knowledge | Can Create Product Knowledge on Facility | The facility's root organization | Facility Admin |
can_read_product_knowledge | Can Read Product Knowledge | Any organization of the facility | Facility Admin, Administrator, Staff, Doctor, Nurse, Volunteer, Pharmacist |
Authorization reads role permissions from the database. Each permission sync rewrites the default roles from code; custom roles can also hold these permissions.
UI notes
- The UI labels
alternate_identifier"HSN Code". - The UI creates records only inside a category with no subcategories, and always sends the current
facility. - The 3.1 UI form has no fields for
ingredients,nutrients, ordrug_characteristic. - The UI's create form opens with the
definitionalblock added, and requiresdosage_formuntil the user removes the block.
Related
- Concept: Product Knowledge
- Reference: Product
- Reference: Inventory Item
- Reference: Supply Request
- Reference: Medication Request
- Reference: Medication Administration
- Reference: Resource Category
- Reference: Favorites
- Base: Base model
- Source: model · spec · value sets · viewset