def step_impl(context, system_url, field_name): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) bad_resource_results = [] for res in resources: if ArgonautObservationDecider(res).should_validate(): found = utils.traverse(res, path) if found: vital_validation_status = vital_unit_validation(field_name, res, system_url) if vital_validation_status: bad_resource_results.append(vital_validation_status) assert len(bad_resource_results) == 0, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_UCUM_CODES, resource=bad_resource_results, field_name=field_name)
def step_impl(context, field_name, value): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: if ArgonautObservationDecider(res).should_validate(): found = utils.traverse(res, path) assert found, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_FIELD_NOT_PRESENT, resource=res, field=field_name, json=json.dumps(res, indent=2)) assert value in found, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_WRONG_FIXED, resource=res, values=found, value=value)
def step_impl(context, resource_type, field_name): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: try: reference = utils.traverse(res, path).get('reference') # Validate the reference for FHIR compliance formatting. # http://hl7.org/fhir/references.html reference_regex = r'((http|https)://([A-Za-z0-9\\\.\:\%\$]\/)*)?(' + \ resource_type + r')\/[A-Za-z0-9\-\.]{1,64}(\/_history\/[A-Za-z0-9\-\.]{1,64})?' compiled_regex = re.compile(reference_regex) regex_search_results = compiled_regex.search(reference) except AttributeError: reference = '' assert regex_search_results, \ utils.bad_response_assert(context.response, ERROR_REFERENCE_MATCH, reference=reference, resource_type=resource_type)
def step_impl(context, name, field_name): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found = utils.traverse(res, path) assert len(found) > 0, utils.bad_response_assert(context.response, ERROR_REQUIRED, name=name)
def step_impl(context, field_name, value_set_url_one, value_set_url_two): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) system_names = '{0} or {1}'.format(value_set_url_one, value_set_url_two) for res in resources: found = utils.traverse(res, path) if isinstance(found, str): found = [found] elif isinstance(found, dict): assert 'coding' in found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_CODING_MISSING, resource=res, field_name=field_name, json=json.dumps(found, indent=2)) found = [ coding.get('code') for coding in found.get('coding') if in_value_set(coding, value_set_url_one) or in_value_set(coding, value_set_url_two) ] assert found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_MISSING_SYSTEM_CODING, resource=res, field_name=field_name, system=system_names) for code in found: try: valid = systems.validate_code(code, value_set_url_one) or \ systems.validate_code(code, value_set_url_two) except systems.SystemNotRecognized: valid = False assert valid, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_INVALID_BINDING, resource=res, code=code, system=system_names, json=json.dumps(res, indent=2))
def step_impl(context, field_name, sub_field): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) sub_path = sub_field.split('.') sub_type = sub_path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found = utils.traverse(res, path) for item in found: match = utils.traverse(item, sub_path) assert match is not None, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_REQUIRED, resource=res, name=sub_type)
def step_impl(context, name, field_one_name, field_two_name): if not StepDecider(context).should_run_test(): return path_one = field_one_name.split('.') path_two = field_two_name.split('.') filter_type = path_one.pop(0) assert filter_type == path_two.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found_one = utils.traverse(res, path_one) found_two = utils.traverse(res, path_two) assert (found_one is not None) or (found_two is not None), \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_REQUIRED, resource=res, name=name )
def step_impl(context, field_string, resource): if not StepDecider(context).should_run_test(): return fields_to_find = field_string.split(",") resources = get_resources(context.response.json(), resource) valid_resource_ids = set([ res.get("id") for res in resources if not ArgonautObservationDecider(res).should_validate() or utils.has_one_of(res, fields_to_find)]) all_resource_ids = set([res.get("id") for res in resources]) invalid_resource_ids = all_resource_ids - valid_resource_ids assert len(invalid_resource_ids) == 0, \ utils.bad_response_assert(context.response, ERROR_MISSING_FIELD, resource_ids=', '.join(invalid_resource_ids), field_list=field_string)