def testSplitIfRelativeReference_withUrlScheme_succeeds(self): ref = datatypes_pb2.Reference( uri=datatypes_pb2.String( value='http://acme.com/ehr/fhir/Practitioner/2323-33-4')) references.split_if_relative_reference(ref) uri_field = ref.DESCRIPTOR.fields_by_name['uri'] self.assertEqual( proto_utils.get_value_at_field(ref, uri_field), datatypes_pb2.String( value='http://acme.com/ehr/fhir/Practitioner/2323-33-4'))
def testSplitIfRelativeReference_withFragmentReference_succeeds(self): ref = datatypes_pb2.Reference(uri=datatypes_pb2.String(value='#org-1')) uri_field = ref.DESCRIPTOR.fields_by_name['uri'] fragment_field = ref.DESCRIPTOR.fields_by_name['fragment'] self.assertTrue(proto_utils.field_is_set(ref, uri_field)) self.assertFalse(proto_utils.field_is_set(ref, fragment_field)) references.split_if_relative_reference(ref) self.assertFalse(proto_utils.field_is_set(ref, uri_field)) self.assertTrue(proto_utils.field_is_set(ref, fragment_field)) self.assertEqual( proto_utils.get_value_at_field(ref, fragment_field), datatypes_pb2.String(value='org-1'))
def testSplitIfRelativeReference_withMalformedUri_raises(self): ref = datatypes_pb2.Reference(uri=datatypes_pb2.String(value='InvalidUri')) with self.assertRaises(ValueError) as e: references.split_if_relative_reference(ref) self.assertIsInstance(e.exception, ValueError)
def testClearFhirExtensions_withMultipleExtensions_succeeds(self): """Tests ClearFhirExtensions when a message has multiple extensions.""" arbitrary_string = datatypes_pb2.String() arbitrary_string.extension.add( url=datatypes_pb2.Uri(value='first'), value=datatypes_pb2.Extension.ValueX(boolean=datatypes_pb2.Boolean( value=True))) arbitrary_string.extension.add( url=datatypes_pb2.Uri(value='second'), value=datatypes_pb2.Extension.ValueX(boolean=datatypes_pb2.Boolean( value=True))) arbitrary_string.extension.add( url=datatypes_pb2.Uri(value='third'), value=datatypes_pb2.Extension.ValueX(boolean=datatypes_pb2.Boolean( value=True))) self.assertLen(extensions.get_fhir_extensions(arbitrary_string), 3) # Remove middle extension extensions.clear_fhir_extensions_with_url(arbitrary_string, 'second') remaining_extensions = extensions.get_fhir_extensions(arbitrary_string) self.assertLen(remaining_extensions, 2) remaining_urls = [ extension.url.value for extension in remaining_extensions ] self.assertEqual(remaining_urls, ['first', 'third'])
def testSplitIfRelativeReference_withRelativeReference_succeeds(self): ref = datatypes_pb2.Reference( uri=datatypes_pb2.String(value='Practitioner/example'), display=datatypes_pb2.String(value='Dr Adam Careful')) uri_field = ref.DESCRIPTOR.fields_by_name['uri'] practitioner_id_field = ref.DESCRIPTOR.fields_by_name['practitioner_id'] self.assertTrue(proto_utils.field_is_set(ref, uri_field)) self.assertFalse(proto_utils.field_is_set(ref, practitioner_id_field)) references.split_if_relative_reference(ref) self.assertFalse(proto_utils.field_is_set(ref, uri_field)) self.assertTrue(proto_utils.field_is_set(ref, practitioner_id_field)) self.assertEqual( proto_utils.get_value_at_field(ref, practitioner_id_field), datatypes_pb2.ReferenceId(value='example'))
def testGetCodeAsString_withInvalidType(self): """Tests get_code_as_string with an invalid value-field type.""" not_a_code = datatypes_pb2.String(value='foo') with self.assertRaises(ValueError) as ve: _ = codes.get_code_as_string(not_a_code) self.assertIsInstance(ve.exception, ValueError)