<?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%2FInvoice</id>
	<title>References/Invoice - 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%2FInvoice"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Invoice&amp;action=history"/>
	<updated>2026-07-06T05:18:46Z</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/Invoice&amp;diff=438&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/Invoice&amp;diff=438&amp;oldid=prev"/>
		<updated>2026-07-06T04:12:01Z</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:42, 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 243:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 243:&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;* The list view (&amp;lt;code&amp;gt;InvoiceReadSpec&amp;lt;/code&amp;gt;) returns a minimal &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt;; the detail view (&amp;lt;code&amp;gt;InvoiceRetrieveSpec&amp;lt;/code&amp;gt;) returns the full account plus charge items, aggregated price components, payments, credit notes, and lock history.&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;* The list view (&amp;lt;code&amp;gt;InvoiceReadSpec&amp;lt;/code&amp;gt;) returns a minimal &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt;; the detail view (&amp;lt;code&amp;gt;InvoiceRetrieveSpec&amp;lt;/code&amp;gt;) returns the full account plus charge items, aggregated price components, payments, credit notes, and lock history.&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;* When &amp;lt;code&amp;gt;locked&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, the read specs serialize &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; as &amp;lt;code&amp;gt;0&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;* When &amp;lt;code&amp;gt;locked&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, the read specs serialize &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; as &amp;lt;code&amp;gt;0&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 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/Invoice&amp;diff=135&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/Invoice&amp;diff=135&amp;oldid=prev"/>
		<updated>2026-07-04T22:44:11Z</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=Invoice&lt;br /&gt;
