<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ohcnwiki.tellmey.fyi/index.php?action=history&amp;feed=atom&amp;title=References%2FMedication_Dispense</id>
	<title>References/Medication Dispense - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ohcnwiki.tellmey.fyi/index.php?action=history&amp;feed=atom&amp;title=References%2FMedication_Dispense"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Medication_Dispense&amp;action=history"/>
	<updated>2026-07-06T07:10:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.4</generator>
	<entry>
		<id>https://ohcnwiki.tellmey.fyi/index.php?title=References/Medication_Dispense&amp;diff=446&amp;oldid=prev</id>
		<title>Admin: Automated edit (via update-page on MediaWiki MCP Server)</title>
		<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Medication_Dispense&amp;diff=446&amp;oldid=prev"/>
		<updated>2026-07-06T04:15:52Z</updated>

		<summary type="html">&lt;p&gt;Automated edit (via update-page on MediaWiki MCP Server)&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:45, 6 July 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 529:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 529:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Set &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; to roll the linked [[References/Medication Request]] into &amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;partial&amp;lt;/code&amp;gt;, so pharmacists don&#039;t re-dispense an already-fulfilled request.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Set &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; to roll the linked [[References/Medication Request]] into &amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;partial&amp;lt;/code&amp;gt;, so pharmacists don&#039;t re-dispense an already-fulfilled request.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Use &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt; to start an order inline, or &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt; to attach to an existing one — never both.&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Use &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt; to start an order inline, or &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt; to attach to an existing one — never both.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Navbox medications}}&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Related}}&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Related}}&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://ohcnwiki.tellmey.fyi/index.php?title=References/Medication_Dispense&amp;diff=164&amp;oldid=prev</id>
		<title>Admin: OHC identity seed</title>
		<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Medication_Dispense&amp;diff=164&amp;oldid=prev"/>
		<updated>2026-07-04T22:45:20Z</updated>

		<summary type="html">&lt;p&gt;OHC identity seed&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Doc header&lt;br /&gt;
