forked from fhir-crucible/fhir_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiversion_test.rb
412 lines (371 loc) · 16.6 KB
/
multiversion_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
require_relative '../test_helper'
class MultiversionTest < Test::Unit::TestCase
def test_autodetect_stu3
root = File.expand_path '..', File.dirname(File.absolute_path(__FILE__))
capabilitystatement = File.read(File.join(root, 'fixtures', 'capabilitystatement.json'))
stub_request(:get, /autodetect/).to_return(body: capabilitystatement)
client = FHIR::Client.new('autodetect')
client.default_json
assert client.detect_version == :stu3
end
def test_autodetect_dstu2
root = File.expand_path '..', File.dirname(File.absolute_path(__FILE__))
conformance = File.read(File.join(root, 'fixtures', 'conformance.json'))
stub_request(:get, /autodetect/).to_return(body: conformance)
client = FHIR::Client.new('autodetect')
client.default_json
assert client.detect_version == :dstu2
end
def test_autodetect_r4
root = File.expand_path '..', File.dirname(File.absolute_path(__FILE__))
conformance = File.read(File.join(root, 'fixtures', 'r4_capabilitystatement.json'))
stub_request(:get, /autodetect/).to_return(body: conformance)
client = FHIR::Client.new('autodetect')
client.default_json
assert client.detect_version == :r4
end
def test_stu3_patient_manual
stub_request(:get, /stu3/).to_return(body: FHIR::STU3::Patient.new.to_json)
client = FHIR::Client.new('stu3')
client.default_json
assert_equal :stu3, client.fhir_version
assert client.read(FHIR::STU3::Patient, 'foo').resource.is_a?(FHIR::STU3::Patient)
end
def test_dstu2_patient_manual
stub_request(:get, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('dstu2')
client.default_json
client.use_dstu2
assert_equal :dstu2, client.fhir_version
assert client.read(FHIR::DSTU2::Patient, 'foo').resource.is_a?(FHIR::DSTU2::Patient)
end
def test_r4_patient_manual
stub_request(:get, /r4/).to_return(body: FHIR::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('r4')
client.default_json
client.use_r4
assert_equal :r4, client.fhir_version
assert client.read(FHIR::Patient, 'foo').resource.is_a?(FHIR::Patient)
end
def test_stu3_patient_klass_access
stub_request(:get, /stu3/).to_return(body: FHIR::STU3::Patient.new.to_json)
client = FHIR::Client.new('stu3')
client.default_json
FHIR::STU3::Model.client = client
assert FHIR::STU3::Patient.read('foo').is_a?(FHIR::STU3::Patient)
end
def test_dstu2_patient_klass_access
stub_request(:get, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('dstu2')
client.default_json
client.use_dstu2
FHIR::DSTU2::Model.client = client
assert FHIR::DSTU2::Patient.read('foo').is_a?(FHIR::DSTU2::Patient)
end
def test_r4_patient_klass_access
stub_request(:get, /r4/).to_return(body: FHIR::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('r4')
client.default_json
client.use_r4
FHIR::Model.client = client
assert FHIR::Patient.read('foo').is_a?(FHIR::Patient)
end
def test_dstu2_reply_fhir_version
stub_request(:get, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('dstu2')
client.default_json
client.use_dstu2
FHIR::DSTU2::Model.client = client
patient = FHIR::DSTU2::Patient.read('foo')
assert_equal :dstu2, client.reply.fhir_version
end
def test_stu3_reply_fhir_version
stub_request(:get, /stu3/).to_return(body: FHIR::STU3::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('stu3')
client.default_json
FHIR::STU3::Model.client = client
patient = FHIR::STU3::Patient.read('foo')
assert_equal :stu3, client.reply.fhir_version
end
def test_r4_reply_fhir_version
stub_request(:get, /r4/).to_return(body: FHIR::Patient.new({ 'id': 'foo' }).to_json)
client = FHIR::Client.new('r4')
client.default_json
FHIR::Model.client = client
patient = FHIR::Patient.read('foo')
assert_equal :stu3, client.reply.fhir_version
end
def test_stu3_accept_mime_type_json
stub_request(:get, /stu3/).to_return(body: FHIR::STU3::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('stu3')
client.default_json
assert_equal :stu3, client.fhir_version
assert_equal 'application/fhir+json', client.read(FHIR::STU3::Patient, 'foo').request[:headers]['Accept']
end
def test_r4_accept_mime_type_json
stub_request(:get, /r4/).to_return(body: FHIR::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('r4')
client.default_json
assert_equal :stu3, client.fhir_version
assert_equal 'application/fhir+json', client.read(FHIR::Patient, 'foo').request[:headers]['Accept']
end
def test_dstu2_accept_mime_type_json
stub_request(:get, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('dstu2')
client.default_json
client.use_dstu2
assert_equal :dstu2, client.fhir_version
# dstu2 fhir type was changed in stu3
assert_equal 'application/json+fhir', client.read(FHIR::DSTU2::Patient, 'foo').request[:headers]['Accept']
end
def test_stu3_content_type_mime_type_json
stub_request(:post, /stu3/).to_return(body: FHIR::STU3::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('stu3')
client.default_json
assert_equal :stu3, client.fhir_version
assert client.create(FHIR::STU3::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/fhir+json')
end
def test_dstu2_content_type_mime_type_json
stub_request(:post, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('dstu2')
client.default_json
client.use_dstu2
assert_equal :dstu2, client.fhir_version
# dstu2 fhir type was changed in stu3
assert client.create(FHIR::DSTU2::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/json+fhir')
end
def test_r4_content_type_mime_type_json
stub_request(:post, /r4/).to_return(body: FHIR::Patient.new({'id': 'foo'}).to_json)
client = FHIR::Client.new('r4')
client.default_json
client.use_r4
assert_equal :r4, client.fhir_version
assert client.create(FHIR::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/fhir+json')
end
def test_stu3_accept_mime_type_xml
stub_request(:get, /stu3/).to_return(body: FHIR::STU3::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
assert_equal :stu3, client.fhir_version
assert_equal 'application/fhir+xml', client.read(FHIR::STU3::Patient, 'foo').request[:headers]['Accept']
end
def test_dstu2_accept_mime_type_xml
stub_request(:get, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
assert_equal :dstu2, client.fhir_version
# dstu2 fhir type was changed in stu3
assert_equal 'application/xml+fhir', client.read(FHIR::DSTU2::Patient, 'foo').request[:headers]['Accept']
end
def test_r4_accept_mime_type_xml
stub_request(:get, /r4/).to_return(body: FHIR::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
assert_equal :r4, client.fhir_version
# dstu2 fhir type was changed in stu3
assert_equal 'application/fhir+xml', client.read(FHIR::Patient, 'foo').request[:headers]['Accept']
end
def test_stu3_content_type_mime_type_xml
stub_request(:post, /stu3/).to_return(body: FHIR::STU3::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
client.use_stu3
assert_equal :stu3, client.fhir_version
assert client.create(FHIR::STU3::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/fhir+xml')
end
def test_r4_content_type_mime_type_xml
stub_request(:post, /r4/).to_return(body: FHIR::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
assert_equal :r4, client.fhir_version
assert client.create(FHIR::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/fhir+xml')
end
def test_dstu2_content_type_mime_type_xml
stub_request(:post, /dstu2/).to_return(body: FHIR::DSTU2::Patient.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
assert_equal :dstu2, client.fhir_version
# dstu2 fhir type was changed in stu3
assert client.create(FHIR::DSTU2::Patient.new({'id': 'foo'})).request[:headers]['Content-Type'].include?('application/xml+fhir')
end
def test_dstu2_transaction
stub_request(:post, /dstu2/).to_return(body: FHIR::DSTU2::Bundle.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
client.begin_transaction
client.add_transaction_request('GET', 'Patient/foo')
client.add_transaction_request('POST', nil, FHIR::DSTU2::Observation.new({'id': 'foo'}))
reply = client.end_transaction
assert_equal :dstu2, reply.fhir_version
assert_equal 'application/xml+fhir', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::DSTU2::Bundle)
end
def test_stu3_transaction
stub_request(:post, /stu3/).to_return(body: FHIR::STU3::Bundle.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
client.begin_transaction
client.add_transaction_request('GET', 'Patient/foo')
client.add_transaction_request('POST', nil, FHIR::STU3::Observation.new({'id': 'foo'}))
reply = client.end_transaction
assert_equal :stu3, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::STU3::Bundle)
end
def test_r4_transaction
stub_request(:post, /r4/).to_return(body: FHIR::Bundle.new({'id': 'foo'}).to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
client.begin_transaction
client.add_transaction_request('GET', 'Patient/foo')
client.add_transaction_request('POST', nil, FHIR::Observation.new({'id': 'foo'}))
reply = client.end_transaction
assert_equal :r4, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::Bundle)
end
def test_dstu2_patient_record
bundle = FHIR::DSTU2::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::DSTU2::Bundle::Entry.new
bundle.entry.last.resource = FHIR::DSTU2::Patient.new({'id': 'example-patient'})
stub_request(:get, 'http:https://dstu2/Patient/example-patient/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
reply = client.fetch_patient_record('example-patient')
assert_equal :dstu2, reply.fhir_version
assert_equal 'application/xml+fhir', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::DSTU2::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::DSTU2::Patient)
end
def test_stu3_patient_record
bundle = FHIR::STU3::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::STU3::Bundle::Entry.new
bundle.entry.last.resource = FHIR::STU3::Patient.new({'id': 'example-patient'})
stub_request(:get, 'http:https://stu3/Patient/example-patient/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
reply = client.fetch_patient_record('example-patient')
assert_equal :stu3, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::STU3::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::STU3::Patient)
end
def test_r4_patient_record
bundle = FHIR::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::Bundle::Entry.new
bundle.entry.last.resource = FHIR::Patient.new({'id': 'example-patient'})
stub_request(:get, 'http:https://r4/Patient/example-patient/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
reply = client.fetch_patient_record('example-patient')
assert_equal :r4, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::Patient)
end
def test_dstu2_encounter_record
bundle = FHIR::DSTU2::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::DSTU2::Bundle::Entry.new
bundle.entry.last.resource = FHIR::DSTU2::Encounter.new({'id': 'example-encounter'})
stub_request(:get, 'http:https://dstu2/Encounter/example-encounter/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
reply = client.fetch_encounter_record('example-encounter')
assert_equal :dstu2, reply.fhir_version
assert_equal 'application/xml+fhir', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::DSTU2::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::DSTU2::Encounter)
end
def test_stu3_encounter_record
bundle = FHIR::STU3::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::STU3::Bundle::Entry.new
bundle.entry.last.resource = FHIR::STU3::Encounter.new({'id': 'example-encounter'})
stub_request(:get, 'http:https://stu3/Encounter/example-encounter/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
reply = client.fetch_encounter_record('example-encounter')
assert_equal :stu3, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::STU3::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::STU3::Encounter)
end
def test_r4_encounter_record
bundle = FHIR::Bundle.new({'id': 'foo'})
bundle.entry << FHIR::Bundle::Entry.new
bundle.entry.last.resource = FHIR::Encounter.new({'id': 'example-encounter'})
stub_request(:get, 'http:https://r4/Encounter/example-encounter/$everything').to_return(body: bundle.to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
reply = client.fetch_encounter_record('example-encounter')
assert_equal :r4, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::Bundle)
assert reply.resource.entry.last.resource.is_a?(FHIR::Encounter)
end
def test_dstu2_terminology_valueset_lookup
stub_request(:post, /dstu2/).to_return(body: FHIR::DSTU2::Parameters.new({'id': 'results'}).to_xml)
client = FHIR::Client.new('dstu2')
client.default_xml
client.use_dstu2
options = {
:operation => {
:method => :get,
:parameters => {
'code' => { type: 'Code', value: 'chol-mmol' },
'system' => { type: 'Uri', value: 'http:https://hl7.org/fhir/CodeSystem/example-crucible' }
}
}
}
reply = client.code_system_lookup(options)
assert_equal :dstu2, reply.fhir_version
assert_equal 'application/xml+fhir', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::DSTU2::Parameters)
end
def test_stu3_terminology_code_system_lookup
stub_request(:post, /stu3/).to_return(body: FHIR::STU3::Parameters.new({'id': 'results'}).to_xml)
client = FHIR::Client.new('stu3')
client.default_xml
options = {
:operation => {
:method => :get,
:parameters => {
'code' => { type: 'Code', value: 'chol-mmol' },
'system' => { type: 'Uri', value: 'http:https://hl7.org/fhir/CodeSystem/example-crucible' }
}
}
}
reply = client.code_system_lookup(options)
assert_equal :stu3, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::STU3::Parameters)
end
def test_r4_terminology_code_system_lookup
stub_request(:post, /r4/).to_return(body: FHIR::Parameters.new({'id': 'results'}).to_xml)
client = FHIR::Client.new('r4')
client.default_xml
client.use_r4
options = {
:operation => {
:method => :get,
:parameters => {
'code' => { type: 'Code', value: 'chol-mmol' },
'system' => { type: 'Uri', value: 'http:https://hl7.org/fhir/CodeSystem/example-crucible' }
}
}
}
reply = client.code_system_lookup(options)
assert_equal :r4, reply.fhir_version
assert_equal 'application/fhir+xml', reply.request[:headers]['Accept']
assert reply.resource.is_a?(FHIR::Parameters)
end
end