diff --git a/lib/davinci_crd_test_kit/requirements/generated/crd_server_v221_requirements_coverage.csv b/lib/davinci_crd_test_kit/requirements/generated/crd_server_v221_requirements_coverage.csv index 48e7b8ce..d86c9934 100644 --- a/lib/davinci_crd_test_kit/requirements/generated/crd_server_v221_requirements_coverage.csv +++ b/lib/davinci_crd_test_kit/requirements/generated/crd_server_v221_requirements_coverage.csv @@ -39,7 +39,7 @@ hl7.fhir.us.davinci-crd_2.2.1,found-13,https://hl7.org/fhir/us/davinci-crd/2.2.1 hl7.fhir.us.davinci-crd_2.2.1,found-14,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-14,"If a CRD server supports [endpoint discovery](http://hl7.org/fhir/us/davinci-hrex/1.2.0/endpoint-discovery.html), they **SHALL** have at most a single endpoint for each coverage (e.g., Medicare, Medicaid, or commercial) they provide coverage under.",SHALL,CRD Server,true,,,"","" hl7.fhir.us.davinci-crd_2.2.1,found-15,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-15,"If a CRD server does not support endpoint discovery, they **SHALL** expose only one CRD endpoint capable of handling all coverages.",SHALL,CRD Server,true,,,"","" hl7.fhir.us.davinci-crd_2.2.1,found-18,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-18,CRD clients and servers **MAY** leverage the [payer registry](http://hl7.org/fhir/us/davinci-pdex-plan-net) developed by PDex (which will eventually fold into the [national directory under FAST](https://confluence.hl7.org/display/FAST/National+Healthcare+Directory)) as a means of determining which endpoints exist for which payers as candidates for configuration.,MAY,"CRD Client,CRD Server",false,,,"","" -hl7.fhir.us.davinci-crd_2.2.1,found-24,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-24,"For this release of the IG, conformant CRD clients and servers **SHALL** support the CDS Hooks prefetch capability.",SHALL,"CRD Client,CRD Server",false,,,"","" +hl7.fhir.us.davinci-crd_2.2.1,found-24,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-24,"For this release of the IG, conformant CRD clients and servers **SHALL** support the CDS Hooks prefetch capability.",SHALL,"CRD Client,CRD Server",false,,,1.05,crd_server_v221-crd_v221_server_discovery_group-crd_v221_discovery_prefetch_support hl7.fhir.us.davinci-crd_2.2.1,found-26,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-26,"They **MAY** include more and/or less prefetch requests than described in 'standard' prefetch section below, based on which data is desired.",MAY,CRD Server,false,,,"","" hl7.fhir.us.davinci-crd_2.2.1,found-27,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-27,Prefetch requests **SHOULD** only include information that is always expected to be needed for each hook invocation.,SHOULD,CRD Server,false,,,"","" hl7.fhir.us.davinci-crd_2.2.1,found-28,https://hl7.org/fhir/us/davinci-crd/2.2.1/en/foundation.html#ci-c-found-28,"When information is only needed for certain invocations of the hook (e.g., for specific types of medications or services), that information **SHOULD** only be retrieved by query using the provided token, not requested universally via prefetch.",SHOULD,CRD Server,true,,,"","" diff --git a/lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_prefetch_support_test.rb b/lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_prefetch_support_test.rb new file mode 100644 index 00000000..3efe246a --- /dev/null +++ b/lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_prefetch_support_test.rb @@ -0,0 +1,43 @@ +require_relative '../../server_test_helper' + +module DaVinciCRDTestKit + module V221 + class DiscoveryPrefetchSupportTest < Inferno::Test + include DaVinciCRDTestKit::ServerTestHelper + + title 'Server demonstrates ability to request the CDS Client perform prefetch queries' + id :crd_v221_discovery_prefetch_support + description %( + This test expects the server to demonstrate support for prefetch queries + by providing a prefetch query in at least one of the advertised service + in the discovery response. + ) + + verifies_requirements 'hl7.fhir.us.davinci-crd_2.2.1@found-24' + + input :cds_services + input :crd_discovery_service_ignore_list, + optional: true + + run do + object = parse_json(cds_services) + assert object['services'], 'Discovery response did not contain `services`' + + services = object['services'] + assert services.is_a?(Array), 'Services field of the CDS Discovery response object is not an array.' + + ignored_service_ids = crd_discovery_service_ignore_list.to_s.split(',').map(&:strip).reject(&:blank?) + services + .select { |service| ignored_service_ids.include?(service['id']) } + .each do |service| + info "Ignoring service `#{service['id']}` because it is in the ignore list." + end + services_for_crd_validation = services.reject { |service| ignored_service_ids.include?(service['id']) } + + prefetch_supported = services_for_crd_validation.any? { |service| service['prefetch'].present? } + + skip_if !prefetch_supported, 'No CRD services advertised prefetch support' + end + end + end +end diff --git a/lib/davinci_crd_test_kit/server/v2.2.1/server_discovery_group.rb b/lib/davinci_crd_test_kit/server/v2.2.1/server_discovery_group.rb index 28d52c53..53fdaac7 100644 --- a/lib/davinci_crd_test_kit/server/v2.2.1/server_discovery_group.rb +++ b/lib/davinci_crd_test_kit/server/v2.2.1/server_discovery_group.rb @@ -2,6 +2,7 @@ require_relative 'discovery/discovery_configuration_test' require_relative 'discovery/discovery_endpoint_test' require_relative 'discovery/discovery_services_validation_test' +require_relative 'discovery/discovery_prefetch_support_test' module DaVinciCRDTestKit module V221 @@ -62,6 +63,7 @@ class ServerDiscoveryGroup < Inferno::TestGroup test from: :crd_v221_discovery_endpoint_test test from: :crd_v221_discovery_services_validation test from: :crd_v221_discovery_configuration + test from: :crd_v221_discovery_prefetch_support end end end diff --git a/spec/davinci_crd_test_kit/v2.2.1/discovery_prefetch_support_test_spec.rb b/spec/davinci_crd_test_kit/v2.2.1/discovery_prefetch_support_test_spec.rb new file mode 100644 index 00000000..acd51486 --- /dev/null +++ b/spec/davinci_crd_test_kit/v2.2.1/discovery_prefetch_support_test_spec.rb @@ -0,0 +1,49 @@ +RSpec.describe DaVinciCRDTestKit::V221::DiscoveryPrefetchSupportTest do + let(:suite_id) { 'crd_client' } + let(:runnable) { described_class } + let(:results_repo) { Inferno::Repositories::Results.new } + let(:cds_service) do + { + 'hook' => 'appointment-book', + 'title' => 'Appointment Booking CDS Service', + 'description' => 'An example of a CDS Service that is invoked when user of a CRD Client books an appointment', + 'id' => 'appointment-book-service', + 'prefetch' => { + 'user' => '{{context.userId}}', + 'patient' => 'Patient/{{context.patientId}}' + } + } + end + + def entity_result_messages + results_repo.current_results_for_test_session_and_runnables(test_session.id, [runnable]) + .first + .messages + end + + it 'succeeds when a service contains a prefetch query' do + service1 = cds_service.merge('extension' => { 'davinci-crd.version' => ['2.1', '2.2'] }) + service2 = cds_service.merge('extension' => { 'davinci-crd.version' => ['2.2'] }) + + cds_services = { 'services' => [service1, service2] }.to_json + + result = run(runnable, cds_services:) + + expect(result.result).to eq('pass'), result.result_message + end + + it 'skips if no services advertise prefetch support' do + service1 = cds_service.merge('extension' => { 'davinci-crd.version' => ['2.1', '2.2'] }) + service2 = cds_service.merge('extension' => { 'davinci-crd.version' => ['2.2'] }) + + service1.delete 'prefetch' + service2.delete 'prefetch' + + cds_services = { 'services' => [service1, service2] }.to_json + + result = run(runnable, cds_services:) + + expect(result.result).to eq('skip'), result.result_message + expect(result.result_message).to match(/No CRD services advertised prefetch support/) + end +end