|order=4&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|model=Invoice&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;Invoice&amp;lt;/code&amp;gt; groups [[References/Charge Item|charge items]] raised against a single [[References/Account|account]] into one billable document, with snapshotted line items, totals, and a lifecycle &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;. You touch it whenever you bill a patient, issue a refund, or reconcile payments.&lt;br /&gt;
&lt;br /&gt;
The data splits across two layers. The Django model is storage: columns plus several opaque &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;s (&amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lock_history&amp;lt;/code&amp;gt;) whose real structure lives in the Pydantic resource specs. The specs define the API request/response schemas, the &amp;lt;code&amp;gt;InvoiceStatusOptions&amp;lt;/code&amp;gt; enum, the shape of those JSON fields, validation, and the server-side totalling and snapshot behaviour.&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/invoice.py &amp;lt;code&amp;gt;care/emr/models/invoice.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/invoice/spec.py &amp;lt;code&amp;gt;spec.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/invoice/sync_items.py &amp;lt;code&amp;gt;sync_items.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/invoice/return_items_invoice.py &amp;lt;code&amp;gt;return_items_invoice.py&amp;lt;/code&amp;gt;] · [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/invoice/default_expression_evaluator.py &amp;lt;code&amp;gt;default_expression_evaluator.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Shared types: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py &amp;lt;code&amp;gt;base.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;Invoice&amp;lt;/code&amp;gt;&lt;br /&gt;
| A billable grouping of charge items for one account, with snapshotted line items, totals, and status&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Invoice&amp;lt;/code&amp;gt; extends [[References/Base models &amp;amp;amp; conventions|&amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;]] (shared Care EMR base with &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, audit fields, and soft-delete semantics).&lt;br /&gt;
&lt;br /&gt;
On issue, the server computes net and gross totals and snapshots each charge item, so the invoice stays stable even when its charge items change later. The retrieve view reports [[References/Payment Reconciliation|payment reconciliation]] records — payments and credit notes — against the invoice.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;Invoice&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
=== References ===&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=Invoice|section=References|name=facility|type=FK → facility.Facility (PROTECT)|notes=Facility where the invoice is created}}&lt;br /&gt;
{{Field|model=Invoice|section=References|name=patient|type=FK → emr.Patient (PROTECT)|notes=Entity that incurred the charges; set server-side from &amp;lt;code&amp;gt;account.patient&amp;lt;/code&amp;gt; on write}}&lt;br /&gt;
{{Field|model=Invoice|section=References|name=account|type=FK → emr.Account (PROTECT)|notes=Account being balanced by this invoice}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Status &amp;amp;amp; metadata ===&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 / values&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=status|type=CharField(100)|notes=&amp;lt;code&amp;gt;InvoiceStatusOptions&amp;lt;/code&amp;gt; enum — required on write}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=title|type=CharField(1024)|notes=&amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=cancelled_reason|type=TextField|notes=&amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=payment_terms|type=TextField|notes=&amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=note|type=TextField|notes=&amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=number|type=CharField(1000)|notes=&amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=issue_date|type=DateTimeField|notes=&amp;lt;code&amp;gt;datetime | None&amp;lt;/code&amp;gt; (tz-aware), default &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Status &amp;amp;amp; metadata|name=is_refund|type=BooleanField|notes=&amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt;, default &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Charge items ===&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 shape&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=Invoice|section=Charge items|name=charge_items|type=ArrayField[int], default []|notes=write: &amp;lt;code&amp;gt;list[UUID4]&amp;lt;/code&amp;gt;; storage: list of integer PKs}}&lt;br /&gt;
{{Field|model=Invoice|section=Charge items|name=charge_items_copy|type=JSONField, default []|notes=&amp;lt;code&amp;gt;list[dict]&amp;lt;/code&amp;gt; — array of serialized &amp;lt;code&amp;gt;ChargeItemReadSpec&amp;lt;/code&amp;gt;}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Totals (server-maintained) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;sync_invoice_items&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;calculate_charge_items_summary&amp;lt;/code&amp;gt; compute these. Never send them from a client.&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 shape&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=Invoice|section=Totals (server-maintained)|name=total_price_components|type=JSONField, default {}|notes=retrieve: &amp;lt;code&amp;gt;list[dict]&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;MonetaryComponent&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Totals (server-maintained)|name=total_net|type=DecimalField(20, 6), default 0|notes=&amp;lt;code&amp;gt;Decimal(max_digits=20, decimal_places=6)&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Field|model=Invoice|section=Totals (server-maintained)|name=total_gross|type=DecimalField(20, 6), default 0|notes=&amp;lt;code&amp;gt;Decimal(max_digits=20, decimal_places=6)&amp;lt;/code&amp;gt;}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When &amp;lt;code&amp;gt;locked&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, the read specs serialize both &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; as &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Locking ===&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 shape&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=Invoice|section=Locking|name=locked|type=BooleanField, default False|notes=&amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt; (read-only on read specs)}}&lt;br /&gt;
{{Field|model=Invoice|section=Locking|name=lock_history|type=JSONField, default []|notes=&amp;lt;code&amp;gt;list[dict]&amp;lt;/code&amp;gt; — each entry &amp;lt;code&amp;gt;{ user, ... }&amp;lt;/code&amp;gt;}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Enums ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;InvoiceStatusOptions&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
Defined in &amp;lt;code&amp;gt;care/emr/resources/invoice/spec.py&amp;lt;/code&amp;gt;. The API value is &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; (underscore), not the FHIR-style hyphen.&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;draft&amp;lt;/code&amp;gt;&lt;br /&gt;
| In progress; retrieve serializes live charge items, not the snapshot&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;issued&amp;lt;/code&amp;gt;&lt;br /&gt;
| Issued to the patient/payer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;balanced&amp;lt;/code&amp;gt;&lt;br /&gt;
| Fully settled&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;cancelled&amp;lt;/code&amp;gt;&lt;br /&gt;
| Cancelled&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;&lt;br /&gt;
| Recorded in error&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;INVOICE_CANCELLED_STATUS = [&amp;amp;quot;cancelled&amp;amp;quot;, &amp;amp;quot;entered_in_error&amp;amp;quot;]&amp;lt;/code&amp;gt; — the two terminal/void states.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;MonetaryComponentType&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
Defined in &amp;lt;code&amp;gt;care/emr/resources/common/monetary_component.py&amp;lt;/code&amp;gt;. Each type contributes to net and gross differently during totalling.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value&lt;br /&gt;
! Effect on totals&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt;&lt;br /&gt;
| Added to net (one base component per item; must carry an &amp;lt;code&amp;gt;amount&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;
| Added to net&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;discount&amp;lt;/code&amp;gt;&lt;br /&gt;
| Subtracted from net&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;tax&amp;lt;/code&amp;gt;&lt;br /&gt;
| Added to gross only (excluded from net)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;informational&amp;lt;/code&amp;gt;&lt;br /&gt;
| Carried for display; not summed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
All specs subclass &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 &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;BaseInvoiceSpec.__model__ = Invoice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;__exclude__ = [&amp;amp;quot;account&amp;amp;quot;, &amp;amp;quot;charge_items&amp;amp;quot;]&amp;lt;/code&amp;gt;; the hooks handle those two fields rather than the generic mapper.&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;
! Fields beyond base&lt;br /&gt;
! Server behaviour&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;BaseInvoiceSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared&lt;br /&gt;
| &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;title&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt; (required), &amp;lt;code&amp;gt;cancelled_reason&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;payment_terms&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;note&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;issue_date&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;number&amp;lt;/code&amp;gt;&lt;br /&gt;
| Base for all specs&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;InvoiceWriteSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create + update&lt;br /&gt;
| &amp;lt;code&amp;gt;account: UUID4&amp;lt;/code&amp;gt; (required), &amp;lt;code&amp;gt;charge_items: list[UUID4]&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt;)&lt;br /&gt;
| &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt;: resolves &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, sets &amp;lt;code&amp;gt;patient = account.patient&amp;lt;/code&amp;gt;, stages &amp;lt;code&amp;gt;charge_items&amp;lt;/code&amp;gt; (rewritten in &amp;lt;code&amp;gt;perform_create&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;InvoiceReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list&lt;br /&gt;
| &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;locked&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;, &amp;lt;code&amp;gt;account: dict&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is_refund&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;perform_extra_serialization&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;id = external_id&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt; → &amp;lt;code&amp;gt;AccountMinimalReadSpec&amp;lt;/code&amp;gt;; if &amp;lt;code&amp;gt;locked&amp;lt;/code&amp;gt;, zero out &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;InvoiceRetrieveSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · detail&lt;br /&gt;
| (all read fields) + &amp;lt;code&amp;gt;charge_items: list[dict]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_price_components: list[dict]&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;, &amp;lt;code&amp;gt;payments: list[dict]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_payments&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;credit_notes: list[dict]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_credit_notes&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lock_history: list[dict]&amp;lt;/code&amp;gt;&lt;br /&gt;
| See retrieve serialization below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;InvoiceWriteSpec&amp;lt;/code&amp;gt; handles both create and update — there&amp;#039;s no separate Update spec. &amp;lt;code&amp;gt;InvoiceRetrieveSpec&amp;lt;/code&amp;gt; extends &amp;lt;code&amp;gt;InvoiceReadSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;InvoiceRetrieveSpec.perform_extra_serialization&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;id = external_id&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt; serialized via &amp;lt;code&amp;gt;AccountReadSpec&amp;lt;/code&amp;gt; (full account on detail).&lt;br /&gt;
* &amp;lt;code&amp;gt;charge_items&amp;lt;/code&amp;gt;: if &amp;lt;code&amp;gt;status == draft&amp;lt;/code&amp;gt;, live &amp;lt;code&amp;gt;ChargeItemReadSpec.serialize(...)&amp;lt;/code&amp;gt; over &amp;lt;code&amp;gt;ChargeItem.objects.filter(id__in=charge_items)&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;select_related&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;paid_invoice&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;charge_item_definition&amp;lt;/code&amp;gt;); otherwise the stored &amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt; snapshot.&lt;br /&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;: hydrated via &amp;lt;code&amp;gt;serialize_audit_users&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Reconciliations against this invoice with &amp;lt;code&amp;gt;outcome = complete&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;status = active&amp;lt;/code&amp;gt; are split into:&lt;br /&gt;
** &amp;lt;code&amp;gt;payments&amp;lt;/code&amp;gt; (+ &amp;lt;code&amp;gt;total_payments&amp;lt;/code&amp;gt;) where &amp;lt;code&amp;gt;is_credit_note&amp;lt;/code&amp;gt; is false,&lt;br /&gt;
** &amp;lt;code&amp;gt;credit_notes&amp;lt;/code&amp;gt; (+ &amp;lt;code&amp;gt;total_credit_notes&amp;lt;/code&amp;gt;) where &amp;lt;code&amp;gt;is_credit_note&amp;lt;/code&amp;gt; is true,&lt;br /&gt;
** each serialized via &amp;lt;code&amp;gt;PaymentReconciliationRetrieveSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;lock_history&amp;lt;/code&amp;gt;: each entry&amp;#039;s &amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; id replaced with a cached &amp;lt;code&amp;gt;UserSpec&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;
Stored inside &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt;. Source: &amp;lt;code&amp;gt;care/emr/resources/common/monetary_component.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;MonetaryComponent {&lt;br /&gt;
  monetary_component_type: MonetaryComponentType   # required (base|surcharge|discount|tax|informational)&lt;br /&gt;
  code:                   Coding | None            # { system?, version?, code, display? }&lt;br /&gt;
  factor:                 Decimal(20,6) | None&lt;br /&gt;
  amount:                 Decimal(20,6) | None&lt;br /&gt;
  tax_included_amount:    Decimal(20,6) | None      # only valid on base&lt;br /&gt;
  global_component:       bool = False&lt;br /&gt;
  conditions:             list[EvaluatorConditionSpec] = []&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Per-component validation: &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt; must carry an &amp;lt;code&amp;gt;amount&amp;lt;/code&amp;gt; and no &amp;lt;code&amp;gt;conditions&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;tax_included_amount&amp;lt;/code&amp;gt; is allowed only on &amp;lt;code&amp;gt;base&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; at least 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 component 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;. Collection-level rules (&amp;lt;code&amp;gt;MonetaryComponents&amp;lt;/code&amp;gt;) forbid duplicate codes, require exactly one &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt;, and reconcile &amp;lt;code&amp;gt;tax_included_amount&amp;lt;/code&amp;gt; against the sum of tax components.&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
* [[References/Charge Item|&amp;lt;code&amp;gt;ChargeItem&amp;lt;/code&amp;gt;]] — line items grouped by the invoice; snapshotted into &amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;ChargeItemReadSpec&amp;lt;/code&amp;gt;.&lt;br /&gt;
* [[References/Account|&amp;lt;code&amp;gt;Account&amp;lt;/code&amp;gt;]] — the billing account; resolved on write, rebalanced after return-invoice generation/cancellation.&lt;br /&gt;
* [[References/Payment Reconciliation|&amp;lt;code&amp;gt;PaymentReconciliation&amp;lt;/code&amp;gt;]] — payments and credit notes reported on the retrieve view (filtered to &amp;lt;code&amp;gt;outcome=complete&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;status=active&amp;lt;/code&amp;gt;).&lt;br /&gt;
* [[References/Charge Item Definition|&amp;lt;code&amp;gt;ChargeItemDefinition&amp;lt;/code&amp;gt;]] — applied when building return-invoice charge items.&lt;br /&gt;
&lt;br /&gt;
== Methods &amp;amp;amp; save behaviour ==&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;sync_invoice_items(invoice)&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;sync_items.py&amp;lt;/code&amp;gt;) — recomputes &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_price_components&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt; from the linked charge items, then rounds totals using &amp;lt;code&amp;gt;INVOICE_FINAL_AMOUNT_PRECISION&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;INVOICE_FINAL_AMOUNT_ROUNDING_METHOD&amp;lt;/code&amp;gt;. &amp;#039;&amp;#039;&amp;#039;Validation:&amp;#039;&amp;#039;&amp;#039; if &amp;lt;code&amp;gt;is_refund&amp;lt;/code&amp;gt; is false and either total is negative, raises &amp;lt;code&amp;gt;ValidationError(&amp;amp;quot;A Refund Ivoice is required for negative values&amp;amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;calculate_charge_items_summary(charge_items)&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — net = Σ base + Σ surcharge − Σ discount; gross = net + Σ tax; components aggregated per &amp;lt;code&amp;gt;type + code&amp;lt;/code&amp;gt; (key = &amp;lt;code&amp;gt;system + code&amp;lt;/code&amp;gt;, else &amp;lt;code&amp;gt;No-Code&amp;lt;/code&amp;gt;).&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;evaluate_invoice_identifier_default_expression(facility)&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;default_expression_evaluator.py&amp;lt;/code&amp;gt;) — generates &amp;lt;code&amp;gt;number&amp;lt;/code&amp;gt; from the facility&amp;#039;s &amp;lt;code&amp;gt;invoice_number_expression&amp;lt;/code&amp;gt; with context &amp;lt;code&amp;gt;{ invoice_count, current_year_yyyy, current_year_yy }&amp;lt;/code&amp;gt;; returns &amp;lt;code&amp;gt;&amp;amp;quot;&amp;amp;quot;&amp;lt;/code&amp;gt; if unset. &amp;lt;code&amp;gt;evaluate_invoice_dummy_expression&amp;lt;/code&amp;gt; previews an expression with sample context.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;generate_return_invoice(delivery_order)&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;return_items_invoice.py&amp;lt;/code&amp;gt;) — creates a &amp;lt;code&amp;gt;draft&amp;lt;/code&amp;gt; refund invoice (&amp;lt;code&amp;gt;is_refund=True&amp;lt;/code&amp;gt;), reverses each completed &amp;lt;code&amp;gt;SupplyDelivery&amp;lt;/code&amp;gt;&amp;#039;s charge item via &amp;lt;code&amp;gt;apply_charge_item_definition(reverse=True)&amp;lt;/code&amp;gt;, marks items &amp;lt;code&amp;gt;billed&amp;lt;/code&amp;gt;, runs &amp;lt;code&amp;gt;sync_invoice_items&amp;lt;/code&amp;gt;, sets status &amp;lt;code&amp;gt;issued&amp;lt;/code&amp;gt;, then triggers &amp;lt;code&amp;gt;rebalance_account_task&amp;lt;/code&amp;gt;. Raises if any delivery is still &amp;lt;code&amp;gt;in_progress&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;cancel_return_invoice(delivery_order)&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; — sets the invoice &amp;lt;code&amp;gt;cancelled&amp;lt;/code&amp;gt;, marks its charge items &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt; (clears &amp;lt;code&amp;gt;paid_invoice&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;paid_on&amp;lt;/code&amp;gt;), voids the supply deliveries, rebalances the account, and resyncs inventory.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt; is the control surface for the billing lifecycle. Drive transitions through the API rather than editing rows directly; the values are &amp;lt;code&amp;gt;draft&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;issued&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;balanced&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;cancelled&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;entered_in_error&amp;lt;/code&amp;gt;.&lt;br /&gt;
* On write (&amp;lt;code&amp;gt;InvoiceWriteSpec&amp;lt;/code&amp;gt;): send &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;charge_items&amp;lt;/code&amp;gt; as external UUIDs. The server derives &amp;lt;code&amp;gt;patient&amp;lt;/code&amp;gt; from the account, so don&amp;#039;t send it. &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;charge_items&amp;lt;/code&amp;gt; bypass the generic field mapper and are handled in &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;charge_items_copy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_price_components&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; are platform-maintained snapshots derived from the linked charge items — don&amp;#039;t set them directly.&lt;br /&gt;
* The list view (&amp;lt;code&amp;gt;InvoiceReadSpec&amp;lt;/code&amp;gt;) returns a minimal &amp;lt;code&amp;gt;account&amp;lt;/code&amp;gt;; the detail view (&amp;lt;code&amp;gt;InvoiceRetrieveSpec&amp;lt;/code&amp;gt;) returns the full account plus charge items, aggregated price components, payments, credit notes, and lock history.&lt;br /&gt;
* When &amp;lt;code&amp;gt;locked&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, the read specs serialize &amp;lt;code&amp;gt;total_net&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;total_gross&amp;lt;/code&amp;gt; as &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>