Module: DaVinciPASTestKit::MustSupportTest
- Extended by:
- Forwardable
- Includes:
- FHIRResourceNavigation
- Included in:
- DaVinciPASV201::ClientInquiryRequestBeneficiaryMustSupportTest, DaVinciPASV201::ClientInquiryRequestClaimInquiryMustSupportTest, DaVinciPASV201::ClientInquiryRequestCoverageMustSupportTest, DaVinciPASV201::ClientInquiryRequestInsurerMustSupportTest, DaVinciPASV201::ClientInquiryRequestPasInquiryRequestBundleMustSupportTest, DaVinciPASV201::ClientInquiryRequestPractitionerMustSupportTest, DaVinciPASV201::ClientInquiryRequestPractitionerRoleMustSupportTest, DaVinciPASV201::ClientInquiryRequestRequestorMustSupportTest, DaVinciPASV201::ClientInquiryRequestSubscriberMustSupportTest, DaVinciPASV201::ClientSubmitRequestBeneficiaryMustSupportTest, DaVinciPASV201::ClientSubmitRequestClaimUpdateMustSupportTest, DaVinciPASV201::ClientSubmitRequestCoverageMustSupportTest, DaVinciPASV201::ClientSubmitRequestDeviceRequestMustSupportTest, DaVinciPASV201::ClientSubmitRequestEncounterMustSupportTest, DaVinciPASV201::ClientSubmitRequestInsurerMustSupportTest, DaVinciPASV201::ClientSubmitRequestMedicationRequestMustSupportTest, DaVinciPASV201::ClientSubmitRequestNutritionOrderMustSupportTest, DaVinciPASV201::ClientSubmitRequestPasRequestBundleMustSupportTest, DaVinciPASV201::ClientSubmitRequestPractitionerMustSupportTest, DaVinciPASV201::ClientSubmitRequestPractitionerRoleMustSupportTest, DaVinciPASV201::ClientSubmitRequestRequestorMustSupportTest, DaVinciPASV201::ClientSubmitRequestServiceRequestMustSupportTest, DaVinciPASV201::ClientSubmitRequestSubscriberMustSupportTest, DaVinciPASV201::PasClientMustSupportRequirementTest, DaVinciPASV201::PasServerMustSupportRequirementTest, DaVinciPASV201::ServerInquiryRequestBeneficiaryMustSupportTest, DaVinciPASV201::ServerInquiryRequestClaimInquiryMustSupportTest, DaVinciPASV201::ServerInquiryRequestCoverageMustSupportTest, DaVinciPASV201::ServerInquiryRequestInsurerMustSupportTest, DaVinciPASV201::ServerInquiryRequestPasInquiryRequestBundleMustSupportTest, DaVinciPASV201::ServerInquiryRequestPractitionerMustSupportTest, DaVinciPASV201::ServerInquiryRequestPractitionerRoleMustSupportTest, DaVinciPASV201::ServerInquiryRequestRequestorMustSupportTest, DaVinciPASV201::ServerInquiryRequestSubscriberMustSupportTest, DaVinciPASV201::ServerInquiryResponseBeneficiaryMustSupportTest, DaVinciPASV201::ServerInquiryResponseClaiminquiryresponseMustSupportTest, DaVinciPASV201::ServerInquiryResponseInsurerMustSupportTest, DaVinciPASV201::ServerInquiryResponsePasInquiryResponseBundleMustSupportTest, DaVinciPASV201::ServerInquiryResponsePractitionerMustSupportTest, DaVinciPASV201::ServerInquiryResponsePractitionerRoleMustSupportTest, DaVinciPASV201::ServerInquiryResponseRequestorMustSupportTest, DaVinciPASV201::ServerInquiryResponseTaskMustSupportTest, DaVinciPASV201::ServerSubmitRequestBeneficiaryMustSupportTest, DaVinciPASV201::ServerSubmitRequestClaimUpdateMustSupportTest, DaVinciPASV201::ServerSubmitRequestCoverageMustSupportTest, DaVinciPASV201::ServerSubmitRequestDeviceRequestMustSupportTest, DaVinciPASV201::ServerSubmitRequestEncounterMustSupportTest, DaVinciPASV201::ServerSubmitRequestInsurerMustSupportTest, DaVinciPASV201::ServerSubmitRequestMedicationRequestMustSupportTest, DaVinciPASV201::ServerSubmitRequestNutritionOrderMustSupportTest, DaVinciPASV201::ServerSubmitRequestPasRequestBundleMustSupportTest, DaVinciPASV201::ServerSubmitRequestPractitionerMustSupportTest, DaVinciPASV201::ServerSubmitRequestPractitionerRoleMustSupportTest, DaVinciPASV201::ServerSubmitRequestRequestorMustSupportTest, DaVinciPASV201::ServerSubmitRequestServiceRequestMustSupportTest, DaVinciPASV201::ServerSubmitRequestSubscriberMustSupportTest, DaVinciPASV201::ServerSubmitResponseBeneficiaryMustSupportTest, DaVinciPASV201::ServerSubmitResponseClaimresponseMustSupportTest, DaVinciPASV201::ServerSubmitResponseCommunicationRequestMustSupportTest, DaVinciPASV201::ServerSubmitResponseInsurerMustSupportTest, DaVinciPASV201::ServerSubmitResponsePasResponseBundleMustSupportTest, DaVinciPASV201::ServerSubmitResponsePractitionerMustSupportTest, DaVinciPASV201::ServerSubmitResponsePractitionerRoleMustSupportTest, DaVinciPASV201::ServerSubmitResponseRequestorMustSupportTest, DaVinciPASV201::ServerSubmitResponseTaskMustSupportTest
- Defined in:
- lib/davinci_pas_test_kit/must_support_test.rb
Constant Summary
Constants included from FHIRResourceNavigation
FHIRResourceNavigation::DAR_EXTENSION_URL
Instance Method Summary collapse
- #all_must_support_errors ⇒ Object
- #all_scratch_resources ⇒ Object
- #exclude_uscdi_only_test? ⇒ Boolean
- #find_slice(resource, path, discriminator) ⇒ Object
- #find_slice_by_values(element, value_definitions) ⇒ Object
- #handle_must_support_choices ⇒ Object
- #is_any_choice_supported?(choices) ⇒ Boolean
- #missing_element_string(element_definition) ⇒ Object
- #missing_elements(resources = []) ⇒ Object
- #missing_extensions(resources = []) ⇒ Object
- #missing_must_support_strings ⇒ Object
- #missing_slices(resources = []) ⇒ Object
- #must_support_elements ⇒ Object
- #must_support_extensions ⇒ Object
- #must_support_slices ⇒ Object
- #perform_must_support_test(resources) ⇒ Object
- #reset_variables ⇒ Object
- #tagged_resources(tag) ⇒ Object
- #validate_must_support(user_input_validation) ⇒ Object
Methods included from FHIRResourceNavigation
#find_a_value_at, #get_next_value, #resolve_path
Instance Method Details
#all_must_support_errors ⇒ Object
40 41 42 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 40 def all_must_support_errors @all_must_support_errors ||= [] end |
#all_scratch_resources ⇒ Object
10 11 12 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 10 def all_scratch_resources scratch_resources[:all] ||= [] end |
#exclude_uscdi_only_test? ⇒ Boolean
119 120 121 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 119 def exclude_uscdi_only_test? config.[:exclude_uscdi_only_test] == true end |
#find_slice(resource, path, discriminator) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 197 def find_slice(resource, path, discriminator) find_a_value_at(resource, path) do |element| case discriminator[:type] when 'patternCodeableConcept' coding_path = discriminator[:path].present? ? "#{discriminator[:path]}.coding" : 'coding' find_a_value_at(element, coding_path) do |coding| coding.code == discriminator[:code] && coding.system == discriminator[:system] end when 'patternCoding' coding_path = discriminator[:path].present? ? discriminator[:path] : '' find_a_value_at(element, coding_path) do |coding| coding.code == discriminator[:code] && coding.system == discriminator[:system] end when 'patternIdentifier' find_a_value_at(element, discriminator[:path]) { |identifier| identifier.system == discriminator[:system] } when 'value' values = discriminator[:values].map { |value| value.merge(path: value[:path].split('.')) } find_slice_by_values(element, values) when 'type' case discriminator[:code] when 'Date' begin Date.parse(element) rescue ArgumentError false end when 'DateTime' begin DateTime.parse(element) rescue ArgumentError false end when 'String' element.is_a? String else res = element.try(:resource) || element res.is_a? FHIR.const_get(discriminator[:code]) end when 'requiredBinding' coding_path = discriminator[:path].present? ? "#{discriminator[:path]}.coding" : 'coding' find_a_value_at(element, coding_path) { |coding| discriminator[:values].include?(coding.code) } end end end |
#find_slice_by_values(element, value_definitions) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 242 def find_slice_by_values(element, value_definitions) path_prefixes = value_definitions.map { |value_definition| value_definition[:path].first }.uniq Array.wrap(element).find do |el| path_prefixes.all? do |path_prefix| value_definitions_for_path = value_definitions .select { |value_definition| value_definition[:path].first == path_prefix } .each { |value_definition| value_definition[:path].shift } find_a_value_at(el, path_prefix) do |el_found| child_element_value_definitions, current_element_value_definitions = value_definitions_for_path.partition { |value_definition| value_definition[:path].present? } current_element_values_match = current_element_value_definitions.all? do |value_definition| (value_definition[:value].present? && value_definition[:value] == el_found) || (value_definition[:value].blank? && el_found.present?) end child_element_values_match = if child_element_value_definitions.present? find_slice_by_values(el_found, child_element_value_definitions) else true end current_element_values_match && child_element_values_match end end end end |
#handle_must_support_choices ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 75 def handle_must_support_choices missing_elements.delete_if do |element| choices = .must_supports[:choices].find { |choice| choice[:paths]&.include?(element[:path]) } is_any_choice_supported?(choices) end missing_extensions.delete_if do |extension| choices = .must_supports[:choices].find { |choice| choice[:extension_ids]&.include?(extension[:id]) } is_any_choice_supported?(choices) end missing_slices.delete_if do |slice| choices = .must_supports[:choices].find { |choice| choice[:slice_names]&.include?(slice[:slice_id]) } is_any_choice_supported?(choices) end end |
#is_any_choice_supported?(choices) ⇒ Boolean
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 92 def is_any_choice_supported?(choices) choices.present? && ( choices[:paths]&.any? { |path| missing_elements.none? { |element| element[:path] == path } } || choices[:extension_ids]&.any? do |extension_id| missing_extensions.none? do |extension| extension[:id] == extension_id end end || choices[:slice_names]&.any? { |slice_name| missing_slices.none? { |slice| slice[:slice_id] == slice_name } } ) end |
#missing_element_string(element_definition) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 111 def missing_element_string(element_definition) if element_definition[:fixed_value].present? "#{element_definition[:path]}:#{element_definition[:fixed_value]}" else element_definition[:path] end end |
#missing_elements(resources = []) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 157 def missing_elements(resources = []) @missing_elements ||= must_support_elements.select do |element_definition| # PAS: The MS Claim.supportingInfo slices do not have timing[x] next if resource_type == 'Claim' && element_definition[:path] == 'supportingInfo.timing[x]' resources.none? do |resource| path = element_definition[:path] # .delete_suffix('[x]') value_found = find_a_value_at(resource, path) do |value| value_without_extensions = value.respond_to?(:to_hash) ? value.to_hash.except('extension') : value (value_without_extensions.present? || value_without_extensions == false) && (element_definition[:fixed_value].blank? || value == element_definition[:fixed_value]) end # Note that false.present? => false, which is why we need to add this extra check value_found.present? || value_found == false end end @missing_elements.compact end |
#missing_extensions(resources = []) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 131 def missing_extensions(resources = []) @missing_extensions ||= must_support_extensions.select do |extension_definition| resources.none? do |resource| path = extension_definition[:path] if extension_definition[:path] == 'extension' resource.extension.any? { |extension| extension.url == extension_definition[:url] } else extension = find_a_value_at(resource, path) do |el| el.url == extension_definition[:url] end extension&.url == extension_definition[:url] end end end end |
#missing_must_support_strings ⇒ Object
105 106 107 108 109 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 105 def missing_must_support_strings missing_elements.map { |element_definition| missing_element_string(element_definition) } + missing_slices.map { |slice_definition| slice_definition[:name] } + missing_extensions.map { |extension_definition| extension_definition[:id] } end |
#missing_slices(resources = []) ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 187 def missing_slices(resources = []) @missing_slices ||= must_support_slices.select do |slice| resources.none? do |resource| path = slice[:path] # .delete_suffix('[x]') find_slice(resource, path, slice[:discriminator]).present? end end end |
#must_support_elements ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 149 def must_support_elements if exclude_uscdi_only_test? .must_supports[:elements].reject { |element| element[:uscdi_only] } else .must_supports[:elements] end end |
#must_support_extensions ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 123 def must_support_extensions if exclude_uscdi_only_test? .must_supports[:extensions].reject { |extension| extension[:uscdi_only] } else .must_supports[:extensions] end end |
#must_support_slices ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 179 def must_support_slices if exclude_uscdi_only_test? .must_supports[:slices].reject { |slice| slice[:uscdi_only] } else .must_supports[:slices] end end |
#perform_must_support_test(resources) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 52 def perform_must_support_test(resources) assert resources.present?, "No #{resource_type} resources were found" missing_elements(resources) missing_slices(resources) missing_extensions(resources) handle_must_support_choices if .must_supports[:choices].present? return unless (missing_elements + missing_slices + missing_extensions).compact.reject(&:empty?).present? all_must_support_errors << "Could not find #{missing_must_support_strings.join(', ')} " \ "in the #{resources.length} provided #{resource_type} resource(s)." all_must_support_errors.reject! { |err| err.downcase.include?('x12') } reset_variables # pass if (missing_elements + missing_slices + missing_extensions).empty? # assert false, "Could not find #{missing_must_support_strings.join(', ')} in the #{resources.length} " \ # "provided #{resource_type} resource(s)" end |
#reset_variables ⇒ Object
14 15 16 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 14 def reset_variables @missing_elements = @missing_slices = @missing_extensions = nil end |
#tagged_resources(tag) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 18 def tagged_resources(tag) resources = [] load_tagged_requests(tag) return resources if requests.empty? requests.each do |req| begin bundle = FHIR.from_contents(req.request_body) rescue StandardError next end next unless bundle.is_a?(FHIR::Bundle) resources << bundle entry_resources = bundle.entry.map(&:resource) resources.concat(entry_resources) end resources end |
#validate_must_support(user_input_validation) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/davinci_pas_test_kit/must_support_test.rb', line 44 def validate_must_support(user_input_validation) if user_input_validation skip_if !all_must_support_errors.empty?, all_must_support_errors.join("\n") else assert all_must_support_errors.empty?, all_must_support_errors.join("\n") end end |