<?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%2FEncounter</id>
	<title>References/Encounter - 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%2FEncounter"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Encounter&amp;action=history"/>
	<updated>2026-07-06T05:20:42Z</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/Encounter&amp;diff=392&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/Encounter&amp;diff=392&amp;oldid=prev"/>
		<updated>2026-07-06T04:01:40Z</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:31, 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 441:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 441:&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;* &amp;lt;code&amp;gt;current_location&amp;lt;/code&amp;gt; is a cached convenience field. The authoritative record is &amp;lt;code&amp;gt;location_history&amp;lt;/code&amp;gt;, from &amp;lt;code&amp;gt;FacilityLocationEncounter&amp;lt;/code&amp;gt;.&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;* &amp;lt;code&amp;gt;current_location&amp;lt;/code&amp;gt; is a cached convenience field. The authoritative record is &amp;lt;code&amp;gt;location_history&amp;lt;/code&amp;gt;, from &amp;lt;code&amp;gt;FacilityLocationEncounter&amp;lt;/code&amp;gt;.&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;* &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt; holds custom key-value data without a schema migration, validated by &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;.&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;* &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt; holds custom key-value data without a schema migration, validated by &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;.&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 clinical}}&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;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;Wiki: ohcnwiki.tellmey.fyi&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/Encounter&amp;diff=141&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/Encounter&amp;diff=141&amp;oldid=prev"/>
		<updated>2026-07-04T22:44:22Z</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=clinical&lt;br /&gt;
