Class: DaVinciCRDTestKit::V201::CoverageInformationSystemActionValidationTest

Inherits:
Inferno::Test
  • Object
show all
Includes:
ServerHookRequestValidation, ServerTestHelper
Defined in:
lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb

Constant Summary

Constants included from ProfilesAndResourceTypes

ProfilesAndResourceTypes::ORDER_OR_ENCOUNTER_RESOURCE_CLASSES, ProfilesAndResourceTypes::ORDER_RESOURCE_CLASSES, ProfilesAndResourceTypes::ORDER_RESOURCE_TYPES

Constants included from RequestsLogicalModelValidation

RequestsLogicalModelValidation::CRD_CDS_HOOK_REQUEST_MODEL_URL, RequestsLogicalModelValidation::PERFORMER_ALLOWED_RESOURCE_TYPES, RequestsLogicalModelValidation::USER_ID_ALLOWED_RESOURCE_TYPES

Instance Method Summary collapse

Methods included from ServerTestHelper

#parse_json, #verify_at_least_one_test_passes

Methods included from ServerHookRequestValidation

#client_test?, #server_test?

Methods included from HookRequestFieldValidation

#hook_request_context_check, #hook_request_optional_fields_check, #hook_request_prefetch_check, #hook_request_required_fields_check, #json_parse, #no_error_validation

Methods included from ProfilesAndResourceTypes

#structure_definition_map, #structure_definition_map_v201, #structure_definition_map_v221

Methods included from ServerBaseURLs

#client_fhir_base_url, #fhir_url, #instance_url, #search_url

Methods included from BaseURLs

#inferno_base_url, #resume_fail_url, #resume_pass_url

Methods included from RequestsLogicalModelValidation

#validate_request_against_logical_model

Methods included from LogicalModelsOverrideHelper

#allowed_resource_type?, #check_appointment_conformance, #check_order_like_resource_conformance, #check_resource_conformance_to_coverage_profile, #check_resource_conformance_to_order_or_encounter_profile, #check_resource_conformance_to_order_profile, #check_resource_conformance_to_questionnaire_task_profile, #check_resource_type_and_validate, #local_reference?, #manually_check_appointment_validation_errors, #parse_action_resource, #primary_performer_type?, #referenced_resource_present_in_bundle?, #reject_resource_issues, #resolved_participant_patient_slice_issue?, #resolved_participant_primary_performer_slice_issue?

Instance Method Details

#collect_extensions_id(extensions, url, *properties) ⇒ Object



77
78
79
80
81
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 77

def collect_extensions_id(extensions, url, *properties)
  extensions.map do |extension|
    find_extension_value(extension, url, *properties)
  end
end

#coverage_info_system_action_check(coverage_info_system_action) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 91

def coverage_info_system_action_check(coverage_info_system_action)
  type = coverage_info_system_action['type']
  assert type, '`type` field is missing.'
  assert type == 'update', "`type` must be `update`, but was `#{type}`"

  resource = FHIR.from_contents(coverage_info_system_action['resource'].to_json)
  profile_url = structure_definition_map('v201')[resource.resourceType]
  assert_valid_resource(resource:, profile_url:)

  grouped_coverage_info = extract_and_group_coverage_info(resource)
  multiple_extensions_conformance_check(grouped_coverage_info, resource)
end

#different_coverage_conformance_error_msg(resource_ref, id_name) ⇒ Object



87
88
89
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 87

def different_coverage_conformance_error_msg(resource_ref, id_name)
  "#{resource_ref}: extensions referencing differing coverage SHALL have distinct #{id_name}."
end

#extract_and_group_coverage_info(resource) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 38

def extract_and_group_coverage_info(resource)
  resource.extension.each_with_object({}) do |extension, grouped_extensions|
    next unless extension.url == 'http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information'

    coverage_key = find_extension_value(extension, 'coverage', 'valueReference', 'reference')
    grouped_extensions[coverage_key] ||= []
    grouped_extensions[coverage_key] << extension
  end
end

#find_extension_value(extension, url, *properties) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 27

def find_extension_value(extension, url, *properties)
  found_extension = extension.extension.find { |ext| ext.url == url }
  return nil unless found_extension

  properties.reduce(found_extension) do |current, prop|
    return current unless current.respond_to?(prop)

    current.send(prop)
  end
end

#multiple_extensions_conformance_check(grouped_coverage_info, resource) ⇒ Object

For the same coverage, ensure coverage-assertion-ids and satisfied-pa-ids are the same. For different coverages, ensure coverage-assertion-ids and satisfied-pa-ids are distinct.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 50

def multiple_extensions_conformance_check(grouped_coverage_info, resource)
  resource_ref = "#{resource.resourceType}/#{resource.id}"
  assertion_ids_across_coverages = Set.new
  pa_ids_across_coverages = Set.new

  grouped_coverage_info.each do |coverage, extensions|
    coverage_assertion_ids = collect_extensions_id(extensions, 'coverage-assertion-id', 'valueString').uniq
    satisfied_pa_ids = collect_extensions_id(extensions, 'satisfied-pa-id', 'valueString').uniq.compact
    assert coverage_assertion_ids.length == 1,
           same_coverage_conformance_error_msg(resource_ref, coverage, 'coverage-assertion-ids')

    assert satisfied_pa_ids.length <= 1,
           same_coverage_conformance_error_msg(resource_ref, coverage, 'satisfied-pa-ids')

    assertion_id = coverage_assertion_ids.first
    assert !assertion_ids_across_coverages.include?(assertion_id),
           different_coverage_conformance_error_msg(resource_ref, 'coverage-assertion-ids')
    assertion_ids_across_coverages.add(assertion_id)
    pa_id = satisfied_pa_ids.first
    next unless pa_id

    assert !pa_ids_across_coverages.include?(pa_id),
           different_coverage_conformance_error_msg(resource_ref, 'satisfied-pa-ids')
    pa_ids_across_coverages.add(pa_id)
  end
end

#same_coverage_conformance_error_msg(resource_ref, coverage, id_name) ⇒ Object



83
84
85
# File 'lib/davinci_crd_test_kit/server/v2.0.1/verify_response/coverage_information_system_action_validation_test.rb', line 83

def same_coverage_conformance_error_msg(resource_ref, coverage, id_name)
  "#{resource_ref}: extension has multiple repetitions of coverage `#{coverage}` with different #{id_name}."
end