예제 #1
0
 def prepare_value(value):
     """
     Returns a list of unique values, or the value if there is only
     one.
     """
     if isinstance(value, list):
         if value and isinstance(value[0], list):
             set_ = {item for list_ in value for item in list_}
             return simplify_list(list(set_))
         return simplify_list(list(set(value)))
     return value
예제 #2
0
 def find_match(self, candidates: Iterable[dict]):
     matches = self.find_matches(candidates, keep_dups=False)
     match = simplify_list(matches)
     if isinstance(match, list):
         raise DuplicateWarning('Duplicate matches found for resource '
                                f'{self.resource}')
     return match
예제 #3
0
def import_related(
    requests: Requests,
    resource_type: FHIRImportResourceType,
    resource: dict,
    case_id: str,
    child_cases: List[ParentInfo],
):
    for rel in resource_type.jsonpaths_to_related_resource_types.all():
        jsonpath = jsonpath_parse(rel.jsonpath)
        reference = simplify_list([x.value for x in jsonpath.find(resource)])
        validate_parent_ref(reference, rel.related_resource_type)
        related_resource = get_resource(requests, reference)

        if rel.related_resource_is_parent:
            parent_info = ParentInfo(
                child_case_id=case_id,
                parent_ref=reference,
                parent_resource_type=rel.related_resource_type,
            )
            child_cases.append(parent_info)

        import_resource(
            requests,
            rel.related_resource_type,
            related_resource,
            child_cases,
        )
예제 #4
0
 def get_value(self, resource: dict) -> Union[None, str, List[str]]:
     value = simplify_list([x.value for x in self.jsonpath.find(resource)])
     return None if value is None else self.prepare_value(value)
예제 #5
0
 def is_match(self, resource: dict, candidate: dict) -> Optional[bool]:
     a = simplify_list([x.value for x in self.jsonpath.find(resource)])
     b = simplify_list([x.value for x in self.jsonpath.find(candidate)])
     if a is None or b is None:
         return None
     return self.compare(a, b)