1+ resourceType : Questionnaire
2+ id : enable-when-options
3+ name : enable-when-options
4+ title : EnableWhen Options
5+ status : active
6+ url : " http://example.org/fhir/Questionnaire/enable-when-options"
7+ meta :
8+ profile :
9+ - https://emr-core.beda.software/StructureDefinition/fhir-emr-questionnaire
10+ item :
11+ - linkId : instructions
12+ text : >-
13+ Instructions: Set Any allergies? and Follow-up visit needed? to test classic
14+ enableWhen, enableWhenExpression, and enableBehavior (any / all).
15+ Then enter any text in Chief complaint to trigger the operator: exists example.
16+ type : display
17+
18+ - linkId : has-allergy
19+ text : Any allergies?
20+ type : choice
21+ answerOption :
22+ - valueCoding :
23+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
24+ code : " N"
25+ display : " No"
26+ - valueCoding :
27+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
28+ code : " Y"
29+ display : " Yes"
30+
31+ - linkId : follow-up-needed
32+ text : Follow-up visit needed?
33+ type : choice
34+ answerOption :
35+ - valueCoding :
36+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
37+ code : " N"
38+ display : " No"
39+ - valueCoding :
40+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
41+ code : " Y"
42+ display : " Yes"
43+
44+ # Standard FHIR Questionnaire.item.enableWhen (question + operator + answer*).
45+ - linkId : allergy-details-classic
46+ text : Allergy details (classic enableWhen)
47+ type : text
48+ enableWhen :
49+ - question : has-allergy
50+ operator : " ="
51+ answerCoding :
52+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
53+ code : " Y"
54+ display : " Yes"
55+
56+ # Same visibility rule via SDC enableWhenExpression (FHIRPath on the client).
57+ # If both were on one item, sdc-qrf would prefer enableWhenExpression and ignore enableWhen.
58+ - linkId : allergy-details-expression
59+ text : Allergy details (enableWhenExpression)
60+ type : text
61+ enableWhenExpression :
62+ language : text/fhirpath
63+ # Do not use `code.first() = 'Y'`: empty answer yields empty collection, not false — sdc-qrf requires a boolean.
64+ expression : >-
65+ iif(
66+ %resource.repeat(item).where(linkId='has-allergy').answer.valueCoding.where(code='Y').exists(),
67+ true,
68+ false
69+ )
70+
71+ # enableBehavior any — at least one enableWhen rule must match (OR).
72+ - linkId : contact-preference-any
73+ text : Contact preference (shown if allergy Yes OR follow-up Yes)
74+ type : text
75+ enableBehavior : any
76+ enableWhen :
77+ - question : has-allergy
78+ operator : " ="
79+ answerCoding :
80+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
81+ code : " Y"
82+ display : " Yes"
83+ - question : follow-up-needed
84+ operator : " ="
85+ answerCoding :
86+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
87+ code : " Y"
88+ display : " Yes"
89+
90+ # enableBehavior all (default) — every enableWhen rule must match (AND).
91+ - linkId : schedule-deep-review-all
92+ text : Schedule deep review (only when allergy Yes AND follow-up Yes)
93+ type : text
94+ enableBehavior : all
95+ enableWhen :
96+ - question : has-allergy
97+ operator : " ="
98+ answerCoding :
99+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
100+ code : " Y"
101+ display : " Yes"
102+ - question : follow-up-needed
103+ operator : " ="
104+ answerCoding :
105+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
106+ code : " Y"
107+ display : " Yes"
108+
109+ # Whole group is toggled by classic enableWhen; children inherit visibility context.
110+ - linkId : allergy-extra-group
111+ text : Extra allergy block (group-level enableWhen)
112+ type : group
113+ enableWhen :
114+ - question : has-allergy
115+ operator : " ="
116+ answerCoding :
117+ system : " http://terminology.hl7.org/CodeSystem/v2-0136"
118+ code : " Y"
119+ display : " Yes"
120+ item :
121+ - linkId : reaction-note
122+ text : Reaction / severity notes
123+ type : text
124+ - linkId : last-episode-date
125+ text : Last episode date
126+ type : date
127+
128+ # Parent variable reused in enableWhenExpression.
129+ - linkId : variable-group
130+ text : Expression using parent variable %AllergyYes
131+ type : group
132+ variable :
133+ - name : AllergyYes
134+ language : text/fhirpath
135+ expression : >-
136+ iif(
137+ %resource.repeat(item).where(linkId='has-allergy').answer.valueCoding.where(code='Y').exists(),
138+ true,
139+ false
140+ )
141+ item :
142+ - linkId : details-with-variable
143+ text : Enabled via %AllergyYes (same logic as allergy-details-expression)
144+ type : text
145+ enableWhenExpression :
146+ language : text/fhirpath
147+ expression : >-
148+ iif(%AllergyYes = true, true, false)
149+
150+ # operator exists — show when the referenced question has any answer (answerBoolean drives sense of exists).
151+ - linkId : chief-complaint-free
152+ text : Chief complaint (Enter any text here to show the Detail field below)
153+ type : string
154+
155+ # operator exists — show when the referenced question has any answer (answerBoolean drives sense of exists).
156+ - linkId : chief-complaint-detail-exists
157+ text : Detail (appears after you type something above)
158+ type : text
159+ enableWhen :
160+ - question : chief-complaint-free
161+ operator : exists
162+ answerBoolean : true
0 commit comments