Class: DaVinciCRDTestKit::V221::ClientLocationAddressPropagationTest
- Inherits:
-
Inferno::Test
- Object
- Inferno::Test
- DaVinciCRDTestKit::V221::ClientLocationAddressPropagationTest
show all
- Includes:
- TaggedRequestLoadHelper
- Defined in:
- lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb
Constant Summary
TaggedRequestLoadHelper::ALL_HOOKS
Instance Method Summary
collapse
#crd_test_group, #hook_name, #load_hook_requests, #requests_to_analyze, #tags_to_load
Instance Method Details
#add_location_to_hash(location, location_hash) ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 125
def add_location_to_hash(location, location_hash)
return unless location.is_a?(FHIR::Location) && location.id.present?
relative_reference = "#{location.resourceType}/#{location.id}"
return if location_hash.key?(relative_reference)
location_hash[relative_reference] = location
end
|
#build_fetched_locations_hash ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 117
def build_fetched_locations_hash
load_tagged_requests(PARENT_LOCATION_FETCH_TAG, DATA_FETCH_TAG).each_with_object({}) do |request, location_hash|
add_location_to_hash(FHIR.from_contents(request.response_body), location_hash)
rescue JSON::ParserError
next
end
end
|
#build_prefetched_locations_hash ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 88
def build_prefetched_locations_hash
loaded_requests.each_with_object({}) do |request, location_hash|
request_body = JSON.parse(request.request_body)
next unless request_body.is_a?(Hash)
prefetched_location_bundle = (request_body)
next unless prefetched_location_bundle.present?
prefetched_location_bundle.entry.each do |entry|
add_location_to_hash(entry.resource, location_hash)
end
rescue JSON::ParserError
next
end
end
|
#check_location_address_propagation(location, root_id = location.id) ⇒ Object
checks that the location has an address if a parent also has an address
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 39
def check_location_address_propagation(location, root_id = location.id)
return if location.address.present?
return unless location.partOf.present? && location.partOf.reference.present?
parent = prefetched_location_hash[location.partOf.reference]
parent = fetched_location_hash[location.partOf.reference] unless parent.present?
if parent.present?
check_location_conformance(parent, root_id)
if parent.address.present?
add_message('error', "Address missing on prefetched 'Location/#{root_id}': " \
"parent 'Location/#{parent.id}' has an address.")
else
check_location_address_propagation(parent, root_id)
end
else
add_message('error', "Unable to check address propagation prefetched 'Location/#{root_id}': " \
"`partOf` reference '#{location.partOf.reference}' could not be fetched.")
end
nil
end
|
skip profile check if in the prefetch hash (done elsewhere) or already checked
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 62
def check_location_conformance(location, root_id)
key = "Location/#{location.id}"
return if prefetched_location_hash.key?(key) || fetched_locations_checked_for_conformance.key?(key)
fetched_locations_checked_for_conformance[key] = location
validator_response_details = []
return if resource_is_valid?(resource: location, profile_url: 'http://hl7.org/fhir/us/davinci-crd/StructureDefinition/profile-location|2.2.1',
add_messages_to_runnable: false, validator_response_details:)
message_prefix = "Parent of prefetched 'Location/#{root_id}'"
add_message('error', "Location/#{location.id}: #{message_prefix} does not conform to the CRD Location profile.")
validator_response_details.each { |issue| add_message(issue.severity, "(#{message_prefix}) #{issue.message}") }
end
|
104
105
106
107
108
109
110
111
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 104
def (request_body)
locations_data = request_body.dig('prefetch', 'locations') || request_body.dig('prefetch', 'locs')
locations = FHIR.from_contents(locations_data.to_json) if locations_data.present?
return locations if locations.is_a?(FHIR::Bundle)
return nil unless locations.is_a?(FHIR::Location)
FHIR::Bundle.new({ entry: [FHIR::Bundle::Entry.new({ resource: locations })] })
end
|
#fetched_location_hash ⇒ Object
113
114
115
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 113
def fetched_location_hash
@fetched_location_hash ||= build_fetched_locations_hash
end
|
76
77
78
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 76
def fetched_locations_checked_for_conformance
@fetched_locations_checked_for_conformance ||= {}
end
|
#loaded_requests ⇒ Object
80
81
82
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 80
def loaded_requests
@loaded_requests ||= requests_to_analyze
end
|
#prefetched_location_hash ⇒ Object
84
85
86
|
# File 'lib/davinci_crd_test_kit/client/v2.2.1/cross_hook/client_location_address_propagation_test.rb', line 84
def prefetched_location_hash
@prefetched_location_hash ||= build_prefetched_locations_hash
end
|