Beispiel #1
0
def step_impl(context, field_name, value_set_url_one, value_set_url_two):
    path = field_name.split('.')
    filter_type = path.pop(0)
    resources = get_resources(context.response.json(), filter_type)

    for res in resources:
        found = traverse(res, path)
        if isinstance(found, str):
            found = [found]
        elif isinstance(found, dict):
            assert 'coding' in found, \
                utils.bad_response_assert(context.response,
                                          ERROR_CODING_MISSING,
                                          field_name=field_name,
                                          json=json.dumps(found, indent=2))
            found = [coding.get('code') for coding in found.get('coding')]

        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

            system_names = '{0} or {1}'.format(value_set_url_one,
                                               value_set_url_two)
            assert valid, utils.bad_response_assert(context.response,
                                                    ERROR_INVALID_BINDING,
                                                    code=code,
                                                    system=system_names)
Beispiel #2
0
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, 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))
Beispiel #4
0
def in_value_set(coding, value_set_url):

    try:
        return systems.validate_code(coding.get('code'), value_set_url)
    except systems.SystemNotRecognized:
        return False