Module: USQualityCoreTestKit::SearchTest
- Extended by:
- Forwardable
- Includes:
- Inferno::DSL::FHIRResourceNavigation, DateSearchValidation, ResourceSearchParamChecker, WellKnownCodeSystems
- Included in:
- USQualityCoreV050::AdverseEventProvenanceRevincludeSearchTest, USQualityCoreV050::AdverseEventSubjectEventSearchTest, USQualityCoreV050::AdverseEventSubjectRecordedDateSearchTest, USQualityCoreV050::AdverseEventSubjectSearchTest, USQualityCoreV050::AllergyIntolerancePatientSearchTest, USQualityCoreV050::AllergyIntoleranceProvenanceRevincludeSearchTest, USQualityCoreV050::CarePlanPatientCategorySearchTest, USQualityCoreV050::CarePlanProvenanceRevincludeSearchTest, USQualityCoreV050::CareTeamPatientStatusSearchTest, USQualityCoreV050::CareTeamProvenanceRevincludeSearchTest, USQualityCoreV050::ConditionEncounterDiagnosisPatientCategorySearchTest, USQualityCoreV050::ConditionEncounterDiagnosisPatientCodeSearchTest, USQualityCoreV050::ConditionEncounterDiagnosisPatientSearchTest, USQualityCoreV050::ConditionEncounterDiagnosisProvenanceRevincludeSearchTest, USQualityCoreV050::ConditionProblemsHealthConcernsPatientCategorySearchTest, USQualityCoreV050::ConditionProblemsHealthConcernsPatientCodeSearchTest, USQualityCoreV050::ConditionProblemsHealthConcernsPatientSearchTest, USQualityCoreV050::ConditionProblemsHealthConcernsProvenanceRevincludeSearchTest, USQualityCoreV050::CoveragePatientSearchTest, USQualityCoreV050::CoverageProvenanceRevincludeSearchTest, USQualityCoreV050::DevicenotrequestedPatientCodeSearchTest, USQualityCoreV050::DevicenotrequestedPatientDoNotPerformSearchTest, USQualityCoreV050::DevicenotrequestedPatientSearchTest, USQualityCoreV050::DevicenotrequestedProvenanceRevincludeSearchTest, USQualityCoreV050::DevicerequestPatientCodeSearchTest, USQualityCoreV050::DevicerequestPatientDoNotPerformSearchTest, USQualityCoreV050::DevicerequestPatientSearchTest, USQualityCoreV050::DevicerequestProvenanceRevincludeSearchTest, USQualityCoreV050::DiagnosticReportLabPatientCategoryDateSearchTest, USQualityCoreV050::DiagnosticReportLabPatientCategorySearchTest, USQualityCoreV050::DiagnosticReportLabPatientCodeSearchTest, USQualityCoreV050::DiagnosticReportLabPatientSearchTest, USQualityCoreV050::DiagnosticReportLabProvenanceRevincludeSearchTest, USQualityCoreV050::DiagnosticReportNotePatientCategoryDateSearchTest, USQualityCoreV050::DiagnosticReportNotePatientCategorySearchTest, USQualityCoreV050::DiagnosticReportNotePatientCodeSearchTest, USQualityCoreV050::DiagnosticReportNotePatientSearchTest, USQualityCoreV050::DiagnosticReportNoteProvenanceRevincludeSearchTest, USQualityCoreV050::DocumentReferenceIdSearchTest, USQualityCoreV050::DocumentReferencePatientCategoryDateSearchTest, USQualityCoreV050::DocumentReferencePatientCategorySearchTest, USQualityCoreV050::DocumentReferencePatientSearchTest, USQualityCoreV050::DocumentReferencePatientTypeSearchTest, USQualityCoreV050::DocumentReferenceProvenanceRevincludeSearchTest, USQualityCoreV050::EncounterIdSearchTest, USQualityCoreV050::EncounterPatientDateSearchTest, USQualityCoreV050::EncounterPatientSearchTest, USQualityCoreV050::EncounterPatientTypeSearchTest, USQualityCoreV050::EncounterProvenanceRevincludeSearchTest, USQualityCoreV050::FamilyMemberHistoryPatientSearchTest, USQualityCoreV050::FamilyMemberHistoryProvenanceRevincludeSearchTest, USQualityCoreV050::GoalPatientSearchTest, USQualityCoreV050::GoalProvenanceRevincludeSearchTest, USQualityCoreV050::HeadOccipitalFrontalCircumferencePercentilePatientCategoryDateSearchTest, USQualityCoreV050::HeadOccipitalFrontalCircumferencePercentilePatientCategorySearchTest, USQualityCoreV050::HeadOccipitalFrontalCircumferencePercentilePatientCategoryStatusSearchTest, USQualityCoreV050::HeadOccipitalFrontalCircumferencePercentilePatientCodeSearchTest, USQualityCoreV050::HeadOccipitalFrontalCircumferencePercentileProvenanceRevincludeSearchTest, USQualityCoreV050::ImmunizationPatientSearchTest, USQualityCoreV050::ImmunizationPatientStatusSearchTest, USQualityCoreV050::ImmunizationProvenanceRevincludeSearchTest, USQualityCoreV050::ImmunizationnotdonePatientSearchTest, USQualityCoreV050::ImmunizationnotdonePatientStatusSearchTest, USQualityCoreV050::ImmunizationnotdoneProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationadministrationPatientCodeSearchTest, USQualityCoreV050::MedicationadministrationPatientEffectiveTimeSearchTest, USQualityCoreV050::MedicationadministrationPatientSearchTest, USQualityCoreV050::MedicationadministrationPatientStatusSearchTest, USQualityCoreV050::MedicationadministrationProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationadministrationnotdonePatientCodeSearchTest, USQualityCoreV050::MedicationadministrationnotdonePatientEffectiveTimeSearchTest, USQualityCoreV050::MedicationadministrationnotdonePatientSearchTest, USQualityCoreV050::MedicationadministrationnotdonePatientStatusSearchTest, USQualityCoreV050::MedicationadministrationnotdoneProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationdispensePatientSearchTest, USQualityCoreV050::MedicationdispensePatientStatusSearchTest, USQualityCoreV050::MedicationdispenseProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationdispensedeclinedPatientSearchTest, USQualityCoreV050::MedicationdispensedeclinedPatientStatusSearchTest, USQualityCoreV050::MedicationdispensedeclinedProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationnotrequestedPatientIntentDoNotPerformSearchTest, USQualityCoreV050::MedicationnotrequestedPatientIntentSearchTest, USQualityCoreV050::MedicationnotrequestedProvenanceRevincludeSearchTest, USQualityCoreV050::MedicationrequestPatientIntentDoNotPerformSearchTest, USQualityCoreV050::MedicationrequestPatientIntentSearchTest, USQualityCoreV050::MedicationrequestProvenanceRevincludeSearchTest, USQualityCoreV050::ObservationClinicalResultPatientCategoryDateSearchTest, USQualityCoreV050::ObservationClinicalResultPatientCategorySearchTest, USQualityCoreV050::ObservationClinicalResultPatientCategoryStatusSearchTest, USQualityCoreV050::ObservationClinicalResultPatientCodeSearchTest, USQualityCoreV050::ObservationClinicalResultProvenanceRevincludeSearchTest, USQualityCoreV050::ObservationLabPatientCategoryDateSearchTest, USQualityCoreV050::ObservationLabPatientCategorySearchTest, USQualityCoreV050::ObservationLabPatientCategoryStatusSearchTest, USQualityCoreV050::ObservationLabPatientCodeSearchTest, USQualityCoreV050::ObservationLabProvenanceRevincludeSearchTest, USQualityCoreV050::ObservationScreeningAssessmentPatientCategoryDateSearchTest, USQualityCoreV050::ObservationScreeningAssessmentPatientCategorySearchTest, USQualityCoreV050::ObservationScreeningAssessmentPatientCategoryStatusSearchTest, USQualityCoreV050::ObservationScreeningAssessmentPatientCodeSearchTest, USQualityCoreV050::ObservationScreeningAssessmentProvenanceRevincludeSearchTest, USQualityCoreV050::ObservationcancelledPatientCategoryDateSearchTest, USQualityCoreV050::ObservationcancelledPatientCategorySearchTest, USQualityCoreV050::ObservationcancelledPatientCategoryStatusSearchTest, USQualityCoreV050::ObservationcancelledPatientCodeSearchTest, USQualityCoreV050::ObservationcancelledProvenanceRevincludeSearchTest, USQualityCoreV050::PatientIdSearchTest, USQualityCoreV050::PatientProvenanceRevincludeSearchTest, USQualityCoreV050::PediatricBmiForAgePatientCategoryDateSearchTest, USQualityCoreV050::PediatricBmiForAgePatientCategorySearchTest, USQualityCoreV050::PediatricBmiForAgePatientCategoryStatusSearchTest, USQualityCoreV050::PediatricBmiForAgePatientCodeSearchTest, USQualityCoreV050::PediatricBmiForAgeProvenanceRevincludeSearchTest, USQualityCoreV050::PediatricWeightForHeightPatientCategoryDateSearchTest, USQualityCoreV050::PediatricWeightForHeightPatientCategorySearchTest, USQualityCoreV050::PediatricWeightForHeightPatientCategoryStatusSearchTest, USQualityCoreV050::PediatricWeightForHeightPatientCodeSearchTest, USQualityCoreV050::PediatricWeightForHeightProvenanceRevincludeSearchTest, USQualityCoreV050::ProcedurePatientDateSearchTest, USQualityCoreV050::ProcedurePatientSearchTest, USQualityCoreV050::ProcedurePatientStatusSearchTest, USQualityCoreV050::ProcedureProvenanceRevincludeSearchTest, USQualityCoreV050::ProcedurenotdonePatientDateSearchTest, USQualityCoreV050::ProcedurenotdonePatientSearchTest, USQualityCoreV050::ProcedurenotdonePatientStatusSearchTest, USQualityCoreV050::ProcedurenotdoneProvenanceRevincludeSearchTest, USQualityCoreV050::RelatedPersonIdSearchTest, USQualityCoreV050::RelatedPersonPatientSearchTest, USQualityCoreV050::RelatedPersonProvenanceRevincludeSearchTest, USQualityCoreV050::ServicenotrequestedIdSearchTest, USQualityCoreV050::ServicenotrequestedPatientCategoryAuthoredSearchTest, USQualityCoreV050::ServicenotrequestedPatientCategorySearchTest, USQualityCoreV050::ServicenotrequestedPatientCodeSearchTest, USQualityCoreV050::ServicenotrequestedPatientDoNotPerformSearchTest, USQualityCoreV050::ServicenotrequestedPatientSearchTest, USQualityCoreV050::ServicenotrequestedProvenanceRevincludeSearchTest, USQualityCoreV050::ServicerequestIdSearchTest, USQualityCoreV050::ServicerequestPatientCategoryAuthoredSearchTest, USQualityCoreV050::ServicerequestPatientCategorySearchTest, USQualityCoreV050::ServicerequestPatientCodeSearchTest, USQualityCoreV050::ServicerequestPatientDoNotPerformSearchTest, USQualityCoreV050::ServicerequestPatientSearchTest, USQualityCoreV050::ServicerequestProvenanceRevincludeSearchTest, USQualityCoreV050::SimpleObservationPatientCategoryDateSearchTest, USQualityCoreV050::SimpleObservationPatientCategorySearchTest, USQualityCoreV050::SimpleObservationPatientCategoryStatusSearchTest, USQualityCoreV050::SimpleObservationPatientCodeSearchTest, USQualityCoreV050::SimpleObservationProvenanceRevincludeSearchTest, USQualityCoreV050::SpecimenIdSearchTest, USQualityCoreV050::TaskPatientCodeSearchTest, USQualityCoreV050::TaskPatientSearchTest, USQualityCoreV050::TaskPatientStatusSearchTest, USQualityCoreV050::TaskProvenanceRevincludeSearchTest, USQualityCoreV050::TaskrejectedPatientCodeSearchTest, USQualityCoreV050::TaskrejectedPatientSearchTest, USQualityCoreV050::TaskrejectedPatientStatusSearchTest, USQualityCoreV050::TaskrejectedProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreBloodPressurePatientCategoryDateSearchTest, USQualityCoreV050::UsCoreBloodPressurePatientCategorySearchTest, USQualityCoreV050::UsCoreBloodPressurePatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreBloodPressurePatientCodeSearchTest, USQualityCoreV050::UsCoreBloodPressureProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreBmiPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreBmiPatientCategorySearchTest, USQualityCoreV050::UsCoreBmiPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreBmiPatientCodeSearchTest, USQualityCoreV050::UsCoreBmiProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreBodyHeightPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreBodyHeightPatientCategorySearchTest, USQualityCoreV050::UsCoreBodyHeightPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreBodyHeightPatientCodeSearchTest, USQualityCoreV050::UsCoreBodyHeightProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreBodyTemperaturePatientCategoryDateSearchTest, USQualityCoreV050::UsCoreBodyTemperaturePatientCategorySearchTest, USQualityCoreV050::UsCoreBodyTemperaturePatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreBodyTemperaturePatientCodeSearchTest, USQualityCoreV050::UsCoreBodyTemperatureProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreBodyWeightPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreBodyWeightPatientCategorySearchTest, USQualityCoreV050::UsCoreBodyWeightPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreBodyWeightPatientCodeSearchTest, USQualityCoreV050::UsCoreBodyWeightProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreHeartRatePatientCategoryDateSearchTest, USQualityCoreV050::UsCoreHeartRatePatientCategorySearchTest, USQualityCoreV050::UsCoreHeartRatePatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreHeartRatePatientCodeSearchTest, USQualityCoreV050::UsCoreHeartRateProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreObservationOccupationPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreObservationOccupationPatientCategorySearchTest, USQualityCoreV050::UsCoreObservationOccupationPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreObservationOccupationPatientCodeSearchTest, USQualityCoreV050::UsCoreObservationOccupationProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreObservationPregnancyintentPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreObservationPregnancyintentPatientCategorySearchTest, USQualityCoreV050::UsCoreObservationPregnancyintentPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreObservationPregnancyintentPatientCodeSearchTest, USQualityCoreV050::UsCoreObservationPregnancyintentProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreObservationPregnancystatusPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreObservationPregnancystatusPatientCategorySearchTest, USQualityCoreV050::UsCoreObservationPregnancystatusPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreObservationPregnancystatusPatientCodeSearchTest, USQualityCoreV050::UsCoreObservationPregnancystatusProvenanceRevincludeSearchTest, USQualityCoreV050::UsCorePulseOximetryPatientCategoryDateSearchTest, USQualityCoreV050::UsCorePulseOximetryPatientCategorySearchTest, USQualityCoreV050::UsCorePulseOximetryPatientCategoryStatusSearchTest, USQualityCoreV050::UsCorePulseOximetryPatientCodeSearchTest, USQualityCoreV050::UsCorePulseOximetryProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreRespiratoryRatePatientCategoryDateSearchTest, USQualityCoreV050::UsCoreRespiratoryRatePatientCategorySearchTest, USQualityCoreV050::UsCoreRespiratoryRatePatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreRespiratoryRatePatientCodeSearchTest, USQualityCoreV050::UsCoreRespiratoryRateProvenanceRevincludeSearchTest, USQualityCoreV050::UsCoreSmokingstatusPatientCategoryDateSearchTest, USQualityCoreV050::UsCoreSmokingstatusPatientCategorySearchTest, USQualityCoreV050::UsCoreSmokingstatusPatientCategoryStatusSearchTest, USQualityCoreV050::UsCoreSmokingstatusPatientCodeSearchTest, USQualityCoreV050::UsCoreSmokingstatusProvenanceRevincludeSearchTest
- Defined in:
- lib/us_quality_core_test_kit/search_test.rb
Constant Summary collapse
- EXTENSION_VALUE_PATH_REGEX =
/ \A (?<extension_type>modifierExtension|extension) \.where\(url='(?<url>[^']+)'\) \.(?<value_path>value(?:[A-Z]\w*|\[x\])?) \z /x
Constants included from WellKnownCodeSystems
WellKnownCodeSystems::HL7_CODE_SYSTEMS, WellKnownCodeSystems::WELL_KNOWN_CODE_SYSTEMS
Instance Method Summary collapse
- #all_comparator_searches_tested? ⇒ Boolean
- #all_provenance_revinclude_search_params ⇒ Object
- #all_scratch_resources ⇒ Object
- #all_search_params ⇒ Object
- #all_search_params_present?(params) ⇒ Boolean
- #all_search_variants_tested? ⇒ Boolean
- #any_valid_search_params?(search_params) ⇒ Boolean
- #array_of_codes(array) ⇒ Object
-
#check_resource_against_params(resource, params) ⇒ Object
RESULT CHECKING ####.
- #check_search_response ⇒ Object
- #date_comparator_value(comparator, date) ⇒ Object
- #default_search_values(param_name) ⇒ Object
- #element_has_valid_value?(element, include_system) ⇒ Boolean
- #empty_search_params_message(empty_search_params) ⇒ Object
- #excluded_code?(coding, codes_to_exclude) ⇒ Boolean
- #fetch_and_assert_all_bundled_resources(resource_type: self.resource_type, reply_handler: nil, max_pages: 20, additional_resource_types: [], params: nil) ⇒ Object
- #filter_adi_document_reference(resources) ⇒ Object
- #fixed_value_search_param_name ⇒ Object
- #fixed_value_search_param_names ⇒ Object
- #fixed_value_search_param_values ⇒ Object
- #fixed_value_search_params(value, patient_id) ⇒ Object
- #get_next_value(element, property) ⇒ Object
- #initial_search_variant_test_records ⇒ Object
- #no_resources_skip_message(resource_type = self.resource_type) ⇒ Object
- #patient_id_list ⇒ Object
- #patient_id_param?(name) ⇒ Boolean
- #patient_search? ⇒ Boolean
- #perform_comparator_searches(params, patient_id) ⇒ Object
- #perform_multiple_or_search_test ⇒ Object
- #perform_post_search(get_search_resources, params) ⇒ Object
- #perform_reference_with_type_search(params, resource_count) ⇒ Object
- #perform_search(params, patient_id) ⇒ Object
- #perform_search_with_status(original_params, _patient_id, status_search_values: self.status_search_values, resource_type: self.resource_type) ⇒ Object
- #perform_search_with_system(params, patient_id) ⇒ Object
- #prefer_well_known_code_system(element, include_system) ⇒ Object
- #reference_match?(reference, local_reference) ⇒ Boolean
- #references_to_save(resource_type = nil) ⇒ Object
- #required_comparators(name) ⇒ Object
- #resolve_reference_value(element) ⇒ Object
- #resolve_search_param_path(resource, path) ⇒ Object
- #resolved_reference_cache ⇒ Object
- #resource_matches_param?(resource, search_param_name, escaped_search_value, values_found = []) ⇒ Boolean
- #resource_type_and_id_from_reference(reference) ⇒ Object
- #run_provenance_revinclude_search_test ⇒ Object
- #run_search_test ⇒ Object
- #save_delayed_references(resources, containing_resource_type = resource_type) ⇒ Object
- #save_resource_reference(resource_type, reference, referencing_resource) ⇒ Object
- #scratch_resources_for_patient(patient_id) ⇒ Object
- #search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
- #search_param_paths(name) ⇒ Object
- #search_param_value(name, resource, include_system: false) ⇒ Object
- #search_params_tag(params) ⇒ Object
- #search_params_with_values(search_param_names, patient_id, include_system: false) ⇒ Object
- #search_variant_test_records ⇒ Object
- #split_escaped_search_values(search_value) ⇒ Object
- #status_search_param_name ⇒ Object
- #status_search_values ⇒ Object
- #tags(params) ⇒ Object
- #test_medication_inclusion(base_resources, params, patient_id) ⇒ Object
- #token_matches?(token, system, code) ⇒ Boolean
- #token_search_system_and_code(search_value) ⇒ Object
- #token_value_matches?(values_found, search_value) ⇒ Boolean
- #token_values_from_element(value) ⇒ Object
- #unable_to_resolve_params_message ⇒ Object
- #unescape_search_value(value) ⇒ Object
Methods included from WellKnownCodeSystems
Methods included from DateSearchValidation
#date?, #fhir_date_comparer, #get_fhir_datetime_range, #get_fhir_period_range, #validate_date_search, #validate_datetime_search, #validate_period_search
Instance Method Details
#all_comparator_searches_tested? ⇒ Boolean
213 214 215 216 217 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 213 def all_comparator_searches_tested? return true if params_with_comparators.blank? Set.new(params_with_comparators) == search_variant_test_records[:comparator_searches] end |
#all_provenance_revinclude_search_params ⇒ Object
50 51 52 53 54 55 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 50 def all_provenance_revinclude_search_params @all_provenance_revinclude_search_params ||= all_search_params.transform_values! do |params_list| params_list.map { |params| params.merge(_revinclude: 'Provenance:target') } end end |
#all_scratch_resources ⇒ Object
448 449 450 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 448 def all_scratch_resources scratch_resources[:all] ||= [] end |
#all_search_params ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 32 def all_search_params @all_search_params ||= patient_id_list.each_with_object({}) do |patient_id, params| params[patient_id] ||= [] new_params = if fixed_value_search? fixed_value_search_param_values.map { |value| fixed_value_search_params(value, patient_id) } else [search_params_with_values(search_param_names, patient_id)] end new_params.reject! do |a_params| a_params.any? { |_key, value| value.blank? } end params[patient_id].concat(new_params) end end |
#all_search_params_present?(params) ⇒ Boolean
533 534 535 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 533 def all_search_params_present?(params) params.all? { |_name, value| value.present? } end |
#all_search_variants_tested? ⇒ Boolean
208 209 210 211 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 208 def all_search_variants_tested? search_variant_test_records.all? { |_variant, tested| tested.present? } && all_comparator_searches_tested? end |
#any_valid_search_params?(search_params) ⇒ Boolean
57 58 59 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 57 def any_valid_search_params?(search_params) search_params.any? { |_patient_id, params| params.present? } end |
#array_of_codes(array) ⇒ Object
537 538 539 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 537 def array_of_codes(array) array.map { |name| "`#{name}`" }.join(', ') end |
#check_resource_against_params(resource, params) ⇒ Object
RESULT CHECKING ####
700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 700 def check_resource_against_params(resource, params) params.each do |name, escaped_search_value| values_found = [] search_value = unescape_search_value(escaped_search_value) match_found = resource_matches_param?(resource, name, escaped_search_value, values_found) assert match_found, "#{resource_type}/#{resource.id} did not match the search parameters:\n" \ "* Expected: #{unescape_search_value(search_value)}\n" \ "* Found: #{values_found.map(&:inspect).join(', ')}" end end |
#check_search_response ⇒ Object
188 189 190 191 192 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 188 def check_search_response assert_response_status(200) assert_resource_type(:bundle) # NOTE: how do we want to handle validating Bundles? end |
#date_comparator_value(comparator, date) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 219 def date_comparator_value(comparator, date) date = date.start || date.end if date.is_a? FHIR::Period case comparator when 'lt', 'le' comparator + (DateTime.xmlschema(date) + 1).xmlschema when 'gt', 'ge' comparator + (DateTime.xmlschema(date) - 1).xmlschema else # '' raise "Unsupported comparator '#{comparator}'" end end |
#default_search_values(param_name) ⇒ Object
331 332 333 334 335 336 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 331 def default_search_values(param_name) definition = .search_definitions[param_name] return [] if definition.blank? definition[:multiple_or] == 'SHALL' ? [definition[:values].join(',')] : Array.wrap(definition[:values]) end |
#element_has_valid_value?(element, include_system) ⇒ Boolean
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 646 def element_has_valid_value?(element, include_system) case element when FHIR::Reference element.reference.present? when FHIR::CodeableConcept coding = prefer_well_known_code_system(element, include_system) coding.present? when FHIR::Identifier include_system ? element.value.present? && element.system.present? : element.value.present? when FHIR::Coding include_system ? element.code.present? && element.system.present? : element.code.present? when FHIR::HumanName (element.family || element.given&.first || element.text).present? when FHIR::Address (element.text || element.city || element.state || element.postalCode || element.country).present? when Inferno::DSL::PrimitiveType element.value.present? else true end end |
#empty_search_params_message(empty_search_params) ⇒ Object
545 546 547 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 545 def (empty_search_params) "Could not find values for the search parameters #{array_of_codes(empty_search_params.keys)}" end |
#excluded_code?(coding, codes_to_exclude) ⇒ Boolean
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 160 def excluded_code?(coding, codes_to_exclude) codes_to_exclude.any? do |exclude_code| if exclude_code.include?('|') system, code = exclude_code.split('|') coding.code == code && coding.system == system else code = exclude_code coding.code == code end end end |
#fetch_and_assert_all_bundled_resources(resource_type: self.resource_type, reply_handler: nil, max_pages: 20, additional_resource_types: [], params: nil) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 553 def fetch_and_assert_all_bundled_resources( resource_type: self.resource_type, reply_handler: nil, max_pages: 20, additional_resource_types: [], params: nil ) = (params) bundle = resource additional_resource_types << 'Medication' if %w[MedicationRequest MedicationDispense].include?(resource_type) assert_handler = proc do |response| assert_response_status(200, response: response) assert_valid_json(response[:body], "Could not resolve bundle as JSON: #{response[:body]}") end reply_and_assert_handler = if reply_handler proc do |response| assert_handler.call(response) reply_handler.call(response) end else assert_handler end fetch_all_bundled_resources(resource_type:, bundle:, reply_handler: reply_and_assert_handler, max_pages:, additional_resource_types:, tags:) end |
#filter_adi_document_reference(resources) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 172 def filter_adi_document_reference(resources) resources.select! do |resource| resource.category.any? do |category| category.coding.any? do |coding| .search_definitions[:category][:values].include? coding.code end end end end |
#fixed_value_search_param_name ⇒ Object
463 464 465 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 463 def fixed_value_search_param_name (search_param_names - ['patient']).first end |
#fixed_value_search_param_names ⇒ Object
854 855 856 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 854 def fixed_value_search_param_names search_param_names.reject { |name| patient_id_param?(name) } end |
#fixed_value_search_param_values ⇒ Object
467 468 469 470 471 472 473 474 475 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 467 def fixed_value_search_param_values names = fixed_value_search_param_names values = names.map { |name| Array(.search_definitions.dig(name.to_sym, :values)) } return values.first if values.one? return [] if values.empty? || values.any?(&:empty?) values.first.product(*values.drop(1)).map { |combination| names.zip(combination).to_h } end |
#fixed_value_search_params(value, patient_id) ⇒ Object
477 478 479 480 481 482 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 477 def fixed_value_search_params(value, patient_id) search_param_names.each_with_object({}) do |name, params| param_value = value.is_a?(Hash) ? value[name] : value params[name] = patient_id_param?(name) ? patient_id : param_value end end |
#get_next_value(element, property) ⇒ Object
817 818 819 820 821 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 817 def get_next_value(element, property) return resolve_reference_value(element) if property.to_s == 'resolve()' super end |
#initial_search_variant_test_records ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 198 def initial_search_variant_test_records {}.tap do |records| records[:post_variant] = false if test_post_search? records[:medication_inclusion] = false if test_medication_inclusion? records[:reference_variants] = false if test_reference_variants? records[:token_variants] = false if token_search_params.present? records[:comparator_searches] = Set.new if params_with_comparators.present? end end |
#no_resources_skip_message(resource_type = self.resource_type) ⇒ Object
549 550 551 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 549 def (resource_type = self.resource_type) "No #{resource_type} resources appear to be available. Please use patients with more information" end |
#patient_id_list ⇒ Object
512 513 514 515 516 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 512 def patient_id_list return [nil] unless respond_to? :patient_ids patient_ids.split(',').map(&:strip) end |
#patient_id_param?(name) ⇒ Boolean
522 523 524 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 522 def patient_id_param?(name) name == 'patient' || name == 'subject' || (name == '_id' && resource_type == 'Patient') end |
#patient_search? ⇒ Boolean
518 519 520 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 518 def patient_search? search_param_names.any? { |name| patient_id_param? name } end |
#perform_comparator_searches(params, patient_id) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 241 def perform_comparator_searches(params, patient_id) params_with_comparators.each do |name| next if search_variant_test_records[:comparator_searches].include? name required_comparators(name).each do |comparator| paths = search_param_paths(name).first date_element = find_a_value_at(scratch_resources_for_patient(patient_id), paths) params_with_comparator = params.merge(name => date_comparator_value(comparator, date_element)) search_and_check_response(params_with_comparator) fetch_and_assert_all_bundled_resources(params: params_with_comparator).each do |resource| check_resource_against_params(resource, params_with_comparator) if resource.resourceType == resource_type end end search_variant_test_records[:comparator_searches] << name end end |
#perform_multiple_or_search_test ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 338 def perform_multiple_or_search_test resolved_one = false all_search_params.each do |patient_id, params_list| next unless params_list.present? search_params = params_list.first existing_values = {} missing_values = {} multiple_or_search_params.each do |param_name| search_value = default_search_values(param_name.to_sym) search_params = search_params.merge(param_name.to_s => search_value) existing_values[param_name.to_sym] = scratch_resources_for_patient(patient_id).map(¶m_name.to_sym).compact.uniq end # skip patient without multiple-or values next if existing_values.values.any?(&:empty?) resolved_one = true search_and_check_response(search_params) resources_returned = fetch_and_assert_all_bundled_resources(params: search_params) .select { |resource| resource.resourceType == resource_type } multiple_or_search_params.each do |param_name| missing_values[param_name.to_sym] = existing_values[param_name.to_sym] - resources_returned.map(¶m_name.to_sym) end = missing_values .reject { |_param_name, missing_value| missing_value.empty? } .map { |param_name, missing_value| "#{missing_value.join(',')} values from #{param_name}" } .join(' and ') assert .blank?, "Could not find #{} in any of the resources returned for Patient/#{patient_id}" break if resolved_one end end |
#perform_post_search(get_search_resources, params) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 138 def perform_post_search(get_search_resources, params) fhir_search resource_type, params:, search_method: :post check_search_response post_search_resources = fetch_and_assert_all_bundled_resources.select do |resource| resource.resourceType == resource_type end filter_devices(post_search_resources) if resource_type == 'Device' get_resource_count = get_search_resources.length post_resource_count = post_search_resources.length search_variant_test_records[:post_variant] = true assert get_resource_count == post_resource_count, 'Expected search by POST to return the same results as search by GET, ' \ "but GET search returned #{get_resource_count} resources, and POST search " \ "returned #{post_resource_count} resources." end |
#perform_reference_with_type_search(params, resource_count) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 261 def perform_reference_with_type_search(params, resource_count) return if resource_count.zero? return if search_variant_test_records[:reference_variants] new_search_params = params.merge('patient' => "Patient/#{params['patient']}") search_and_check_response(new_search_params) reference_with_type_resources = fetch_and_assert_all_bundled_resources(params: new_search_params) .select { |resource| resource.resourceType == resource_type } new_resource_count = reference_with_type_resources.count assert new_resource_count == resource_count, "Expected search by `#{params['patient']}` to to return the same results as searching " \ "by `#{new_search_params['patient']}`, but found #{resource_count} resources with " \ "`#{params['patient']}` and #{new_resource_count} with `#{new_search_params['patient']}`" search_variant_test_records[:reference_variants] = true end |
#perform_search(params, patient_id) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 103 def perform_search(params, patient_id) fhir_search resource_type, params:, tags: (params) perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search? check_search_response resources_returned = fetch_and_assert_all_bundled_resources(params:).select { |resource| resource.resourceType == resource_type } return [] if resources_returned.blank? perform_comparator_searches(params, patient_id) if params_with_comparators.present? if first_search? all_scratch_resources.concat(resources_returned).uniq! scratch_resources_for_patient(patient_id).concat(resources_returned).uniq! end resources_returned.each do |resource| check_resource_against_params(resource, params) end save_delayed_references(resources_returned) if saves_delayed_references? return resources_returned if all_search_variants_tested? perform_post_search(resources_returned, params) if test_post_search? test_medication_inclusion(resources_returned, params, patient_id) if test_medication_inclusion? perform_reference_with_type_search(params, resources_returned.count) if test_reference_variants? perform_search_with_system(params, patient_id) if token_search_params.present? resources_returned end |
#perform_search_with_status(original_params, _patient_id, status_search_values: self.status_search_values, resource_type: self.resource_type) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 300 def perform_search_with_status( original_params, _patient_id, status_search_values: self.status_search_values, resource_type: self.resource_type ) assert resource.is_a?(FHIR::OperationOutcome), 'Server returned a status of 400 without an OperationOutcome' # TODO: warn about documenting status requirements status_search_values.flat_map do |status_value| search_params = original_params.merge("#{status_search_param_name}": status_value) search_and_check_response(search_params) entries = resource.entry.select { |entry| entry.resource.resourceType == resource_type } if entries.present? original_params.merge!("#{status_search_param_name}": status_value) break end end end |
#perform_search_with_system(params, patient_id) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 282 def perform_search_with_system(params, patient_id) return if search_variant_test_records[:token_variants] new_search_params = search_params_with_values(token_search_params, patient_id, include_system: true) return if new_search_params.any? { |_name, value| value.blank? } search_params = params.merge(new_search_params) search_and_check_response(search_params) resources_returned = fetch_and_assert_all_bundled_resources(params: search_params) .select { |resource| resource.resourceType == resource_type } assert resources_returned.present?, 'No resources were returned when searching by `system|code`' search_variant_test_records[:token_variants] = true end |
#prefer_well_known_code_system(element, include_system) ⇒ Object
582 583 584 585 586 587 588 589 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 582 def prefer_well_known_code_system(element, include_system) coding = find_a_value_at(element, 'coding') { |c| c.code.present? && WellKnownCodeSystems.include?(c.system) } return coding if coding.present? find_a_value_at(element, 'coding') { |c| c.code.present? && (!include_system || c.system.present?) } end |
#reference_match?(reference, local_reference) ⇒ Boolean
443 444 445 446 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 443 def reference_match?(reference, local_reference) regex_pattern = %r{^(#{Regexp.escape(local_reference)}|\S+/#{Regexp.escape(local_reference)}(?:[/|]\S+)*)$} reference.match?(regex_pattern) end |
#references_to_save(resource_type = nil) ⇒ Object
458 459 460 461 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 458 def references_to_save(resource_type = nil) = resource_type == 'Provenance' ? : .delayed_references end |
#required_comparators(name) ⇒ Object
232 233 234 235 236 237 238 239 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 232 def required_comparators(name) .search_definitions .dig(name.to_sym, :comparators) .select { |_comparator, expectation| expectation == 'SHALL' } .keys .map(&:to_s) end |
#resolve_reference_value(element) ⇒ Object
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 823 def resolve_reference_value(element) reference = element&.reference return if reference.blank? || reference.start_with?('#') resolved_reference_cache[reference] ||= begin resource_type, resource_id = resource_type_and_id_from_reference(reference) if resource_type.blank? || resource_id.blank? nil else fhir_read(resource_type, resource_id)&.resource end rescue StandardError => e Inferno::Application['logger'].error("Unable to resolve reference #{reference}") Inferno::Application['logger'].error(e.) nil end end |
#resolve_search_param_path(resource, path) ⇒ Object
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 898 def resolve_search_param_path(resource, path) values = resolve_path(resource, path) match = path.match(EXTENSION_VALUE_PATH_REGEX) return values if values.present? || match.blank? value_path = match[:value_path] generic_value_path = %w[value value[x]].include?(value_path) extensions = case match[:extension_type] when 'modifierExtension' resource.modifierExtension if resource.respond_to?(:modifierExtension) when 'extension' resource.extension if resource.respond_to?(:extension) end Array(extensions) .select { |extension| extension.url == match[:url] } .map do |extension| extension_hash = extension.to_hash generic_value_path ? extension_hash.find { |key, _value| key.start_with?('value') }&.last : extension_hash[value_path] end .compact rescue NoMethodError [] end |
#resolved_reference_cache ⇒ Object
842 843 844 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 842 def resolved_reference_cache @resolved_reference_cache ||= {} end |
#resource_matches_param?(resource, search_param_name, escaped_search_value, values_found = []) ⇒ Boolean
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 718 def resource_matches_param?(resource, search_param_name, escaped_search_value, values_found = []) search_value = unescape_search_value(escaped_search_value) paths = search_param_paths(search_param_name) match_found = false paths.each do |path| type = .search_definitions[search_param_name.to_sym][:type] resolve_search_param_path(resource, path).each do |value| values_found << if value.is_a? FHIR::Reference value.reference elsif value.is_a? Inferno::DSL::PrimitiveType value.value else value end end values_found.compact! match_found = case type when 'Period', 'date', 'instant', 'dateTime' values_found.any? { |date| validate_date_search(search_value, date) } when 'HumanName' # When a string search parameter refers to the types HumanName and Address, # the search covers the elements of type string, and does not cover elements such as use and period # https://www.hl7.org/fhir/search.html#string search_value_downcase = search_value.downcase values_found.any? do |name| name&.text&.downcase&.start_with?(search_value_downcase) || name&.family&.downcase&.start_with?(search_value_downcase) || name&.given&.any? { |given| given.downcase.start_with?(search_value_downcase) } || name&.prefix&.any? { |prefix| prefix.downcase.start_with?(search_value_downcase) } || name&.suffix&.any? { |suffix| suffix.downcase.start_with?(search_value_downcase) } end when 'Address' search_value_downcase = search_value.downcase values_found.any? do |address| address&.text&.downcase&.start_with?(search_value_downcase) || address&.city&.downcase&.start_with?(search_value_downcase) || address&.state&.downcase&.start_with?(search_value_downcase) || address&.postalCode&.downcase&.start_with?(search_value_downcase) || address&.country&.downcase&.start_with?(search_value_downcase) end when 'CodeableConcept', 'Coding', 'Identifier', 'token' token_value_matches?(values_found, search_value) when 'boolean' search_values = split_escaped_search_values(search_value).map(&:downcase) values_found.any? { |value_found| search_values.include?(value_found.to_s.downcase) } when 'string' searched_values = split_escaped_search_values(search_value).map(&:downcase) values_found.any? do |value_found| searched_values.any? { |searched_value| value_found.downcase.starts_with? searched_value } end else # searching by patient requires special case because we are searching by a resource identifier # references can also be URLs, so we may need to resolve those URLs if %w[subject patient].include? search_param_name.to_s id = search_value.split('Patient/').last possible_values = [id, "Patient/#{id}", "#{url}/Patient/#{id}"] values_found.any? do |reference| possible_values.include? reference end else search_values = split_escaped_search_values(search_value) values_found.any? { |value_found| search_values.include? value_found } end end break if match_found end match_found end |
#resource_type_and_id_from_reference(reference) ⇒ Object
846 847 848 849 850 851 852 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 846 def resource_type_and_id_from_reference(reference) parts = reference.split('/') history_index = parts.index('_history') parts = parts.first(history_index) if history_index parts.last(2) end |
#run_provenance_revinclude_search_test ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 61 def run_provenance_revinclude_search_test # TODO: skip if not supported? skip_if !any_valid_search_params?(all_provenance_revinclude_search_params), provenance_resources = all_provenance_revinclude_search_params.flat_map do |_patient_id, params_list| params_list.flat_map do |params| fhir_search resource_type, params:, tags: (params) perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search? check_search_response # TODO: check that only provenance resources for resources matching # granular scopes returned fetch_and_assert_all_bundled_resources(additional_resource_types: ['Provenance'], params:) .select { |resource| resource.resourceType == 'Provenance' } end end scratch_provenance_resources[:all] ||= [] scratch_provenance_resources[:all].concat(provenance_resources) save_delayed_references(provenance_resources, 'Provenance') skip_if provenance_resources.empty?, ('Provenance') end |
#run_search_test ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 89 def run_search_test # TODO: skip if not supported? skip_if !any_valid_search_params?(all_search_params), resources_returned = all_search_params.flat_map do |patient_id, params_list| params_list.flat_map { |params| perform_search(params, patient_id) } end skip_if resources_returned.empty?, perform_multiple_or_search_test if multiple_or_search_params.present? end |
#save_delayed_references(resources, containing_resource_type = resource_type) ⇒ Object
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 674 def save_delayed_references(resources, containing_resource_type = resource_type) resources.each do |resource| references_to_save(containing_resource_type).each do |reference_to_save| references = resolve_path(resource, reference_to_save[:path]).select do |reference| reference.is_a?(FHIR::Reference) && !reference.contained? && reference.reference.present? end references.each do |reference| resource_type = reference.resource_class.name.demodulize need_to_save = reference_to_save[:resources].include?(resource_type) next unless need_to_save reference_resource_type = resource.resourceType reference_resource_id = resource.id referencing_resource = "#{reference_resource_type}/#{reference_resource_id}" save_resource_reference(resource_type, reference, referencing_resource) end end end end |
#save_resource_reference(resource_type, reference, referencing_resource) ⇒ Object
668 669 670 671 672 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 668 def save_resource_reference(resource_type, reference, referencing_resource) scratch[:references] ||= {} scratch[:references][resource_type] ||= Set.new scratch[:references][resource_type] << { reference: reference, referencing_resource: referencing_resource } end |
#scratch_resources_for_patient(patient_id) ⇒ Object
452 453 454 455 456 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 452 def scratch_resources_for_patient(patient_id) return all_scratch_resources if patient_id.nil? scratch_resources[patient_id] ||= [] end |
#search_and_check_response(params, resource_type = self.resource_type) ⇒ Object
182 183 184 185 186 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 182 def search_and_check_response(params, resource_type = self.resource_type) fhir_search resource_type, params:, tags: (params) check_search_response end |
#search_param_paths(name) ⇒ Object
526 527 528 529 530 531 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 526 def search_param_paths(name) paths = .search_definitions[name.to_sym][:paths] paths[0] = 'local_class' if paths.first == 'class' paths end |
#search_param_value(name, resource, include_system: false) ⇒ Object
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 591 def search_param_value(name, resource, include_system: false) paths = search_param_paths(name) search_value = nil paths.each do |path| element = find_a_value_at(resource, path) { |ele| element_has_valid_value?(ele, include_system) } search_value = case element when FHIR::Period if element.start.present? "gt#{(DateTime.xmlschema(element.start) - 1).xmlschema}" else end_datetime = get_fhir_datetime_range(element.end)[:end] "lt#{(end_datetime + 1).xmlschema}" end when FHIR::Reference element.reference when FHIR::CodeableConcept coding = prefer_well_known_code_system(element, include_system) include_system ? "#{coding.system}|#{coding.code}" : coding.code when FHIR::Identifier include_system ? "#{element.system}|#{element.value}" : element.value when FHIR::Coding include_system ? "#{element.system}|#{element.code}" : element.code when FHIR::HumanName element.family || element.given&.first || element.text when FHIR::Address element.text || element.city || element.state || element.postalCode || element.country when Inferno::DSL::PrimitiveType element.value else if .search_definitions[name.to_sym][:type] == 'date' && params_with_comparators&.include?(name) # convert date search to greath-than comparator search with correct precision # For all date search parameters: # Patient.birthDate does not mandate comparators so cannot be converted # Goal.target-date has day precision # All others have second + time offset precision if /^\d{4}(-\d{2})?$/.match?(element) || # YYYY or YYYY-MM (/^\d{4}-\d{2}-\d{2}$/.match?(element) && resource_type != 'Goal') # YYY-MM-DD AND Resource is NOT Goal "gt#{(DateTime.xmlschema(element) - 1).xmlschema}" else element end else element end end break if search_value.present? end search_value.to_s.gsub(',', '\\,') end |
#search_params_tag(params) ⇒ Object
805 806 807 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 805 def search_params_tag(params) "#{resource_type}?#{params.keys.join('&')}" end |
#search_params_with_values(search_param_names, patient_id, include_system: false) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 484 def search_params_with_values(search_param_names, patient_id, include_system: false) resources = scratch_resources_for_patient(patient_id) if resources.empty? return search_param_names.each_with_object({}) do |name, params| value = patient_id_param?(name) ? patient_id : nil params[name] = value end end resources.each_with_object({}) do |resource, outer_params| results_from_one_resource = search_param_names.each_with_object({}) do |name, params| value = if patient_id_param?(name) patient_id else search_param_value(name, resource, include_system: include_system) end params[name] = value end outer_params.merge!(results_from_one_resource) # stop if all parameter values are found return outer_params if outer_params.all? { |_key, value| value.present? } end end |
#search_variant_test_records ⇒ Object
194 195 196 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 194 def search_variant_test_records @search_variant_test_records ||= initial_search_variant_test_records end |
#split_escaped_search_values(search_value) ⇒ Object
925 926 927 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 925 def split_escaped_search_values(search_value) search_value.split(/(?<!\\\\),/).map { |value| value.gsub('\\,', ',') } end |
#status_search_param_name ⇒ Object
322 323 324 325 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 322 def status_search_param_name @status_search_param_name ||= .search_definitions.keys.find { |key| key.to_s.include? 'status' } end |
#status_search_values ⇒ Object
327 328 329 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 327 def status_search_values default_search_values(status_search_param_name) end |
#tags(params) ⇒ Object
795 796 797 798 799 800 801 802 803 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 795 def (params) return nil unless config.[:tag_requests] return nil if params.blank? return [search_params_tag(params)] if %w[Condition DiagnosticReport DocumentReference Observation ServiceRequest].include? resource_type nil end |
#test_medication_inclusion(base_resources, params, patient_id) ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 383 def test_medication_inclusion(base_resources, params, patient_id) return if search_variant_test_records[:medication_inclusion] scratch[:medication_resources] ||= {} scratch[:medication_resources][:all] ||= [] scratch[:medication_resources][patient_id] ||= [] scratch[:medication_resources][:contained] ||= [] base_resources_with_external_reference = base_resources .select { |request| request&.medicationReference&.present? } .reject { |request| request&.medicationReference&.reference&.start_with? '#' } contained_medications = base_resources .select { |request| request&.medicationReference&.reference&.start_with? '#' } .flat_map(&:contained) .select { |resource| resource.resourceType == 'Medication' } scratch[:medication_resources][:all] += contained_medications scratch[:medication_resources][patient_id] += contained_medications scratch[:medication_resources][:contained] += contained_medications return if base_resources_with_external_reference.blank? search_params = params.merge(_include: "#{resource_type}:medication") search_and_check_response(search_params) medications = fetch_and_assert_all_bundled_resources(params: search_params) .select { |resource| resource.resourceType == 'Medication' } assert medications.present?, 'No Medications were included in the search results' included_medications = medications.map { |medication| "#{medication.resourceType}/#{medication.id}" } matched_base_resources = base_resources_with_external_reference.select do |base_resource| included_medications.any? do |medication_reference| reference_match?(base_resource.medicationReference.reference, medication_reference) end end not_matched_included_medications = included_medications.select do |medication_reference| matched_base_resources.none? do |base_resource| reference_match?(base_resource.medicationReference.reference, medication_reference) end end not_matched_included_medications_string = not_matched_included_medications.join(',') assert not_matched_included_medications.empty?, "No #{resource_type} references #{not_matched_included_medications_string} in the search result." medications.uniq!(&:id) scratch[:medication_resources][:all] += medications scratch[:medication_resources][patient_id] += medications search_variant_test_records[:medication_inclusion] = true end |
#token_matches?(token, system, code) ⇒ Boolean
885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 885 def token_matches?(token, system, code) return false if token[:code].blank? code_matches = if token[:case_sensitive] token[:code] == code else token[:code].casecmp?(code) end code_matches && (system.blank? || token[:system] == system) end |
#token_search_system_and_code(search_value) ⇒ Object
881 882 883 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 881 def token_search_system_and_code(search_value) search_value.include?('|') ? search_value.split('|', 2) : [nil, search_value] end |
#token_value_matches?(values_found, search_value) ⇒ Boolean
858 859 860 861 862 863 864 865 866 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 858 def token_value_matches?(values_found, search_value) token_values = values_found.flat_map { |value| token_values_from_element(value) } search_tokens = split_escaped_search_values(search_value) search_tokens.any? do |search_token| system, code = token_search_system_and_code(search_token) token_values.any? { |token| token_matches?(token, system, code) } end end |
#token_values_from_element(value) ⇒ Object
868 869 870 871 872 873 874 875 876 877 878 879 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 868 def token_values_from_element(value) case value when FHIR::CodeableConcept value.coding.flat_map { |coding| token_values_from_element(coding) } when FHIR::Coding [{ system: value.system, code: value.code, case_sensitive: false }] when FHIR::Identifier [{ system: value.system, code: value.value, case_sensitive: true }] else [{ system: nil, code: value.to_s, case_sensitive: false }] end end |
#unable_to_resolve_params_message ⇒ Object
541 542 543 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 541 def "Could not find values for all search params #{array_of_codes(search_param_names)}" end |
#unescape_search_value(value) ⇒ Object
714 715 716 |
# File 'lib/us_quality_core_test_kit/search_test.rb', line 714 def unescape_search_value(value) value&.gsub('\\,', ',') end |