Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

References/Resource Category: Difference between revisions

From OHC Network Wiki
More languages
Content deleted Content added
Add Navbox platform (via update-page on MediaWiki MCP Server)
Fix unclosed wikilink so calculated_monetary_components row stores in ModelField table (via update-page on MediaWiki MCP Server)
 
(3 intermediate revisions by the same user not shown)
Line 13: Line 13:
The Django model is just storage. The behaviour you code against lives in the Pydantic resource specs in <code>care/emr/resources/resource_category/</code>: the <code>resource_type</code> enum, the <code>MonetaryComponent</code> shape behind the <code>*_monetary_components</code> JSON fields, slug validation, and the split between read and write schemas. Several model fields are opaque <code>JSONField</code>s whose real structure exists only in the specs — see [[#resource-specs-api-schema|Resource specs (API schema)]].
The Django model is just storage. The behaviour you code against lives in the Pydantic resource specs in <code>care/emr/resources/resource_category/</code>: the <code>resource_type</code> enum, the <code>MonetaryComponent</code> shape behind the <code>*_monetary_components</code> JSON fields, slug validation, and the split between read and write schemas. Several model fields are opaque <code>JSONField</code>s whose real structure exists only in the specs — see [[#resource-specs-api-schema|Resource specs (API schema)]].


'''Source:'''

* Model: [<nowiki/>https://github.com/ohcnetwork/care/blob/develop/care/emr/models/resource_category.py <code>care/emr/models/resource_category.py</code>]
* Spec: [<nowiki/>https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/resource_category/spec.py <code>care/emr/resources/resource_category/spec.py</code>]
* Shared: [<nowiki/>https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/base.py <code>base.py</code>] · [<nowiki/>https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/monetary_component.py <code>common/monetary_component.py</code>] · [<nowiki/>https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/coding.py <code>common/coding.py</code>]


== Models ==
== Models ==
Line 61: Line 56:
{{Field|model=ResourceCategory|section=Tree structure|name=parent|type=FK → emr.ResourceCategory (CASCADE)|notes=Self-reference to the parent node; nullable. <code>related_name=&quot;children&quot;</code>. <code>__exclude__</code>d from spec serialization — written via slug lookup, read via <code>get_parent_json()</code>}}
{{Field|model=ResourceCategory|section=Tree structure|name=parent|type=FK → emr.ResourceCategory (CASCADE)|notes=Self-reference to the parent node; nullable. <code>related_name=&quot;children&quot;</code>. <code>__exclude__</code>d from spec serialization — written via slug lookup, read via <code>get_parent_json()</code>}}
{{Field|model=ResourceCategory|section=Tree structure|name=is_child|type=BooleanField|notes=Default <code>False</code>. Exposed on write (<code>ResourceCategoryWriteSpec</code>) and read}}
{{Field|model=ResourceCategory|section=Tree structure|name=is_child|type=BooleanField|notes=Default <code>False</code>. Exposed on write (<code>ResourceCategoryWriteSpec</code>) and read}}
{{Field|model=ResourceCategory|section=Tree structure|name=has_children|type=BooleanField|notes=Default <code>False</code>. Flips to <code>True</code> on the parent when a child is created (see [[#methods--save-behaviour}}
{{Field|model=ResourceCategory|section=Tree structure|name=has_children|type=BooleanField|notes=Default <code>False</code>. Flips to <code>True</code> on the parent when a child is created (see [[#methods--save-behaviour|Methods &amp; save behaviour]]}}
{{Field|model=ResourceCategory|section=Tree structure|name=root_org|type=FK → emr.ResourceCategory (CASCADE)|notes=Self-reference to the root of this node's tree; nullable. <code>related_name=&quot;root&quot;</code>. Not exposed in specs}}
{{Field|model=ResourceCategory|section=Tree structure|name=root_org|type=FK → emr.ResourceCategory (CASCADE)|notes=Self-reference to the root of this node's tree; nullable. <code>related_name=&quot;root&quot;</code>. Not exposed in specs}}
|}
|}
Line 110: Line 105:
! Notes
! Notes
{{Field|model=ResourceCategory|section=Charge item monetary components|name=configured_monetary_components|type=JSONField → list[MonetaryComponent] | None|notes=Components configured directly on this category}}
{{Field|model=ResourceCategory|section=Charge item monetary components|name=configured_monetary_components|type=JSONField → list[MonetaryComponent] | None|notes=Components configured directly on this category}}
{{Field|model=ResourceCategory|section=Charge item monetary components|name=calculated_monetary_components|type=JSONField → list[MonetaryComponent] | None|notes=Effective components after merging the parent's calculated components with this node's configured components (see [[#methods--save-behaviour}}
{{Field|model=ResourceCategory|section=Charge item monetary components|name=calculated_monetary_components|type=JSONField → list[MonetaryComponent] | None|notes=Effective components after merging the parent's calculated components with this node's configured components (see [[#methods--save-behaviour|Methods &amp; save behaviour]]}}
|}
|}


Line 267: Line 262:
* Monetary-component propagation runs through Celery, so descendants' <code>calculated_monetary_components</code> is eventually consistent after a write.
* Monetary-component propagation runs through Celery, so descendants' <code>calculated_monetary_components</code> is eventually consistent after a write.
* Monetary-component fields serialize only for <code>resource_type == &quot;charge_item_definition&quot;</code>; during merges, component identity rests on the nested <code>code.system</code> + <code>code.code</code> pair.
* Monetary-component fields serialize only for <code>resource_type == &quot;charge_item_definition&quot;</code>; during merges, component identity rests on the nested <code>code.system</code> + <code>code.code</code> pair.
* Categories can be '''deleted''' (<code>DELETE</code> on the category endpoint, added in ENG-441). Deletion is a soft delete (<code>deleted = True</code>) guarded by <code>validate_destroy</code>: a category with children, or with resources still linked through <code>ActivityDefinition.category</code>, <code>ChargeItemDefinition.category</code>, or <code>ProductKnowledge.category</code>, is rejected. Deleting the last remaining child resets the parent's <code>has_children</code> to <code>False</code>.



{{SourceCode
|model=care/emr/models/resource_category.py
|spec=care/emr/resources/resource_category/spec.py
|extra1_label=Shared
|extra1_path=care/emr/resources/base.py
|extra2_label=monetary_component.py
|extra2_path=care/emr/resources/common/monetary_component.py
|extra3_label=coding.py
|extra3_path=care/emr/resources/common/coding.py
}}
{{Navbox platform}}
{{Navbox platform}}