(case_config)
return property_map
Returns a map of case properties to OpenMRS patient properties and
    attributes, and a value source dict to deserialize them.
Returns a map of case properties to OpenMRS patient properties and
    attributes, and a value source dict to deserialize them.
Returns a map of case properties to OpenMRS patient properties and attributes and a value source dict to deserialize them .
def get_property_map(case_config):
    """
    Returns a map of case properties to OpenMRS patient properties and
    attributes, and a value source dict to deserialize them.
    """
    property_map = {}

    for person_prop, value_source_dict in case_config['person_properties'].items():
        if 'case_property' in value_source_dict:
            jsonpath = parse_jsonpath('person.' + person_prop)
            property_map[value_source_dict['case_property']] = (jsonpath, value_source_dict)

    for attr_type_uuid, value_source_dict in case_config['person_attributes'].items():
        # jsonpath-ng offers programmatic JSONPath expressions. For details on how to create JSONPath
        # expressions programmatically see the
        # `jsonpath-ng documentation <https://github.com/h2non/jsonpath-ng#programmatic-jsonpath>`__
        #
        # The `Where` JSONPath expression "*jsonpath1* `where` *jsonpath2*" returns nodes matching *jsonpath1*
        # where a child matches *jsonpath2*. `Cmp` does a comparison in *jsonpath2*. It accepts a
        # comparison operator and a value. The JSONPath expression for matching simple attribute values is::
        #
        #     (person.attributes[*] where attributeType.uuid eq attr_type_uuid).value
        #
        # This extracts the person attribute values where their attribute type UUIDs match those configured in
        # case_config['person_attributes'].
        #
        # Person attributes with Concept values have UUIDs. The following JSONPath uses Union to match both simple
        # values and Concept values.
        if 'case_property' in value_source_dict:
            jsonpath = Union(
                # Simple values: Return value if it has no children.
                # (person.attributes[*] where attributeType.uuid eq attr_type_uuid).(value where not *)
                Child(
                    Where(
                        Child(Child(Fields('person'), Fields('attributes')), Slice()),
                        Cmp(Child(Fields('attributeType'), Fields('uuid')), eq, attr_type_uuid)
                    ),
                    WhereNot(Fields('value'), Fields('*'))
                ),
                # Concept values: Return value.uuid if value.uuid exists:
                # (person.attributes[*] where attributeType.uuid eq attr_type_uuid).value.uuid
                Child(
                    Where(
                        Child(Child(Fields('person'), Fields('attributes')), Slice()),
                        Cmp(Child(Fields('attributeType'), Fields('uuid')), eq, attr_type_uuid)
                    ),
                    Child(Fields('value'), Fields('uuid'))
                )
            )
            property_map[value_source_dict['case_property']] = (jsonpath, value_source_dict)

    for name_prop, value_source_dict in case_config['person_preferred_name'].items():
        if 'case_property' in value_source_dict:
            jsonpath = parse_jsonpath('person.preferredName.' + name_prop)
            property_map[value_source_dict['case_property']] = (jsonpath, value_source_dict)

    for addr_prop, value_source_dict in case_config['person_preferred_address'].items():
        if 'case_property' in value_source_dict:
            jsonpath = parse_jsonpath('person.preferredAddress.' + addr_prop)
            property_map[value_source_dict['case_property']] = (jsonpath, value_source_dict)

    for id_type_uuid, value_source_dict in case_config['patient_identifiers'].items():
        if 'case_property' in value_source_dict:
            if id_type_uuid == 'uuid':
                jsonpath = parse_jsonpath('uuid')
            else:
                # The JSONPath expression below is the equivalent of::
                #
                #     (identifiers[*] where identifierType.uuid eq id_type_uuid).identifier
                #
                # Similar to `person_attributes` above, this will extract the person identifier values where
                # their identifier type UUIDs match those configured in case_config['patient_identifiers']
                jsonpath = Child(
                    Where(
                        Child(Fields('identifiers'), Slice()),
                        Cmp(Child(Fields('identifierType'), Fields('uuid')), eq, id_type_uuid)
                    ),
                    Fields('identifier')
                )
            property_map[value_source_dict['case_property']] = (jsonpath, value_source_dict)

    return property_map
