<?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%2FAccount</id>
	<title>References/Account - 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%2FAccount"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Account&amp;action=history"/>
	<updated>2026-07-06T05:23:01Z</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/Account&amp;diff=436&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/Account&amp;diff=436&amp;oldid=prev"/>
		<updated>2026-07-06T04:10:41Z</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:40, 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 277:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 277:&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; is the supported place for custom key-value data without schema migrations; &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; checks it, and it surfaces only on the retrieve spec.&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; is the supported place for custom key-value data without schema migrations; &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; checks it, and it surfaces only on the retrieve spec.&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;* Gate account data behind permissions that restrict access to users with rights to financial information.&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;* Gate account data behind permissions that restrict access to users with rights to financial information.&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 billing}}&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/Account&amp;diff=133&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/Account&amp;diff=133&amp;oldid=prev"/>
		<updated>2026-07-04T22:44: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=billing&lt;br /&gt;
|title=Account&lt;br /&gt;
|order=1&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|model=Account&lt;br /&gt;
|concept=Concepts/Patient&lt;br /&gt;
|reference=References/Base models &amp;amp;amp; conventions&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
An &amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; is the financial bucket that aggregates every transaction made against a patient within a facility. You touch it indirectly: charge items land on a patient&amp;#039;s default account, and invoices and reconciliations settle against it.&lt;br /&gt;
&lt;br /&gt;
Several model fields are opaque &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;s whose real structure lives in the Pydantic resource specs under &amp;lt;code&amp;gt;care/emr/resources/account/&amp;lt;/code&amp;gt;. Each field below is paired with the spec-defined enums, JSON shapes, validation, and read/write schemas that govern it.&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/account.py &amp;lt;code&amp;gt;care/emr/models/account.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Resource spec: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/spec.py &amp;lt;code&amp;gt;care/emr/resources/account/spec.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Default account helper: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/default_account.py &amp;lt;code&amp;gt;account/default_account.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Balance sync: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/sync_items.py &amp;lt;code&amp;gt;account/sync_items.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;
&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;Account&amp;lt;/code&amp;gt;&lt;br /&gt;
| Aggregates charges and balances for one patient in one facility across encounters&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; extends [[References/Base models &amp;amp;amp; conventions|&amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;]], which contributes &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, the audit fields &amp;lt;code&amp;gt;created_date&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;modified_date&amp;lt;/code&amp;gt;, soft-delete via &amp;lt;code&amp;gt;deleted&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;, and &amp;lt;code&amp;gt;history&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;meta&amp;lt;/code&amp;gt; JSON.&lt;br /&gt;
&lt;br /&gt;
Accounts are perpetual. One active, open account exists per patient per facility (see [[#default-account|&amp;lt;code&amp;gt;get_default_account&amp;lt;/code&amp;gt;]]), and charge items land on it. After discharge, the account can be balanced and closed. Invoices are raised against an account or against the items within it.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
=== Identity &amp;amp;amp; scope ===&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=Account|section=Identity &amp;amp;amp; scope|name=facility|type=FK → facility.Facility (PROTECT)|notes=yes}}&lt;br /&gt;
{{Field|model=Account|section=Identity &amp;amp;amp; scope|name=patient|type=FK → emr.Patient (PROTECT)|notes=yes}}&lt;br /&gt;
{{Field|model=Account|section=Identity &amp;amp;amp; scope|name=name|type=CharField(255)|notes=yes}}&lt;br /&gt;
{{Field|model=Account|section=Identity &amp;amp;amp; scope|name=description|type=TextField|notes=no}}&lt;br /&gt;
{{Field|model=Account|section=Identity &amp;amp;amp; scope|name=primary_encounter|type=FK → emr.Encounter (SET_NULL, nullable)|notes=no}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== 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;
! Required&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=Account|section=Status|name=status|type=CharField(255)|notes=yes}}&lt;br /&gt;
{{Field|model=Account|section=Status|name=billing_status|type=CharField(255)|notes=yes}}&lt;br /&gt;
{{Field|model=Account|section=Status|name=service_period|type=JSONField (default {})|notes=yes (on spec)}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Balances &amp;amp;amp; totals ===&lt;br /&gt;
&lt;br /&gt;
These decimal totals (&amp;lt;code&amp;gt;max_digits=20, decimal_places=6&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;) are platform-maintained aggregates that [[#balance-sync|&amp;lt;code&amp;gt;sync_account_items&amp;lt;/code&amp;gt;]] recomputes. None are client-writable, and none appear on a write spec.&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=Account|section=Balances &amp;amp;amp; totals|name=total_net|type=DecimalField|notes=Net total before adjustments. Not populated — the &amp;lt;code&amp;gt;sync_account_items&amp;lt;/code&amp;gt; logic is commented out, so it holds the default &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=total_gross|type=DecimalField|notes=Sum of &amp;lt;code&amp;gt;total_price&amp;lt;/code&amp;gt; over charge items in &amp;lt;code&amp;gt;paid&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;billed&amp;lt;/code&amp;gt; status}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=total_paid|type=DecimalField|notes=Sum of &amp;lt;code&amp;gt;active&amp;lt;/code&amp;gt;+&amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; payment reconciliations, minus credit-note reconciliations}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=total_balance|type=DecimalField|notes=&amp;lt;code&amp;gt;total_gross − total_paid&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=total_billable_charge_items|type=DecimalField|notes=Sum of &amp;lt;code&amp;gt;total_price&amp;lt;/code&amp;gt; over charge items in &amp;lt;code&amp;gt;billable&amp;lt;/code&amp;gt; status}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=total_price_components|type=JSONField (default {})|notes=Intended price-component breakdown (taxes, discounts, etc.) as a list of &amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt; (see [[#monetarycomponent-shape}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=cached_items|type=JSONField (default {})|notes=Denormalized snapshot of the account&amp;#039;s charge items, serialized as a &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; on retrieve. Not populated — the sync logic is commented out}}&lt;br /&gt;
{{Field|model=Account|section=Balances &amp;amp;amp; totals|name=calculated_at|type=DateTimeField (nullable)|notes=When the balances were last computed; set to &amp;lt;code&amp;gt;care_now()&amp;lt;/code&amp;gt; on each sync}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== 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=Account|section=Tags &amp;amp;amp; extensions|name=tags|type=ArrayField[int] (default [])|notes=Tag IDs applied to the account; rendered through &amp;lt;code&amp;gt;SingleFacilityTagManager&amp;lt;/code&amp;gt; on read}}&lt;br /&gt;
{{Field|model=Account|section=Tags &amp;amp;amp; extensions|name=extensions|type=JSONField (default {})|notes=Open bag for deployment-specific metadata. &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; checks it against &amp;lt;code&amp;gt;ExtensionResource.account&amp;lt;/code&amp;gt;; surfaced only on the retrieve spec}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Enum values ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;AccountStatusOptions&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
Stored as the raw enum value string in &amp;lt;code&amp;gt;status&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;active&amp;lt;/code&amp;gt;&lt;br /&gt;
| Open and in use (the default-account state)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;inactive&amp;lt;/code&amp;gt;&lt;br /&gt;
| No longer actively used&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;&lt;br /&gt;
| Created in error&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;on_hold&amp;lt;/code&amp;gt;&lt;br /&gt;
| Temporarily paused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Values use underscores (&amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;on_hold&amp;lt;/code&amp;gt;), not the FHIR-style hyphenated forms.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;AccountBillingStatusOptions&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
Stored as the raw enum value string in &amp;lt;code&amp;gt;billing_status&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;open&amp;lt;/code&amp;gt;&lt;br /&gt;
| Billing open and accruing (the default-account state)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;carecomplete_notbilled&amp;lt;/code&amp;gt;&lt;br /&gt;
| Care complete, not yet billed&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;billing&amp;lt;/code&amp;gt;&lt;br /&gt;
| Billing in progress&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;closed_baddebt&amp;lt;/code&amp;gt;&lt;br /&gt;
| Closed as bad debt&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;closed_voided&amp;lt;/code&amp;gt;&lt;br /&gt;
| Closed and voided&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;closed_completed&amp;lt;/code&amp;gt;&lt;br /&gt;
| Closed, billing completed&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;closed_combined&amp;lt;/code&amp;gt;&lt;br /&gt;
| Closed, combined into another account&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== JSON field shapes ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;service_period&amp;lt;/code&amp;gt; shape ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;service_period&amp;lt;/code&amp;gt; stores a &amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt; (from [&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;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;PeriodSpec {&lt;br /&gt;
  start: datetime | null   # ISO 8601, timezone-aware&lt;br /&gt;
  end:   datetime | null   # ISO 8601, timezone-aware&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;PeriodSpec.validate_period&amp;lt;/code&amp;gt; enforces three rules:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt;, if present, must be timezone-aware — a naive datetime raises &amp;lt;code&amp;gt;&amp;amp;quot;Start Date must be timezone aware&amp;amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt;, if present, must be timezone-aware — &amp;lt;code&amp;gt;&amp;amp;quot;End Date must be timezone aware&amp;amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* With both present, &amp;lt;code&amp;gt;start &amp;amp;lt;= end&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;&amp;amp;quot;Start Date cannot be greater than End Date&amp;amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The default account sets only &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt;, formatted as &amp;lt;code&amp;gt;&amp;amp;quot;%Y-%m-%dT%H:%M:%S.%fZ&amp;amp;quot;&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;care_now()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The FHIR-style [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/period.py &amp;lt;code&amp;gt;Period&amp;lt;/code&amp;gt;] common type (&amp;lt;code&amp;gt;{ id?, start?, end? }&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;extra=&amp;amp;quot;forbid&amp;amp;quot;&amp;lt;/code&amp;gt;) is a related but distinct shape — &amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; binds &amp;lt;code&amp;gt;service_period&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;Period&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt; shape ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt; is meant to hold a list of [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/monetary_component.py &amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt;] entries, the same shape used across billing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;MonetaryComponent {&lt;br /&gt;
  monetary_component_type: base | surcharge | discount | tax | informational&lt;br /&gt;
  code:                    Coding | null&lt;br /&gt;
  factor:                  Decimal(max_digits=20, decimal_places=6) | null&lt;br /&gt;
  amount:                  Decimal(max_digits=20, decimal_places=6) | null&lt;br /&gt;
  tax_included_amount:     Decimal(max_digits=20, decimal_places=6) | null&lt;br /&gt;
  global_component:        bool = false&lt;br /&gt;
  conditions:              EvaluatorConditionSpec[] = []&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt; validation: &amp;lt;code&amp;gt;tax_included_amount&amp;lt;/code&amp;gt; is allowed only on a &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt; component; a &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt; component must carry an &amp;lt;code&amp;gt;amount&amp;lt;/code&amp;gt;, no &amp;lt;code&amp;gt;factor&amp;lt;/code&amp;gt;, and no &amp;lt;code&amp;gt;conditions&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;amount&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;factor&amp;lt;/code&amp;gt; are mutually exclusive; exactly one of &amp;lt;code&amp;gt;amount&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;factor&amp;lt;/code&amp;gt; is required unless the entry is a &amp;lt;code&amp;gt;global_component&amp;lt;/code&amp;gt; with a &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
The API layer lives in [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/spec.py &amp;lt;code&amp;gt;resources/account/spec.py&amp;lt;/code&amp;gt;]. Every spec builds on &amp;lt;code&amp;gt;EMRResource&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;serialize&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;de_serialize&amp;lt;/code&amp;gt;, with 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;AccountSpec&amp;lt;/code&amp;gt; sets &amp;lt;code&amp;gt;__exclude__ = [&amp;amp;quot;patient&amp;amp;quot;]&amp;lt;/code&amp;gt; and binds &amp;lt;code&amp;gt;___extension_resource_type__ = ExtensionResource.account&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;
! Fields exposed (beyond base)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base&lt;br /&gt;
| &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;billing_status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;service_period&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;PeriodSpec&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountCreateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create&lt;br /&gt;
| base + &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; (UUID, required)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountUpdateSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · update&lt;br /&gt;
| base + &amp;lt;code&amp;gt;primary_encounter&amp;lt;/code&amp;gt; (UUID, optional)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountMinimalReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · minimal&lt;br /&gt;
| base + &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_paid&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_balance&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_billable_charge_items&amp;lt;/code&amp;gt; (all &amp;lt;code&amp;gt;Decimal&amp;lt;/code&amp;gt; 20/6), &amp;lt;code&amp;gt;calculated_at&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;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| minimal + &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; (serialized &amp;lt;code&amp;gt;PatientListSpec&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;tags&amp;lt;/code&amp;gt; (rendered tag dicts)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AccountRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| read + &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; (serialized &amp;lt;code&amp;gt;PatientRetrieveSpec&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;primary_encounter&amp;lt;/code&amp;gt; (serialized &amp;lt;code&amp;gt;EncounterRetrieveSpec&amp;lt;/code&amp;gt; when set), &amp;lt;code&amp;gt;cached_items&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;)&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;Create&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;AccountCreateSpec&amp;lt;/code&amp;gt;): mixes in &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; to validate &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt;, and requires &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; as a UUID. &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; resolves it via &amp;lt;code&amp;gt;get_object_or_404(Patient, external_id=...)&amp;lt;/code&amp;gt; and assigns &amp;lt;code&amp;gt;obj.patient&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; is otherwise excluded from the base serialize loop.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Update&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;AccountUpdateSpec&amp;lt;/code&amp;gt;): mixes in &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;primary_encounter&amp;lt;/code&amp;gt; is optional. When supplied, &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; resolves it via &amp;lt;code&amp;gt;get_object_or_404(Encounter, external_id=...)&amp;lt;/code&amp;gt; and assigns &amp;lt;code&amp;gt;obj.primary_encounter&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Status / billing_status&amp;#039;&amp;#039;&amp;#039;: the Pydantic enums &amp;lt;code&amp;gt;AccountStatusOptions&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;AccountBillingStatusOptions&amp;lt;/code&amp;gt; reject any value outside their members.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Read serialization&amp;#039;&amp;#039;&amp;#039;: &amp;lt;code&amp;gt;perform_extra_serialization&amp;lt;/code&amp;gt; sets &amp;lt;code&amp;gt;mapping[&amp;amp;quot;id&amp;amp;quot;] = obj.external_id&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;AccountReadSpec&amp;lt;/code&amp;gt; serializes the patient (&amp;lt;code&amp;gt;PatientListSpec&amp;lt;/code&amp;gt;) and renders tags via &amp;lt;code&amp;gt;SingleFacilityTagManager&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;AccountRetrieveSpec&amp;lt;/code&amp;gt; serializes the full patient (&amp;lt;code&amp;gt;PatientRetrieveSpec&amp;lt;/code&amp;gt;, scoped to &amp;lt;code&amp;gt;obj.facility&amp;lt;/code&amp;gt;) and, when present, the primary encounter (&amp;lt;code&amp;gt;EncounterRetrieveSpec&amp;lt;/code&amp;gt;).&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Totals are read-only&amp;#039;&amp;#039;&amp;#039;: balance and aggregate fields appear only on read specs. &amp;lt;code&amp;gt;sync_account_items&amp;lt;/code&amp;gt; recomputes them; client payloads never set them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;a id=&amp;quot;default-account&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default account ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;get_default_account(patient, facility)&amp;lt;/code&amp;gt; ([&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/default_account.py &amp;lt;code&amp;gt;default_account.py&amp;lt;/code&amp;gt;]) returns the first account for that &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;facility&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;status = active&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;billing_status = open&amp;lt;/code&amp;gt;. If none exists, it creates one with:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;status = active&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;billing_status = open&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;service_period = { &amp;amp;quot;start&amp;amp;quot;: care_now() }&amp;lt;/code&amp;gt; (start only)&lt;br /&gt;
* &amp;lt;code&amp;gt;name = &amp;amp;quot;{patient.name} {YYYY-MM-DD}&amp;amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This runs when the first charge item is added, so the default account materializes on demand. Clients normally never create accounts directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;a id=&amp;quot;balance-sync&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Balance sync ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sync_account_items(account)&amp;lt;/code&amp;gt; ([&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/account/sync_items.py &amp;lt;code&amp;gt;sync_items.py&amp;lt;/code&amp;gt;]) recomputes the totals under an &amp;lt;code&amp;gt;AccountLock&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;total_billable_charge_items&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;Σ total_price&amp;lt;/code&amp;gt; of charge items with status &amp;lt;code&amp;gt;billable&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;Σ total_price&amp;lt;/code&amp;gt; of charge items with status &amp;lt;code&amp;gt;paid&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;billed&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;total_paid&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;Σ amount&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;active&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;complete&amp;lt;/code&amp;gt; non-credit-note payment reconciliations − the same for credit notes&lt;br /&gt;
* &amp;lt;code&amp;gt;total_balance&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;total_gross − total_paid&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;calculated_at&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;care_now()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every sum runs through &amp;lt;code&amp;gt;care_round&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cached_items&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt; are not updated — their logic is commented out — so they hold their defaults. &amp;lt;code&amp;gt;rebalance_account_task(account_id)&amp;lt;/code&amp;gt; is the Celery wrapper that runs the sync and saves.&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; is the only class in &amp;lt;code&amp;gt;account.py&amp;lt;/code&amp;gt;. Its relationships:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;facility          → FK facility.Facility (PROTECT)&lt;br /&gt;
patient           → FK emr.Patient (PROTECT)&lt;br /&gt;
primary_encounter → FK emr.Encounter (SET_NULL, nullable)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[References/Charge Item|Charge items]] reference the account they belong to and drive its totals; [[References/Invoice|invoices]] and [[References/Payment Reconciliation|payment reconciliations]] settle against the account or its items.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* The REST API aligns to the FHIR &amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt; resource, but spec field names and enum values differ (enums use underscores, not hyphens).&lt;br /&gt;
* &amp;lt;code&amp;gt;get_default_account&amp;lt;/code&amp;gt; creates the default account when the first charge item is added for a patient in a facility; clients normally do not create accounts directly.&lt;br /&gt;
* On &amp;#039;&amp;#039;&amp;#039;create&amp;#039;&amp;#039;&amp;#039;, supply &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; as the patient&amp;#039;s &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt; (UUID); &amp;lt;code&amp;gt;facility&amp;lt;/code&amp;gt; is server-scoped.&lt;br /&gt;
* On &amp;#039;&amp;#039;&amp;#039;update&amp;#039;&amp;#039;&amp;#039;, &amp;lt;code&amp;gt;primary_encounter&amp;lt;/code&amp;gt; accepts an encounter &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt; (UUID); only the base fields plus &amp;lt;code&amp;gt;primary_encounter&amp;lt;/code&amp;gt; are mutable.&lt;br /&gt;
* Balance and aggregate fields (&amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_paid&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_balance&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_billable_charge_items&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cached_items&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;calculated_at&amp;lt;/code&amp;gt;) are platform-maintained and appear only on read specs — never set them from clients.&lt;br /&gt;
* &amp;lt;code&amp;gt;service_period&amp;lt;/code&amp;gt; requires timezone-aware datetimes with &amp;lt;code&amp;gt;start &amp;amp;lt;= end&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;extensions&amp;lt;/code&amp;gt; is the supported place for custom key-value data without schema migrations; &amp;lt;code&amp;gt;ExtensionValidator&amp;lt;/code&amp;gt; checks it, and it surfaces only on the retrieve spec.&lt;br /&gt;
* Gate account data behind permissions that restrict access to users with rights to financial information.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>