def instantiate_from(self, filename): datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or \ os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'fhir-parser', 'downloads')) with io.open(os.path.join(datadir, filename), 'r', encoding='utf-8') as handle: js = json.load(handle) self.assertEqual("Bundle", js["resourceType"]) return bundle.Bundle(js)
def testBundle10(self): inst = self.instantiate_from("location-examples-general.json") self.assertIsNotNone(inst, "Must have instantiated a Bundle instance") self.implBundle10(inst) js = inst.as_json() self.assertEqual("Bundle", js["resourceType"]) inst2 = bundle.Bundle(js) self.implBundle10(inst2)
def testBundle9(self): inst = self.instantiate_from("document-example-dischargesummary.json") self.assertIsNotNone(inst, "Must have instantiated a Bundle instance") self.implBundle9(inst) js = inst.as_json() self.assertEqual("Bundle", js["resourceType"]) inst2 = bundle.Bundle(js) self.implBundle9(inst2)
def testBundle5(self): inst = self.instantiate_from("diagnosticreport-example-lipids.json") self.assertIsNotNone(inst, "Must have instantiated a Bundle instance") self.implBundle5(inst) js = inst.as_json() self.assertEqual("Bundle", js["resourceType"]) inst2 = bundle.Bundle(js) self.implBundle5(inst2)
def testBundleReferences(self): with io.open(os.path.join(filedir, 'test_bundle.json'), 'r', encoding='utf-8') as h: data = json.load(h) b = bundle.Bundle(data) self.assertIsNotNone(b, "Must instantiate Bundle") self.assertEqual('Bundle', b.resource_type) b._server = MockServer() # get resources pat23 = b.entry[0].resource self.assertEqual('Patient', pat23.resource_type) self.assertEqual('Darth', pat23.name[0].given[0]) patURN = b.entry[1].resource self.assertEqual('Patient', patURN.resource_type) self.assertEqual('Ben', patURN.name[0].given[0]) obs123 = b.entry[2].resource self.assertEqual('Observation', obs123.resource_type) obs56 = b.entry[3].resource self.assertEqual('Observation', obs56.resource_type) obs34 = b.entry[4].resource self.assertEqual('Observation', obs34.resource_type) # test resolving w/o server (won't work) res = obs123.subject.resolved(patient.Patient) # TODO: Patient 23 is now part of the bundle, so the test below fails # self.assertIsNone(res) # test resolving with server b._server = MockServer() res = obs123.subject.resolved(patient.Patient) self.assertEqual(res, pat23) res = obs123.subject.resolved(medication.Medication) self.assertIsNone(res, "Must not resolve on type mismatch") res = obs56.subject.resolved(patient.Patient) self.assertEqual(res, patURN) res = obs34.subject.resolved(patient.Patient) self.assertIsNone( res, "Must not resolve Patient on same server but different endpoint")