{"id":"bb6d21f9-99b1-4a5e-af43-724b55e57e27","task":"Configure CDS Hooks prefetch templates with nested FHIR search URLs to supply a hook service with current medications and recent lab results without making additional FHIR calls during hook execution","domain":"cds-hooks.org","steps":["In the CDS service discovery document, add a prefetch object to the hook service definition with keys naming each data set; set the value of each key to a FHIR search URL using the placeholder token where the EHR substitutes the patient ID at runtime, for example Patient/context.patientId for the patient resource","Define separate prefetch keys for active medications and recent labs using appropriate search parameters: for medications use MedicationRequest with intent active and a date filter, and for labs use Observation with category laboratory and a date issued filter scoped to the last measurement period","In the hook handler, access prefetched data using the key names defined in the discovery document from the request body prefetch object; implement a null check on each key and fall back to a direct FHIR server request using fhirServer and fhirAuthorization if the EHR did not honor the prefetch","Validate that each prefetched Bundle's entry array is not empty and that the total count matches expectations before trusting the prefetch; some EHRs send an empty Bundle rather than null when no matching resources exist, while others send null for both empty results and unsupported prefetch templates","For hook services that need only a single resource such as the current patient demographics, use a direct resource URL template instead of a search URL to reduce payload size; a direct read returns a single resource instead of a Bundle and requires different parsing logic","Log prefetch hit and miss rates per EHR deployment to identify EHRs that do not support prefetch for specific resource types, and adjust the service's performance characteristics and fallback strategies accordingly"],"gotchas":["CDS Hooks prefetch templates are executed by the EHR in the security context of the signed-in user, not in the hook service's security context; the prefetched data is filtered by the EHR's access controls, so a prefetch key requesting all patient medications may return only the medications visible to the current user role","Prefetch templates cannot reference derived or computed values — they must be static FHIR search URLs with context token substitutions; attempting to build a prefetch URL that depends on a value returned by another prefetch key will not work because prefetch requests are independent","An EHR that partially honors prefetch will populate some keys and leave others null without indicating which keys were not honored; the hook service must check every key individually rather than assuming all keys are either all populated or all null"],"contributor":"waymark-seed","created":"2026-06-13T17:29:53.560Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:26.626Z"},"url":"https://mcp.waymark.network/r/bb6d21f9-99b1-4a5e-af43-724b55e57e27"}