|title=Encounter&lt;br /&gt;
|order=2&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|fhir=Encounter&lt;br /&gt;
|model=Encounter&lt;br /&gt;
|concept=Concepts/Patient&lt;br /&gt;
|reference=References/User &amp;amp;amp; Skills&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
An &amp;lt;code&amp;gt;Encounter&amp;lt;/code&amp;gt; records a single interaction between a patient and a facility — a visit, admission, or consultation — and maps to the FHIR &amp;lt;code&amp;gt;Encounter&amp;lt;/code&amp;gt; resource. You create one when a patient presents, drive it through its status lifecycle, and read it back to render the clinical timeline.&lt;br /&gt;
&lt;br /&gt;
The Django model is only the storage layer: several fields are opaque &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;s whose real shape lives in the Pydantic resource specs, so the model alone won&amp;#039;t tell you what a write must look like. The spec tables below carry that detail.&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/encounter.py &amp;lt;code&amp;gt;care/emr/models/encounter.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/encounter/spec.py &amp;lt;code&amp;gt;care/emr/resources/encounter/spec.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/encounter/constants.py &amp;lt;code&amp;gt;constants.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/encounter/valueset.py &amp;lt;code&amp;gt;valueset.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/encounter/enum_display_names.py &amp;lt;code&amp;gt;enum_display_names.py&amp;lt;/code&amp;gt;]&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;Encounter&amp;lt;/code&amp;gt;&lt;br /&gt;
| A single interaction between a patient and a facility (visit, admission, consultation)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt;&lt;br /&gt;
| Links an &amp;lt;code&amp;gt;Encounter&amp;lt;/code&amp;gt; to a &amp;lt;code&amp;gt;FacilityOrganization&amp;lt;/code&amp;gt; for access control&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;]], the shared Care EMR base that provides &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;Encounter&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
=== Classification &amp;amp;amp; status ===&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=status|type=CharField(100)|notes=Nullable in DB; &amp;#039;&amp;#039;&amp;#039;required&amp;#039;&amp;#039;&amp;#039; in API. One of &amp;lt;code&amp;gt;StatusChoices&amp;lt;/code&amp;gt; (see below)}}&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=status_history|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. Server-maintained. Shape: &amp;lt;code&amp;gt;{ &amp;amp;quot;history&amp;amp;quot;: [{ &amp;amp;quot;status&amp;amp;quot;: str, &amp;amp;quot;moved_at&amp;amp;quot;: str (ISO datetime) }] }&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=encounter_class|type=CharField(100)|notes=Nullable in DB; &amp;#039;&amp;#039;&amp;#039;required&amp;#039;&amp;#039;&amp;#039; in API. One of &amp;lt;code&amp;gt;ClassChoices&amp;lt;/code&amp;gt; (see below)}}&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=encounter_class_history|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. Server-maintained. Shape: &amp;lt;code&amp;gt;{ &amp;amp;quot;history&amp;amp;quot;: [{ &amp;amp;quot;status&amp;amp;quot;: str, &amp;amp;quot;moved_at&amp;amp;quot;: str (ISO datetime) }] }&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=priority|type=CharField(100)|notes=Nullable in DB; &amp;#039;&amp;#039;&amp;#039;required&amp;#039;&amp;#039;&amp;#039; in API. One of &amp;lt;code&amp;gt;EncounterPriorityChoices&amp;lt;/code&amp;gt; (see below)}}&lt;br /&gt;
{{Field|model=Encounter|section=Classification &amp;amp;amp; status|name=external_identifier|type=CharField(100)|notes=Nullable. Identifier from an external/source system}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Subject &amp;amp;amp; facility ===&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=Subject &amp;amp;amp; facility|name=patient|type=FK → Patient|notes=&amp;lt;code&amp;gt;CASCADE&amp;lt;/code&amp;gt;. The patient this encounter is for. Set on create only}}&lt;br /&gt;
{{Field|model=Encounter|section=Subject &amp;amp;amp; facility|name=facility|type=FK → Facility|notes=&amp;lt;code&amp;gt;PROTECT&amp;lt;/code&amp;gt;. The facility where the encounter takes place. Set on create only}}&lt;br /&gt;
{{Field|model=Encounter|section=Subject &amp;amp;amp; facility|name=appointment|type=FK → TokenBooking|notes=&amp;lt;code&amp;gt;SET_NULL&amp;lt;/code&amp;gt;, nullable. Originating [[References/Booking}}&lt;br /&gt;
{{Field|model=Encounter|section=Subject &amp;amp;amp; facility|name=current_location|type=FK → FacilityLocation|notes=&amp;lt;code&amp;gt;SET_NULL&amp;lt;/code&amp;gt;, nullable. Cached current [[References/Location}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Timing &amp;amp;amp; disposition ===&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=Timing &amp;amp;amp; disposition|name=period|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;PeriodSpec { start: datetime (tz-aware, optional), end: datetime (tz-aware, optional) }&amp;lt;/code&amp;gt;. If both set, &amp;lt;code&amp;gt;start ≤ end&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Encounter|section=Timing &amp;amp;amp; disposition|name=hospitalization|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;HospitalizationSpec&amp;lt;/code&amp;gt; (see shape below). Nullable}}&lt;br /&gt;
{{Field|model=Encounter|section=Timing &amp;amp;amp; disposition|name=discharge_summary_advice|type=TextField|notes=Nullable. Free-text discharge advice. Explicitly cleared to &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt; on update when omitted}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Care team ===&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=Care team|name=care_team|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. Stored as a list of &amp;lt;code&amp;gt;{ &amp;amp;quot;user_id&amp;amp;quot;: int, &amp;amp;quot;role&amp;amp;quot;: Coding }&amp;lt;/code&amp;gt; entries. &amp;#039;&amp;#039;&amp;#039;Not&amp;#039;&amp;#039;&amp;#039; writable on create/update (excluded); managed via the dedicated care-team write spec}}&lt;br /&gt;
{{Field|model=Encounter|section=Care team|name=care_team_users|type=ArrayField[int]|notes=Platform-maintained denormalized cache of user IDs derived from &amp;lt;code&amp;gt;care_team&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;sync_care_team_users_cache()&amp;lt;/code&amp;gt; on every save}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Organization cache, tags &amp;amp;amp; extensions ===&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=Organization cache, tags &amp;amp;amp; extensions|name=facility_organization_cache|type=ArrayField[int]|notes=Platform-maintained cache of facility-[[References/Organization}}&lt;br /&gt;
{{Field|model=Encounter|section=Organization cache, tags &amp;amp;amp; extensions|name=tags|type=ArrayField[int]|notes=Tag IDs applied to the encounter. Serialized via &amp;lt;code&amp;gt;SingleFacilityTagManager().render_tags()&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Encounter|section=Organization cache, tags &amp;amp;amp; extensions|name=extensions|type=JSONField|notes=Default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. Open extension bag for deployment-specific metadata. Validated by &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; against &amp;lt;code&amp;gt;ExtensionResource.encounter&amp;lt;/code&amp;gt;}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Nested JSON shapes ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;period&amp;lt;/code&amp;gt;) ===&lt;br /&gt;
&lt;br /&gt;
Defined in [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py &amp;lt;code&amp;gt;resources/base.py&amp;lt;/code&amp;gt;].&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;
! Notes&lt;br /&gt;
{{Field|model=Encounter|section=PeriodSpec (period)|name=start|type=datetime | None|notes=Must be timezone-aware if provided}}&lt;br /&gt;
{{Field|model=Encounter|section=PeriodSpec (period)|name=end|type=datetime | None|notes=Must be timezone-aware if provided}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;validate_period&amp;lt;/code&amp;gt; rejects naive datetimes, and when both &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; are set it requires &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt; not to exceed &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;HospitalizationSpec&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hospitalization&amp;lt;/code&amp;gt;) ===&lt;br /&gt;
&lt;br /&gt;
Defined in &amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;. All fields optional/nullable.&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;
! Values&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;re_admission&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;bool | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| —&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;admit_source&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;AdmitSourcesChoices | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| see [[#admit-source-values-admitsourceschoices&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discharge_disposition&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DischargeDispositionChoices | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| see [[#discharge-disposition-values-dischargedispositionchoices&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;diet_preference&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;DietPreferenceChoices | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| see [[#diet-preference-values-dietpreferencechoices&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Enum values ==&lt;br /&gt;
&lt;br /&gt;
=== Status values (&amp;lt;code&amp;gt;StatusChoices&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;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;planned&amp;lt;/code&amp;gt;&lt;br /&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;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;on_hold&amp;lt;/code&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discharged&amp;lt;/code&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;completed&amp;lt;/code&amp;gt;&lt;br /&gt;
| terminal (in &amp;lt;code&amp;gt;COMPLETED_CHOICES&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;
| terminal (in &amp;lt;code&amp;gt;COMPLETED_CHOICES&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discontinued&amp;lt;/code&amp;gt;&lt;br /&gt;
| terminal (in &amp;lt;code&amp;gt;COMPLETED_CHOICES&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;
| terminal (in &amp;lt;code&amp;gt;COMPLETED_CHOICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ERROR_CHOICES&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;unknown&amp;lt;/code&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;COMPLETED_CHOICES = [completed, cancelled, entered_in_error, discontinued]&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;ERROR_CHOICES = [entered_in_error]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Class values (&amp;lt;code&amp;gt;ClassChoices&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;imp&amp;lt;/code&amp;gt;&lt;br /&gt;
| inpatient&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;amb&amp;lt;/code&amp;gt;&lt;br /&gt;
| ambulatory&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;obsenc&amp;lt;/code&amp;gt;&lt;br /&gt;
| observation&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;emer&amp;lt;/code&amp;gt;&lt;br /&gt;
| emergency&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vr&amp;lt;/code&amp;gt;&lt;br /&gt;
| virtual&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;hh&amp;lt;/code&amp;gt;&lt;br /&gt;
| home health&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Priority values (&amp;lt;code&amp;gt;EncounterPriorityChoices&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;ASAP&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;callback_results&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;callback_for_scheduling&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;elective&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;emergency&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;preop&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;as_needed&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;routine&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;rush_reporting&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;stat&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;timing_critical&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;use_as_directed&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;urgent&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Admit source values (&amp;lt;code&amp;gt;AdmitSourcesChoices&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;
! Display (&amp;lt;code&amp;gt;get_admit_source_display&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;hosp_trans&amp;lt;/code&amp;gt;&lt;br /&gt;
| Transferred from other hospital&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;emd&amp;lt;/code&amp;gt;&lt;br /&gt;
| From accident/emergency department&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;outp&amp;lt;/code&amp;gt;&lt;br /&gt;
| From outpatient department&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;born&amp;lt;/code&amp;gt;&lt;br /&gt;
| Born in hospital&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gp&amp;lt;/code&amp;gt;&lt;br /&gt;
| General Practitioner referral&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mp&amp;lt;/code&amp;gt;&lt;br /&gt;
| Medical Practitioner/physician referral&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;nursing&amp;lt;/code&amp;gt;&lt;br /&gt;
| From nursing home&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;psych&amp;lt;/code&amp;gt;&lt;br /&gt;
| From psychiatric hospital&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;rehab&amp;lt;/code&amp;gt;&lt;br /&gt;
| From rehabilitation facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;other&amp;lt;/code&amp;gt;&lt;br /&gt;
| Other&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Discharge disposition values (&amp;lt;code&amp;gt;DischargeDispositionChoices&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;
! Display (&amp;lt;code&amp;gt;get_discharge_disposition_display&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;home&amp;lt;/code&amp;gt;&lt;br /&gt;
| Home&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;alt_home&amp;lt;/code&amp;gt;&lt;br /&gt;
| Alternate Home&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;other_hcf&amp;lt;/code&amp;gt;&lt;br /&gt;
| Other Health Care Facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;hosp&amp;lt;/code&amp;gt;&lt;br /&gt;
| Hospital&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| Long-term Care Facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aadvice&amp;lt;/code&amp;gt;&lt;br /&gt;
| Against Medical Advice&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exp&amp;lt;/code&amp;gt;&lt;br /&gt;
| Expired&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;psy&amp;lt;/code&amp;gt;&lt;br /&gt;
| Psychiatric Hospital&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;rehab&amp;lt;/code&amp;gt;&lt;br /&gt;
| Rehabilitation Facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;snf&amp;lt;/code&amp;gt;&lt;br /&gt;
| Skilled Nursing Facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;oth&amp;lt;/code&amp;gt;&lt;br /&gt;
| Other&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Diet preference values (&amp;lt;code&amp;gt;DietPreferenceChoices&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;vegetarian&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;dairy_free&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;nut_free&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;gluten_free&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;halal&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;kosher&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
All specs build on &amp;lt;code&amp;gt;EMRResource&amp;lt;/code&amp;gt;, which provides &amp;lt;code&amp;gt;serialize&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;de_serialize&amp;lt;/code&amp;gt; plus the &amp;lt;code&amp;gt;perform_extra_serialization&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; hooks. &amp;lt;code&amp;gt;EncounterSpecBase&amp;lt;/code&amp;gt; sets &amp;lt;code&amp;gt;__exclude__ = [patient, organizations, facility, appointment, current_location, care_team]&amp;lt;/code&amp;gt;; those fields move through hooks or dedicated endpoints rather than direct assignment, which is why the create and read schemas diverge from the raw model.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Spec&lt;br /&gt;
! Role&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterSpecBase&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared&lt;br /&gt;
| Fields: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;encounter_class&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;period&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;hospitalization&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;HospitalizationSpec | None&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;priority&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;external_identifier&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;discharge_summary_advice&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;__model__ = Encounter&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterCreateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create&lt;br /&gt;
| Extends base + &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;. Adds &amp;lt;code&amp;gt;patient: UUID4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;facility: UUID4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;organizations: list[UUID4] = []&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;appointment: UUID4 | None&amp;lt;/code&amp;gt;. Resolves FKs by &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;; validates appointment belongs to the patient and facility&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterUpdateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · update&lt;br /&gt;
| Extends base + &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;. Does not accept &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;facility&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;organizations&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;appointment&amp;lt;/code&amp;gt; — only mutable fields. Appends to status/class history on change&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterListSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| Adds serialized &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; ([[References/Patient&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| Extends list + &amp;lt;code&amp;gt;EncounterPermissionsMixin&amp;lt;/code&amp;gt;. Adds &amp;lt;code&amp;gt;appointment&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;TokenBookingReadSpec&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;updated_by&amp;lt;/code&amp;gt; ([[References/User &amp;amp;amp; Skills&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;HospitalizationSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| nested&lt;br /&gt;
| Plain &amp;lt;code&amp;gt;BaseModel&amp;lt;/code&amp;gt;; see shape above&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterCareTeamMemberSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| nested (write)&lt;br /&gt;
| &amp;lt;code&amp;gt;{ user_id: UUID4, role: Coding }&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;role&amp;lt;/code&amp;gt; bound to the &amp;lt;code&amp;gt;system-practitioner-role-code&amp;lt;/code&amp;gt; value set&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;EncounterCareTeamMemberWriteSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · care team&lt;br /&gt;
| &amp;lt;code&amp;gt;{ members: list[EncounterCareTeamMemberSpec] }&amp;lt;/code&amp;gt;. Dedicated payload for replacing the care team&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Server-maintained behaviour ===&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Status history&amp;#039;&amp;#039;&amp;#039;: on create, &amp;lt;code&amp;gt;status_history&amp;lt;/code&amp;gt; starts as &amp;lt;code&amp;gt;{ &amp;amp;quot;history&amp;amp;quot;: [{ status, moved_at }] }&amp;lt;/code&amp;gt; carrying the initial status; on update, a new entry is appended only when &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt; changes. &amp;lt;code&amp;gt;encounter_class_history&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;encounter_class&amp;lt;/code&amp;gt; follow the same rule.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;FK resolution (create)&amp;#039;&amp;#039;&amp;#039;: &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;facility&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;appointment&amp;lt;/code&amp;gt; resolve from &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt; (404 if not found). The appointment must belong to the same patient and to a slot whose resource sits in the same facility.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Organizations (create)&amp;#039;&amp;#039;&amp;#039;: &amp;lt;code&amp;gt;organizations&amp;lt;/code&amp;gt;, deduplicated to a list of UUIDs, is stashed on &amp;lt;code&amp;gt;obj._organizations&amp;lt;/code&amp;gt;, and the resulting &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt; rows drive &amp;lt;code&amp;gt;facility_organization_cache&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Discharge advice (update)&amp;#039;&amp;#039;&amp;#039;: omitting &amp;lt;code&amp;gt;discharge_summary_advice&amp;lt;/code&amp;gt; on update clears it to &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt; rather than leaving the prior value.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Care team&amp;#039;&amp;#039;&amp;#039;: &amp;lt;code&amp;gt;role&amp;lt;/code&amp;gt; binds to the &amp;lt;code&amp;gt;PRACTITIONER_ROLE_VALUESET&amp;lt;/code&amp;gt; (slug &amp;lt;code&amp;gt;system-practitioner-role-code&amp;lt;/code&amp;gt;), a SNOMED CT value set of descendants of &amp;lt;code&amp;gt;223366009&amp;lt;/code&amp;gt; (healthcare professional) and &amp;lt;code&amp;gt;224930009&amp;lt;/code&amp;gt; (healthcare-related occupation).&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Associates an encounter with a facility-scoped [[References/Organization|organization]] to drive organization-based access control on encounters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;encounter    → FK Encounter (CASCADE)&lt;br /&gt;
organization → FK FacilityOrganization (CASCADE)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Saving an &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;encounter.sync_organization_cache()&amp;lt;/code&amp;gt;, which rebuilds the encounter&amp;#039;s &amp;lt;code&amp;gt;facility_organization_cache&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Methods &amp;amp;amp; save behaviour ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;sync_care_team_users_cache()&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
When &amp;lt;code&amp;gt;care_team&amp;lt;/code&amp;gt; is a list, fills &amp;lt;code&amp;gt;care_team_users&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;int(entry[&amp;amp;quot;user_id&amp;amp;quot;])&amp;lt;/code&amp;gt; for each entry, falling back to &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; when a &amp;lt;code&amp;gt;user_id&amp;lt;/code&amp;gt; is missing. The flat integer array lets queries skip JSON traversal.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;sync_organization_cache()&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Recomputes &amp;lt;code&amp;gt;facility_organization_cache&amp;lt;/code&amp;gt; as the union of:&lt;br /&gt;
&lt;br /&gt;
* every linked &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt; organization plus its &amp;lt;code&amp;gt;parent_cache&amp;lt;/code&amp;gt; chain, and&lt;br /&gt;
* the facility&amp;#039;s &amp;lt;code&amp;gt;default_internal_organization_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Persists the result with &amp;lt;code&amp;gt;super().save(update_fields=[&amp;amp;quot;facility_organization_cache&amp;amp;quot;])&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt; side effects ===&lt;br /&gt;
&lt;br /&gt;
On every save:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;sync_care_team_users_cache()&amp;lt;/code&amp;gt; runs, refreshing &amp;lt;code&amp;gt;care_team_users&amp;lt;/code&amp;gt;.&lt;br /&gt;
# A record with no &amp;lt;code&amp;gt;pk&amp;lt;/code&amp;gt; is flagged as newly &amp;lt;code&amp;gt;created&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Inside a single &amp;lt;code&amp;gt;transaction.atomic()&amp;lt;/code&amp;gt; block, the base &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt; runs. For newly created encounters, &amp;lt;code&amp;gt;evaluate_patient_facility_default_values(patient, facility)&amp;lt;/code&amp;gt; then generates facility-scoped patient identifier defaults.&lt;br /&gt;
# After the transaction, &amp;lt;code&amp;gt;sync_organization_cache()&amp;lt;/code&amp;gt; runs, performing a second write (&amp;lt;code&amp;gt;update_fields=[&amp;amp;quot;facility_organization_cache&amp;amp;quot;]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Expect two write passes per create or update through the ORM, plus identifier-default generation on creation.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* Reads use &amp;lt;code&amp;gt;EncounterListSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;EncounterRetrieveSpec&amp;lt;/code&amp;gt;; writes use &amp;lt;code&amp;gt;EncounterCreateSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;EncounterUpdateSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;encounter_class&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;priority&amp;lt;/code&amp;gt; are required on write and validated against their enums, even though the DB columns are nullable.&lt;br /&gt;
* Never set &amp;lt;code&amp;gt;status_history&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;encounter_class_history&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;care_team_users&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;facility_organization_cache&amp;lt;/code&amp;gt; from a client; the server appends history on create and update and derives the caches from &amp;lt;code&amp;gt;care_team&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EncounterOrganization&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Create and update don&amp;#039;t touch the care team. Replace it through the dedicated care-team endpoint with &amp;lt;code&amp;gt;EncounterCareTeamMemberWriteSpec&amp;lt;/code&amp;gt;, where each member&amp;#039;s &amp;lt;code&amp;gt;role&amp;lt;/code&amp;gt; must resolve within the &amp;lt;code&amp;gt;system-practitioner-role-code&amp;lt;/code&amp;gt; value set.&lt;br /&gt;
* &amp;lt;code&amp;gt;period&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hospitalization&amp;lt;/code&amp;gt; carry structured JSON matching the nested-spec shapes above; &amp;lt;code&amp;gt;period.start&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;period.end&amp;lt;/code&amp;gt; must be timezone-aware.&lt;br /&gt;
* &amp;lt;code&amp;gt;current_location&amp;lt;/code&amp;gt; is a cached convenience field. The authoritative record is &amp;lt;code&amp;gt;location_history&amp;lt;/code&amp;gt;, from &amp;lt;code&amp;gt;FacilityLocationEncounter&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt; holds custom key-value data without a schema migration, validated by &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>