def conformance_filter(text_block, fmt): """ Filter FHIR Conformance Statement based on supported ResourceTypes """ # if fmt == "xml": # # First attempt at xml filtering # # logger.debug("xml block as text:\n%s" % text_block) # # xml_dict = xml_to_dict(text_block) # # logger.debug("xml dict:\n%s" % xml_dict) # return xml_dict # Get a list of resource names resource_names = get_resource_names() ct = 0 for k in text_block['rest']: for i, v in k.items(): if i == 'resource': supported_resources = get_supported_resources( v, resource_names) text_block['rest'][ct]['resource'] = supported_resources ct += 1 return text_block
def conformance_filter(text_block, resource_router): """ Filter FHIR Conformance Statement based on supported ResourceTypes """ # Get a list of resource names if resource_router is None: resource_router = get_resourcerouter() resource_names = get_resource_names(resource_router) ct = 0 if text_block: if 'rest' in text_block: for k in text_block['rest']: for i, v in k.items(): if i == 'resource': supp_resources = get_supported_resources( v, resource_names) text_block['rest'][ct]['resource'] = supp_resources ct += 1 else: text_block = "" else: text_block = "" return text_block
def conformance_filter(text_block, fmt, rr=None): """ Filter FHIR Conformance Statement based on supported ResourceTypes """ # if fmt == "xml": # # First attempt at xml filtering # # logger.debug("xml block as text:\n%s" % text_block) # # xml_dict = xml_to_dict(text_block) # # logger.debug("xml dict:\n%s" % xml_dict) # return xml_dict # Get a list of resource names if rr is None: rr = get_resourcerouter() resource_names = get_resource_names(rr) ct = 0 if text_block: if 'rest' in text_block: for k in text_block['rest']: for i, v in k.items(): if i == 'resource': supp_resources = get_supported_resources(v, resource_names, rr) text_block['rest'][ct]['resource'] = supp_resources ct += 1 else: text_block = "" else: text_block = "" return text_block
def filter_dom(root, rr=None, ns=FHIR_NAMESPACE): """ remove unwanted elements from dom :param dom: :param ns: :return: """ if rr is None: rr = get_resourcerouter() # Get the published fhir resources as a list pub_resources = get_resource_names(rr) element_rest = root.findall('{%s}rest' % ns_string(ns), ns) for rest in element_rest: # logger.debug("REST:%s" % rest.tag) # We want the resource elements child_list = get_named_child(rest, '{%s}resource' % ns_string(ns)) # logger.debug("Rest KIDS:%s" % child_list) for resource in child_list: # logger.debug("Resource:%s" % resource.tag) # Now we need to find the type element in resource element_type = resource.findall('{%s}type' % ns_string(ns)) element_interaction = resource.findall('{%s}' 'interaction' % ns_string(ns)) for t in element_type: # logger.debug("R:%s" % no_ns_name(t.attrib)) if no_ns_name(t.attrib) in pub_resources: # logger.debug("Publishing:%s" % no_ns_name(t.attrib)) # this resource is to be published # We need to remove unsupported interactions # get all interactions in resource # check interaction code against supported resource type # actions # remove disabled actions pub_interactions = valid_interaction( no_ns_name(t.attrib), rr) # logger.debug("Interactions:%s" % pub_interactions) for e in element_interaction: for c in e.findall('{%s}code' % ns_string(ns)): e_action = c.attrib['value'] # print("What is element:%s" % e_action) if e_action in pub_interactions: pass # logger.debug("Interaction " # "Enabled:%s" % e_action) # No change - valid interaction else: # logger.debug("Interaction " # "Removed:%s" % e_action) # Remove interaction from the resource resource.remove(e) else: # remove this node from child_list # logger.debug("Removing:%s" % no_ns_name(t.attrib)) # logger.debug("Resource:%s" % resource) rest.remove(resource) # logger.debug("Child_list:%s" % child_list) # logger.debug("Root:%s" % root) return root