<?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%2FValue_Set</id>
	<title>References/Value Set - 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%2FValue_Set"/>
	<link rel="alternate" type="text/html" href="https://ohcnwiki.tellmey.fyi/index.php?title=References/Value_Set&amp;action=history"/>
	<updated>2026-07-06T05:17:36Z</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/Value_Set&amp;diff=400&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/Value_Set&amp;diff=400&amp;oldid=prev"/>
		<updated>2026-07-06T04:02:20Z</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:32, 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 343:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 343:&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;* Treat &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt; value sets as read-only — they are platform-maintained. Author your own for local terminology; the &amp;lt;code&amp;gt;system-&amp;lt;/code&amp;gt; slug prefix is reserved for system value sets.&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;* Treat &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt; value sets as read-only — they are platform-maintained. Author your own for local terminology; the &amp;lt;code&amp;gt;system-&amp;lt;/code&amp;gt; slug prefix is reserved for system value sets.&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;favorite_codes&amp;lt;/code&amp;gt; (via &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt;) and recent views (via &amp;lt;code&amp;gt;RecentViewsManager&amp;lt;/code&amp;gt;/Redis) are per-user personalization, not part of the value set definition.&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;favorite_codes&amp;lt;/code&amp;gt; (via &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt;) and recent views (via &amp;lt;code&amp;gt;RecentViewsManager&amp;lt;/code&amp;gt;/Redis) are per-user personalization, not part of the value set definition.&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 definitions}}&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;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://ohcnwiki.tellmey.fyi/index.php?title=References/Value_Set&amp;diff=155&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/Value_Set&amp;diff=155&amp;oldid=prev"/>
		<updated>2026-07-04T22:44:54Z</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=definitions&lt;br /&gt;
