HL7-DaVinci / CRD

Coverage Requirements Discovery (CRD) Reference Implementation (RI)
Apache License 2.0
31 stars 21 forks source link

Invalid Prefetch in CDS Hooks Discovery #296

Open cfeltner opened 4 months ago

cfeltner commented 4 months ago

According to the CDS Hooks specification (https://cds-hooks.hl7.org/2.0/#prefetch-tokens),

"Only root-level fields with a primitive value within the context object are eligible to be used as prefetch tokens. For example, {{context.medication.id}} is not a valid prefetch token because it attempts to access the id field of the medication field."

The prefetch specified in CDS Hooks Discovery response returned from the Davinci CRD Reference Implementation is not following the above prefetch token guidance. Specifically, the following prefetch tokens are not "root-level fields with a primitive value": context.draftOrders.ServiceRequest.id, context.medications.MedicationRequest.id, and context.draftOrders.DeviceRequest.id

Prefetch excerpt:

"prefetch": {
  "serviceRequestBundle": "ServiceRequest?_id={{context.draftOrders.ServiceRequest.id}}&_include=ServiceRequest:patient&_include=ServiceRequest:performer&_include=ServiceRequest:requester&_include:iterate=PractitionerRole:organization&_include:iterate=PractitionerRole:practitioner",
  "medicationRequestBundle": "MedicationRequest?_id={{context.medications.MedicationRequest.id}}&_include=MedicationRequest:patient&_include=MedicationRequest:intended-dispenser&_include=MedicationRequest:requester:PractitionerRole&_include=MedicationRequest:medication&_include:iterate=PractitionerRole:organization&_include:iterate=PractitionerRole:practitioner",
  "coverageBundle": "Coverage?patient={{context.patientId}}",
  "deviceRequestBundle": "DeviceRequest?_id={{context.draftOrders.DeviceRequest.id}}&_include=DeviceRequest:patient&_include=DeviceRequest:performer&_include=DeviceRequest:requester&_include=DeviceRequest:device&_include:iterate=PractitionerRole:organization&_include:iterate=PractitionerRole:practitioner"
},  

Recommend refactoring prefetch to request the Patient and Practitioner resources by themselves. Since these are draft orders they may not be persisted and even able to be accessed with a FHIR search which the current prefetch is dependent on.

"prefetch": {
    "patient": "Patient/{{context.patientId}}",
    "practitioner": "Practitioner/{{context.userId}}"
    "coverageBundle": "Coverage?patient={{context.patientId}}",
},