<?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%2FFacility</id>
	<title>References/Facility - 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%2FFacility"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Facility&amp;action=history"/>
	<updated>2026-07-06T05:20:03Z</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/Facility&amp;diff=417&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/Facility&amp;diff=417&amp;oldid=prev"/>
		<updated>2026-07-06T04:04:21Z</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:34, 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 442:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 442:&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;* Discount/tax/invoice billing config is managed through &amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;FacilityInvoiceExpressionSpec&amp;lt;/code&amp;gt; and surfaced on &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt;; it&#039;s backed by [[References/Facility Config|&amp;lt;code&amp;gt;FacilityMonetoryConfig&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;* Discount/tax/invoice billing config is managed through &amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;FacilityInvoiceExpressionSpec&amp;lt;/code&amp;gt; and surfaced on &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt;; it&#039;s backed by [[References/Facility Config|&amp;lt;code&amp;gt;FacilityMonetoryConfig&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;FacilityRetrieveSpec&amp;lt;/code&amp;gt; also returns the requesting user&#039;s permissions and feature flags; flags come via &amp;lt;code&amp;gt;get_facility_flags()&amp;lt;/code&amp;gt; rather than a row-by-row query.&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;FacilityRetrieveSpec&amp;lt;/code&amp;gt; also returns the requesting user&#039;s permissions and feature flags; flags come via &amp;lt;code&amp;gt;get_facility_flags()&amp;lt;/code&amp;gt; rather than a row-by-row query.&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 facility}}&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/Facility&amp;diff=159&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/Facility&amp;diff=159&amp;oldid=prev"/>
		<updated>2026-07-04T22:45:04Z</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=facility&lt;br /&gt;
