示例#1
0
 def testGetSourceCodeSystem_withInvalidCodeSystem_returnsNone(self):
   """Test get_source_code_system when source_code_system is not present."""
   year_value_descriptor = (
       datatypes_pb2.Date.Precision.DESCRIPTOR.values_by_number[
           datatypes_pb2.Date.Precision.YEAR])
   self.assertIsNone(
       annotation_utils.get_source_code_system(year_value_descriptor))
示例#2
0
def get_system_for_code(code: message.Message) -> str:
    """Returns the code system associated with the provided Code."""
    system_field = code.DESCRIPTOR.fields_by_name.get('system')
    if system_field is not None:
        return proto_utils.get_value_at_field(code, system_field)

    fixed_coding_system = annotation_utils.get_fixed_coding_system(code)
    if fixed_coding_system is not None:
        # The entire profiled coding can only be from a single system. Use that.
        return fixed_coding_system

    # There is no single system for the whole coding. Look for the coding system
    # annotation on the enum.
    enum_field = code.DESCRIPTOR.fields_by_name.get('value')
    if (enum_field is None
            or enum_field.type != descriptor.FieldDescriptor.TYPE_ENUM):
        raise fhir_errors.InvalidFhirError(
            f'Invalid profiled Coding: {code.DESCRIPTOR.full_name}; missing system '
            'information on string code.')

    enum_value = proto_utils.get_value_at_field(code, enum_field)
    enum_value_descriptor = enum_field.enum_type.values_by_number[enum_value]
    if not annotation_utils.has_source_code_system(enum_value_descriptor):
        raise fhir_errors.InvalidFhirError(
            f'Invalid profiled Coding: {code.DESCRIPTOR.full_name}; missing system '
            'information on enum code')
    return cast(str,
                annotation_utils.get_source_code_system(enum_value_descriptor))
示例#3
0
    def testGetSourceCodeSystem_withValidCodeSystem_returnsValue(self):
        """Test get_source_code_system when source_code_system is present."""
        birth_sex_valueset = uscore_codes_pb2.BirthSexValueSet()
        female_value_descriptor = (
            birth_sex_valueset.Value.DESCRIPTOR.values_by_number[
                birth_sex_valueset.Value.F])
        self.assertEqual(
            annotation_utils.get_source_code_system(female_value_descriptor),
            'http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender')

        male_value_descriptor = (birth_sex_valueset.Value.DESCRIPTOR.
                                 values_by_number[birth_sex_valueset.Value.M])
        self.assertEqual(
            annotation_utils.get_source_code_system(male_value_descriptor),
            'http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender')

        unk_value_descriptor = (birth_sex_valueset.Value.DESCRIPTOR.
                                values_by_number[birth_sex_valueset.Value.UNK])
        self.assertEqual(
            annotation_utils.get_source_code_system(unk_value_descriptor),
            'http://terminology.hl7.org/CodeSystem/v3-NullFlavor')