Convert your FHIR JSON -> XML and back here. The CDA Book is sometimes listed for Kindle here and it is also SHIPPING from Amazon! See here for Errata.

Friday, June 8, 2012

Matching Items in one list against another list in XSLT

This is an overdue explanation for how to do something in XSLT that I was supposed to write up a couple of weeks ago for the HL7 CCD Bluebutton project.

The challenge is that we have two lists:  One of observations (particular lab results) for a particular patient, and the other a set of lab results that mean something (e.g., blood type).  The challenge is to find the set of results from the first list that match any of the codes in the second list.

The key is setting up a test of an item against a node list.

If you have in one file:

   <code code='interestingCode1' codeSystem='...'/> 

   <code code='interestingCode2' codeSystem='...'/> 

And in another file you have a list of codes:

<RetrieveValueSetResponse ... >
  <ValueSet id="..." 
    displayName="An Interesting Code Set" version="20061023">
    <ConceptList xml:lang="en-US">
      <Concept code="interestingCode1" displayName="Code 1"
      <Concept code="interestingCode2" displayName="Code 2"

You can make the second file available through the document function:

<xsl:variable name='InterestingCodes' 

And then select the observations using the following expression:

<xsl:for-each select='//cda:observation[cda:code/@code = $InterestingCodes//svs:Concept/@code]'>

Inside the for-each, you'd do something interesting with the matched coded.  If you just needed the first on, you could add a [1] to the end of the expression.

According to XSLT and XPath, this will work because:
If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.
So, that's how you'd do it.

1 comment:

  1. Success!
    Thanks, that is one less item on the CCD to BlueButton list.