|title=Value Set&lt;br /&gt;
|order=3&lt;br /&gt;
|introduced=3.0&lt;br /&gt;
|model=ValueSet&lt;br /&gt;
|reference=References/Base models &amp;amp;amp; conventions&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; is a FHIR-aligned composition of coded concepts drawn from one or more code systems. Reach for one when a [[References/Questionnaire|questionnaire]] needs to constrain a coded answer to a fixed set of options.&lt;br /&gt;
&lt;br /&gt;
The Django model is only storage — &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; is an opaque &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;. The structure that matters (include/exclude clauses, filters, the status enum, validation, and the read/write API schemas) lives in the Pydantic resource specs, covered alongside the model here.&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/valueset.py &amp;lt;code&amp;gt;care/emr/models/valueset.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/valueset/spec.py &amp;lt;code&amp;gt;care/emr/resources/valueset/spec.py&amp;lt;/code&amp;gt;]&lt;br /&gt;
* Compose schema: [&amp;lt;nowiki/&amp;gt;https://github.com/ohcnetwork/care/blob/develop/care/emr/resources/common/valueset.py &amp;lt;code&amp;gt;care/emr/resources/common/valueset.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;ValueSet&amp;lt;/code&amp;gt;&lt;br /&gt;
| A named, FHIR-compatible composition of codes from one or more code systems&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
| Stores a user&amp;#039;s favorited codes within a value set&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;RecentViewsManager&amp;lt;/code&amp;gt;&lt;br /&gt;
| Redis-backed helper for tracking a user&amp;#039;s recently used codes (not a database model)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt; extend [[References/Base models &amp;amp;amp; conventions|&amp;lt;code&amp;gt;EMRBaseModel&amp;lt;/code&amp;gt;]], the shared Care EMR base that supplies &amp;lt;code&amp;gt;external_id&amp;lt;/code&amp;gt;, audit fields, &amp;lt;code&amp;gt;history&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;meta&amp;lt;/code&amp;gt; JSON, and soft-delete semantics.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; fields ==&lt;br /&gt;
&lt;br /&gt;
A value set stores rules, not a flat list of codes: a &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; object of include/exclude clauses against code systems. Members resolve in real time against terminology servers when the value set is searched or a code is looked up.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Model type&lt;br /&gt;
! Spec type&lt;br /&gt;
! Required&lt;br /&gt;
! Default&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;slug&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SlugField(255)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SlugType&amp;lt;/code&amp;gt;&lt;br /&gt;
| yes&lt;br /&gt;
| —&lt;br /&gt;
| &amp;lt;code&amp;gt;unique&amp;lt;/code&amp;gt;, indexed. Public identifier. Spec constrains to min 5 / max 50 chars, URL-safe (&amp;lt;code&amp;gt;^[a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9]$&amp;lt;/code&amp;gt;); must start and end alphanumeric. Uniqueness re-checked in spec; &amp;lt;code&amp;gt;system-&amp;lt;/code&amp;gt; prefix reserved (see validation)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CharField(255)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| yes&lt;br /&gt;
| —&lt;br /&gt;
| Display name. Spec rejects blank/whitespace-only and strips surrounding whitespace&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TextField&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| yes (in spec)&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;amp;quot;&amp;amp;quot;&amp;lt;/code&amp;gt; (model)&lt;br /&gt;
| Free text. The model defaults to an empty string; the spec requires the field present&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;JSONField&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt;&lt;br /&gt;
| yes&lt;br /&gt;
| &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
| Composition rules — structured &amp;lt;code&amp;gt;include&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;exclude&amp;lt;/code&amp;gt; clauses (see [[#compose-shape&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CharField(255)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetStatusOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| yes&lt;br /&gt;
| —&lt;br /&gt;
| Publication status enum (see [[#valuesetstatusoptions-values&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;BooleanField&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt;&lt;br /&gt;
| no&lt;br /&gt;
| &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;&lt;br /&gt;
| Marks value sets shipped and maintained by the platform rather than authored by a deployment&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;ValueSetStatusOptions&amp;lt;/code&amp;gt; values ===&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt; enum in &amp;lt;code&amp;gt;resources/valueset/spec.py&amp;lt;/code&amp;gt;. The model column is a free &amp;lt;code&amp;gt;CharField&amp;lt;/code&amp;gt;; the spec restricts writes to these four values.&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;
| Authored, not yet in use&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;active&amp;lt;/code&amp;gt;&lt;br /&gt;
| Published and usable&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;retired&amp;lt;/code&amp;gt;&lt;br /&gt;
| No longer recommended for use&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;unknown&amp;lt;/code&amp;gt;&lt;br /&gt;
| Status not known&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; shape ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; holds a &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt; structure (&amp;lt;code&amp;gt;care.emr.resources.common.valueset&amp;lt;/code&amp;gt;). Each clause targets a &amp;lt;code&amp;gt;system&amp;lt;/code&amp;gt; (a code system URI) and selects concepts directly or through filters. Every nested model sets &amp;lt;code&amp;gt;extra=&amp;amp;quot;forbid&amp;amp;quot;&amp;lt;/code&amp;gt;, so unknown keys are rejected.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Required&lt;br /&gt;
! Default&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetCompose|name=id|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetCompose|name=include|type=list[ValueSetInclude]|notes=yes}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetCompose|name=exclude|type=list[ValueSetInclude] | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetCompose|name=property|type=list[str] | None|notes=no}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;ValueSetInclude&amp;lt;/code&amp;gt; (used for both &amp;lt;code&amp;gt;include&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;exclude&amp;lt;/code&amp;gt;) ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Required&lt;br /&gt;
! Default&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetInclude (used for both include and exclude)|name=id|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetInclude (used for both include and exclude)|name=system|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetInclude (used for both include and exclude)|name=version|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetInclude (used for both include and exclude)|name=concept|type=list[ValueSetConcept] | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetInclude (used for both include and exclude)|name=filter|type=list[ValueSetFilter] | None|notes=no}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A clause may set &amp;lt;code&amp;gt;concept&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt;, not both — enforced by &amp;lt;code&amp;gt;check_concept_or_filter&amp;lt;/code&amp;gt; (mode=after).&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;ValueSetConcept&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Required&lt;br /&gt;
! Default&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| no&lt;br /&gt;
| &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| no&lt;br /&gt;
| &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;display&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;str | None&amp;lt;/code&amp;gt;&lt;br /&gt;
| no&lt;br /&gt;
| &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;ValueSetFilter&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Required&lt;br /&gt;
! Default&lt;br /&gt;
! Notes&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetFilter|name=id|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetFilter|name=property|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetFilter|name=op|type=str | None|notes=no}}&lt;br /&gt;
{{Field|model=ValueSet|section=ValueSetFilter|name=value|type=str | None|notes=no}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; allowed values =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;validate_op&amp;lt;/code&amp;gt; rejects anything outside this set: &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is-a&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;descendent-of&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is-not-a&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;regex&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;in&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not-in&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;generalizes&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;child-of&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;descendent-leaf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;exists&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;compose:&lt;br /&gt;
  include:&lt;br /&gt;
    - system:  &amp;lt;code system uri&amp;gt;&lt;br /&gt;
      version: &amp;lt;optional system version&amp;gt;&lt;br /&gt;
      concept: [ { code, display } ]      # pin concepts (mutually exclusive with filter)&lt;br /&gt;
      filter:  [ { property, op, value } ] # rule-based selection&lt;br /&gt;
  exclude:&lt;br /&gt;
    - ... same ValueSetInclude shape ...&lt;br /&gt;
  property: [ &amp;lt;property names to return&amp;gt; ]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;create_composition()&amp;lt;/code&amp;gt; regroups these clauses by &amp;lt;code&amp;gt;system&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;{ &amp;amp;lt;system&amp;amp;gt;: {include: [...], exclude: [...]} }&amp;lt;/code&amp;gt; so each system can be queried independently, dumping each clause with &amp;lt;code&amp;gt;exclude_defaults=True&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Note: a second, simpler &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; BaseModel (&amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt;) plus &amp;lt;code&amp;gt;ValueSetConcept&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;ValueSetFilter&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;ValueSetInclude&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt; all live in &amp;lt;code&amp;gt;resources/common/valueset.py&amp;lt;/code&amp;gt;. The persisted/API resource model is &amp;lt;code&amp;gt;ValueSetBaseSpec&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;resources/valueset/spec.py&amp;lt;/code&amp;gt;, which reuses the same &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
== Resource specs (API schema) ==&lt;br /&gt;
&lt;br /&gt;
Every spec extends &amp;lt;code&amp;gt;EMRResource&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;resources/base.py&amp;lt;/code&amp;gt;), which provides &amp;lt;code&amp;gt;serialize&amp;lt;/code&amp;gt; (DB object → pydantic, via &amp;lt;code&amp;gt;model_construct&amp;lt;/code&amp;gt;) and &amp;lt;code&amp;gt;de_serialize&amp;lt;/code&amp;gt; (pydantic → DB object). &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; leaves &amp;lt;code&amp;gt;__store_metadata__&amp;lt;/code&amp;gt; unset, so spec fields map directly to model columns — there is no &amp;lt;code&amp;gt;meta&amp;lt;/code&amp;gt; bag.&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&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetBaseSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| shared base (&amp;lt;code&amp;gt;__model__ = ValueSet&amp;lt;/code&amp;gt;)&lt;br /&gt;
| &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; (UUID4), &amp;lt;code&amp;gt;slug&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| write · create &amp;amp;amp; update&lt;br /&gt;
| inherits base + validation + &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| read · list &amp;amp;amp; detail&lt;br /&gt;
| inherits base + &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;updated_by&amp;lt;/code&amp;gt; (dicts)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Validation (&amp;lt;code&amp;gt;ValueSetSpec&amp;lt;/code&amp;gt;) ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Rule&lt;br /&gt;
! Where&lt;br /&gt;
! Behaviour&lt;br /&gt;
|-&lt;br /&gt;
| Name not empty&lt;br /&gt;
| &amp;lt;code&amp;gt;validate_name&amp;lt;/code&amp;gt; (field)&lt;br /&gt;
| Rejects blank/whitespace-only; strips surrounding whitespace&lt;br /&gt;
|-&lt;br /&gt;
| Slug unique&lt;br /&gt;
| &amp;lt;code&amp;gt;validate_slug&amp;lt;/code&amp;gt; (field)&lt;br /&gt;
| Queries existing &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; rows; on update, excludes the current object (via &amp;lt;code&amp;gt;context[&amp;amp;quot;object&amp;amp;quot;].id&amp;lt;/code&amp;gt; when &amp;lt;code&amp;gt;context[&amp;amp;quot;is_update&amp;amp;quot;]&amp;lt;/code&amp;gt;); otherwise raises &amp;lt;code&amp;gt;&amp;amp;quot;Slug must be unique&amp;amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Reserved slug&lt;br /&gt;
| &amp;lt;code&amp;gt;validate_slug_system&amp;lt;/code&amp;gt; (model, after)&lt;br /&gt;
| If the value set is not &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt; and the slug contains &amp;lt;code&amp;gt;&amp;amp;quot;system-&amp;amp;quot;&amp;lt;/code&amp;gt;, raises &amp;lt;code&amp;gt;&amp;amp;quot;Cannot create valueset with system like slug&amp;amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Slug format&lt;br /&gt;
| &amp;lt;code&amp;gt;SlugType&amp;lt;/code&amp;gt;&lt;br /&gt;
| min 5 / max 50 chars, URL-safe, alphanumeric start/end&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; allowlist&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetFilter.validate_op&amp;lt;/code&amp;gt;&lt;br /&gt;
| See [[#op-allowed-values&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;concept&amp;lt;/code&amp;gt; xor &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetInclude.check_concept_or_filter&amp;lt;/code&amp;gt;&lt;br /&gt;
| Both present → error&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Server-side serialization hooks ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Hook&lt;br /&gt;
! Spec&lt;br /&gt;
! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;perform_extra_deserialization(is_update, obj)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| On write, sets &amp;lt;code&amp;gt;obj.compose = self.compose.model_dump(exclude_defaults=True, exclude_none=True)&amp;lt;/code&amp;gt;, normalizing the JSON stored in the model&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;perform_extra_serialization(mapping, obj)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;ValueSetReadSpec&amp;lt;/code&amp;gt;&lt;br /&gt;
| On read, sets &amp;lt;code&amp;gt;mapping[&amp;amp;quot;id&amp;amp;quot;] = obj.external_id&amp;lt;/code&amp;gt; and populates &amp;lt;code&amp;gt;created_by&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;updated_by&amp;lt;/code&amp;gt; via &amp;lt;code&amp;gt;serialize_audit_users&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ValueSetSpec.model_rebuild()&amp;lt;/code&amp;gt; runs at module load so the forward reference to &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt; resolves.&lt;br /&gt;
&lt;br /&gt;
== Related models ==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Holds the codes a single user has favorited within one value set.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;user          → FK users.User (CASCADE)&lt;br /&gt;
valueset      → FK emr.ValueSet (CASCADE)&lt;br /&gt;
favorite_codes → JSONField (default=list)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;unique_together = (&amp;amp;quot;user&amp;amp;quot;, &amp;amp;quot;valueset&amp;amp;quot;)&amp;lt;/code&amp;gt; enforces one preference row per user per value set. The class constant &amp;lt;code&amp;gt;MAX_FAVORITES&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;50&amp;lt;/code&amp;gt;, overridable via &amp;lt;code&amp;gt;settings.MAX_FAVORITES_FOR_VALUESET&amp;lt;/code&amp;gt;) caps how many codes a user may favorite.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;RecentViewsManager&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
A classmethod-only helper, not a database model. It tracks a user&amp;#039;s recently viewed codes in a Redis list (one per &amp;lt;code&amp;gt;cache_key&amp;lt;/code&amp;gt;) so pickers can surface recent codes alongside favorites.&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;get_client()&amp;lt;/code&amp;gt;&lt;br /&gt;
| Lazily opens the &amp;lt;code&amp;gt;&amp;amp;quot;default&amp;amp;quot;&amp;lt;/code&amp;gt; Redis connection&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;get_recent_views(cache_key)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Returns the decoded list of recent code objects&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;add_recent_view(cache_key, code_obj)&amp;lt;/code&amp;gt;&lt;br /&gt;
| De-dupes by &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; (no-op if &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; missing), &amp;lt;code&amp;gt;LPUSH&amp;lt;/code&amp;gt;es the entry, then &amp;lt;code&amp;gt;LTRIM&amp;lt;/code&amp;gt;s to &amp;lt;code&amp;gt;MAX_RECENT_VIEW&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;remove_recent_view(cache_key, code_obj)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Removes any list entry matching &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; (no-op if &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; missing)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear_recent_views(cache_key)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Deletes the whole list&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_remove_by_code(cache_key, code)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Internal: scans the list and &amp;lt;code&amp;gt;LREM&amp;lt;/code&amp;gt;s matching entries; malformed JSON entries are skipped&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MAX_RECENT_VIEW&amp;lt;/code&amp;gt; defaults to &amp;lt;code&amp;gt;20&amp;lt;/code&amp;gt; (overridable via &amp;lt;code&amp;gt;settings.MAX_RECENT_VIEW_FOR_VALUESET&amp;lt;/code&amp;gt;). Entries are JSON-encoded; malformed ones are skipped on read and remove.&lt;br /&gt;
&lt;br /&gt;
== Methods &amp;amp;amp; save behaviour ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; does not override &amp;lt;code&amp;gt;save()&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;delete()&amp;lt;/code&amp;gt; — soft-delete is inherited from the base. Its methods drive terminology resolution:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;create_composition()&amp;lt;/code&amp;gt; — converts &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; (a dict or &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt;) into a per-system map of &amp;lt;code&amp;gt;include&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;exclude&amp;lt;/code&amp;gt; clauses, dumping each clause with &amp;lt;code&amp;gt;exclude_defaults=True&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;search(search=&amp;amp;quot;&amp;amp;quot;, count=10, display_language=None)&amp;lt;/code&amp;gt; — runs &amp;lt;code&amp;gt;ValueSetResource().filter(...).search()&amp;lt;/code&amp;gt; for each system in the composition (optionally filtered by &amp;lt;code&amp;gt;display_language&amp;lt;/code&amp;gt;) and concatenates the results. Codes are fetched from the terminology server at request time; nothing is materialized into the value set.&lt;br /&gt;
* &amp;lt;code&amp;gt;lookup(code)&amp;lt;/code&amp;gt; — checks whether &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt; is a member by running &amp;lt;code&amp;gt;ValueSetResource().filter(...).lookup(code)&amp;lt;/code&amp;gt; against each system, returning &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; if any system matches.&lt;br /&gt;
&lt;br /&gt;
Membership resolves live, so editing &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; immediately changes which codes the value set yields. There is no expansion or cache to rebuild.&lt;br /&gt;
&lt;br /&gt;
== API integration notes ==&lt;br /&gt;
&lt;br /&gt;
* The REST API aligns with the FHIR &amp;lt;code&amp;gt;ValueSet&amp;lt;/code&amp;gt; resource. Writes go through &amp;lt;code&amp;gt;ValueSetSpec&amp;lt;/code&amp;gt;, reads through &amp;lt;code&amp;gt;ValueSetReadSpec&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;search&amp;lt;/code&amp;gt; powers code pickers and &amp;lt;code&amp;gt;lookup&amp;lt;/code&amp;gt; validates submitted codes.&lt;br /&gt;
* The model column &amp;lt;code&amp;gt;compose&amp;lt;/code&amp;gt; is opaque JSON, so always write through the &amp;lt;code&amp;gt;ValueSetCompose&amp;lt;/code&amp;gt; schema (clauses, filters, the &amp;lt;code&amp;gt;op&amp;lt;/code&amp;gt; allowlist, &amp;lt;code&amp;gt;concept&amp;lt;/code&amp;gt; xor &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt;). &amp;lt;code&amp;gt;perform_extra_deserialization&amp;lt;/code&amp;gt; re-dumps it with &amp;lt;code&amp;gt;exclude_defaults&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;exclude_none&amp;lt;/code&amp;gt; to keep stored JSON normalized.&lt;br /&gt;
* Composition rules are stored, not expanded code lists. Members are queried in real time from terminology servers, so results shift as upstream systems change.&lt;br /&gt;
* Treat &amp;lt;code&amp;gt;is_system_defined&amp;lt;/code&amp;gt; value sets as read-only — they are platform-maintained. Author your own for local terminology; the &amp;lt;code&amp;gt;system-&amp;lt;/code&amp;gt; slug prefix is reserved for system value sets.&lt;br /&gt;
* &amp;lt;code&amp;gt;favorite_codes&amp;lt;/code&amp;gt; (via &amp;lt;code&amp;gt;UserValueSetPreference&amp;lt;/code&amp;gt;) and recent views (via &amp;lt;code&amp;gt;RecentViewsManager&amp;lt;/code&amp;gt;/Redis) are per-user personalization, not part of the value set definition.&lt;br /&gt;
&lt;br /&gt;
{{Related}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>