Skip to content

Commit 43e47d2

Browse files
committed
Document prefetch token format and update examples (fixes #151)
- {{User.id}} -> {{user}} - {{Patient.id}} -> {{context.patientId}}
1 parent e25d41a commit 43e47d2

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

docs/specification/1.0.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ curl "https://example.com/cds-services"
7777
"description": "An example of a CDS Service that returns a static set of cards",
7878
"id": "static-patient-greeter",
7979
"prefetch": {
80-
"patientToGreet": "Patient/{{Patient.id}}"
80+
"patientToGreet": "Patient/{{context.patientId}}"
8181
}
8282
},
8383
{
@@ -86,8 +86,8 @@ curl "https://example.com/cds-services"
8686
"description": "An example of a CDS Service that simply echos the medication being prescribed",
8787
"id": "medication-echo",
8888
"prefetch": {
89-
"patient": "Patient/{{Patient.id}}",
90-
"medications": "MedicationOrder?patient={{Patient.id}}"
89+
"patient": "Patient/{{context.patientId}}",
90+
"medications": "MedicationOrder?patient={{context.patientId}}"
9191
}
9292
}
9393
]
@@ -173,12 +173,28 @@ Similarly, each EHR will decide what FHIR resources to authorize and to prefetch
173173
### Prefetch Template
174174

175175
The prefetch template is a dictionary of `read` and `search` requests to supply
176-
relevant data, where the following variables are defined:
176+
relevant data. In order to allow for prefetch templates that are dependent upon the particular CDS Service request, prefetch tokens or variables may be defined.
177+
178+
Prefetch tokens are delimited by `{{` and `}}` and named based upon the field they correspond to, including any objects they may be nested within.
179+
180+
The CDS Hooks specification defines just one prefetch token:
177181

178182
|variable|meaning|
179183
---------|--------
180-
|`{{Patient.id}}`|The id of the patient in context for this activity (e.g. `123`)|
181-
|`{{User.id}}`|The type and id of the user for this session (e.g. `Practitioner/123`)|
184+
|`{{user}}`|The value of the `user` field from this CDS Service request (e.g. `Practitioner/123`)|
185+
186+
Individual hooks can define their own prefetch tokens from its hook-specific `context` object. The hook documentation will specify, for each field in the context, whether it can be used as a prefetch token. For instance, given a hook of `example-hook` with the following context in which the `patientId` and `medicationId` fields are both denoted as prefix tokens:
187+
188+
```json
189+
"context": {
190+
"patientId": "123",
191+
"medication": {
192+
"medicationId": "456"
193+
}
194+
}
195+
```
196+
197+
The prefetch tokens defined by this `example-hook` would be `{{context.patientId}}` and `{{context.medication.medicationId}}`.
182198

183199
An EHR MAY choose to honor some or all of the desired prefetch templates, and is free to choose the most appropriate source for these data. For example:
184200

@@ -198,9 +214,9 @@ The CDS Service MUST NOT receive any prefetch template key that the EHR chooses
198214
```json
199215
{
200216
"prefetch": {
201-
"p": "Patient/{{Patient.id}}",
202-
"a1c": "Observation?patient={{Patient.id}}&code=4548-4&_count=1&sort:desc=date",
203-
"u": "Practitioner/{{User.id}}"
217+
"p": "Patient/{{context.patientId}}",
218+
"a1c": "Observation?patient={{context.patientId}}&code=4548-4&_count=1&sort:desc=date",
219+
"u": "Practitioner/{{user}}"
204220
}
205221
}
206222
```
@@ -257,7 +273,7 @@ To reduce the implementation burden on EHRs that support CDS Services, CDS Hooks
257273

258274
* _instance_ level [read](https://www.hl7.org/fhir/http.html#read) interactions (for resources with known ids such as `Patient` and `Practitioner`)
259275
* _type_ level [search](https://www.hl7.org/fhir/http.html#search) interactions
260-
* Patient references (e.g. `patient={{Patient}}`)
276+
* Patient references (e.g. `patient={{context.patientId}}`)
261277
* _token_ search parameters using equality (e.g. `code=4548-4`) and optionally the `:in` modifier (no other modifiers for token parameters)
262278
* _date_ search parameters on `date`, `dateTime`, `instant`, or `Period` types only, and using only the prefixes `eq`, `lt`, `gt`, `ge`, `le`
263279
* the `_count` parameter to limit the number of results returned
@@ -551,7 +567,7 @@ As another example, an extension defined on the discovery response could look li
551567
"hook": "patient-view",
552568
"id": "patientview",
553569
"prefetch": {
554-
"patient": "Patient/{{Patient.id}}"
570+
"patient": "Patient/{{context.patientId}}"
555571
},
556572
"description": "clinical decision support for patient view",
557573
"extension": {

0 commit comments

Comments
 (0)