Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting and HL7 segment to XML

i have an XML that we were able to generate using HAPI libraries and use XSL to change the format of the XML. I am using the following template. The current template looks at the OBX.5 segment for a digital value and then interprets the OBX6 (units of measure). However I am trying to also interpret the OBX6 when they come from one of the clients in a style as duplicates with the caret ^ in between (ex: %^% or mL^mL). My current template ignores this but I would like to be able to get the value of the segment substring before or after the ^.

<xsl:template match="hl7:OBX.6[matches(./../hl7:OBX.5, '^\d+(\.\d+)?$') and index-of($percentList, .) or index-of($mgdlList, .) or index-of($mlList, .) or index-of($mmList, .) or index-of($mgList, .))]">
    <result><xsl:value-of select="./../hl7:OBX.5" /></result>
        <xsl:when test="index-of($percentList, .)">
            <units>%</units>
        </xsl:when>
...
        <xsl:when test="index-of($mlList, .)">
            <units>ml</units>
        </xsl:when>

        <xsl:otherwise>
            <units><xsl:value-of select="./hl7:CE.1" /></units>
        </xsl:otherwise>
...

</xsl:template>

The result should produce

            <result>38.0</result>
            <units>%</units>

from

                <OBX.5>38.0</OBX.5>
                <OBX.6>
                    <CE.1>%^%</CE.1>
                </OBX.6>

Thanks in advance!

like image 415
iowatiger08 Avatar asked Nov 16 '25 17:11

iowatiger08


1 Answers

Use:

tokenize(hl7:CE.1, '\^')[1]

Here is a simple XSLT 2.0 - based verification:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="OBX.6">
  <xsl:sequence select="tokenize(CE.1, '\^')[1]"/>
 </xsl:template>

 <xsl:template match="text()"/>
</xsl:stylesheet>

when this transformation is applied on the following XML document (derived from the provided XML fragment and made well-formed):

<t>
    <OBX.5>38.0</OBX.5>
    <OBX.6>
        <CE.1>%^%</CE.1>
    </OBX.6>
</t>

the wanted, correct result is produced:

%
like image 173
Dimitre Novatchev Avatar answered Nov 19 '25 10:11

Dimitre Novatchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!