Class: DaVinciCRDTestKit::V221::DiscoveryStandardPrefetchExpressionsTest

Inherits:
Inferno::Test
  • Object
show all
Includes:
ServerTestHelper
Defined in:
lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_standard_prefetch_expressions_test.rb

Constant Summary collapse

ALL_HOOKS =
[
  'appointment-book',
  'encounter-start',
  'encounter-discharge',
  'order-dispatch',
  'order-select',
  'order-sign'
].freeze

Instance Method Summary collapse

Methods included from ServerTestHelper

#parse_json, #verify_at_least_one_test_passes

Instance Method Details

#expression_signature(expression) ⇒ Object

The IG examples contain FHIRPath alternatives separated by |, and CDS Hooks prefetch field names can vary. Build a canonical signature so alternative ordering and %prefetchKey names do not affect matching.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_standard_prefetch_expressions_test.rb', line 118

def expression_signature(expression)
  expression = expression.to_s
  # CRD's standard expressions use one `{{...}}` token; split that token into its surrounding request string.
  match = expression.match(/\A(.*?)\{\{(.*)\}\}(.*)\z/)
  return expression unless match

  prefix, fhirpath_expression, suffix = match.captures
  alternatives =
    fhirpath_expression
      .split('|')
      .map { |alternative| alternative.gsub(/%[A-Za-z][A-Za-z0-9_-]*/, '%prefetch') }
      .uniq
      .sort

  [prefix, alternatives, suffix]
end

#ignored_service_idsObject



40
41
42
# File 'lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_standard_prefetch_expressions_test.rb', line 40

def ignored_service_ids
  crd_discovery_service_ignore_list.to_s.split(',').map(&:strip).reject(&:blank?)
end

#services_for_crd_validation(services) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_standard_prefetch_expressions_test.rb', line 44

def services_for_crd_validation(services)
  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.reject { |service| ignored_service_ids.include?(service['id']) }
end

#standard_prefetch_expressions(hook) ⇒ Object

rubocop:disable Layout/LineLength



55
56
57
58
59
60
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/davinci_crd_test_kit/server/v2.2.1/discovery/discovery_standard_prefetch_expressions_test.rb', line 55