|type=reference&lt;br /&gt;
|domain=medications&lt;br /&gt;
|title=Medication Dispense&lt;br /&gt;
|order=3&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|model=MedicationDispense&lt;br /&gt;
|reference=References/Base models &amp;amp;amp; conventions&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt; records products handed to a patient and draws down the location&amp;#039;s inventory as it does so. It closes out the workflow a [[References/Medication Request]] opens: in inpatient settings, items are dispensed into the room and refilled as needed; in outpatient settings, they go out once an encounter completes. A dispense can carry a [[References/Charge Item]] for billing.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Source:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* Model: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/models/medication_dispense.py &amp;lt;code&amp;gt;care/emr/models/medication_dispense.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Spec: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/medication/dispense/spec.py &amp;lt;code&amp;gt;care/emr/resources/medication/dispense/spec.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Spec: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/medication/dispense/dispense_order.py &amp;lt;code&amp;gt;care/emr/resources/medication/dispense/dispense_order.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Viewset: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/api/viewsets/medication_dispense.py &amp;lt;code&amp;gt;care/emr/api/viewsets/medication_dispense.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
The Django model is the storage layer; several of its fields are opaque &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;s. The Pydantic resource specs under &amp;lt;code&amp;gt;care/emr/resources/medication/dispense/&amp;lt;/code&amp;gt; define the API schema — enums, JSON-field shapes, validation, and the read/write contracts. Where the two disagree, the spec wins: &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt; stores underscored enum values like &amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt;, not the FHIR hyphenated forms.&lt;br /&gt;
&lt;br /&gt;
== Models ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Model&lt;br /&gt;
! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt;&lt;br /&gt;
| A single dispense event: a quantity of one inventory item handed to a patient&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;DispenseOrder&amp;lt;/code&amp;gt;&lt;br /&gt;
| Groups dispense events at a location into a named order with a shared status&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Both extend [[References/Base models &amp;amp;amp; conventions|&amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;]], which supplies &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, audit fields, and soft-delete semantics.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
=== Status &amp;amp;amp; classification ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Model type&lt;br /&gt;
! Spec type&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CharField(100)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseStatus&amp;lt;/code&amp;gt;&lt;br /&gt;
| Required. See [[#medicationdispensestatus-values&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;not_performed_reason&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CharField(100)&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseNotPerformedReason | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| Coded reason a dispense was not performed. See [[#medicationdispensenotperformedreason-values&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;category&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CharField(100)&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseCategory | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| Setting the dispense happened in. See [[#medicationdispensecategory-values&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Timing &amp;amp;amp; instructions ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Model type&lt;br /&gt;
! Spec type&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;when_prepared&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DateTimeField&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;datetime | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| When the product was prepared&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;when_handed_over&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DateTimeField&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;datetime | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| When the product was handed to the patient&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;note&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TextField&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| Free-text annotation&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;dosage_instruction&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;)&lt;br /&gt;
| &amp;lt;code&amp;gt;list[DosageInstruction]&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt;)&lt;br /&gt;
| Structured dosage directions. See [[#dosageinstruction-shape&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;substitution&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;)&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseSubstitution | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| Substitution record. See [[#medicationdispensesubstitution-shape&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Quantities ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Model type&lt;br /&gt;
! Spec type&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;quantity&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DecimalField(20, 6)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;Decimal&amp;lt;/code&amp;gt; (write: &amp;lt;code&amp;gt;max_digits=20, decimal_places=0&amp;lt;/code&amp;gt;)&lt;br /&gt;
| Required. Amount dispensed; checked against inventory stock on create&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;days_supply&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DecimalField(20, 6)&amp;lt;/code&amp;gt;, null&lt;br /&gt;
| &amp;lt;code&amp;gt;Decimal | None&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;max_digits=20, decimal_places=0&amp;lt;/code&amp;gt;)&lt;br /&gt;
| Expected number of days the dispensed amount lasts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Relationships ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Model type&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → Encounter&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;. Resolved from the &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt; UUID on write; &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; is derived from it rather than sent directly&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → Patient&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;. Server-set from &amp;lt;code&amp;gt;encounter.patient&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → FacilityLocation&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;. Must belong to the encounter&amp;#039;s facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → MedicationRequest&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SET_NULL&amp;lt;/code&amp;gt;, null. The prescription this dispense fulfils; must be on the same encounter. Cleared server-side when the dispense is cancelled&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → InventoryItem&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;. Stock item consumed; must sit in a location of the encounter&amp;#039;s facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;charge_item&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → ChargeItem&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;, null. Server-created from the product&amp;#039;s charge item definition when one exists&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;FK → DispenseOrder&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;, null. Parent dispense order, when grouped&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt; sit in &amp;lt;code&amp;gt;__exclude__&amp;lt;/code&amp;gt; on the spec base. The viewset resolves them by hand in &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; instead of copying them off the Pydantic object.&lt;br /&gt;
&lt;br /&gt;
== Enum values ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MedicationDispenseStatus&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
From &amp;lt;code&amp;gt;MedicationDispenseStatus&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;preparation&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;cancelled&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;on_hold&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;completed&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;stopped&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;declined&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MEDICATION_DISPENSE_CANCELLED_STATUSES = [cancelled, entered_in_error, stopped, declined]&amp;lt;/code&amp;gt; are terminal. Once a dispense lands in one, no further updates are allowed, and the transition into it triggers charge-item cancellation (see [[#methods--save-behaviour|Methods &amp;amp;amp; save behaviour]]).&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MedicationDispenseNotPerformedReason&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
From &amp;lt;code&amp;gt;MedicationDispenseNotPerformedReason&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;). Coded reasons drawn from FHIR &amp;lt;code&amp;gt;medicationdispense-status-reason&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;outofstock&amp;lt;/code&amp;gt;&lt;br /&gt;
| Out of stock&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;washout&amp;lt;/code&amp;gt;&lt;br /&gt;
| Washout&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;surg&amp;lt;/code&amp;gt;&lt;br /&gt;
| Surgery&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sintol&amp;lt;/code&amp;gt;&lt;br /&gt;
| Sensitivity / intolerance to drug&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sddi&amp;lt;/code&amp;gt;&lt;br /&gt;
| Drug interaction&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sdupther&amp;lt;/code&amp;gt;&lt;br /&gt;
| Duplicate therapy&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;saig&amp;lt;/code&amp;gt;&lt;br /&gt;
| Allergy to ingredient of medication&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;preg&amp;lt;/code&amp;gt;&lt;br /&gt;
| Patient pregnant&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MedicationDispenseCategory&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
From &amp;lt;code&amp;gt;MedicationDispenseCategory&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;inpatient&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;outpatient&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;community&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discharge&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;SubstitutionType&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
From &amp;lt;code&amp;gt;SubstitutionType&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;) — used in &amp;lt;code&amp;gt;substitution.substitution_type&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;E&amp;lt;/code&amp;gt;&lt;br /&gt;
| Equivalent&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EC&amp;lt;/code&amp;gt;&lt;br /&gt;
| Equivalent composition&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;BC&amp;lt;/code&amp;gt;&lt;br /&gt;
| Brand composition&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;&lt;br /&gt;
| Generic composition&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TE&amp;lt;/code&amp;gt;&lt;br /&gt;
| Therapeutic alternative&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TB&amp;lt;/code&amp;gt;&lt;br /&gt;
| Therapeutic brand&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;TG&amp;lt;/code&amp;gt;&lt;br /&gt;
| Therapeutic generic&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;F&amp;lt;/code&amp;gt;&lt;br /&gt;
| Formulary&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;&lt;br /&gt;
| None&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;SubstitutionReason&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
From &amp;lt;code&amp;gt;SubstitutionReason&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;) — used in &amp;lt;code&amp;gt;substitution.reason&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CT&amp;lt;/code&amp;gt;&lt;br /&gt;
| Continuing therapy&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FP&amp;lt;/code&amp;gt;&lt;br /&gt;
| Formulary policy&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;OS&amp;lt;/code&amp;gt;&lt;br /&gt;
| Out of stock&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;RR&amp;lt;/code&amp;gt;&lt;br /&gt;
| Regulatory requirement&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== JSON field shapes ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MedicationDispenseSubstitution&amp;lt;/code&amp;gt; shape ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;substitution&amp;lt;/code&amp;gt; field (&amp;lt;code&amp;gt;MedicationDispenseSubstitution&amp;lt;/code&amp;gt;). When present, all three keys are required:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;substitution = {&lt;br /&gt;
  was_substituted:   bool                # required&lt;br /&gt;
  substitution_type: SubstitutionType    # required; see SubstitutionType values&lt;br /&gt;
  reason:            SubstitutionReason   # required; see SubstitutionReason values&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== &amp;lt;code&amp;gt;DosageInstruction&amp;lt;/code&amp;gt; shape ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;dosage_instruction&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;list[DosageInstruction]&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;DosageInstruction&amp;lt;/code&amp;gt; comes straight from the [[References/Medication Request]] spec (&amp;lt;code&amp;gt;care/emr/resources/medication/request/spec.py&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;DosageInstruction {&lt;br /&gt;
  sequence:               int | None&lt;br /&gt;
  text:                   str | None&lt;br /&gt;
  additional_instruction: list[Coding]@system-additional-instruction | None&lt;br /&gt;
  patient_instruction:    str | None&lt;br /&gt;
  timing:                 Timing | None&lt;br /&gt;
  as_needed_boolean:      bool                                     # required&lt;br /&gt;
  as_needed_for:          Coding@system-as-needed-reason | None&lt;br /&gt;
  site:                   Coding@system-body-site | None&lt;br /&gt;
  route:                  Coding@system-route | None&lt;br /&gt;
  method:                 Coding@system-administration-method | None&lt;br /&gt;
  dose_and_rate:          DoseAndRate | None&lt;br /&gt;
  max_dose_per_period:    DoseRange | None&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Timing      { repeat: TimingRepeat, code: Coding | None }&lt;br /&gt;
TimingRepeat{ frequency: int, period: Decimal(20,0), period_unit: TimingUnit, bounds_duration: TimingQuantity }&lt;br /&gt;
TimingQuantity { value: Decimal(20,0), unit: TimingUnit }&lt;br /&gt;
DoseAndRate { type: DoseType, dose_range: DoseRange | None, dose_quantity: DosageQuantity | None }&lt;br /&gt;
DoseRange   { low: DosageQuantity, high: DosageQuantity }&lt;br /&gt;
DosageQuantity { value: Decimal(20,6), unit: Coding }&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;Coding@&amp;amp;lt;slug&amp;amp;gt;&amp;lt;/code&amp;gt; denotes a &amp;lt;code&amp;gt;Coding&amp;lt;/code&amp;gt; bound to a Care value set (&amp;lt;code&amp;gt;ValueSetBoundCoding&amp;lt;/code&amp;gt;), where &amp;lt;code&amp;gt;Coding = { system?, version?, code (required), display? }&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;TimingUnit ∈ {s, min, h, d, wk, mo, a}&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;DoseType ∈ {ordered, calculated}&amp;lt;/code&amp;gt;. The shared &amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt; (from &amp;lt;code&amp;gt;base.py&amp;lt;/code&amp;gt;) — &amp;lt;code&amp;gt;{ start: datetime, end: datetime }&amp;lt;/code&amp;gt;, both tz-aware, &amp;lt;code&amp;gt;start ≤ end&amp;lt;/code&amp;gt; — is the standard period shape elsewhere, but &amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt; exposes no period field of its own.&lt;br /&gt;
&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
Every spec extends &amp;lt;code&amp;gt;EMRResource&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;base.py&amp;lt;/code&amp;gt;) and rides its &amp;lt;code&amp;gt;serialize&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;de_serialize&amp;lt;/code&amp;gt; plumbing. Read-side data is assembled in &amp;lt;code&amp;gt;perform_extra_serialization&amp;lt;/code&amp;gt;; write-side FK resolution and side effects happen in &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Spec class&lt;br /&gt;
! Role&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;BaseMedicationDispenseSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base&lt;br /&gt;
| &amp;lt;code&amp;gt;__model__ = MedicationDispense&amp;lt;/code&amp;gt;. Exposes &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not_performed_reason&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;category&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;when_prepared&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;when_handed_over&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;note&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;dosage_instruction&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;substitution&amp;lt;/code&amp;gt;. Excludes the FK fields&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseWriteSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create&lt;br /&gt;
| Adds &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt; (UUIDs), &amp;lt;code&amp;gt;quantity&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;days_supply&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt;. Resolves FKs and runs create-time logic&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseUpdateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · update&lt;br /&gt;
| Base fields plus &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt;. Cannot re-point &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| Serializes nested &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;charge_item&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt;; adds &amp;lt;code&amp;gt;created_date&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;modified_date&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| Extends &amp;lt;code&amp;gt;ReadSpec&amp;lt;/code&amp;gt;, also serializing the full &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseSubstitution&amp;lt;/code&amp;gt;&lt;br /&gt;
| nested&lt;br /&gt;
| Shape of the &amp;lt;code&amp;gt;substitution&amp;lt;/code&amp;gt; JSON field&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CreateDispenseOrder&amp;lt;/code&amp;gt;&lt;br /&gt;
| nested (write)&lt;br /&gt;
| Inline order creation payload — see below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Write-spec fields ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Required&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=encounter|type=UUID4|notes=yes}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=location|type=UUID4|notes=yes}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=item|type=UUID4|notes=yes}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=authorizing_request|type=UUID4 | None|notes=no}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=quantity|type=Decimal|notes=yes}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=days_supply|type=Decimal | None|notes=no}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=fully_dispensed|type=bool | None|notes=no}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=order|type=UUID4 | None|notes=no}}&lt;br /&gt;
{{Field|model=MedicationDispense|section=Write-spec fields|name=create_dispense_order|type=CreateDispenseOrder | None|notes=no}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;validate_prescription&amp;lt;/code&amp;gt; rejects a payload that sends both &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;CreateDispenseOrder&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Inline order payload on the write spec. With no matching order (by &amp;lt;code&amp;gt;alternate_identifier&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;), one is created. A matching order whose status is not &amp;lt;code&amp;gt;draft&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt; is rejected with &amp;lt;code&amp;gt;&amp;amp;quot;Prescription is not active&amp;amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;CreateDispenseOrder {&lt;br /&gt;
  name:                 str | None&lt;br /&gt;
  note:                 str | None&lt;br /&gt;
  alternate_identifier: str                              # required&lt;br /&gt;
  status:               CreateDispenseOrderStatusOptions # default &amp;quot;draft&amp;quot;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;CreateDispenseOrderStatusOptions ∈ {draft, in_progress}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Bound value sets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;dosage_instruction&amp;lt;/code&amp;gt; codings bind to Care value sets, all SNOMED CT and registered as systems:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field (within &amp;lt;code&amp;gt;DosageInstruction&amp;lt;/code&amp;gt;)&lt;br /&gt;
! Value set slug&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;additional_instruction&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;system-additional-instruction&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;as_needed_for&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;system-as-needed-reason&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;site&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;system-body-site&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;route&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;system-route&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;system-administration-method&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The dispense-level &amp;lt;code&amp;gt;not_performed_reason&amp;lt;/code&amp;gt; lines up with the &amp;lt;code&amp;gt;system-medication-not-given&amp;lt;/code&amp;gt; value set (&amp;lt;code&amp;gt;medication_not_given_reason.py&amp;lt;/code&amp;gt;), but it is stored and validated as the &amp;lt;code&amp;gt;MedicationDispenseNotPerformedReason&amp;lt;/code&amp;gt; enum, not as a bound &amp;lt;code&amp;gt;Coding&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;DispenseOrder&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Groups one or more &amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt; events at a location into a named order under a single status.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;location              → FK FacilityLocation (CASCADE)&lt;br /&gt;
patient               → FK Patient (CASCADE)&lt;br /&gt;
facility              → FK Facility (CASCADE)&lt;br /&gt;
name                  → CharField(255), nullable&lt;br /&gt;
status                → CharField(255)&lt;br /&gt;
note                  → TextField, nullable&lt;br /&gt;
tags                  → ArrayField[int], default []&lt;br /&gt;
alternate_identifier  → CharField(100), nullable&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;unique_alternate_identifier_encounter_location&amp;lt;/code&amp;gt; constraint enforces uniqueness on &amp;lt;code&amp;gt;(alternate_identifier, patient, location)&amp;lt;/code&amp;gt;, so each external identifier appears at most once per patient and location.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Source / specs:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* Model: &amp;lt;code&amp;gt;DispenseOrder&amp;lt;/code&amp;gt; in [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/models/medication_dispense.py &amp;lt;code&amp;gt;medication_dispense.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Specs: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/medication/dispense/dispense_order.py &amp;lt;code&amp;gt;dispense_order.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Viewset: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/api/viewsets/inventory/dispense_order.py &amp;lt;code&amp;gt;api/viewsets/inventory/dispense_order.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;MedicationDispenseOrderStatusOptions&amp;lt;/code&amp;gt; values ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;draft&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;completed&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;abandoned&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MEDICATION_DISPENSE_ORDER_COMPLETED_STATUSES = [abandoned, entered_in_error, completed]&amp;lt;/code&amp;gt; are terminal. &amp;lt;code&amp;gt;abandoned&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; are the cancel transitions.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;DispenseOrder&amp;lt;/code&amp;gt; specs ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Spec class&lt;br /&gt;
! Role&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;BaseMedicationDispenseOrderSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base / update&lt;br /&gt;
| Exposes &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;note&amp;lt;/code&amp;gt;. Doubles as the update spec&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseOrderWriteSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create&lt;br /&gt;
| Adds &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt; (UUIDs), resolved in deserialization. &amp;lt;code&amp;gt;facility&amp;lt;/code&amp;gt; is set server-side from the URL&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseOrderReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| Serializes nested &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; (list spec), &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;; adds &amp;lt;code&amp;gt;created_date&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;modified_date&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MedicationDispenseOrderRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| Full &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; (retrieve spec) plus &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;updated_by&amp;lt;/code&amp;gt; audit users&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Methods &amp;amp;amp; save behaviour ==&lt;br /&gt;
&lt;br /&gt;
The model has no custom &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt;. The dispense workflow lives in &amp;lt;code&amp;gt;MedicationDispenseViewSet&amp;lt;/code&amp;gt;, inside a &amp;lt;code&amp;gt;transaction.atomic()&amp;lt;/code&amp;gt; block, layering side effects over the spec&amp;#039;s &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;On create (&amp;lt;code&amp;gt;perform_create&amp;lt;/code&amp;gt;):&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* Takes an &amp;lt;code&amp;gt;InventoryItemLock&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt; and rejects if &amp;lt;code&amp;gt;item.net_content &amp;amp;lt; quantity&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;&amp;amp;quot;Inventory item does not have enough stock&amp;amp;quot;&amp;lt;/code&amp;gt;).&lt;br /&gt;
* When &amp;lt;code&amp;gt;item.product.charge_item_definition&amp;lt;/code&amp;gt; exists, applies it to create a &amp;lt;code&amp;gt;ChargeItem&amp;lt;/code&amp;gt; (resource &amp;lt;code&amp;gt;medication_dispense&amp;lt;/code&amp;gt;, linked to this dispense&amp;#039;s &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;performer_actor&amp;lt;/code&amp;gt; is the authorizing request&amp;#039;s requester when present) and attaches it via &amp;lt;code&amp;gt;charge_item&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Calls &amp;lt;code&amp;gt;sync_inventory_item(item.location, item.product)&amp;lt;/code&amp;gt; to draw down stock.&lt;br /&gt;
* When &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; is set and an &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt; exists, sets that request&amp;#039;s &amp;lt;code&amp;gt;dispense_status&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; (on &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;partial&amp;lt;/code&amp;gt; (on &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Order resolution: &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt; does a get-or-create by &amp;lt;code&amp;gt;(alternate_identifier, patient, location)&amp;lt;/code&amp;gt;; an existing non-&amp;lt;code&amp;gt;draft&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt; order is rejected.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;On update (&amp;lt;code&amp;gt;perform_update&amp;lt;/code&amp;gt;):&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;validate_data&amp;lt;/code&amp;gt; rejects any update while the current status is in &amp;lt;code&amp;gt;MEDICATION_DISPENSE_CANCELLED_STATUSES&amp;lt;/code&amp;gt;.&lt;br /&gt;
* A transition &amp;#039;&amp;#039;into&amp;#039;&amp;#039; a cancelling status with a &amp;lt;code&amp;gt;charge_item&amp;lt;/code&amp;gt; attached cancels that charge item (&amp;lt;code&amp;gt;handle_charge_item_cancel&amp;lt;/code&amp;gt;, status → &amp;lt;code&amp;gt;aborted&amp;lt;/code&amp;gt;), sets the authorizing request&amp;#039;s &amp;lt;code&amp;gt;dispense_status&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;incomplete&amp;lt;/code&amp;gt;, and detaches &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;SET_NULL&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Re-syncs inventory and re-applies the &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; → &amp;lt;code&amp;gt;dispense_status&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;partial&amp;lt;/code&amp;gt;) logic.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Dispense-order cancellation (&amp;lt;code&amp;gt;cancel_dispense_order&amp;lt;/code&amp;gt; in the order viewset):&amp;#039;&amp;#039;&amp;#039; moving an order to &amp;lt;code&amp;gt;abandoned&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; cascades to every member dispense. It cancels their charge items, marks each dispense &amp;lt;code&amp;gt;cancelled&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; respectively, sets authorizing requests&amp;#039; &amp;lt;code&amp;gt;dispense_status&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;incomplete&amp;lt;/code&amp;gt;, and detaches them. An order already in &amp;lt;code&amp;gt;abandoned&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; cannot transition, and a &amp;lt;code&amp;gt;completed&amp;lt;/code&amp;gt; order can only be cancelled.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* The resource is exposed through &amp;lt;code&amp;gt;MedicationDispenseViewSet&amp;lt;/code&amp;gt; (create, retrieve, update, list, upsert) and tracks the FHIR &amp;lt;code&amp;gt;MedicationDispense&amp;lt;/code&amp;gt; resource. API field names may differ from FHIR — &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt; ≈ FHIR &amp;lt;code&amp;gt;authorizingPrescription&amp;lt;/code&amp;gt; — and enum &amp;#039;&amp;#039;&amp;#039;values&amp;#039;&amp;#039;&amp;#039; use underscores (&amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;), not FHIR hyphens.&lt;br /&gt;
* List and summary need either a &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt; query param, otherwise they &amp;lt;code&amp;gt;400&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;include_children=true&amp;lt;/code&amp;gt; widens a location query to descendant locations via &amp;lt;code&amp;gt;parent_cache&amp;lt;/code&amp;gt;. Filters: &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;exclude_status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;category&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;encounter&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;authorizing_prescription&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;authorizing_request&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;summary&amp;lt;/code&amp;gt; action returns per-encounter dispense counts.&lt;br /&gt;
* Permissions are location-centric. Creating needs only write access to the dispensing &amp;lt;code&amp;gt;location&amp;lt;/code&amp;gt; — pharmacists often lack encounter access — while reads need either location-list or encounter-view permission.&lt;br /&gt;
* Send &amp;lt;code&amp;gt;item&amp;lt;/code&amp;gt; as an &amp;lt;code&amp;gt;InventoryItem&amp;lt;/code&amp;gt; UUID, not a bare product code; that UUID is what draws down stock.&lt;br /&gt;
* &amp;lt;code&amp;gt;quantity&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;days_supply&amp;lt;/code&amp;gt; are constrained to whole units (&amp;lt;code&amp;gt;decimal_places=0&amp;lt;/code&amp;gt;) on the write spec, even though the column stores 6 decimal places.&lt;br /&gt;
* Leave &amp;lt;code&amp;gt;charge_item&amp;lt;/code&amp;gt; alone. It is server-managed: created from the product&amp;#039;s charge item definition and cancelled on dispense or order cancellation.&lt;br /&gt;
* Set &amp;lt;code&amp;gt;fully_dispensed&amp;lt;/code&amp;gt; to roll the linked [[References/Medication Request]] into &amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;partial&amp;lt;/code&amp;gt;, so pharmacists don&amp;#039;t re-dispense an already-fulfilled request.&lt;br /&gt;
* Use &amp;lt;code&amp;gt;create_dispense_order&amp;lt;/code&amp;gt; to start an order inline, or &amp;lt;code&amp;gt;order&amp;lt;/code&amp;gt; to attach to an existing one — never both.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>