Wednesday, January 21, 2015

Finding a Resource matching a value set in FHIR

Cecil Lynch posed this challenge to me in the bar, and of course it being late, and my birthday (which meant I wasn't paying for beers today), I couldn't find the answer immediately.  But I posed the following question to the FHIR Implementers list on Skype:
"I seem to recall a discussion here earlier where someone described how you could issue a query to request conditions that matched a value set expansion.  Anyone remember what that looked like?"
Lloyd McKenzie had the answer not three minutes later (just after Cecil left the bar).
"Search for ":in" here: http://hl7-fhir.github.io/search.html
(also ":not-in") "
I had promised Cecil a blog post on the answer to his question here, so here it is.

His question: How can I find a FHIR Observation resource where Patient = John Smith, and Observation.code = Culture, and Observation.value is in a Value Set describing all codes for Salmonella.

If you read the recommended link and find the second occurrence of :in on the page it says:

inthe search parameter is a URI (relative or absolute) that identifies a value set, and the search parameter tests whether the coding is in the specified value set. The reference may be literal (to an address where the value set can be found) or logical (a referecnce to ValueSet.identifier)

So, the query is:

GET [base]/Observation?subject.name=John+Smith&name=System|Culture&value:in=ValueSetReference
And what this means is find me the observation whose subject has the name of John Smith, where the type of observation is Culture from some code system identified by System, which appears in the Value Set resource that can be retrieved from ValueSetReference, where in this particular case, the Value Set resource would describe somehow all codes for Salmonella.

Now, the beauty of this is that the FHIR server performing the query doesn't actually have to expand the value set more than once to perform this or any other query against the value set.  And if the value set resource is resident on the same server as the observation, it may not even need to fully expand the resource to perform the search, it only need to execute an algorithm that determines whether the code in a candidate resource could be in that expansion.  There are a couple of ways the server could do that, including precomputing a DFA for matching all codes in the value set.

I was told that if I could show that this was possible in FHIR, Cecil would become a believer.

Now, I'm already a believer in FHIR, but this exercise demonstrated for me once again why, because within 10 minutes of issuing my query, I had the answer, and it was documented right here all along.

     -- Keith

1 comment:

  1. Keith,

    I think this indirectly surfaces a question I have about FHIR (as someone not involved in it yet beyond occasional perusing of high-level discussions) - how does FHIR handed the wide variety of target audiences it is intending to address?

    For a "standards guy" - the ability to get a quick answer to question like this one and the presence of well-documented built-in capabilities is great. To a mobile app developer looking to develop some PHR-style capabilities in their cool app, "request conditions that match a value set expansion" is the beginning of the end.

    Is there going to be a need for "Green FHIR" (a la the ill-fated "Green CDA")?



    ReplyDelete