|title=Facility&lt;br /&gt;
|order=1&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|model=Facility&lt;br /&gt;
|reference=References/Device&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; is a physical or virtual care site — hospital, clinic, lab, telemedicine endpoint — and the root of a deployment&amp;#039;s administrative hierarchy. You create one before any patient, organization, or device can attach to it.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; spans two layers. The Django model is the storage layer, where columns like &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;print_templates&amp;lt;/code&amp;gt; are opaque blobs. The API contract — enums, validation, JSON-field shapes, and the read/write schema split — lives in the Pydantic resource specs. When the two disagree (a stored integer vs. a wire label, an object key vs. a resolved URL), the spec wins on the wire.&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/facility/models/facility.py &amp;lt;code&amp;gt;care/facility/models/facility.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Resource specs: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/facility/spec.py &amp;lt;code&amp;gt;care/emr/resources/facility/spec.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Base resource: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py &amp;lt;code&amp;gt;care/emr/resources/base.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Common types: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/coding.py &amp;lt;code&amp;gt;coding.py&amp;lt;/code&amp;gt;], [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/monetary_component.py &amp;lt;code&amp;gt;monetary_component.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;Facility&amp;lt;/code&amp;gt;&lt;br /&gt;
| A care site and the root of a deployment&amp;#039;s administrative org hierarchy&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityMonetoryConfig&amp;lt;/code&amp;gt;&lt;br /&gt;
| Per-facility billing config (one-to-one): discount codes, discount monetary components, discount configuration, invoice-number expression. Backs the discount/invoice fields of &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt;. See [[References/Facility Config&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; extends [[References/Base models &amp;amp;amp; conventions|&amp;lt;code&amp;gt;BaseModel&amp;lt;/code&amp;gt;]], not &amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;. It gets &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;created_date&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;modified_date&amp;lt;/code&amp;gt;, and soft-delete via &amp;lt;code&amp;gt;deleted&amp;lt;/code&amp;gt;, but none of the &amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt; audit/history/meta machinery: it declares its own &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; FK and has no &amp;lt;code&amp;gt;updated_by&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;history&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;meta&amp;lt;/code&amp;gt; columns. &amp;lt;code&amp;gt;FacilityMonetoryConfig&amp;lt;/code&amp;gt; does extend &amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The choice sets and enums it uses are defined alongside the model — see [[#choices--enums|Choices &amp;amp;amp; enums]].&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Type&amp;#039;&amp;#039;&amp;#039; column is the Django storage type. &amp;#039;&amp;#039;&amp;#039;Spec / Notes&amp;#039;&amp;#039;&amp;#039; records where the API representation, validation, or bound enum from the Pydantic specs diverges from storage.&lt;br /&gt;
&lt;br /&gt;
=== Identity &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;
! Type&lt;br /&gt;
! Spec / Notes&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=name|type=CharField(1000)|notes=Required (&amp;lt;code&amp;gt;blank=False, null=False&amp;lt;/code&amp;gt;). Spec enforces case-insensitive uniqueness across all facilities (&amp;lt;code&amp;gt;Lower(Trim(name))&amp;lt;/code&amp;gt;); on update the current row is excluded.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=description|type=TextField|notes=&amp;lt;code&amp;gt;blank=True, null=False&amp;lt;/code&amp;gt;; defaults to empty string. Required (&amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;) in &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=facility_type|type=IntegerField|notes=Required; choices from &amp;lt;code&amp;gt;FACILITY_TYPES&amp;lt;/code&amp;gt; (see below). Wire format is the label string, not the integer: create validates the label against &amp;lt;code&amp;gt;REVERSE_REVERSE_FACILITY_TYPES&amp;lt;/code&amp;gt; then maps to the int; read maps the int back to the label via &amp;lt;code&amp;gt;REVERSE_FACILITY_TYPES&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=features|type=ArrayField[SmallIntegerField]|notes=Nullable; each element a &amp;lt;code&amp;gt;FacilityFeature&amp;lt;/code&amp;gt; choice. Spec type &amp;lt;code&amp;gt;list[int]&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=is_active|type=BooleanField|notes=&amp;lt;code&amp;gt;default=True&amp;lt;/code&amp;gt;. Server-managed; the specs don&amp;#039;t expose it.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=verified|type=BooleanField|notes=&amp;lt;code&amp;gt;default=False&amp;lt;/code&amp;gt;. Server-managed; the specs don&amp;#039;t expose it.}}&lt;br /&gt;
{{Field|model=Facility|section=Identity &amp;amp;amp; classification|name=is_public|type=BooleanField|notes=&amp;lt;code&amp;gt;default=False&amp;lt;/code&amp;gt;; controls public visibility. Exposed as &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Location &amp;amp;amp; contact ===&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;
! Spec / Notes&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=address|type=TextField|notes=Free-text address. Required (&amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;).}}&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=pincode|type=IntegerField|notes=&amp;lt;code&amp;gt;default=None, null=True&amp;lt;/code&amp;gt; on the model; required &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=longitude|type=DecimalField(22, 16)|notes=Nullable. Spec type &amp;lt;code&amp;gt;Longitude | None&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;pydantic_extra_types&amp;lt;/code&amp;gt;, range −180…180).}}&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=latitude|type=DecimalField(22, 16)|notes=Nullable. Spec type &amp;lt;code&amp;gt;Latitude | None&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;pydantic_extra_types&amp;lt;/code&amp;gt;, range −90…90).}}&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=phone_number|type=CharField(14)|notes=&amp;lt;code&amp;gt;blank=True&amp;lt;/code&amp;gt;; validated with &amp;lt;code&amp;gt;mobile_or_landline_number_validator&amp;lt;/code&amp;gt;. Spec type &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
{{Field|model=Facility|section=Location &amp;amp;amp; contact|name=middleware_address|type=CharField(200)|notes=Nullable, &amp;lt;code&amp;gt;default=None&amp;lt;/code&amp;gt;. Hostname of an external device/middleware integration. Spec type &amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Organization links &amp;amp;amp; caches ===&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;
! Spec / Notes&lt;br /&gt;
{{Field|model=Facility|section=Organization links &amp;amp;amp; caches|name=geo_organization|type=FK → emr.Organization|notes=&amp;lt;code&amp;gt;on_delete=SET_NULL&amp;lt;/code&amp;gt;, nullable. Geographic/administrative org placement. On write (&amp;lt;code&amp;gt;FacilityCreateSpec&amp;lt;/code&amp;gt;): a required &amp;lt;code&amp;gt;UUID4&amp;lt;/code&amp;gt; (the org&amp;#039;s &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;), resolved on deserialization to an &amp;lt;code&amp;gt;Organization&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;org_type=&amp;amp;quot;govt&amp;amp;quot;&amp;lt;/code&amp;gt;. On read: a nested &amp;lt;code&amp;gt;OrganizationReadSpec&amp;lt;/code&amp;gt; dict (empty &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt; when unset).}}&lt;br /&gt;
{{Field|model=Facility|section=Organization links &amp;amp;amp; caches|name=geo_organization_cache|type=ArrayField[int]|notes=&amp;lt;code&amp;gt;default=list&amp;lt;/code&amp;gt;. Denormalized cache of &amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt;&amp;#039;s &amp;lt;code&amp;gt;parent_cache&amp;lt;/code&amp;gt; chain plus its own id; rebuilt by &amp;lt;code&amp;gt;sync_cache()&amp;lt;/code&amp;gt;. Not exposed by specs.}}&lt;br /&gt;
{{Field|model=Facility|section=Organization links &amp;amp;amp; caches|name=default_internal_organization|type=FK → emr.FacilityOrganization|notes=&amp;lt;code&amp;gt;on_delete=SET_NULL&amp;lt;/code&amp;gt;, nullable, &amp;lt;code&amp;gt;related_name=&amp;amp;quot;default_facilities&amp;amp;quot;&amp;lt;/code&amp;gt;. The auto-created root &amp;lt;code&amp;gt;Administration&amp;lt;/code&amp;gt; org. Not exposed by specs.}}&lt;br /&gt;
{{Field|model=Facility|section=Organization links &amp;amp;amp; caches|name=internal_organization_cache|type=ArrayField[int]|notes=&amp;lt;code&amp;gt;default=list&amp;lt;/code&amp;gt;. Denormalized cache of all &amp;lt;code&amp;gt;FacilityOrganization&amp;lt;/code&amp;gt; ids (with parent chains) under this facility; rebuilt by &amp;lt;code&amp;gt;sync_cache()&amp;lt;/code&amp;gt;. Not exposed by specs.}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Both cache fields are platform-maintained denormalizations, rebuilt on every &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt; so org-scoped filtering avoids deep joins. Never write them directly. See [[#methods--save-behaviour|Methods &amp;amp;amp; save behaviour]].&lt;br /&gt;
&lt;br /&gt;
=== Media &amp;amp;amp; presentation ===&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;
! Spec / Notes&lt;br /&gt;
{{Field|model=Facility|section=Media &amp;amp;amp; presentation|name=cover_image_url|type=CharField(500)|notes=Nullable, &amp;lt;code&amp;gt;default=None&amp;lt;/code&amp;gt;. Stores an object key, not a URL. Read specs expose both the raw &amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt; and a resolved &amp;lt;code&amp;gt;read_cover_image_url&amp;lt;/code&amp;gt; (full URL via &amp;lt;code&amp;gt;read_cover_image_url()&amp;lt;/code&amp;gt;).}}&lt;br /&gt;
{{Field|model=Facility|section=Media &amp;amp;amp; presentation|name=print_templates|type=JSONField|notes=&amp;lt;code&amp;gt;default=list&amp;lt;/code&amp;gt;. Opaque on the model; the real shape is &amp;lt;code&amp;gt;list[PrintTemplate]&amp;lt;/code&amp;gt; (see [[#printtemplate-json-shape}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Integration &amp;amp;amp; audit ===&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;
! Spec / Notes&lt;br /&gt;
{{Field|model=Facility|section=Integration &amp;amp;amp; audit|name=created_by|type=FK → users.User|notes=&amp;lt;code&amp;gt;on_delete=SET_NULL&amp;lt;/code&amp;gt;, nullable. Set to the facility administrator when the root org is provisioned. Read specs expose it as a nested &amp;lt;code&amp;gt;UserSpec&amp;lt;/code&amp;gt; dict (cache-backed), &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt; when unset.}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Choices &amp;amp;amp; enums ==&lt;br /&gt;
&lt;br /&gt;
These choice sets live in the model module and are consumed by &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; and related code.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;FacilityFeature&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;IntegerChoices&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;
! Name&lt;br /&gt;
! Label&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;lt;code&amp;gt;CT_SCAN_FACILITY&amp;lt;/code&amp;gt;&lt;br /&gt;
| CT Scan Facility&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;lt;code&amp;gt;MATERNITY_CARE&amp;lt;/code&amp;gt;&lt;br /&gt;
| Maternity Care&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| &amp;lt;code&amp;gt;X_RAY_FACILITY&amp;lt;/code&amp;gt;&lt;br /&gt;
| X-Ray Facility&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| &amp;lt;code&amp;gt;NEONATAL_CARE&amp;lt;/code&amp;gt;&lt;br /&gt;
| Neonatal Care&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| &amp;lt;code&amp;gt;OPERATION_THEATER&amp;lt;/code&amp;gt;&lt;br /&gt;
| Operation Theater&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| &amp;lt;code&amp;gt;BLOOD_BANK&amp;lt;/code&amp;gt;&lt;br /&gt;
| Blood Bank&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;HubRelationship&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;IntegerChoices&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;
! Name&lt;br /&gt;
! Label&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;lt;code&amp;gt;REGULAR_HUB&amp;lt;/code&amp;gt;&lt;br /&gt;
| Regular Hub&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;lt;code&amp;gt;TELE_ICU_HUB&amp;lt;/code&amp;gt;&lt;br /&gt;
| Tele ICU Hub&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;FACILITY_TYPES&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
A list of &amp;lt;code&amp;gt;(int code, label)&amp;lt;/code&amp;gt;. Codes are sparse and namespaced (8xx govt hospitals/health centres, 9xx labs/cooperatives, 10xx–16xx COVID-era centres, 3xxx/4xxx NGO/CBO). Commented-out legacy codes (&amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;801&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;820&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;831&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;850&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;950&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1000&amp;lt;/code&amp;gt;) survive in source as historical mapping notes and are not valid. The API binds on the label, not the code.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code&lt;br /&gt;
! Label&lt;br /&gt;
! Code&lt;br /&gt;
! Label&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Educational Inst&lt;br /&gt;
| 870&lt;br /&gt;
| Govt Medical College Hospitals&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Private Hospital&lt;br /&gt;
| 900&lt;br /&gt;
| Co-operative hospitals&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Other&lt;br /&gt;
| 910&lt;br /&gt;
| Autonomous healthcare facility&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Hostel&lt;br /&gt;
| 1010&lt;br /&gt;
| COVID-19 Domiciliary Care Center&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Hotel&lt;br /&gt;
| 1100&lt;br /&gt;
| First Line Treatment Centre&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Lodge&lt;br /&gt;
| 1200&lt;br /&gt;
| Second Line Treatment Center&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| TeleMedicine&lt;br /&gt;
| 1300&lt;br /&gt;
| Shifting Centre&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Govt Labs&lt;br /&gt;
| 1400&lt;br /&gt;
| Covid Management Center&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Private Labs&lt;br /&gt;
| 1500&lt;br /&gt;
| Request Approving Center&lt;br /&gt;
|-&lt;br /&gt;
| 800&lt;br /&gt;
| Primary Health Centres&lt;br /&gt;
| 1510&lt;br /&gt;
| Request Fulfilment Center&lt;br /&gt;
|-&lt;br /&gt;
| 802&lt;br /&gt;
| Family Health Centres&lt;br /&gt;
| 1600&lt;br /&gt;
| District War Room&lt;br /&gt;
|-&lt;br /&gt;
| 803&lt;br /&gt;
| Community Health Centres&lt;br /&gt;
| 3000&lt;br /&gt;
| Clinical Non Governmental Organization&lt;br /&gt;
|-&lt;br /&gt;
| 830&lt;br /&gt;
| Taluk Hospitals&lt;br /&gt;
| 3001&lt;br /&gt;
| Non Clinical Non Governmental Organization&lt;br /&gt;
|-&lt;br /&gt;
| 840&lt;br /&gt;
| Women and Child Health Centres&lt;br /&gt;
| 4000&lt;br /&gt;
| Community Based Organization&lt;br /&gt;
|-&lt;br /&gt;
| 860&lt;br /&gt;
| District Hospitals&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;REVERSE_FACILITY_TYPES&amp;lt;/code&amp;gt; (code → label) and &amp;lt;code&amp;gt;REVERSE_REVERSE_FACILITY_TYPES&amp;lt;/code&amp;gt; (label → code) are derived from &amp;lt;code&amp;gt;FACILITY_TYPES&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;reverse_choices&amp;lt;/code&amp;gt;. Create validates against the label set and stores the code; read maps the code back to the label.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;DOCTOR_TYPES&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
A list of &amp;lt;code&amp;gt;(int, label)&amp;lt;/code&amp;gt; covering 64 medical specialties (&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; General Medicine, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; Pulmonology, &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; Cardiologist, &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; Nurse, &amp;lt;code&amp;gt;64&amp;lt;/code&amp;gt; Critical Care Physician, etc.). Defined in this module but not referenced by the &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; model or facility specs.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MonetaryComponentType&amp;lt;/code&amp;gt; (str enum, from &amp;lt;code&amp;gt;monetary_component.py&amp;lt;/code&amp;gt;) ===&lt;br /&gt;
&lt;br /&gt;
Used by the discount monetary components in &amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;FacilityRetrieveSpec&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;base&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;surcharge&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discount&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;tax&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;informational&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;DiscountApplicability&amp;lt;/code&amp;gt; (str enum, from &amp;lt;code&amp;gt;monetary_component.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;total_asc&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;total_desc&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Nested JSON shapes ==&lt;br /&gt;
&lt;br /&gt;
These Pydantic models define the real structure behind the model&amp;#039;s JSON/array fields and the discount config.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;PrintTemplate&amp;lt;/code&amp;gt; JSON shape ===&lt;br /&gt;
&lt;br /&gt;
Element type of the &amp;lt;code&amp;gt;print_templates&amp;lt;/code&amp;gt; field.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;PrintTemplate {&lt;br /&gt;
  slug:        str (required)&lt;br /&gt;
  page:        PageConfig | null&lt;br /&gt;
  print_setup: PrintSetupConfig | null&lt;br /&gt;
  branding:    BrandingConfig | null&lt;br /&gt;
  watermark:   WatermarkConfig | null&lt;br /&gt;
}&lt;br /&gt;
PageConfig        { size: &amp;quot;A4&amp;quot;|&amp;quot;A5&amp;quot;|&amp;quot;Letter&amp;quot;|&amp;quot;Legal&amp;quot; | null,&lt;br /&gt;
                    orientation: &amp;quot;portrait&amp;quot;|&amp;quot;landscape&amp;quot; | null,&lt;br /&gt;
                    margin: PageMargin | null }&lt;br /&gt;
PageMargin        { top: float≥0, bottom: float≥0, left: float≥0, right: float≥0 }   # all required&lt;br /&gt;
PrintSetupConfig  { auto_print: bool | null }&lt;br /&gt;
BrandingConfig    { logo: LogoConfig | null, header_image: HeaderImageConfig | null,&lt;br /&gt;
                    footer_image: FooterImageConfig | null }&lt;br /&gt;
LogoConfig        { url: str (required), width: float | null, height: float | null,&lt;br /&gt;
                    alignment: &amp;quot;left&amp;quot;|&amp;quot;center&amp;quot;|&amp;quot;right&amp;quot; (required) }&lt;br /&gt;
HeaderImageConfig { url: str (required), height: float | null }&lt;br /&gt;
FooterImageConfig { url: str | null, height: float | null }&lt;br /&gt;
WatermarkConfig   { enabled: bool | null, text: str | null,&lt;br /&gt;
                    opacity: float | null (0…1), rotation: float | null }&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Discount config shapes (&amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;FacilityMonetoryConfig&amp;lt;/code&amp;gt;) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;discount_codes:                list[Coding]                     # see Coding below&lt;br /&gt;
discount_monetary_components:  list[MonetaryComponentDefinition]&lt;br /&gt;
discount_configuration:        DiscountConfiguration | null&lt;br /&gt;
&lt;br /&gt;
Coding { system: str|null, version: str|null, code: str (required), display: str|null }   # extra=&amp;quot;forbid&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MonetaryComponentDefinition (extends MonetaryComponent) {&lt;br /&gt;
  title:                   str (required)&lt;br /&gt;
  monetary_component_type: MonetaryComponentType   # base not allowed in a definition&lt;br /&gt;
  code:                    Coding | null&lt;br /&gt;
  factor:                  Decimal | null (max_digits=20, decimal_places=6)&lt;br /&gt;
  amount:                  Decimal | null (max_digits=20, decimal_places=6)&lt;br /&gt;
  tax_included_amount:     Decimal | null (base component only)&lt;br /&gt;
  global_component:        bool = false&lt;br /&gt;
  conditions:              list[EvaluatorConditionSpec] = []&lt;br /&gt;
}&lt;br /&gt;
EvaluatorConditionSpec { metric: str, operation: str, value: dict|str }   # metric validated against EvaluatorMetricsRegistry&lt;br /&gt;
DiscountConfiguration  { max_applicable: int≥0 (required), applicability_order: DiscountApplicability (required) }&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;base.py&amp;lt;/code&amp;gt;) is the shared period shape used across EMR resources. &amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt; doesn&amp;#039;t use it directly; it&amp;#039;s here for reference: &amp;lt;code&amp;gt;{ start: datetime|null, end: datetime|null }&amp;lt;/code&amp;gt;, both must be timezone-aware, and &amp;lt;code&amp;gt;start ≤ end&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
Every spec subclasses &amp;lt;code&amp;gt;EMRResource&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;base.py&amp;lt;/code&amp;gt;), which supplies &amp;lt;code&amp;gt;serialize&amp;lt;/code&amp;gt; (DB object → Pydantic), &amp;lt;code&amp;gt;de_serialize&amp;lt;/code&amp;gt; (Pydantic → DB object), and 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;__exclude__&amp;lt;/code&amp;gt; lists fields skipped during (de)serialization; &amp;lt;code&amp;gt;__store_metadata__&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;) controls whether unknown fields land in the model&amp;#039;s &amp;lt;code&amp;gt;meta&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The hierarchy is &amp;lt;code&amp;gt;FacilityBareMinimumSpec → FacilityBaseSpec → {FacilityCreateSpec, FacilityReadSpec → FacilityRetrieveSpec, FacilityMinimalReadSpec}&amp;lt;/code&amp;gt;. There is no separate &amp;lt;code&amp;gt;UpdateSpec&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;FacilityCreateSpec&amp;lt;/code&amp;gt; handles both create and update, with its validators reading &amp;lt;code&amp;gt;is_update&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; from the serializer context.&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;
! Key fields / behaviour&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityBareMinimumSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base (&amp;lt;code&amp;gt;@cacheable&amp;lt;/code&amp;gt;, base manager)&lt;br /&gt;
| &amp;lt;code&amp;gt;id: UUID4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;__exclude__=[&amp;amp;quot;geo_organization&amp;amp;quot;]&amp;lt;/code&amp;gt;. Cacheable, fetchable via &amp;lt;code&amp;gt;model_from_cache&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base&lt;br /&gt;
| Adds &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;longitude&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;latitude&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pincode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;address&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;phone_number&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;middleware_address&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is_public&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityCreateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create &amp;amp;amp; update&lt;br /&gt;
| Adds &amp;lt;code&amp;gt;geo_organization: UUID4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;features: list[int]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;print_templates: list[PrintTemplate] = []&amp;lt;/code&amp;gt;. Validates the &amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt; label and case-insensitive &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; uniqueness. &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; resolves &amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt; (must be &amp;lt;code&amp;gt;org_type=&amp;amp;quot;govt&amp;amp;quot;&amp;lt;/code&amp;gt;) and maps the &amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt; label → int.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;read_cover_image_url&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;geo_organization: dict&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;created_by: dict|null&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;perform_extra_serialization&amp;lt;/code&amp;gt; sets &amp;lt;code&amp;gt;id=external_id&amp;lt;/code&amp;gt;, resolves the cover image URL, maps &amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt; int → label, serializes &amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;OrganizationReadSpec&amp;lt;/code&amp;gt;, and resolves &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; via cached &amp;lt;code&amp;gt;UserSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| Extends &amp;lt;code&amp;gt;FacilityReadSpec&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;FacilityPermissionsMixin&amp;lt;/code&amp;gt;. Adds &amp;lt;code&amp;gt;flags&amp;lt;/code&amp;gt; (from &amp;lt;code&amp;gt;get_facility_flags()&amp;lt;/code&amp;gt;), facility + instance discount/tax/informational code lists, patient identifier configs, &amp;lt;code&amp;gt;invoice_number_expression&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;print_templates: list[dict]&amp;lt;/code&amp;gt;. The permissions mixin adds &amp;lt;code&amp;gt;permissions&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;root_org_permissions&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;child_org_permissions&amp;lt;/code&amp;gt;. Discount/invoice fields come from &amp;lt;code&amp;gt;FacilityMonetoryConfig.get_monetory_config()&amp;lt;/code&amp;gt;; instance-level lists come from Django &amp;lt;code&amp;gt;settings&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityMinimalReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · minimal&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityBaseSpec&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;read_cover_image_url&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;geo_organization: dict&amp;lt;/code&amp;gt;. Same serialization as &amp;lt;code&amp;gt;FacilityReadSpec&amp;lt;/code&amp;gt; minus &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · billing config&lt;br /&gt;
| Bound to &amp;lt;code&amp;gt;FacilityMonetoryConfig&amp;lt;/code&amp;gt;. Validates ≤ 100 discount codes and ≤ 100 monetary components, forbids duplicate / system-redefining codes, and requires every monetary-component code to be a defined facility or system code.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FacilityInvoiceExpressionSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · invoice config&lt;br /&gt;
| &amp;lt;code&amp;gt;invoice_number_expression: str&amp;lt;/code&amp;gt;, validated by &amp;lt;code&amp;gt;evaluate_invoice_dummy_expression&amp;lt;/code&amp;gt; (raises &amp;amp;quot;Invalid Expression&amp;amp;quot;).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Validation &amp;amp;amp; server-side behaviour ===&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — unique case-insensitively (&amp;lt;code&amp;gt;Lower(Trim(name))&amp;lt;/code&amp;gt;); on update the current object (from context) is excluded from the check.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — write accepts the label; an unknown label is rejected with the sorted valid-label list. Stored as the integer code; read maps it back to the label.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — write is a &amp;lt;code&amp;gt;UUID4&amp;lt;/code&amp;gt; resolved to an &amp;lt;code&amp;gt;Organization&amp;lt;/code&amp;gt; filtered by &amp;lt;code&amp;gt;org_type=&amp;amp;quot;govt&amp;amp;quot;&amp;lt;/code&amp;gt;, falling to &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt; if no match. Read embeds the full &amp;lt;code&amp;gt;OrganizationReadSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — &amp;lt;code&amp;gt;list[int]&amp;lt;/code&amp;gt;; each int should correspond to a &amp;lt;code&amp;gt;FacilityFeature&amp;lt;/code&amp;gt; value.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Bound value sets / coded fields&amp;#039;&amp;#039;&amp;#039; — discount/tax/informational components use &amp;lt;code&amp;gt;Coding&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;extra=&amp;amp;quot;forbid&amp;amp;quot;&amp;lt;/code&amp;gt;); &amp;lt;code&amp;gt;MonetaryComponentDefinition&amp;lt;/code&amp;gt; enforces no &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt; type, the single-base rules inherited from &amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt;, and amount/factor mutual exclusion.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — stores an object key; &amp;lt;code&amp;gt;read_cover_image_url&amp;lt;/code&amp;gt; is the resolved URL, present only on read specs.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Permissions&amp;#039;&amp;#039;&amp;#039; — &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt; computes them per requesting user from facility root and sub-org roles (&amp;lt;code&amp;gt;FacilityAccess&amp;lt;/code&amp;gt;); &amp;lt;code&amp;gt;can_update_facility&amp;lt;/code&amp;gt; is excluded from &amp;lt;code&amp;gt;child_org_permissions&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Facility&amp;lt;/code&amp;gt;&amp;#039;s relationships resolve through models in adjacent modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;geo_organization               → FK emr.Organization (SET_NULL)        # write: UUID4 of a govt org&lt;br /&gt;
default_internal_organization  → FK emr.FacilityOrganization (SET_NULL) # auto-provisioned root org&lt;br /&gt;
created_by                     → FK users.User (SET_NULL)&lt;br /&gt;
FacilityMonetoryConfig         → OneToOne facility.Facility (CASCADE)   # billing/discount config&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On creation, &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt; provisions a root [[References/Organization|&amp;lt;code&amp;gt;FacilityOrganization&amp;lt;/code&amp;gt;]] named &amp;lt;code&amp;gt;Administration&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;org_type=&amp;amp;quot;root&amp;amp;quot;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;system_generated=True&amp;lt;/code&amp;gt;) and a &amp;lt;code&amp;gt;FacilityOrganizationUser&amp;lt;/code&amp;gt; linking &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; to it with the &amp;lt;code&amp;gt;FACILITY_ADMIN_ROLE&amp;lt;/code&amp;gt;. Feature flags live in [[References/Facility Flag|&amp;lt;code&amp;gt;FacilityFlag&amp;lt;/code&amp;gt;]] and surface via &amp;lt;code&amp;gt;get_facility_flags()&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;Facility&amp;lt;/code&amp;gt; overrides &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt; and adds a few helpers.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Member&lt;br /&gt;
! Behaviour&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt;&lt;br /&gt;
| On &amp;#039;&amp;#039;&amp;#039;create&amp;#039;&amp;#039;&amp;#039; only: persists the row, then creates the root &amp;lt;code&amp;gt;Administration&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;FacilityOrganization&amp;lt;/code&amp;gt;, sets it as &amp;lt;code&amp;gt;default_internal_organization&amp;lt;/code&amp;gt; (an extra write), and creates a &amp;lt;code&amp;gt;FacilityOrganizationUser&amp;lt;/code&amp;gt; granting &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; the &amp;lt;code&amp;gt;FACILITY_ADMIN_ROLE&amp;lt;/code&amp;gt;. On &amp;#039;&amp;#039;&amp;#039;every&amp;#039;&amp;#039;&amp;#039; save: calls &amp;lt;code&amp;gt;sync_cache()&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;sync_cache()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Rebuilds &amp;lt;code&amp;gt;geo_organization_cache&amp;lt;/code&amp;gt; (parent chain of &amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt; + its id) and &amp;lt;code&amp;gt;internal_organization_cache&amp;lt;/code&amp;gt; (all &amp;lt;code&amp;gt;FacilityOrganization&amp;lt;/code&amp;gt; parent chains + ids, de-duplicated), then persists only those two fields via &amp;lt;code&amp;gt;update_fields&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read_cover_image_url()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Resolves &amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt; to a full URL via &amp;lt;code&amp;gt;settings.FACILITY_CDN&amp;lt;/code&amp;gt;, else the S3 external endpoint/bucket; returns &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt; when unset.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;get_facility_flags()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Delegates to &amp;lt;code&amp;gt;FacilityFlag.get_all_flags(self.id)&amp;lt;/code&amp;gt; (cache-backed).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;__str__()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Returns &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Creating a facility through the ORM costs three write passes: the initial insert, the &amp;lt;code&amp;gt;default_internal_organization&amp;lt;/code&amp;gt; update, and the &amp;lt;code&amp;gt;sync_cache()&amp;lt;/code&amp;gt; write of the two cache columns.&lt;br /&gt;
&lt;br /&gt;
Deletes are soft (inherited &amp;lt;code&amp;gt;BaseModel.delete()&amp;lt;/code&amp;gt; sets &amp;lt;code&amp;gt;deleted=True&amp;lt;/code&amp;gt;); the row and its child organizations are retained.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt; (UUID) is the public identifier, exposed as &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; by every read spec — the integer &amp;lt;code&amp;gt;pk&amp;lt;/code&amp;gt; stays internal.&lt;br /&gt;
* &amp;lt;code&amp;gt;facility_type&amp;lt;/code&amp;gt; crosses the wire as the label string (e.g. &amp;lt;code&amp;gt;&amp;amp;quot;Private Hospital&amp;amp;quot;&amp;lt;/code&amp;gt;), validated against &amp;lt;code&amp;gt;REVERSE_REVERSE_FACILITY_TYPES&amp;lt;/code&amp;gt;; the integer code is storage-only.&lt;br /&gt;
* &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt; are integer &amp;lt;code&amp;gt;FacilityFeature&amp;lt;/code&amp;gt; codes; map them to labels client-side.&lt;br /&gt;
* &amp;lt;code&amp;gt;geo_organization&amp;lt;/code&amp;gt; is written as the org&amp;#039;s UUID (must be a &amp;lt;code&amp;gt;govt&amp;lt;/code&amp;gt; org) and read as an embedded &amp;lt;code&amp;gt;OrganizationReadSpec&amp;lt;/code&amp;gt; object.&lt;br /&gt;
* &amp;lt;code&amp;gt;print_templates&amp;lt;/code&amp;gt; follows the typed [[#printtemplate-json-shape|&amp;lt;code&amp;gt;PrintTemplate&amp;lt;/code&amp;gt;]] shape on write and comes back as &amp;lt;code&amp;gt;list[dict]&amp;lt;/code&amp;gt; on retrieve.&lt;br /&gt;
* &amp;lt;code&amp;gt;geo_organization_cache&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;internal_organization_cache&amp;lt;/code&amp;gt; are platform-maintained — never set them from clients; they rebuild on every save.&lt;br /&gt;
* Creating a facility automatically provisions its root &amp;lt;code&amp;gt;Administration&amp;lt;/code&amp;gt; organization and an admin membership for &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt;; don&amp;#039;t create these manually.&lt;br /&gt;
* &amp;lt;code&amp;gt;cover_image_url&amp;lt;/code&amp;gt; stores an object key; render &amp;lt;code&amp;gt;read_cover_image_url&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
* Discount/tax/invoice billing config is managed through &amp;lt;code&amp;gt;FacilityMonetaryCodeSpec&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;FacilityInvoiceExpressionSpec&amp;lt;/code&amp;gt; and surfaced on &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt;; it&amp;#039;s backed by [[References/Facility Config|&amp;lt;code&amp;gt;FacilityMonetoryConfig&amp;lt;/code&amp;gt;]].&lt;br /&gt;
* &amp;lt;code&amp;gt;FacilityRetrieveSpec&amp;lt;/code&amp;gt; also returns the requesting user&amp;#039;s permissions and feature flags; flags come via &amp;lt;code&amp;gt;get_facility_flags()&amp;lt;/code&amp;gt; rather than a row-by-row query.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>