def get_property_map ( case_config ) : property_map = { } for person_prop , value_source_dict in case_config [ 'person_properties' ] . items ( ) : if 'case_property' in value_source_dict : jsonpath = parse_jsonpath ( 'person.' + person_prop ) property_map [ value_source_dict [ 'case_property' ] ] = ( jsonpath , value_source_dict ) for attr_type_uuid , value_source_dict in case_config [ 'person_attributes' ] . items ( ) : # jsonpath-ng offers programmatic JSONPath expressions. For details on how to create JSONPath # expressions programmatically see the # `jsonpath-ng documentation <https://github.com/h2non/jsonpath-ng#programmatic-jsonpath>`__ # # The `Where` JSONPath expression "*jsonpath1* `where` *jsonpath2*" returns nodes matching *jsonpath1* # where a child matches *jsonpath2*. `Cmp` does a comparison in *jsonpath2*. It accepts a # comparison operator and a value. The JSONPath expression for matching simple attribute values is:: # #     (person.attributes[*] where attributeType.uuid eq attr_type_uuid).value # # This extracts the person attribute values where their attribute type UUIDs match those configured in # case_config['person_attributes']. # # Person attributes with Concept values have UUIDs. The following JSONPath uses Union to match both simple # values and Concept values. if 'case_property' in value_source_dict : jsonpath = Union ( # Simple values: Return value if it has no children. # (person.attributes[*] where attributeType.uuid eq attr_type_uuid).(value where not *) Child ( Where ( Child ( Child ( Fields ( 'person' ) , Fields ( 'attributes' ) ) , Slice ( ) ) , Cmp ( Child ( Fields ( 'attributeType' ) , Fields ( 'uuid' ) ) , eq , attr_type_uuid ) ) , WhereNot ( Fields ( 'value' ) , Fields ( '*' ) ) ) , # Concept values: Return value.uuid if value.uuid exists: # (person.attributes[*] where attributeType.uuid eq attr_type_uuid).value.uuid Child ( Where ( Child ( Child ( Fields ( 'person' ) , Fields ( 'attributes' ) ) , Slice ( ) ) , Cmp ( Child ( Fields ( 'attributeType' ) , Fields ( 'uuid' ) ) , eq , attr_type_uuid ) ) , Child ( Fields ( 'value' ) , Fields ( 'uuid' ) ) ) ) property_map [ value_source_dict [ 'case_property' ] ] = ( jsonpath , value_source_dict ) for name_prop , value_source_dict in case_config [ 'person_preferred_name' ] . items ( ) : if 'case_property' in value_source_dict : jsonpath = parse_jsonpath ( 'person.preferredName.' + name_prop ) property_map [ value_source_dict [ 'case_property' ] ] = ( jsonpath , value_source_dict ) for addr_prop , value_source_dict in case_config [ 'person_preferred_address' ] . items ( ) : if 'case_property' in value_source_dict : jsonpath = parse_jsonpath ( 'person.preferredAddress.' + addr_prop ) property_map [ value_source_dict [ 'case_property' ] ] = ( jsonpath , value_source_dict ) for id_type_uuid , value_source_dict in case_config [ 'patient_identifiers' ] . items ( ) : if 'case_property' in value_source_dict : if id_type_uuid == 'uuid' : jsonpath = parse_jsonpath ( 'uuid' ) else : # The JSONPath expression below is the equivalent of:: # #     (identifiers[*] where identifierType.uuid eq id_type_uuid).identifier # # Similar to `person_attributes` above, this will extract the person identifier values where # their identifier type UUIDs match those configured in case_config['patient_identifiers'] jsonpath = Child ( Where ( Child ( Fields ( 'identifiers' ) , Slice ( ) ) , Cmp ( Child ( Fields ( 'identifierType' ) , Fields ( 'uuid' ) ) , eq , id_type_uuid ) ) , Fields ( 'identifier' ) ) property_map [ value_source_dict [ 'case_property' ] ] = ( jsonpath , value_source_dict ) return property_map