auscvdrisk_inferno 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,281 @@
1
+ require_relative '../helpers'
2
+ require 'json'
3
+
4
+ module AusCVDRisk
5
+ module PrePopulation
6
+ class Diagnoses < Inferno::TestGroup
7
+ include AusCVDRisk::Helpers
8
+
9
+ title 'Pre-population: Diagnoses'
10
+ id :prepop_diagnoses
11
+
12
+ test do
13
+ optional
14
+ title 'Server declares support for AU Core Condition profile '
15
+ description %(
16
+ The server should declare support for the AU Core Condition profile
17
+ as recommended by the Aus CVD Risk Calculator Launch Server CapabilityStatement.
18
+ )
19
+
20
+ run do
21
+ fhir_get_capability_statement
22
+
23
+ assert_response_status(200)
24
+ assert_resource_type(:capability_statement)
25
+ capability_statement = resource
26
+
27
+ resource_type = 'Condition'
28
+ profile_url = 'http://hl7.org.au/fhir/core/StructureDefinition/au-core-condition'
29
+
30
+ has_profile = check_capability_statement_for_profile(capability_statement, resource_type, profile_url)
31
+
32
+ if has_profile
33
+ pass 'Server declares support for AU Core Condition profile'
34
+ else
35
+ assert false, 'CapabilityStatement does not declare support for AU Core Condition profile'
36
+ end
37
+ end
38
+ end
39
+
40
+ test do
41
+ optional
42
+ title 'Server declares support for Condition patient search parameter'
43
+ description %(
44
+ The server should declare support for the Condition patient search parameter
45
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
46
+ )
47
+
48
+ run do
49
+ fhir_get_capability_statement
50
+
51
+ assert_response_status(200)
52
+ assert_resource_type(:capability_statement)
53
+ capability_statement = resource
54
+
55
+ resource_type = 'Condition'
56
+ parameter_name = 'patient'
57
+
58
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
59
+ pass "Server declares support for Condition search parameter: #{parameter_name}"
60
+ else
61
+ assert false, "Server does not declare support for required Condition search parameter: #{parameter_name}"
62
+ end
63
+ end
64
+ end
65
+
66
+ test do
67
+ optional
68
+ title 'Server declares support for Condition clinical-status search parameter'
69
+ description %(
70
+ The server should declare support for the Condition clinical-status search parameter
71
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
72
+ )
73
+
74
+ run do
75
+ fhir_get_capability_statement
76
+
77
+ assert_response_status(200)
78
+ assert_resource_type(:capability_statement)
79
+ capability_statement = resource
80
+
81
+ resource_type = 'Condition'
82
+ parameter_name = 'clinical-status'
83
+
84
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
85
+ pass "Server declares support for Condition search parameter: #{parameter_name}"
86
+ else
87
+ assert false, "Server does not declare support for required Condition search parameter: #{parameter_name}"
88
+ end
89
+ end
90
+ end
91
+
92
+ test do
93
+ optional
94
+ title 'Server declares support for Condition category search parameter'
95
+ description %(
96
+ The server should declare support for the Condition category search parameter
97
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
98
+ )
99
+
100
+ run do
101
+ fhir_get_capability_statement
102
+
103
+ assert_response_status(200)
104
+ assert_resource_type(:capability_statement)
105
+ capability_statement = resource
106
+
107
+ resource_type = 'Condition'
108
+ parameter_name = 'category'
109
+
110
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
111
+ pass "Server declares support for Condition search parameter: #{parameter_name}"
112
+ else
113
+ assert false, "Server does not declare support for required Condition search parameter: #{parameter_name}"
114
+ end
115
+ end
116
+ end
117
+
118
+ test do
119
+ optional
120
+ title 'Server declares support for Condition _sort search parameter'
121
+ description %(
122
+ The server should declare support for the Condition _sort search parameter
123
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
124
+ )
125
+
126
+ run do
127
+ fhir_get_capability_statement
128
+
129
+ assert_response_status(200)
130
+ assert_resource_type(:capability_statement)
131
+ capability_statement = resource
132
+
133
+ resource_type = 'Condition'
134
+ parameter_name = '_sort'
135
+
136
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
137
+ pass "Server declares support for Condition search parameter: #{parameter_name}"
138
+ else
139
+ assert false, "Server does not declare support for required Condition search parameter: #{parameter_name}"
140
+ end
141
+ end
142
+ end
143
+
144
+ test do
145
+ optional
146
+ title 'Server declares support for Condition combined search parameters'
147
+ description %(
148
+ The server should declare support for the combined Condition search parameters
149
+ (patient+clinical-status+category+_sort) as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
150
+ )
151
+
152
+ run do
153
+ fhir_get_capability_statement
154
+
155
+ assert_response_status(200)
156
+ assert_resource_type(:capability_statement)
157
+ capability_statement = resource
158
+
159
+ resource_type = 'Condition'
160
+ required_params = %w[patient clinical-status category _sort]
161
+ combined_params = 'patient+clinical-status+category+_sort'
162
+
163
+ if check_search_combination_support(capability_statement, resource_type, required_params)
164
+ pass "Server declares support for combined Condition search parameters: #{combined_params}"
165
+ else
166
+ assert false, "Server does not declare support for combined Condition search parameters: #{combined_params}"
167
+ end
168
+ end
169
+ end
170
+
171
+ test do
172
+ optional
173
+ title 'Condition search with patient parameter is successful'
174
+
175
+ run do
176
+ fhir_read(:patient, patient_id)
177
+ assert_response_status(200)
178
+
179
+ search_params = "patient=#{patient_id}"
180
+
181
+ fhir_search(:condition, params: { patient: patient_id })
182
+
183
+ assert_response_status(200)
184
+ bundle = JSON.parse(response[:body])
185
+ verify_search_parameters_in_self_link(bundle, search_params)
186
+ pass 'Successfully searched for Conditions with patient parameter'
187
+ end
188
+ end
189
+
190
+ test do
191
+ optional
192
+ title 'Condition search with clinical-status parameter is successful'
193
+
194
+ run do
195
+ fhir_read(:patient, patient_id)
196
+ assert_response_status(200)
197
+
198
+ search_params = "clinical-status=active,recurrence,relapse&patient=#{patient_id}"
199
+
200
+ fhir_search(:condition, params: {
201
+ "clinical-status": 'active,recurrence,relapse',
202
+ patient: patient_id
203
+ })
204
+
205
+ assert_response_status(200)
206
+ bundle = JSON.parse(response[:body])
207
+ verify_search_parameters_in_self_link(bundle, search_params)
208
+ pass 'Successfully searched for Conditions with clinical-status parameter'
209
+ end
210
+ end
211
+
212
+ test do
213
+ optional
214
+ title 'Condition search with category parameter is successful'
215
+
216
+ run do
217
+ fhir_read(:patient, patient_id)
218
+ assert_response_status(200)
219
+
220
+ search_params = "category=problem-list-item&patient=#{patient_id}"
221
+
222
+ fhir_search(:condition, params: {
223
+ category: 'problem-list-item',
224
+ patient: patient_id
225
+ })
226
+
227
+ assert_response_status(200)
228
+ bundle = JSON.parse(response[:body])
229
+ verify_search_parameters_in_self_link(bundle, search_params)
230
+ pass 'Successfully searched for Conditions with category parameter'
231
+ end
232
+ end
233
+
234
+ test do
235
+ optional
236
+ title 'Condition search with _sort parameter is successful'
237
+
238
+ run do
239
+ fhir_read(:patient, patient_id)
240
+ assert_response_status(200)
241
+
242
+ search_params = "_sort=-recorded-date&patient=#{patient_id}"
243
+
244
+ fhir_search(:condition, params: {
245
+ _sort: '-recorded-date',
246
+ patient: patient_id
247
+ })
248
+
249
+ assert_response_status(200)
250
+ bundle = JSON.parse(response[:body])
251
+ verify_search_parameters_in_self_link(bundle, search_params)
252
+ pass 'Successfully searched for Conditions with _sort parameter'
253
+ end
254
+ end
255
+
256
+ test do
257
+ optional
258
+ title 'Condition search with combined search parameters is successful'
259
+
260
+ run do
261
+ fhir_read(:patient, patient_id)
262
+ assert_response_status(200)
263
+
264
+ search_params = "_sort=-recorded-date&category=problem-list-item&clinical-status=active,recurrence,relapse&patient=#{patient_id}"
265
+
266
+ fhir_search(:condition, params: {
267
+ _sort: '-recorded-date',
268
+ category: 'problem-list-item',
269
+ "clinical-status": 'active,recurrence,relapse',
270
+ patient: patient_id
271
+ })
272
+
273
+ assert_response_status(200)
274
+ bundle = JSON.parse(response[:body])
275
+ verify_search_parameters_in_self_link(bundle, search_params)
276
+ pass 'Successfully searched for Conditions with combined search parameters'
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,372 @@
1
+ require_relative '../helpers'
2
+
3
+ module AusCVDRisk
4
+ module PrePopulation
5
+ class Medications < Inferno::TestGroup
6
+ include AusCVDRisk::Helpers
7
+
8
+ title 'Pre-population: Medications'
9
+ id :prepop_medications
10
+
11
+ test do
12
+ optional
13
+ title 'Server declares support for MedicationRequest patient search parameter'
14
+ description %(
15
+ The server should declare support for the MedicationRequest patient search parameter
16
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
17
+ )
18
+
19
+ run do
20
+ fhir_get_capability_statement
21
+
22
+ assert_response_status(200)
23
+ assert_resource_type(:capability_statement)
24
+ capability_statement = resource
25
+
26
+ resource_type = 'MedicationRequest'
27
+ parameter_name = 'patient'
28
+
29
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
30
+ pass "Server declares support for MedicationRequest search parameter: #{parameter_name}"
31
+ else
32
+ assert false, "Server does not declare support for required MedicationRequest search parameter: #{parameter_name}"
33
+ end
34
+ end
35
+ end
36
+
37
+ test do
38
+ optional
39
+ title 'Server declares support for MedicationRequest status search parameter'
40
+ description %(
41
+ The server should declare support for the MedicationRequest status search parameter
42
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
43
+ )
44
+
45
+ run do
46
+ fhir_get_capability_statement
47
+
48
+ assert_response_status(200)
49
+ assert_resource_type(:capability_statement)
50
+ capability_statement = resource
51
+
52
+ resource_type = 'MedicationRequest'
53
+ parameter_name = 'status'
54
+
55
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
56
+ pass "Server declares support for MedicationRequest search parameter: #{parameter_name}"
57
+ else
58
+ assert false, "Server does not declare support for required MedicationRequest search parameter: #{parameter_name}"
59
+ end
60
+ end
61
+ end
62
+
63
+ test do
64
+ optional
65
+ title 'Server declares support for MedicationRequest intent search parameter'
66
+ description %(
67
+ The server should declare support for the MedicationRequest intent search parameter
68
+ as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
69
+ )
70
+
71
+ run do
72
+ fhir_get_capability_statement
73
+
74
+ assert_response_status(200)
75
+ assert_resource_type(:capability_statement)
76
+ capability_statement = resource
77
+
78
+ resource_type = 'MedicationRequest'
79
+ parameter_name = 'intent'
80
+
81
+ if check_search_parameter_support(capability_statement, resource_type, parameter_name)
82
+ pass "Server declares support for MedicationRequest search parameter: #{parameter_name}"
83
+ else
84
+ assert false, "Server does not declare support for required MedicationRequest search parameter: #{parameter_name}"
85
+ end
86
+ end
87
+ end
88
+
89
+ test do
90
+ optional
91
+ optional
92
+ title 'Server declares support for MedicationRequest _include parameter'
93
+ description %(
94
+ The server should declare support for the MedicationRequest _include parameter
95
+ (MedicationRequest:medication) as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
96
+ )
97
+
98
+ run do
99
+ fhir_get_capability_statement
100
+
101
+ assert_response_status(200)
102
+ assert_resource_type(:capability_statement)
103
+ capability_statement = resource
104
+
105
+ resource_type = 'MedicationRequest'
106
+ include_param = 'MedicationRequest:medication'
107
+
108
+ if check_include_support(capability_statement, resource_type, include_param)
109
+ pass "Server declares support for MedicationRequest _include parameter: #{include_param}"
110
+ else
111
+ assert false, "Server does not declare support for MedicationRequest _include parameter: #{include_param}"
112
+ end
113
+ end
114
+ end
115
+
116
+ test do
117
+ optional
118
+ title 'Server declares support for MedicationRequest basic combined search parameters'
119
+ description %(
120
+ The server should declare support for the combined MedicationRequest search parameters
121
+ (patient+status+intent) as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
122
+ )
123
+
124
+ run do
125
+ fhir_get_capability_statement
126
+
127
+ assert_response_status(200)
128
+ assert_resource_type(:capability_statement)
129
+ capability_statement = resource
130
+
131
+ resource_type = 'MedicationRequest'
132
+ required_params = %w[patient status intent]
133
+ combined_params = 'patient+status+intent'
134
+
135
+ if check_search_combination_support(capability_statement, resource_type, required_params)
136
+ pass "Server declares support for combined MedicationRequest search parameters: #{combined_params}"
137
+ else
138
+ assert false, "Server does not declare support for combined MedicationRequest search parameters: #{combined_params}"
139
+ end
140
+ end
141
+ end
142
+
143
+ test do
144
+ optional
145
+ title 'Server declares support for MedicationRequest combined search parameters with _include'
146
+ description %(
147
+ The server should declare support for the combined MedicationRequest search parameters with _include
148
+ (patient+status+intent+_include) as specified in the Aus CVD Risk Calculator Launch Server CapabilityStatement.
149
+ )
150
+
151
+ run do
152
+ fhir_get_capability_statement
153
+
154
+ assert_response_status(200)
155
+ assert_resource_type(:capability_statement)
156
+ capability_statement = resource
157
+
158
+ resource_type = 'MedicationRequest'
159
+ required_params = %w[patient status intent _include]
160
+ combined_params = 'patient+status+intent+_include'
161
+
162
+ if check_search_combination_support(capability_statement, resource_type, required_params)
163
+ pass "Server declares support for combined MedicationRequest search parameters with _include: #{combined_params}"
164
+ else
165
+ assert false, "Server does not declare support for combined MedicationRequest search parameters with _include: #{combined_params}"
166
+ end
167
+ end
168
+ end
169
+
170
+ test do
171
+ optional
172
+ title 'MedicationRequest search with patient parameter is successful'
173
+
174
+ run do
175
+ fhir_read(:patient, patient_id)
176
+ assert_response_status(200)
177
+
178
+ search_params = "patient=#{patient_id}"
179
+
180
+ fhir_search(:medication_request, params: { patient: patient_id })
181
+
182
+ assert_response_status(200)
183
+ bundle = JSON.parse(response[:body])
184
+ verify_search_parameters_in_self_link(bundle, search_params)
185
+ pass 'Successfully searched for MedicationRequests with patient parameter'
186
+ end
187
+ end
188
+
189
+ test do
190
+ optional
191
+ title 'MedicationRequest search with status parameter is successful'
192
+
193
+ run do
194
+ fhir_read(:patient, patient_id)
195
+ assert_response_status(200)
196
+
197
+ search_params = "status=active,completed&patient=#{patient_id}"
198
+
199
+ fhir_search(:medication_request, params: {
200
+ status: 'active,completed',
201
+ patient: patient_id
202
+ })
203
+
204
+ assert_response_status(200)
205
+ bundle = JSON.parse(response[:body])
206
+ verify_search_parameters_in_self_link(bundle, search_params)
207
+ pass 'Successfully searched for MedicationRequests with status parameter'
208
+ end
209
+ end
210
+
211
+ test do
212
+ optional
213
+ title 'MedicationRequest search with intent parameter is successful'
214
+
215
+ run do
216
+ fhir_read(:patient, patient_id)
217
+ assert_response_status(200)
218
+
219
+ search_params = "intent=order,plan&patient=#{patient_id}"
220
+
221
+ fhir_search(:medication_request, params: {
222
+ intent: 'order,plan',
223
+ patient: patient_id
224
+ })
225
+
226
+ assert_response_status(200)
227
+ bundle = JSON.parse(response[:body])
228
+ verify_search_parameters_in_self_link(bundle, search_params)
229
+ pass 'Successfully searched for MedicationRequests with intent parameter'
230
+ end
231
+ end
232
+
233
+ test do
234
+ optional
235
+ title 'MedicationRequest search with _include parameter is successful'
236
+
237
+ run do
238
+ fhir_read(:patient, patient_id)
239
+ assert_response_status(200)
240
+
241
+ search_params = "_include=MedicationRequest:medication&patient=#{patient_id}"
242
+
243
+ fhir_search(:medication_request, params: {
244
+ _include: 'MedicationRequest:medication',
245
+ patient: patient_id
246
+ })
247
+
248
+ assert_response_status(200)
249
+ bundle = JSON.parse(response[:body])
250
+ verify_search_parameters_in_self_link(bundle, search_params)
251
+
252
+ # Check if any Medication resources are included in the bundle
253
+ medication_entries = bundle['entry']&.select { |entry| entry['resource']['resourceType'] == 'Medication' }
254
+
255
+ if medication_entries&.any?
256
+ pass 'Successfully searched for MedicationRequests with _include parameter and found included Medication resources'
257
+ else
258
+ assert false, 'Successfully searched with _include parameter but no Medication resources were included in the response'
259
+ end
260
+ end
261
+ end
262
+
263
+ test do
264
+ optional
265
+ title 'MedicationRequest search with combined parameters is successful'
266
+
267
+ run do
268
+ fhir_read(:patient, patient_id)
269
+ assert_response_status(200)
270
+
271
+ search_params = "intent=order,plan&status=active,completed&patient=#{patient_id}"
272
+
273
+ fhir_search(:medication_request, params: {
274
+ intent: 'order,plan',
275
+ status: 'active,completed',
276
+ patient: patient_id
277
+ })
278
+
279
+ assert_response_status(200)
280
+ bundle = JSON.parse(response[:body])
281
+ verify_search_parameters_in_self_link(bundle, search_params)
282
+ pass 'Successfully searched for MedicationRequests with combined parameters'
283
+ end
284
+ end
285
+
286
+ test do
287
+ optional
288
+ title 'MedicationRequest search with combined parameters and _include is successful'
289
+
290
+ run do
291
+ fhir_read(:patient, patient_id)
292
+ assert_response_status(200)
293
+
294
+ search_params = "_include=MedicationRequest:medication&intent=order,plan&status=active,completed&patient=#{patient_id}"
295
+
296
+ fhir_search(:medication_request, params: {
297
+ _include: 'MedicationRequest:medication',
298
+ intent: 'order,plan',
299
+ status: 'active,completed',
300
+ patient: patient_id
301
+ })
302
+
303
+ assert_response_status(200)
304
+ bundle = JSON.parse(response[:body])
305
+ verify_search_parameters_in_self_link(bundle, search_params)
306
+
307
+ # Check if any Medication resources are included in the bundle
308
+ medication_entries = bundle['entry']&.select { |entry| entry['resource']['resourceType'] == 'Medication' }
309
+
310
+ if medication_entries&.any?
311
+ pass 'Successfully searched for MedicationRequests with combined parameters and _include, and found included Medication resources'
312
+ else
313
+ assert false, 'Successfully searched with combined parameters and _include but no Medication resources were included in the response'
314
+ end
315
+ end
316
+ end
317
+
318
+ test do
319
+ optional
320
+ title 'Server declares support for CVD Risk MedicationRequest profile '
321
+ description %(
322
+ The server should declare support for the CVD Risk MedicationRequest profile
323
+ as recommended by the Aus CVD Risk Calculator Launch Server CapabilityStatement.
324
+ )
325
+
326
+ run do
327
+ fhir_get_capability_statement
328
+
329
+ assert_response_status(200)
330
+ assert_resource_type(:capability_statement)
331
+ capability_statement = resource
332
+
333
+ resource_type = 'MedicationRequest'
334
+ profile_url = 'https://www.cvdcheck.org.au/fhir/StructureDefinition/CVDRiskMedicationRequest'
335
+
336
+ has_profile = check_capability_statement_for_profile(capability_statement, resource_type, profile_url)
337
+
338
+ if has_profile
339
+ pass "Server declares support for CVD Risk MedicationRequest profile"
340
+ else
341
+ assert false, "CapabilityStatement does not declare support for CVD Risk MedicationRequest profile"
342
+ end
343
+ end
344
+ end
345
+
346
+ test do
347
+ optional
348
+ title 'Server declares support for reading Medication resources'
349
+
350
+ run do
351
+ fhir_get_capability_statement
352
+
353
+ assert_response_status(200)
354
+ assert_resource_type(:capability_statement)
355
+ capability_statement = resource
356
+
357
+ resource_type = 'Medication'
358
+ interaction = 'read'
359
+
360
+ rest_component = capability_statement.rest&.find { |r| r.mode == 'server' }
361
+ assert rest_component.present?, 'CapabilityStatement does not have a REST component with mode "server"'
362
+
363
+ resource_component = rest_component.resource&.find { |r| r.type == resource_type }
364
+ assert resource_component.present?, "CapabilityStatement does not declare support for #{resource_type} resource"
365
+
366
+ has_interaction = resource_component.interaction&.any? { |i| i.code == interaction }
367
+ assert has_interaction, "CapabilityStatement does not declare support for #{interaction} interaction on #{resource_type} resource"
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end