Question: Searching by extensions in #FHIR
Apr 19, 2016Question:
My concern relates to search resources by extensions. I have read a lot about extensions and profiles, but the processing I have never seen.
If I need a new field on patient, like eye color, I’ve the option to extend the standard patient resource and add the new property. Persisting and loading via ID is quite easy. But how is the best way to realize a searching for patients with the new eye color value? Is there ever a solution?
Btw: I’m using the awesome HAPI from James Agnew.
Answer:
This is a question that comes up occasionally because the answer is buried in the spec. When you search a resource, you nominate one or more parameters to search by. In the specification, we define a basic set of search parameters, the ones we think will come up in practice. Servers can decide which of these to support, and define their own additional ones.
Note that the parameters are not direct queries into the resource - they are a name that identifies a path into the resource. The idea is that you can use some kind of map-reduce approach to generate the indexes, or map to an existing index you already have. So for patient, the search parameter “given” is actually a search onto the path Patient.name.given. The ‘path’ there is actually a fluent path expression - and finally, in the latest version of the spec, we have all the ducks in a row to make that formal and explicit.
So to search an extension, the server defines a name - say, ‘eyecolor’ in your case - and generates the index based on the expression Patient.extension(“your-extension-url”). It’s completely transparent to the client where the search parameter refers to unless the server publishes it’s search parameter definitions, and the client processes them.
Oh - but you’ll want to know how to actually do that in HAPI - you’ll have to ask on the HAPI support forum. Btw, yes, both HAPI and James are awesome ;-)