def standard_prefetch_expressions(hook)
  case hook
  when 'appointment-book'
    {
      'patient' => 'Patient/{{context.patientId}}',
      'encounter' => 'Encounter/{{context.encounterId}}',
      'coverage' => 'Coverage?patient={{context.patientId}}&status=active',
      'deviceRequests' => "DeviceRequest?_id={{context.appointments.entry.resource.basedOn.extension('http://hl7.org/fhir/StructureDefinition/alternate-reference').value.resolve().ofType(DeviceRequest).id}}",
      'serviceRequests' => 'ServiceRequest?_id={{context.appointments.entry.resource.basedOn.resolve().ofType(ServiceRequest).id}}',
      'medicationRequests' => "MedicationRequest?_id={{context.appointments.entry.resource.basedOn.extension('http://hl7.org/fhir/StructureDefinition/alternate-reference').value.resolve().ofType(MedicationRequest).id}}",
      'devices' => 'Device?_id={{%deviceRequests.entry.resource.code.resolve().id}}',
      'medications' => 'Medication?_id={{%medicationRequests.entry.resource.medication.resolve().id}}',
      'practitionerRoles' => 'PractitionerRole?_id={{%encounter.participant.individual.resolve().ofType(PractitionerRole).id|context.appointments.entry.resource.participant.actor.resolve().ofType(PractitionerRole).id|%deviceRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%deviceRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%medicationRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%medicationRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%serviceRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%serviceRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id}}',
      'practitioners' => 'Practitioner?_id={{%practitionerRoles.entry.resource.practitioner.resolve().id|%encounter.participant.individual.resolve().ofType(Practitioner).id|context.appointments.entry.resource.participant.actor.resolve().ofType(Practitioner).id|%deviceRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%deviceRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%medicationRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%medicationRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%serviceRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%serviceRequests.entry.resource.requester.resolve().ofType(Practitioner).id}}',
      'organizations' => 'Organization?_id={{%practitionerRoles.entry.resource.organization.resolve().id|%encounter.serviceProvider.resolve().ofType(Organization).id|%medicationRequests.entry.resource.dispenseRequest.performer.resolve().ofType(Organization).id|%serviceRequests.entry.resource.performer.resolve().ofType(Organization).id}}',
      'locations' => 'Location?_id={{%practitionerRoles.entry.resource.location.resolve().id|%encounter.location.location.resolve().id|context.appointments.entry.resource.participant.actor.resolve().ofType(Location).id|%serviceRequests.entry.resource.locationReference.resolve().ofType(Location).id}}'
    }
  when 'encounter-start', 'encounter-discharge'
    {
      'patient' => 'Patient/{{context.patientId}}',
      'encounter' => 'Encounter/{{context.encounterId}}',
      'coverage' => 'Coverage?patient={{context.patientId}}&status=active',
      'practitionerRoles' => 'PractitionerRole?_id={{%encounter.participant.individual.resolve().ofType(PractitionerRole).id}}',
      'practitioners' => 'Practitioner?_id={{%practitionerRoles.entry.resource.practitioner.resolve().id|%encounter.participant.individual.resolve().ofType(Practitioner).id}}',
      'organizations' => 'Organization?_id={{%practitionerRoles.entry.resource.organization.resolve().id|%encounter.serviceProvider.resolve().ofType(Organization).id}}',
      'locations' => 'Location?_id={{%practitionerRoles.entry.resource.location.resolve().id|%encounter.location.location.resolve().id}}'
    }
  when 'order-dispatch'
    {
      'patient' => 'Patient/{{context.patientId}}',
      'encounter' => 'Encounter/{{context.encounterId}}',
      'coverage' => 'Coverage?patient={{context.patientId}}&status=active',
      'communicationRequests' => 'CommunicationRequest?_id={{context.dispatchedOrders.resolve().ofType(CommunicationRequest).id}}',
      'deviceRequests' => 'DeviceRequest?_id={{context.dispatchedOrders.resolve().ofType(DeviceRequest).id}}',
      'medicationRequests' => 'MedicationRequest?_id={{context.dispatchedOrders.resolve().ofType(MedicationRequest).id}}',
      'nutritionOrders' => 'NutritionOrder?_id={{context.dispatchedOrders.resolve().ofType(NutritionOrder).id}}',
      'serviceRequests' => 'ServiceRequest?_id={{context.dispatchedOrders.resolve().ofType(ServiceRequest).id}}',
      'visionPrescriptions' => 'VisionPrescription?_id={{context.dispatchedOrders.resolve().ofType(VisionPrescription).id}}',
      'devices' => 'Device?_id={{%deviceRequests.entry.resource.code.resolve().id}}',
      'medications' => 'Medication?_id={{%medicationRequests.entry.resource.medication.resolve().id}}',
      'practitionerRoles' => 'PractitionerRole?_id={{%encounter.participant.individual.resolve().ofType(PractitionerRole).id|%communicationRequests.entry.resource.sender.resolve().ofType(PractitionerRole).id|%communicationRequests.entry.resource.recipient.resolve().ofType(PractitionerRole).id|%communicationRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%deviceRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%deviceRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%medicationRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%medicationRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%serviceRequests.entry.resource.performer.resolve().ofType(PractitionerRole).id|%serviceRequests.entry.resource.requester.resolve().ofType(PractitionerRole).id|%nutritionOrders.entry.resource.orderer.resolve().ofType(PractitionerRole).id|%visionPrescriptions.entry.resource.prescriber.resolve().ofType(PractitionerRole).id}}',
      'practitioners' => 'Practitioner?_id={{%practitionerRoles.entry.resource.practitioner.resolve().id|%encounter.participant.individual.resolve().ofType(Practitioner).id|%communicationRequests.entry.resource.sender.resolve().ofType(Practitioner).id|%communicationRequests.entry.resource.recipient.resolve().ofType(Practitioner).id|%communicationRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%deviceRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%deviceRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%medicationRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%medicationRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%serviceRequests.entry.resource.performer.resolve().ofType(Practitioner).id|%serviceRequests.entry.resource.requester.resolve().ofType(Practitioner).id|%nutritionOrders.entry.resource.orderer.resolve().ofType(Practitioner).id|%visionPrescriptions.entry.resource.prescriber.resolve().ofType(Practitioner).id}}',
      'organizations' => 'Organization?_id={{%practitionerRoles.entry.resource.organization.resolve().id|%encounter.serviceProvider.resolve().ofType(Organization).id|%communicationRequests.entry.resource.recipient.resolve().ofType(Organization).id|%communicationRequests.entry.resource.sender.resolve().ofType(Organization).id|%medicationRequests.entry.resource.dispenseRequest.performer.resolve().id|%serviceRequests.entry.resource.performer.resolve().ofType(Organization).id}}',
      'locations' => 'Location?_id={{%practitionerRoles.entry.resource.location.resolve().id|%encounter.location.location.resolve().id|%serviceRequests.entry.resource.locationReference.resolve().id}}'
    }
  when 'order-select', 'order-sign'
    {
      'patient' => 'Patient/{{context.patientId}}',
      'encounter' => 'Encounter/{{context.encounterId}}',
      'coverage' => 'Coverage?patient={{context.patientId}}&status=active',
      'devices' => 'Device?_id={{context.draftOrders.entry.resource.ofType(DeviceRequest).code.resolve().id}}',
      'medications' => 'Medication?_id={{context.draftOrders.entry.resource.ofType(MedicationRequest).medication.resolve().id}}',
      'practitionerRoles' => 'PractitionerRole?_id={{%encounter.participant.individual.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.sender.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.recipient.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.requester.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.performer.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.orderer.resolve().ofType(PractitionerRole).id|context.draftOrders.entry.resource.prescriber.resolve().ofType(PractitionerRole).id}}',
      'practitioners' => 'Practitioner?_id={{%practitionerRoles.entry.resource.practitioner.resolve().id|%encounter.participant.individual.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.sender.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.recipient.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.requester.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.performer.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.orderer.resolve().ofType(Practitioner).id|context.draftOrders.entry.resource.prescriber.resolve().ofType(Practitioner).id}}',
      'organizations' => 'Organization?_id={{%practitionerRoles.entry.resource.organization.resolve().id|%encounter.serviceProvider.resolve().ofType(Organization).id|context.draftOrders.entry.resource.dispenseRequest.performer.resolve().id|context.draftOrders.entry.resource.sender.resolve().ofType(Organization).id|context.draftOrders.entry.resource.recipient.resolve().ofType(Organization).id|context.draftOrders.entry.resource.performer.resolve().ofType(Organization).id}}',
      'locations' => 'Location?_id={{%practitionerRoles.entry.resource.location.resolve().id|%encounter.location.location.resolve().id|context.draftOrders.entry.resource.locationReference.resolve().id}}'
    }
  end
end