def testIsTypedReferenceField_withValidTypedReferenceField_returnsTrue(self): """Test is_typed_reference_field functionality on valid input.""" reference = datatypes_pb2.Reference() practitioner_role_id_field = reference.DESCRIPTOR.fields_by_name[ 'practitioner_role_id'] self.assertTrue( annotation_utils.is_typed_reference_field(practitioner_role_id_field))
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 testIsReference_withValidReferenceType_returnsTrue(self): """Test is_reference functionality on valid input.""" reference = datatypes_pb2.Reference() ref_descriptor_proto = self._descriptor_proto_for_descriptor( reference.DESCRIPTOR) self.assertTrue(annotation_utils.is_reference(reference)) self.assertTrue(annotation_utils.is_reference(reference.DESCRIPTOR)) self.assertTrue(annotation_utils.is_reference(ref_descriptor_proto))
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_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 testIsTypedReferenceField_withInvalidTypedReferenceField_returnsFalse( self): """Test is_typed_reference_field functionality on invalid input.""" reference = datatypes_pb2.Reference() uri_field = reference.DESCRIPTOR.fields_by_name['uri'] self.assertFalse(annotation_utils.is_typed_reference_field(uri_field))