Skip to content

Instantly share code, notes, and snippets.

@vaibhavb
Last active August 29, 2015 14:03
Show Gist options
  • Save vaibhavb/0cae48afaf6fd91aac10 to your computer and use it in GitHub Desktop.
Save vaibhavb/0cae48afaf6fd91aac10 to your computer and use it in GitHub Desktop.
HealthVault XSLT for CCD/A documents. Created using the documentation available [here](http://blogs.msdn.com/b/familyhealthguy/archive/2011/07/10/healthvault-data-type-awesomeness.aspx)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="" xmlns:cda="urn:hl7-org:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mif="urn:hl7-org:v3/mif"
xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:h="urn:com.microsoft.wc.thing"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<xsl:output method="xml" indent="no" encoding="utf-8"/>
<xsl:param name="g_debug"/>
<xsl:template name="Write_LF">
<xsl:value-of select="h:lf()"/>
</xsl:template>
<xsl:template name="Write_Line">
<xsl:param name="value"/>
<xsl:if test="$value != ''">
<xsl:value-of select="$value"/>
<xsl:call-template name="Write_LF"/>
</xsl:if>
</xsl:template>
<xsl:template name="Write_Divider">
<xsl:call-template name="Write_Line">
<xsl:with-param name="value">----------</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="Concat">
<xsl:param name="separator"/>
<xsl:param name="nodes"/>
<xsl:variable name="concatResult">
<xsl:for-each select="$nodes">
<xsl:variable name="value" select="string(.)"/>
<xsl:if test="$value != ''">
<xsl:value-of select="$separator"/>
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring-after(string($concatResult), $separator)"/>
</xsl:template>
<xsl:template name="ConcatPhrases">
<xsl:param name="nodes"/>
<xsl:call-template name="Concat">
<xsl:with-param name="nodes" select="$nodes"/>
<xsl:with-param name="separator"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="Write_Concatenated">
<xsl:param name="separator"/>
<xsl:param name="nodes"/>
<xsl:param name="tag"/>
<xsl:variable name="concatResult">
<xsl:for-each select="$nodes">
<xsl:variable name="value" select="string(.)"/>
<xsl:if test="$value != ''">
<xsl:value-of select="$separator"/>
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="value" select="substring-after(string($concatResult), $separator)"/>
<xsl:if test="$value != ''">
<xsl:element name="{$tag}">
<xsl:value-of select="$value"/>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template name="NodeToString">
<xsl:param name="node"/>
<xsl:param name="indent"/>
<xsl:param name="fRecursive"/>
<xsl:variable name="value" select="normalize-space(string($node/text()))"/>
<xsl:variable name="attributes" select="$node/attribute::node()"/>
<xsl:variable name="children" select="$node/child::node()"/>
<xsl:variable name="localName" select="local-name($node)"/>
<xsl:if test="$localName != ''">
<xsl:value-of select="h:lf()"/>
<xsl:value-of select="$indent"/>
<xsl:value-of select="$localName"/>
</xsl:if>
<xsl:if test="$value != ''">
<xsl:if test="$localName != ''">
<xsl:text>: </xsl:text>
<xsl:value-of select="$value"/>
</xsl:if>
</xsl:if>
<xsl:if test="$attributes or $children">
<xsl:for-each select="$attributes">
<xsl:text> [</xsl:text>
<xsl:value-of select="local-name(.)"/>
<xsl:text>=</xsl:text>
<xsl:value-of select="."/>
<xsl:text> ]</xsl:text>
</xsl:for-each>
<xsl:if test="$fRecursive and $children">
<xsl:variable name="childIndent" select="concat($indent, ' ')"/>
<xsl:variable name="hasChildElements"
select="count($node/child::text()) != count($children)"/>
<xsl:if test="$hasChildElements">
<xsl:value-of select="h:lf()"/>
<xsl:value-of select="$indent"/>
<xsl:text>{</xsl:text>
</xsl:if>
<xsl:call-template name="NodesetToString">
<xsl:with-param name="nodeset" select="$children"/>
<xsl:with-param name="indent" select="$childIndent"/>
<xsl:with-param name="fRecursive" select="$fRecursive"/>
</xsl:call-template>
<xsl:if test="$hasChildElements">
<xsl:value-of select="h:lf()"/>
<xsl:value-of select="$indent"/>
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="NodesetToString">
<xsl:param name="nodeset"/>
<xsl:param name="indent"/>
<xsl:param name="fRecursive"/>
<xsl:if test="$nodeset">
<xsl:for-each select="$nodeset">
<xsl:call-template name="NodeToString">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="indent" select="$indent"/>
<xsl:with-param name="fRecursive" select="$fRecursive"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="CopyNodeset">
<xsl:param name="node"/>
<xsl:param name="filter"/>
<xsl:choose>
<xsl:when test="$filter">
<xsl:for-each select="$node">
<xsl:variable name="nodeName" select="local-name()"/>
<xsl:if test="not($nodeName = $filter)">
<xsl:copy>
<xsl:copy-of select="attribute::node()"/>
<xsl:variable name="children" select="child::node()"/>
<xsl:if test="$children">
<xsl:call-template name="CopyNodeset">
<xsl:with-param name="node" select="$children"/>
<xsl:with-param name="filter" select="$filter"/>
</xsl:call-template>
</xsl:if>
</xsl:copy>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$node"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="Throw">
<h:EXCEPTION/>
</xsl:template>
<xsl:template name="Finally">
<xsl:param name="fragment"/>
<xsl:variable name="node" select="msxsl:node-set($fragment)"/>
<xsl:choose>
<xsl:when test="not($node) or $node//h:EXCEPTION">
<xsl:if test="$g_debug">
<xsl:call-template name="Log_Exception">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$node"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CommitSuccessful">
<xsl:param name="nodeset"/>
<xsl:variable name="successful" select="$nodeset[not(descendant-or-self::h:EXCEPTION)]"/>
<xsl:if test="$successful">
<xsl:copy-of select="$successful"/>
</xsl:if>
<xsl:if test="$g_debug and count($successful) != count($nodeset)">
<xsl:call-template name="Log_Exception">
<xsl:with-param name="node" select="$nodeset[descendant-or-self::h:EXCEPTION]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="Log_Exception">
<xsl:param name="node"/>
<xsl:variable name="exceptionString">
<xsl:text>******EXCEPTION*******</xsl:text>
<xsl:value-of select="h:lf()"/>
<xsl:call-template name="NodesetToString">
<xsl:with-param name="nodeset" select="$node"/>
<xsl:with-param name="fRecursive" select="true()"/>
</xsl:call-template>
<xsl:text>**********************</xsl:text>
</xsl:variable>
<xsl:message>
<xsl:value-of select="$exceptionString"/>
</xsl:message>
<xsl:comment><xsl:value-of select="$exceptionString"/></xsl:comment>
</xsl:template>
<xsl:template name="ToInteger">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="$value">
<xsl:variable name="numValue" select="number($value)"/>
<xsl:variable name="numString" select="string($numValue)"/>
<xsl:choose>
<xsl:when test="$numString != 'NaN'">
<xsl:variable name="intValue" select="round($numValue)"/>
<xsl:choose>
<xsl:when test="$intValue = $numValue">
<xsl:value-of select="$numString"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="ToUnsignedInteger">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="$value">
<xsl:variable name="numValue" select="number($value)"/>
<xsl:variable name="numString" select="string($numValue)"/>
<xsl:choose>
<xsl:when test="$numString != 'NaN'">
<xsl:variable name="intValue" select="round($numValue)"/>
<xsl:choose>
<xsl:when test="$intValue = $numValue and $intValue &gt;= 1">
<xsl:value-of select="$numString"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="Write_ISODate">
<xsl:param name="year"/>
<xsl:param name="month"/>
<xsl:param name="day"/>
<xsl:if test="$year != ''">
<xsl:value-of select="format-number($year, '0000')"/>
<xsl:if test="$month != ''">
<xsl:text>-</xsl:text>
<xsl:value-of select="format-number($month, '00')"/>
<xsl:if test="$day != ''">
<xsl:text>-</xsl:text>
<xsl:value-of select="format-number($day, '00')"/>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="Write_ISOTime">
<xsl:param name="hour"/>
<xsl:param name="min"/>
<xsl:param name="sec"/>
<xsl:if test="$hour != ''">
<xsl:text>T</xsl:text>
<xsl:value-of select="format-number($hour, '00')"/>
<xsl:if test="$min != ''">
<xsl:text>:</xsl:text>
<xsl:value-of select="format-number($min, '00')"/>
<xsl:if test="$sec != ''">
<xsl:text>:</xsl:text>
<xsl:value-of select="format-number($sec, '00')"/>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="Write_ISOTimeZone">
<xsl:param name="tz"/>
<xsl:if test="$tz != ''">
<xsl:choose>
<xsl:when test="$tz = 'Z' or $tz = 'GMT'">
<xsl:text>Z</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="offset">
<xsl:choose>
<xsl:when test="starts-with($tz, 'GMT')">
<xsl:value-of select="substring-after($tz, 'GMT')"/>
</xsl:when>
<xsl:when test="starts-with($tz, 'Z')">
<xsl:value-of select="substring-after($tz, 'Z')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$tz"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="starts-with($offset, '+') or starts-with($offset, '-')">
<xsl:variable name="normalized-offset"
select="translate(substring($offset, 2), ':', '')"/>
<xsl:if
test="(string-length($normalized-offset) = 2 or string-length($normalized-offset) = 4)&#xD;&#xA; and string(number($normalized-offset)) != 'NaN'">
<xsl:value-of select="$offset"/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="Write_ISODateTime">
<xsl:param name="year"/>
<xsl:param name="month"/>
<xsl:param name="day"/>
<xsl:param name="hour"/>
<xsl:param name="min"/>
<xsl:param name="sec"/>
<xsl:param name="tz"/>
<xsl:call-template name="Write_ISODate">
<xsl:with-param name="year" select="$year"/>
<xsl:with-param name="month" select="$month"/>
<xsl:with-param name="day" select="$day"/>
</xsl:call-template>
<xsl:call-template name="Write_ISOTime">
<xsl:with-param name="hour" select="$hour"/>
<xsl:with-param name="min" select="$min"/>
<xsl:with-param name="sec" select="$sec"/>
</xsl:call-template>
<xsl:call-template name="Write_ISOTimeZone">
<xsl:with-param name="tz" select="$tz"/>
</xsl:call-template>
</xsl:template>
<xsl:variable name="g_ccrVocabData">
<ccrVocab>
<general>
<healthcare-system>
<export>Healthcare Information System</export>
<import>healthcare information system</import>
</healthcare-system>
<patient>
<export>Patient</export>
<import>patient</import>
</patient>
<priority-primary>
<export>Primary</export>
<import>primary</import>
<import>preferred</import>
<import>primary-preferred</import>
<import>1</import>
</priority-primary>
<priority-secondary>
<export>Secondary</export>
<import>secondary</import>
<import>2</import>
</priority-secondary>
</general>
<measurements>
<inches>
<export>in</export>
<import>in</import>
<import>inch</import>
<import>inches</import>
<ucum>[in_us]</ucum>
</inches>
<feet>
<export>ft</export>
<import>ft</import>
<import>feet</import>
<ucum>[ft_us]</ucum>
</feet>
<kilometers>
<export>km</export>
<import>k</import>
<import>km</import>
<import>kilometers</import>
<import>kilometer</import>
<ucum>km</ucum>
</kilometers>
<meters>
<export>m</export>
<import>m</import>
<import>meter</import>
<import>meters</import>
<ucum>m</ucum>
</meters>
<centimeters>
<export>cm</export>
<import>cm</import>
<import>centimeters</import>
<import>centimetres</import>
<ucum>cm</ucum>
</centimeters>
<miles>
<export>mi</export>
<import>mi</import>
<import>mile</import>
<import>miles</import>
<ucum>[mi_us]</ucum>
</miles>
<pounds>
<export>lbs</export>
<import>lb</import>
<import>lbs</import>
<import>pounds</import>
<ucum>[lb_av]</ucum>
</pounds>
<ounces>
<export>oz</export>
<import>oz</import>
<import>ounce</import>
<import>ounces</import>
<ucum>[oz_av]</ucum>
</ounces>
<kilos>
<export>kg</export>
<import>kg</import>
<import>kgs</import>
<import>kilos</import>
<import>kilogram</import>
<import>kilograms</import>
<ucum>kg</ucum>
</kilos>
<grams>
<export>gm</export>
<import>gm</import>
<import>gram</import>
<import>grams</import>
<ucum>g</ucum>
</grams>
<molarity>
<export>mmol/L</export>
<import>mmol/l</import>
</molarity>
<concentration>
<export>mg/dL</export>
<import>mg/dl</import>
</concentration>
<liters-per-second>
<export>l/s</export>
<import>l/s</import>
<import>liters/second</import>
<import>litres/second</import>
<ucum>L/s</ucum>
</liters-per-second>
<liters>
<export>liters</export>
<import>l</import>
<import>liter</import>
<import>liters</import>
<import>litres</import>
<ucum>L</ucum>
</liters>
<minutes>
<export>min</export>
<import>minutes</import>
<import>minute</import>
<import>min</import>
<import>m</import>
</minutes>
<hour>
<export>hours</export>
<import>h</import>
<import>hr</import>
<import>hour</import>
<import>hours</import>
</hour>
<second>
<export>seconds</export>
<import>s</import>
<import>sec</import>
<import>second</import>
<import>seconds</import>
</second>
<millimeters-mercury>
<export>mmHg</export>
<import>mmhg</import>
<import>mm[Hg]</import>
<ucum>mm[Hg]</ucum>
</millimeters-mercury>
<per-minute>
<export>per min</export>
<import>per min</import>
<import>per minute</import>
<import>per-min</import>
<import>per-minute</import>
<ucum>/min</ucum>
</per-minute>
<milligrams-per-deciliter>
<export>mg/DL</export>
<import>mg/DL</import>
<import>mg/dL</import>
<ucum>mg/dL</ucum>
</milligrams-per-deciliter>
<millimoles-per-liter>
<export>mmol/L</export>
<import>mmol/L</import>
<ucum>mmol/L</ucum>
</millimoles-per-liter>
<percent>
<export>%</export>
<import>%</import>
<ucum>%</ucum>
</percent>
</measurements>
<payer>
<payer-benefit-start-date>
<export>Benefit Start date</export>
<import>benefit start date</import>
<import>start date</import>
<import>effective date</import>
</payer-benefit-start-date>
<payer-benefit-stop-date>
<export>Benefit Stop date</export>
<import>termination date</import>
<import>benefit stop date</import>
<import>expiration date</import>
<import>stop date</import>
<import>end date</import>
</payer-benefit-stop-date>
<payer-primary-health-insurance>
<export>Primary Health Insurance</export>
<import>primary health insurance</import>
</payer-primary-health-insurance>
<payer-plan-code>
<export>Plan code</export>
<import>plan code</import>
<import>plan id</import>
<import>plan number</import>
</payer-plan-code>
<payer-group-number>
<export>Group number</export>
<import>group number</import>
<import>group id</import>
<import>group code</import>
</payer-group-number>
<payer-subscriber-number>
<export>Subscriber number</export>
<import>subscriber number</import>
<import>subscriber id</import>
<import>subscriber code</import>
</payer-subscriber-number>
<payer-carrier-id>
<export>Carrier ID</export>
<import>carrier id</import>
<import>carrier number</import>
<import>carrier code</import>
</payer-carrier-id>
</payer>
<advance-directives>
<directive-start-date>
<export>Start date</export>
<import>start date</import>
</directive-start-date>
<directive-stop-date>
<export>End date</export>
<import>end date</import>
</directive-stop-date>
<directive-treating-physician>
<export>Treating physician</export>
<import>treating clinician</import>
<import>treating physician</import>
<import>treatment provider</import>
<import>attending</import>
<import>attending provider</import>
<import>attending physician</import>
<import>attending clinician</import>
</directive-treating-physician>
<directive-verified-treating-physician>
<export>Verified With Treating Physician</export>
<import>verified with treating physician</import>
</directive-verified-treating-physician>
</advance-directives>
<problem>
<problem-onset-date>
<export>Onset date</export>
<import>onset date</import>
<import>start date</import>
<import>begin date</import>
<import>date of onset</import>
<import>since age</import>
<import>from age</import>
<import>onset</import>
<import>from date</import>
<import>started</import>
<import>diagnosis date</import>
</problem-onset-date>
<problem-end-date>
<export>End date</export>
<import>end date</import>
<import>stop date</import>
<import>ended</import>
<import>to date</import>
</problem-end-date>
<problem-status>
<export-code>
<code>55561003</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>active</displayName>
</export-code>
<export-code>
<code>73425007</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>inactive</displayName>
</export-code>
<export-code>
<code>90734009</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>chronic</displayName>
</export-code>
<export-code>
<code>7087005</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>intermittent</displayName>
</export-code>
<export-code>
<code>255227004</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>recurrent</displayName>
</export-code>
<export-code>
<code>415684004</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>rule out</displayName>
</export-code>
<export-code>
<code>410516002</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>ruled out</displayName>
</export-code>
<export-code>
<code>413322009</code>
<codeSystem>2.16.840.1.113883.1.11.20.13</codeSystem>
<codeSystemName>SNOMED CT</codeSystemName>
<displayName>resolved</displayName>
</export-code>
</problem-status>
</problem>
<alerts>
<allergy>
<export>Allergy</export>
<import>allergy</import>
<import>adverse reaction</import>
</allergy>
<allergy-start-date>
<export>Start date</export>
<import>start date</import>
<import>onset date</import>
<import>date of onset</import>
<import>since age</import>
<import>from date</import>
<import>onset</import>
<import>initial occurrence</import>
</allergy-start-date>
</alerts>
<medication>
<medication-date-range>
<export>range</export>
<import>range</import>
<import>range </import>
</medication-date-range>
<medication-start-date>
<export>Start date</export>
<import>start date</import>
<import>administration date</import>
<import>since age</import>
<import>from age</import>
<import>from date</import>
<import>begin date</import>
<import>started</import>
</medication-start-date>
<medication-stop-date>
<export>Stop date</export>
<import>stop date</import>
<import>end date</import>
<import>to date</import>
<import>stopped</import>
</medication-stop-date>
<medication-prescription-date>
<export>Prescription date</export>
<import>prescription date</import>
<import>prescribed date</import>
<import>date prescribed</import>
<import>prescribed</import>
</medication-prescription-date>
<medication-prescribing-provider>
<export>Prescribing provider</export>
<import>prescribing provider</import>
<import>prescribing physician</import>
<import>prescribing clinician</import>
<import>prescriber</import>
</medication-prescribing-provider>
</medication>
<immunization>
<immunization-date>
<export>Immunization date</export>
<import>immunization date</import>
<import>administration date</import>
<import>administered</import>
<import>start date</import>
</immunization-date>
<immunization-lot-number>
<export>Immunization lot number</export>
<import>immunization lot number</import>
<import>lot number</import>
<import>lot</import>
</immunization-lot-number>
</immunization>
<vital-signs>
<blood-glucose>
<export>Blood glucose</export>
<export-code>
<code>434912009</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Blood glucose</displayName>
</export-code>
<import>glucose, plasma</import>
<import>glucose, serum</import>
<import>plasma</import>
<import>whole blood</import>
<import>blood glucose</import>
<import>blood glucose (before breakfast)</import>
<import>blood glucose (before lunch)</import>
<import>blood glucose (before supper)</import>
<import>blood glucose (before dinner)</import>
<import>blood glucose (bedtime)</import>
<import>blood glucose (night)</import>
<import-code>
<code>434912009</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</blood-glucose>
<blood-oxygen-saturation>
<export>Blood oxygen saturation</export>
<export-code>
<code>103228002</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Blood oxygen saturation</displayName>
</export-code>
<import>blood oxygen saturation</import>
</blood-oxygen-saturation>
<blood-pressure>
<export>Blood Pressure</export>
<export-code>
<code>75367002</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Blood pressure</displayName>
</export-code>
<import>blood pressure</import>
</blood-pressure>
<blood-pressure-systolic>
<export>Systolic Blood Pressure</export>
<export-code>
<code>271649006</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Systolic blood pressure</displayName>
</export-code>
<import>systolic blood pressure</import>
<import>systolic</import>
<import>bp (systolic)</import>
<import>systolic bp-sitting</import>
<import>systolic bp</import>
<import>bp sys</import>
<import>systolic bp sitting</import>
</blood-pressure-systolic>
<blood-pressure-diastolic>
<export>Diastolic Blood Pressure</export>
<export-code>
<code>271650006</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Diastolic blood pressure</displayName>
</export-code>
<import>diastolic blood pressure</import>
<import>diastolic</import>
<import>bp (diastolic)</import>
<import>diastolic bp-sitting</import>
<import>diastolic bp</import>
<import>bp dias</import>
<import>diastolic bp sitting</import>
</blood-pressure-diastolic>
<blood-pressure-pulse>
<export>Pulse Rate</export>
<export-code>
<code>364075005</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Heart rate</displayName>
</export-code>
<import>pulse rate</import>
<import>pulse</import>
<import>pul rate</import>
<import>pulse-rate</import>
<import>heart beat</import>
<import>heart rate</import>
</blood-pressure-pulse>
<cholesterol>
<export>Cholesterol</export>
<import>cholesterol</import>
</cholesterol>
<cholesterol-ldl>
<export>LDL Cholesterol</export>
<export-code>
<code>102739008</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Low density lipoprotein (LDL) cholesterol</displayName>
</export-code>
<import>ldl cholesterol</import>
<import>ldl</import>
<import>cholesterol ldl</import>
<import>ldl cholesterol calc</import>
<import>ldl-cholesterol</import>
<import>low density lipoprotein (LDL) cholesterol</import>
<import-code>
<code>55440-2</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>2089-1</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>13457-7</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>18262-6</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>49132-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>18261-8</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>102739008</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</cholesterol-ldl>
<cholesterol-hdl>
<export>HDL Cholesterol</export>
<export-code>
<code>102737005</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>High density lipoprotein (HDL) cholesterol</displayName>
</export-code>
<import>hdl cholesterol</import>
<import>hdl</import>
<import>cholesterol hdl</import>
<import>hdl cholesterol calc</import>
<import>hdl-cholesterol</import>
<import>high density lipoprotein (HDL) cholesterol</import>
<import-code>
<code>54372-8</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>2085-9</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>49130-8</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>18263-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>102737005</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</cholesterol-hdl>
<cholesterol-total>
<export>Total Cholesterol</export>
<export-code>
<code>301860006</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Total cholesterol</displayName>
</export-code>
<import>total cholesterol</import>
<import>total</import>
<import>cholesterol total</import>
<import>cholesterol, total</import>
</cholesterol-total>
<cholesterol-triglycerides>
<export>Triglycerides</export>
<export-code>
<code>85600001</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Triglycerides</displayName>
</export-code>
<import>triglycerides</import>
<import>triglyceride</import>
<import>trig</import>
<import>triglycerides, blood</import>
</cholesterol-triglycerides>
<exercise-distance>
<export>Exercise distance</export>
<import>exercise distance</import>
</exercise-distance>
<exercise-duration>
<export>Exercise duration</export>
<import>exercise duration</import>
</exercise-duration>
<exercise-details>
<export>Exercise details</export>
<import>exercise details</import>
</exercise-details>
<height>
<export>Height</export>
<export-code>
<code>50373000</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Body height</displayName>
</export-code>
<import>height</import>
<import>hgt</import>
<import>body height</import>
<import-code>
<code>3137-7</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>3138-5</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8301-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8302-2</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8303-0</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8304-8</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8305-5</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8306-3</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8307-1</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8308-9</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>50373000</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</height>
<peak-flow>
<export>Peak Flow</export>
<import>peak flow</import>
</peak-flow>
<peak-flow-fev1>
<export>Forced Expiratory Volume in One Second (FEV1)</export>
<export-code>
<code>59328004</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Forced expiratory volume in 1 second</displayName>
</export-code>
<import>fev1</import>
<import>forced expiratory volume in one second (fev1)</import>
<import>forced expiratory volume in 1 second</import>
<import-code>
<code>59328004</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</peak-flow-fev1>
<peak-flow-fev6>
<export>Forced Expiratory Volume in Six Seconds (FEV6)</export>
<export-code>
<displayName>Forced expiratory volume in 6 seconds</displayName>
</export-code>
<import>fev6</import>
<import>forced expiratory volume in six seconds (fev6)</import>
<import>forced expiratory volume in 6 seconds</import>
</peak-flow-fev6>
<peak-flow-pef>
<export>Peak Expiratory Flow Rate (PEFR)</export>
<export-code>
<code>18491006</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Peak expiratory flow rate</displayName>
</export-code>
<import>pef</import>
<import>pefr</import>
<import>peak expiratory flow rate (pef)</import>
<import>peak expiratory flow rate (pefr)</import>
<import-code>
<code>18491006</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</peak-flow-pef>
<radiology-lab-results>
<export>radiology results</export>
<import>imaging - x-ray</import>
<import>ultrasound</import>
<import>ct</import>
<import>mri</import>
<import>angiography</import>
<import>cardiac echo</import>
<import>nuclear medicine</import>
<import>radiology results</import>
</radiology-lab-results>
<weight>
<export>Weight</export>
<export-code>
<code>27113001</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
<displayName>Body weight</displayName>
</export-code>
<import>weight</import>
<import>wgt</import>
<import>body weight</import>
<import-code>
<code>18833-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>29463-7</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>3141-9</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>3142-7</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>50064-5</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8335-2</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8338-6</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8339-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8340-2</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8341-0</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8342-8</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8343-6</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8344-4</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8345-1</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8346-9</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8347-7</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8348-5</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8349-3</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8350-1</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>8351-9</code>
<codeSystem>2.16.840.1.113883.6.1</codeSystem>
</import-code>
<import-code>
<code>27113001</code>
<codeSystem>2.16.840.1.113883.6.96</codeSystem>
</import-code>
</weight>
</vital-signs>
<results>
<result-collection-date>
<export>Collection start date</export>
<import>collection start date</import>
<import>collection date time</import>
<import>collection time</import>
<import>measurement start date</import>
<import>measurement time</import>
<import>assessment time</import>
<import>performed</import>
</result-collection-date>
<result-ordering-provider>
<export>Ordering provider</export>
<import>ordering provider</import>
<import>ordering physician</import>
<import>ordering clinician</import>
<import>ordered by</import>
</result-ordering-provider>
<result-discharge-summary>
<export>Discharge summary</export>
<import>discharge summary</import>
</result-discharge-summary>
<discharge-summary-create-date>
<export>Created</export>
<import>clinical report creation date</import>
<import>transcribed</import>
<import>created</import>
<import>creation date</import>
</discharge-summary-create-date>
<discharge-summary-comment>
<export>Discharge summary</export>
<import>discharge summary</import>
<import>clinical report</import>
</discharge-summary-comment>
<discharge-summary-primary-provider>
<export>Primary provider</export>
<import>primary provider</import>
</discharge-summary-primary-provider>
<discharge-summary-secondary-provider>
<export>Secondary provider</export>
<import>secondary provider</import>
</discharge-summary-secondary-provider>
<discharge-summary-principal-procedure-physician>
<export>Principal procedure physician</export>
<import>principal procedure physician</import>
</discharge-summary-principal-procedure-physician>
<discharge-summary-primary-endorsement>
<export>Primary provider endorsement</export>
<import>primary provider endorsement</import>
</discharge-summary-primary-endorsement>
<discharge-summary-secondary-endorsement>
<export>Secondary provider endorsement</export>
<import>secondary provider endorsement</import>
</discharge-summary-secondary-endorsement>
<discharge-summary-discharge-date>
<export>Discharge date</export>
<import>discharge date</import>
</discharge-summary-discharge-date>
</results>
<procedures>
<procedure-date>
<export>Performed</export>
<import>performed</import>
<import>start date</import>
<import>procedure date</import>
<import>occurred</import>
<import>service date</import>
</procedure-date>
<procedure-primary-provider>
<export>Treating clinician</export>
<import>treating clinician</import>
<import>treating physician</import>
<import>treatment provider</import>
<import>primary care provider</import>
<import>primary care physician</import>
<import>primary care clinician</import>
<import>administered by</import>
<import>performed by</import>
</procedure-primary-provider>
<procedure-secondary-provider>
<export>Secondary care provider</export>
<import>secondary care provider</import>
<import>secondary care physician</import>
<import>secondary care clinician</import>
</procedure-secondary-provider>
</procedures>
<encounter>
<encounter-date>
<export>Encounter date</export>
<import>encounter date</import>
<import>occurred</import>
</encounter-date>
<encounter-pending>
<export>Pending</export>
<import>pending</import>
<import>scheduled</import>
</encounter-pending>
<appointment-date>
<export>Appointment date</export>
<import>appointment date</import>
<import>encounter date</import>
<import>scheduled date</import>
</appointment-date>
</encounter>
</ccrVocab>
</xsl:variable>
<xsl:variable name="g_ccrVocab" select="msxsl:node-set($g_ccrVocabData)/ccrVocab"/>
<xsl:variable name="g_ccdVocabData">
<ccdVocab>
<results>
<observation-status>
<valid-export>normal</valid-export>
<valid-export>aborted</valid-export>
<valid-export>active</valid-export>
<valid-export>cancelled</valid-export>
<valid-export>completed</valid-export>
<valid-export>held</valid-export>
<valid-export>new</valid-export>
<valid-export>suspended</valid-export>
<valid-export>nullified</valid-export>
<valid-export>obsolete</valid-export>
</observation-status>
<radiology>
<export>Imaging</export>
<export-code>
<code>363679005</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
<displayName>Imaging</displayName>
</export-code>
<import>Imaging</import>
<import>X-ray</import>
<import>CT</import>
<import>MRI</import>
<import>Nuclear Medicine</import>
<import>Angiography</import>
<import>Cardiac Echo</import>
<import>Ultrasound</import>
<import-code>
<code>363679005</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>363680008</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>16310003</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>77477000</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>113091000</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>371572003</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>77343006</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
<import-code>
<code>40701008</code>
<codeSystem>2.16.840.1.113883.1.11.20.16</codeSystem>
</import-code>
</radiology>
</results>
</ccdVocab>
</xsl:variable>
<xsl:variable name="g_ccdVocab" select="msxsl:node-set($g_ccdVocabData)/ccdVocab"/>
<xsl:output method="xml"/>
<xsl:variable name="thingid" select="/thing/thing-id"/>
<xsl:variable name="version" select="/thing/thing-id/@version-stamp"/>
<xsl:variable name="v_vitals" select="$g_ccrVocab/vital-signs"/>
<xsl:variable name="v_measure" select="$g_ccrVocab/measurements"/>
<xsl:variable name="v_results" select="$g_ccdVocab/results"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="cda:ClinicalDocument">
<xsl:apply-templates select="cda:ClinicalDocument"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/thing/data-xml/*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="cda:ClinicalDocument">
<xsl:variable name="payer_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.9</id>
<id>2.16.840.1.113883.10.20.22.2.18</id>
</ids>
</xsl:variable>
<xsl:variable name="payer_templates" select="msxsl:node-set($payer_template_ids)"/>
<xsl:variable name="payer_activity_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.20</id>
<id>2.16.840.1.113883.10.20.22.4.60</id>
</ids>
</xsl:variable>
<xsl:variable name="payer_activity" select="msxsl:node-set($payer_activity_ids)"/>
<xsl:variable name="policy_activity_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.26</id>
<id>2.16.840.1.113883.10.20.22.4.61</id>
</ids>
</xsl:variable>
<xsl:variable name="policy_activity" select="msxsl:node-set($policy_activity_ids)"/>
<xsl:call-template name="Payers">
<xsl:with-param name="payers"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$payer_templates/ids/id]/cda:entry/cda:act[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root=$payer_activity/ids/id]/cda:entryRelationship[./cda:act/cda:templateId/@root=$policy_activity/ids/id]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$payer_templates/ids/id and ./cda:entry/cda:act[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root=$payer_activity/ids/id]/cda:entryRelationship/cda:act[./cda:templateId/@root=$policy_activity/ids/id]]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="ad_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.1</id>
<id>2.16.840.1.113883.10.20.22.2.21</id>
<id>2.16.840.1.113883.10.20.22.2.21.1</id>
</ids>
</xsl:variable>
<xsl:variable name="advanced_directives_templates" select="msxsl:node-set($ad_template_ids)"/>
<xsl:variable name="advanced_directives_observation_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.17</id>
<id>2.16.840.1.113883.10.20.22.4.48</id>
</ids>
</xsl:variable>
<xsl:variable name="advanced_directives_observation"
select="msxsl:node-set($advanced_directives_observation_ids)"/>
<xsl:call-template name="AdvanceDirectives">
<xsl:with-param name="directives"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$advanced_directives_templates/ids/id]/cda:entry/cda:observation[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root=$advanced_directives_observation/ids/id]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$advanced_directives_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="fh_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.4</id>
<id>2.16.840.1.113883.10.20.22.2.15</id>
</ids>
</xsl:variable>
<xsl:variable name="family_history_templates" select="msxsl:node-set($fh_template_ids)"/>
<xsl:call-template name="FamilyHistory">
<xsl:with-param name="histories"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$family_history_templates/ids/id]/cda:entry"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$family_history_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="med_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.8</id>
<id>2.16.840.1.113883.10.20.22.2.1</id>
<id>2.16.840.1.113883.10.20.22.2.1.1</id>
</ids>
</xsl:variable>
<xsl:variable name="medication_templates" select="msxsl:node-set($med_template_ids)"/>
<xsl:call-template name="Medications">
<xsl:with-param name="medications"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$medication_templates/ids/id]/cda:entry/cda:substanceAdministration[not(./@nullFlavor or ./@negationInd = 'true')]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$medication_templates/ids/id and ./cda:entry/cda:substanceAdministration[not(./@nullFlavor or ./@negationInd = 'true')]]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="immunization_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.6</id>
<id>2.16.840.1.113883.10.20.22.2.2</id>
<id>2.16.840.1.113883.10.20.22.2.2.1</id>
</ids>
</xsl:variable>
<xsl:variable name="immunization_templates"
select="msxsl:node-set($immunization_template_ids)"/>
<xsl:variable name="immunization_administration_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.24</id>
<id>2.16.840.1.113883.10.20.22.4.52</id>
</ids>
</xsl:variable>
<xsl:variable name="immunization_administration"
select="msxsl:node-set($immunization_administration_ids)"/>
<xsl:call-template name="Immunizations">
<xsl:with-param name="immunizations"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$immunization_templates/ids/id]/cda:entry/cda:substanceAdministration[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root = $immunization_administration/ids/id]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$immunization_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="vs_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.16</id>
<id>2.16.840.1.113883.10.20.22.2.4</id>
<id>2.16.840.1.113883.10.20.22.2.4.1</id>
</ids>
</xsl:variable>
<xsl:variable name="vital_signs_templates" select="msxsl:node-set($vs_template_ids)"/>
<xsl:call-template name="VitalSigns">
<xsl:with-param name="vital-signs"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$vital_signs_templates/ids/id]/cda:entry"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$vital_signs_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="lr_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.14</id>
<id>2.16.840.1.113883.3.88.11.83.122</id>
<id>1.3.6.1.4.1.19376.1.5.3.1.3.28</id>
<id>2.16.840.1.113883.10.20.22.2.3</id>
<id>2.16.840.1.113883.10.20.22.2.3.1</id>
</ids>
</xsl:variable>
<xsl:variable name="lab_result_templates" select="msxsl:node-set($lr_template_ids)"/>
<xsl:call-template name="LabResults">
<xsl:with-param name="lab-results"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$lab_result_templates/ids/id]/cda:entry"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$lab_result_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="procedure_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.12</id>
<id>2.16.840.1.113883.10.20.22.2.7</id>
<id>2.16.840.1.113883.10.20.22.2.7.1</id>
</ids>
</xsl:variable>
<xsl:variable name="procedure_templates" select="msxsl:node-set($procedure_template_ids)"/>
<xsl:call-template name="Procedures">
<xsl:with-param name="procedures"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$procedure_templates/ids/id]/cda:entry"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$procedure_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="encounter_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.3</id>
<id>2.16.840.1.113883.10.20.22.2.22</id>
<id>2.16.840.1.113883.10.20.22.2.22.1</id>
</ids>
</xsl:variable>
<xsl:variable name="encounter_templates" select="msxsl:node-set($encounter_template_ids)"/>
<xsl:call-template name="Encounters">
<xsl:with-param name="encounters"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$encounter_templates/ids/id]/cda:entry/cda:encounter"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$encounter_templates/ids/id and ./cda:entry/cda:encounter]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="allergies_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.2</id>
<id>2.16.840.1.113883.10.20.22.2.6</id>
<id>2.16.840.1.113883.10.20.22.2.6.1</id>
</ids>
</xsl:variable>
<xsl:variable name="allergies_templates" select="msxsl:node-set($allergies_template_ids)"/>
<xsl:variable name="allergy_activity_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.27</id>
<id>2.16.840.1.113883.10.20.22.4.30</id>
</ids>
</xsl:variable>
<xsl:variable name="allergy_activities" select="msxsl:node-set($allergy_activity_ids)"/>
<xsl:variable name="allergy_observation_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.18</id>
<id>2.16.840.1.113883.10.20.22.4.7</id>
</ids>
</xsl:variable>
<xsl:variable name="allergy_observations" select="msxsl:node-set($allergy_observation_ids)"/>
<xsl:call-template name="Allergies">
<xsl:with-param name="allergies"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$allergies_templates/ids/id]/cda:entry/cda:act[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root = $allergy_activities/ids/id]/cda:entryRelationship/cda:observation[./cda:templateId/@root = $allergy_observations/ids/id and ((./cda:value/@code and ./cda:value/@code != '160244002') or not(./cda:value/@code))]"/>
<xsl:with-param name="effectiveTime"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$allergies_templates/ids/id]/cda:entry/cda:act[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root = $allergy_activities/ids/id]/cda:entryRelationship/cda:effectiveTime"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$allergies_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="conditions_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.11</id>
<id>2.16.840.1.113883.10.20.22.2.5</id>
<id>2.16.840.1.113883.10.20.22.2.5.1</id>
</ids>
</xsl:variable>
<xsl:variable name="conditions_templates" select="msxsl:node-set($conditions_template_ids)"/>
<xsl:variable name="condition_activity_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.27</id>
<id>2.16.840.1.113883.10.20.22.4.3</id>
</ids>
</xsl:variable>
<xsl:variable name="condition_activity" select="msxsl:node-set($condition_activity_ids)"/>
<xsl:variable name="condition_observation_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.28</id>
<id>2.16.840.1.113883.10.20.22.4.4</id>
</ids>
</xsl:variable>
<xsl:variable name="condition_observation"
select="msxsl:node-set($condition_observation_ids)"/>
<xsl:call-template name="Conditions">
<xsl:with-param name="conditions"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$conditions_templates/ids/id]/cda:entry/cda:act[not(./@nullFlavor or ./@negationInd = 'true') and ./cda:templateId/@root=$condition_activity/ids/id]/cda:entryRelationship/cda:observation[./cda:templateId/@root=$condition_observation/ids/id]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$conditions_templates/ids/id]/cda:text"
/>
</xsl:call-template>
<xsl:variable name="appointment_template_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.10</id>
<id>2.16.840.1.113883.10.20.22.2.10</id>
</ids>
</xsl:variable>
<xsl:variable name="appointment_templates"
select="msxsl:node-set($appointment_template_ids)"/>
<xsl:variable name="appointment_encounter_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.25</id>
<id>2.16.840.1.113883.10.20.22.4.40</id>
</ids>
</xsl:variable>
<xsl:variable name="appointment_encounter"
select="msxsl:node-set($appointment_encounter_ids)"/>
<xsl:call-template name="Appointments">
<xsl:with-param name="appointments"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$appointment_templates/ids/id]/cda:entry/cda:encounter[./cda:templateId/@root= $appointment_encounter/ids/id]"/>
<xsl:with-param name="narrative-block"
select="cda:component/cda:structuredBody/cda:component/cda:section[./cda:templateId/@root=$appointment_templates/ids/id]/cda:text"
/>
</xsl:call-template>
</xsl:template>
<xsl:template name="Payers">
<xsl:param name="payers"/>
<xsl:param name="narrative-block"/>
<xsl:for-each select="$payers">
<xsl:variable name="payer" select="cda:act"/>
<xsl:variable name="sequence-number" select="cda:sequenceNumber/@value"/>
<xsl:if test="$payer">
<thing>
<type-id>9366440c-ec81-4b89-b231-308a4c4d70ed</type-id>
<data-xml>
<payer>
<plan-name>
<xsl:choose>
<xsl:when
test="$payer/cda:performer/cda:assignedEntity/cda:representedOrganization/cda:name and&#xD;&#xA; $payer/cda:performer/cda:assignedEntity/cda:representedOrganization/cda:name != ''">
<xsl:value-of
select="$payer/cda:performer/cda:assignedEntity/cda:representedOrganization/cda:name"
/>
</xsl:when>
<xsl:otherwise>Unknown</xsl:otherwise>
</xsl:choose>
</plan-name>
<xsl:if test="$payer/cda:code">
<coverage-type>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value" select="$payer/cda:code"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</coverage-type>
</xsl:if>
<xsl:call-template name="OptionalIdElement">
<xsl:with-param name="element-name" select="'carrier-id'"/>
<xsl:with-param name="id"
select="$payer/cda:performer[@typeCode='PRF']/cda:assignedEntity/cda:id"
/>
</xsl:call-template>
<xsl:call-template name="OptionalIdElement">
<xsl:with-param name="element-name" select="'group-num'"/>
<xsl:with-param name="id" select="$payer/cda:id"/>
</xsl:call-template>
<xsl:variable name="payer_performer_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.19</id>
<id>2.16.840.1.113883.10.20.22.4.87</id>
</ids>
</xsl:variable>
<xsl:variable name="payer_performer"
select="msxsl:node-set($payer_performer_ids)"/>
<xsl:choose>
<xsl:when
test="$payer/cda:entryRelationship[@typeCode='REFR']/cda:act[./cda:templateId/@root = $payer_performer/ids/id]/cda:id">
<xsl:call-template name="OptionalIdElement">
<xsl:with-param name="element-name" select="'plan-code'"/>
<xsl:with-param name="id"
select="$payer/cda:entryRelationship[@typeCode='REFR']/cda:act[./cda:templateId/@root = $payer_performer/ids/id]/cda:id"
/>
</xsl:call-template>
</xsl:when>
<xsl:when
test="$payer/cda:entryRelationship[@typeCode='REFR']/cda:act[@classCode='ACT' and @moodCode='DEF']">
<xsl:call-template name="OptionalIdElement">
<xsl:with-param name="element-name" select="'plan-code'"/>
<xsl:with-param name="id"
select="$payer/cda:entryRelationship[@typeCode='REFR']/cda:act[@classCode='ACT' and @moodCode='DEF']/cda:id"
/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:call-template name="OptionalIdElement">
<xsl:with-param name="element-name" select="'subscriber-id'"/>
<xsl:with-param name="id"
select="$payer/cda:participant[@typeCode='HLD']/cda:participantRole/cda:id"
/>
</xsl:call-template>
<xsl:if
test="$payer/cda:participant[@typeCode='COV']/cda:participantRole/cda:code/@code">
<person-code>
<xsl:value-of
select="$payer/cda:participant[@typeCode='COV']/cda:participantRole/cda:code/@code"
/>
</person-code>
</xsl:if>
<xsl:variable name="name">
<xsl:call-template name="PN_To_String">
<xsl:with-param name="pn"
select="$payer/cda:participant[@typeCode='HLD']/cda:participantRole/cda:playingEntity/cda:name"
/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$name != ''">
<subscriber-name>
<xsl:value-of select="$name"/>
</subscriber-name>
</xsl:if>
<xsl:if test="$sequence-number and $sequence-number = '1'">
<is-primary>true</is-primary>
</xsl:if>
<xsl:if
test="$payer/cda:participant[@typeCode='COV']/cda:time/cda:high[not(@nullFlavor)]">
<expiration-date>
<xsl:call-template name="DateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="$payer/cda:participant[@typeCode='COV']/cda:time/cda:high/@value"
/>
</xsl:call-template>
</expiration-date>
</xsl:if>
<xsl:if
test="$payer/cda:performer[@typeCode='PRF']/cda:assignedEntity and&#xD;&#xA; $payer/cda:performer[@typeCode='PRF']/cda:assignedEntity != ''">
<contact>
<xsl:call-template name="ContactFromCCDAssignedEntity">
<xsl:with-param name="entity"
select="$payer/cda:performer[@typeCode='PRF']/cda:assignedEntity"
/>
</xsl:call-template>
</contact>
</xsl:if>
</payer>
<xsl:for-each select="$payer/../..">
<xsl:call-template name="AddCommonSection"/>
</xsl:for-each>
</data-xml>
</thing>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="OptionalIdElement">
<xsl:param name="element-name"/>
<xsl:param name="id"/>
<xsl:choose>
<xsl:when test="$id/@extension">
<xsl:element name="{$element-name}">
<xsl:value-of select="$id/@extension"/>
</xsl:element>
</xsl:when>
<xsl:when test="$id/@root">
<xsl:element name="{$element-name}">
<xsl:value-of select="$id/@root"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="AdvanceDirectives">
<xsl:param name="directives"/>
<xsl:param name="narrative-block"/>
<xsl:for-each select="$directives">
<thing>
<type-id>822a5e5a-14f1-4d06-b92f-8f3f1b05218f</type-id>
<data-xml>
<directive>
<start-date>
<xsl:choose>
<xsl:when test="cda:effectiveTime/cda:low/@value">
<xsl:call-template name="ApproxDateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:low/@value"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="cda:effectiveTime/@value">
<xsl:call-template name="ApproxDateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/@value"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<descriptive>Unknown</descriptive>
</xsl:otherwise>
</xsl:choose>
</start-date>
<xsl:choose>
<xsl:when test="cda:effectiveTime/cda:high/@value">
<stop-date>
<xsl:call-template name="ApproxDateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:high/@value"/>
</xsl:call-template>
</stop-date>
</xsl:when>
<xsl:otherwise>
<stop-date>
<descriptive>Unknown</descriptive>
</stop-date>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="descriptionValue">
<xsl:call-template name="StringFromAny">
<xsl:with-param name="value" select="cda:value"/>
<xsl:with-param name="reference-text" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="descriptionTranslation">
<xsl:call-template name="StringFromAny">
<xsl:with-param name="value" select="cda:value/cda:translation"/>
<xsl:with-param name="reference-text" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="descriptionText">
<xsl:call-template name="StringFromED">
<xsl:with-param name="value" select="cda:text"/>
<xsl:with-param name="reference-text" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$descriptionValue != ''">
<description>
<xsl:value-of select="$descriptionValue"/>
</description>
</xsl:when>
<xsl:when test="$descriptionTranslation != ''">
<description>
<xsl:value-of select="$descriptionTranslation"/>
</description>
</xsl:when>
<xsl:when test="$descriptionText != ''">
<description>
<xsl:value-of select="$descriptionText"/>
</description>
</xsl:when>
</xsl:choose>
</directive>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:for-each>
</xsl:template>
<xsl:variable name="fh_observation_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.22</id>
<id>2.16.840.1.113883.10.20.22.4.46</id>
</ids>
</xsl:variable>
<xsl:variable name="family_history_observation" select="msxsl:node-set($fh_observation_ids)"/>
<xsl:template name="FamilyHistory">
<xsl:param name="histories"/>
<xsl:param name="narrative-block"/>
<xsl:variable name="fh_organizer_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.23</id>
<id>2.16.840.1.113883.10.20.22.4.45</id>
</ids>
</xsl:variable>
<xsl:variable name="family_history_organizer" select="msxsl:node-set($fh_organizer_ids)"/>
<xsl:for-each select="$histories">
<xsl:call-template name="Organizer-familyhistory_To_family-history">
<xsl:with-param name="history"
select="cda:organizer[./cda:templateId/@root = $family_history_organizer/ids/id]"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
<xsl:if
test="cda:observation[./cda:templateId/@root = $family_history_observation/ids/id]">
<thing>
<type-id>4a04fcc8-19c1-4d59-a8c7-2031a03f21de</type-id>
<data-xml>
<family-history>
<xsl:call-template name="Observation-familyhistory_To_family-history">
<xsl:with-param name="history"
select="cda:observation[./cda:templateId/@root = $family_history_observation/ids/id]"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</family-history>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="Organizer-familyhistory_To_family-history">
<xsl:param name="history"/>
<xsl:param name="narrative-block"/>
<xsl:for-each select="$history">
<thing>
<type-id>4a04fcc8-19c1-4d59-a8c7-2031a03f21de</type-id>
<data-xml>
<family-history>
<xsl:variable name="subject" select="cda:subject/cda:relatedSubject"/>
<xsl:variable name="conditions"
select="cda:component/cda:observation[./cda:templateId/@root = $family_history_observation/ids/id]"/>
<xsl:variable name="fm_cause_of_death_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.42</id>
<id>2.16.840.1.113883.10.20.22.4.47</id>
</ids>
</xsl:variable>
<xsl:variable name="fm_cause_of_death"
select="msxsl:node-set($fm_cause_of_death_ids)"/>
<xsl:variable name="cause-of-death"
select="cda:component/cda:observation[./cda:templateId/@root = $fm_cause_of_death/ids/id]"/>
<xsl:call-template name="Observation-familyhistory_To_family-history">
<xsl:with-param name="history" select="$conditions"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
<xsl:if test="$cause-of-death">
<xsl:call-template name="Observation-familyhistory_To_family-history">
<xsl:with-param name="history" select="$cause-of-death"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="resolution" select="'Cause of death'"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$subject">
<relative>
<xsl:choose>
<xsl:when test="$subject/cda:code">
<relationship>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value"
select="$subject/cda:code"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</relationship>
</xsl:when>
<xsl:otherwise>
<relationship>
<text>Unknown</text>
</relationship>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$subject/cda:subject/cda:birthTime/@value">
<date-of-birth>
<xsl:call-template name="ApproxDateFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="$subject/cda:subject/cda:birthTime/@value"/>
</xsl:call-template>
</date-of-birth>
</xsl:if>
<xsl:if xmlns:sdtc="urn:hl7-org:sdtc"
test="$subject/cda:subject/sdtc:deceasedTime/@value">
<date-of-death>
<xsl:call-template name="ApproxDateFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="$subject/cda:subject/sdtc:deceasedTime/@value"
/>
</xsl:call-template>
</date-of-death>
</xsl:if>
</relative>
</xsl:if>
</family-history>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:for-each>
</xsl:template>
<xsl:template name="Observation-familyhistory_To_family-history">
<xsl:param name="history"/>
<xsl:param name="narrative-block"/>
<xsl:param name="resolution"/>
<xsl:for-each select="$history">
<condition>
<name><xsl:choose><xsl:when
test="(cda:value/@displayName or cda:value/cda:originalText or cda:value/@code) and not(cda:value/@nullFlavor)"
><xsl:call-template name="CodableValueFromAny"><xsl:with-param
name="value" select="cda:value"/><xsl:with-param
name="reference-text" select="$narrative-block"
/></xsl:call-template></xsl:when><xsl:when test="cda:text"
><text><xsl:call-template name="StringFromED"><xsl:with-param
name="value" select="cda:text"/><xsl:with-param
name="reference-text" select="$narrative-block"
/></xsl:call-template></text></xsl:when><xsl:when
test="cda:value/cda:translation"><xsl:call-template
name="CodableValueFromAny"><xsl:with-param name="value"
select="cda:value/cda:translation"/><xsl:with-param
name="reference-text" select="$narrative-block"/><xsl:with-param
name="type" select="cda:value/@xsi:type"
/></xsl:call-template></xsl:when><xsl:otherwise><text>Unknown</text></xsl:otherwise></xsl:choose></name>
<xsl:choose>
<xsl:when test="cda:effectiveTime/cda:low/@value">
<onset-date>
<xsl:call-template name="ApproxDateFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:low/@value"/>
</xsl:call-template>
</onset-date>
</xsl:when>
<xsl:when test="cda:effectiveTime/@value">
<onset-date>
<xsl:call-template name="ApproxDateFromCCDNumericDate">
<xsl:with-param name="numericDate" select="cda:effectiveTime/@value"
/>
</xsl:call-template>
</onset-date>
</xsl:when>
</xsl:choose>
<xsl:if test="cda:effectiveTime/cda:high/@value">
<resolution-date>
<xsl:call-template name="ApproxDateFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:high/@value"/>
</xsl:call-template>
</resolution-date>
</xsl:if>
<xsl:if test="$resolution and $resolution != ''">
<resolution>
<xsl:value-of select="$resolution"/>
</resolution>
</xsl:if>
</condition>
</xsl:for-each>
</xsl:template>
<xsl:template name="Medications">
<xsl:param name="medications"/>
<xsl:param name="narrative-block"/>
<xsl:for-each select="$medications">
<xsl:variable name="try">
<xsl:variable name="medication-code"
select="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"/>
<xsl:variable name="brand-name"
select="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:name"/>
<thing>
<type-id>30cafccc-047d-4288-94ef-643571f7919d</type-id>
<data-xml>
<medication>
<xsl:choose>
<xsl:when
test="$brand-name and $brand-name != '' and not($medication-code/@displayName)">
<name><text><xsl:value-of select="$brand-name"
/></text><xsl:call-template name="CodedValueFromCCDCode"
><xsl:with-param name="code-value"
select="$medication-code"
/></xsl:call-template></name>
<xsl:if
test="$medication-code and (&#xD;&#xA; ($medication-code/cda:originalText/cda:reference/@value and $narrative-block) or&#xD;&#xA; $medication-code/cda:originalText/text() != '' or&#xD;&#xA; translate(normalize-space($medication-code/text()), ' ', '') != '')">
<generic-name>
<text>
<xsl:call-template name="StringFromED">
<xsl:with-param name="value"
select="$medication-code/cda:originalText"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</text>
</generic-name>
</xsl:if>
</xsl:when>
<xsl:when test="$medication-code">
<name><xsl:call-template name="CodableValueFromCCDCode"
><xsl:with-param name="code-value"
select="$medication-code"/><xsl:with-param
name="reference-text" select="$narrative-block"
/></xsl:call-template></name>
<xsl:if
test="$medication-code and (&#xD;&#xA; ($medication-code/cda:originalText/cda:reference/@value and $narrative-block) or&#xD;&#xA; $medication-code/cda:originalText/text() != '' or&#xD;&#xA; translate(normalize-space($medication-code/text()), ' ', '') != '')">
<generic-name>
<text>
<xsl:call-template name="StringFromED">
<xsl:with-param name="value"
select="$medication-code/cda:originalText"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</text>
</generic-name>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="cda:doseQuantity/@value or cda:maxDoseQuantity/@value">
<dose>
<xsl:choose>
<xsl:when test="cda:doseQuantity/@value">
<xsl:call-template name="PQValueToGeneralMeasurement">
<xsl:with-param name="value"
select="cda:doseQuantity"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="cda:maxDoseQuantity/@value">
<xsl:call-template name="PQValueToGeneralMeasurement">
<xsl:with-param name="value"
select="cda:maxDoseQuantity"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</dose>
</xsl:if>
<xsl:if test="cda:effectiveTime[./@xsi:type = 'PIVL_TS']">
<frequency>
<xsl:call-template name="PIVL_TS-to-general-measurement">
<xsl:with-param name="effectiveTime"
select="cda:effectiveTime[./@xsi:type = 'PIVL_TS'][1]"/>
</xsl:call-template>
</frequency>
</xsl:if>
<xsl:if test="cda:routeCode">
<route>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value" select="cda:routeCode"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</route>
</xsl:if>
<xsl:variable name="medication_indication_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.28</id>
<id>2.16.840.1.113883.10.20.22.4.19</id>
</ids>
</xsl:variable>
<xsl:variable name="medication_indication"
select="msxsl:node-set($medication_indication_ids)"/>
<xsl:if
test="cda:entryRelationship[./@typeCode='RSON']/cda:observation[./cda:templateId/@root = $medication_indication/ids/id]">
<indication>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value"
select="cda:entryRelationship[./@typeCode='RSON']/cda:observation[./cda:templateId/@root = $medication_indication/ids/id]/cda:value"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</indication>
</xsl:if>
<xsl:if test="cda:effectiveTime/cda:low/@value">
<date-started>
<xsl:call-template name="ApproxDateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:low/@value"/>
</xsl:call-template>
</date-started>
</xsl:if>
<xsl:if test="cda:statusCode/@code = 'completed'">
<xsl:if test="cda:effectiveTime/cda:high/@value">
<date-discontinued>
<xsl:call-template name="ApproxDateTimeFromCCDNumericDate">
<xsl:with-param name="numericDate"
select="cda:effectiveTime/cda:high/@value"/>
</xsl:call-template>
</date-discontinued>
</xsl:if>
</xsl:if>
<xsl:variable name="medication_instruction_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.49</id>
<id>2.16.840.1.113883.10.20.22.4.20</id>
</ids>
</xsl:variable>
<xsl:variable name="medication_instruction"
select="msxsl:node-set($medication_instruction_ids)"/>
<xsl:variable name="instructions"
select="cda:entryRelationship[./@typeCode = 'SUBJ']/cda:act[./cda:templateId/@root = $medication_instruction/ids/id]"/>
<xsl:variable name="medication_supply_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.34</id>
<id>2.16.840.1.113883.10.20.22.4.17</id>
</ids>
</xsl:variable>
<xsl:variable name="medication_supply"
select="msxsl:node-set($medication_supply_ids)"/>
<xsl:variable name="supply"
select="cda:entryRelationshp[./@typeCode = 'REFR']/cda:supply[./@moodCode = 'INT' and ./cda:templateId/@root = $medication_supply/ids/id]"/>
<xsl:if test="$supply or $instructions">
<prescription>
<prescribed-by>
<xsl:choose>
<xsl:when test="$supply/cda:author">
<xsl:call-template
name="PersonFromCCDAssignedEntity">
<xsl:with-param name="entity"
select="$supply/cda:author"/>
</xsl:call-template>
<date-prescribed>
<xsl:call-template
name="ApproxDateTimeFromCCDEffectiveTime">
<xsl:with-param name="effectiveTime"
select="$supply/cda:author/cda:time"/>
</xsl:call-template>
</date-prescribed>
</xsl:when>
<xsl:otherwise>
<name><full>Unknown</full></name>
</xsl:otherwise>
</xsl:choose>
</prescribed-by>
<xsl:if test="$supply/cda:quantity">
<amount-prescribed>
<xsl:call-template name="PQValueToGeneralMeasurement">
<xsl:with-param name="value"
select="$supply/cda:quantity"/>
<xsl:with-param name="reference-text"
select="$narrative-block"/>
</xsl:call-template>
</amount-prescribed>
</xsl:if>
<xsl:choose>
<xsl:when test="$instructions/cda:text">
<instructions>
<text>
<xsl:value-of select="$instructions/cda:text"/>
</text>
</instructions>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="instructionId"
select="substring($instructions/cda:text/cda:reference/@value, 2)"/>
<xsl:if test="$instructionId">
<xsl:if
test="$narrative-block//cda:td/@ID = $instructionId or&#xD;&#xA; ($narrative-block//cda:content/@ID = $instructionId and&#xD;&#xA; $narrative-block//cda:content/@revised != 'delete')">
<instructions>
<text>
<xsl:call-template name="GetFromTextById">
<xsl:with-param name="text"
select="$narrative-block"/>
<xsl:with-param name="id" select="$instructionId"
/>
</xsl:call-template>
</text>
</instructions>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</prescription>
</xsl:if>
</medication>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:variable>
<xsl:call-template name="Finally">
<xsl:with-param name="fragment" select="$try"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="Immunizations">
<xsl:param name="immunizations"/>
<xsl:param name="narrative-block"/>
<xsl:for-each select="$immunizations">
<thing>
<type-id>cd3587b5-b6e1-4565-ab3b-1c3ad45eb04f</type-id>
<data-xml>
<immunization>
<xsl:if
test="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code">
<name><xsl:call-template name="CodableValueFromCCDCode"><xsl:with-param
name="code-value"
select="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
/><xsl:with-param name="reference-text"
select="$narrative-block"/></xsl:call-template></name>
</xsl:if>
<xsl:if test="cda:effectiveTime">
<administration-date>
<xsl:call-template name="ApproxDateTimeFromCCDEffectiveTime">
<xsl:with-param name="effectiveTime" select="cda:effectiveTime"
/>
</xsl:call-template>
</administration-date>
</xsl:if>
<xsl:if test="cda:performer/cda:assignedEntity">
<administrator>
<xsl:call-template name="PersonFromCCDAssignedEntity">
<xsl:with-param name="entity"
select="cda:performer/cda:assignedEntity"/>
</xsl:call-template>
</administrator>
</xsl:if>
<xsl:if
test="cda:consumable/cda:manufacturedProduct/cda:manufacturerOrganization/cda:name">
<manufacturer>
<text>
<xsl:value-of
select="cda:consumable/cda:manufacturedProduct/cda:manufacturerOrganization/cda:name"
/>
</text>
</manufacturer>
</xsl:if>
<xsl:if
test="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:lotNumberText">
<lot>
<xsl:value-of
select="cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:lotNumberText"
/>
</lot>
</xsl:if>
<xsl:if test="cda:routeCode">
<route>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value" select="cda:routeCode"/>
<xsl:with-param name="reference-text" select="$narrative-block"
/>
</xsl:call-template>
</route>
</xsl:if>
<xsl:choose>
<xsl:when test="@moodCode = 'EVN' and cda:repeatNumber">
<sequence>
<xsl:value-of select="cda:repeatNumber"/>
</sequence>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="sequence"
select="cda:entryRelationship[./@typeCode = 'SUBJ']/cda:observation[./cda:templateId/@root = '2.16.840.1.113883.10.20.1.46']/cda:value/@value"/>
<xsl:if test="$sequence and $sequence != ''">
<sequence>
<xsl:value-of select="$sequence"/>
</sequence>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="cda:approachSiteCode">
<anatomic-surface>
<xsl:call-template name="CodableValueFromCCDCode">
<xsl:with-param name="code-value" select="cda:approachSiteCode"/>
<xsl:with-param name="reference-text" select="$narrative-block"
/>
</xsl:call-template>
</anatomic-surface>
</xsl:if>
<xsl:variable name="immunization_adverse_event_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.54</id>
<id>2.16.840.1.113883.10.20.22.4.9</id>
</ids>
</xsl:variable>
<xsl:variable name="immunization_adverse_event"
select="msxsl:node-set($immunization_adverse_event_ids)"/>
<xsl:variable name="adverse-event"
select="cda:entryRelationship[./cda:typeCode = 'CAUS']/cda:observation[./cda:templateId/@root = $immunization_adverse_event/ids/id]/cda:value"/>
<xsl:if test="$adverse-event">
<adverse-event>
<xsl:call-template name="StringFromAny">
<xsl:with-param name="value" select="$adverse-event"/>
<xsl:with-param name="reference-text" select="$narrative-block"
/>
</xsl:call-template>
</adverse-event>
</xsl:if>
</immunization>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:for-each>
</xsl:template>
<xsl:variable name="vital_signs_observation_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.31</id>
<id>2.16.840.1.113883.10.20.22.4.27</id>
</ids>
</xsl:variable>
<xsl:variable name="vital_signs_observation"
select="msxsl:node-set($vital_signs_observation_ids)"/>
<xsl:template name="VitalSigns">
<xsl:param name="vital-signs"/>
<xsl:param name="narrative-block"/>
<xsl:variable name="vs_organizer_ids">
<ids>
<id>2.16.840.1.113883.10.20.1.35</id>
<id>2.16.840.1.113883.10.20.22.4.26</id>
</ids>
</xsl:variable>
<xsl:variable name="vital_signs_organizer" select="msxsl:node-set($vs_organizer_ids)"/>
<xsl:for-each select="$vital-signs">
<xsl:variable name="organizers"
select="cda:organizer[./cda:templateId/@root = $vital_signs_organizer/ids/id]"/>
<xsl:call-template name="Organizers_to_Things">
<xsl:with-param name="organizers" select="$organizers"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback" select="true()"/>
<xsl:with-param name="allowed-observation-ids"
select="$vital_signs_observation/ids/id"/>
</xsl:call-template>
<xsl:if test="cda:observation[./cda:templateId/@root = $vital_signs_observation/ids/id]">
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:observation[./cda:templateId/@root = $vital_signs_observation/ids/id]"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback" select="true()"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="Organizers_to_Things">
<xsl:param name="organizers"/>
<xsl:param name="narrative-block"/>
<xsl:param name="allowVitalSignFallback" select="false()"/>
<xsl:param name="allowed-observation-ids"/>
<xsl:for-each select="$organizers">
<xsl:variable name="defaultEffectiveTime" select="cda:effectiveTime"/>
<xsl:variable name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:variable name="bp-systolic-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-systolic"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-systolic"
select="msxsl:node-set($bp-systolic-nodes)[1]/cda:observation"/>
<xsl:variable name="bp-diastolic-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-diastolic"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-diastolic"
select="msxsl:node-set($bp-diastolic-nodes)[1]/cda:observation"/>
<xsl:variable name="bp-pulse-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-pulse"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-pulse"
select="msxsl:node-set($bp-pulse-nodes)[1]/cda:observation"/>
<xsl:variable name="ldl">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-ldl"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cholesterol-ldl" select="msxsl:node-set($ldl)[1]/cda:observation"/>
<xsl:variable name="hdl">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-hdl"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cholesterol-hdl" select="msxsl:node-set($hdl)[1]/cda:observation"/>
<xsl:variable name="total">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-total"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cholesterol-total"
select="msxsl:node-set($total)[1]/cda:observation"/>
<xsl:variable name="pef-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/peak-flow-pef"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="pef" select="msxsl:node-set($pef-nodes)[1]/cda:observation"/>
<xsl:variable name="fev1-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/peak-flow-fev1"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="fev1" select="msxsl:node-set($fev1-nodes)[1]/cda:observation"/>
<xsl:variable name="fev6-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/peak-flow-fev6"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="fev6" select="msxsl:node-set($fev6-nodes)[1]/cda:observation"/>
<xsl:choose>
<xsl:when test="$defaultEffectiveTime and $bp-systolic and $bp-diastolic">
<xsl:variable name="thingXml">
<xsl:call-template name="Organizer_To_blood-pressure">
<xsl:with-param name="organizer" select="."/>
<xsl:with-param name="effectiveTime" select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowed-observation-ids"
select="$allowed-observation-ids"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="things" select="msxsl:node-set($thingXml)"/>
<xsl:choose>
<xsl:when test="$things">
<xsl:copy-of select="$things"/>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="ignore-items"
select="$bp-systolic | $bp-diastolic | $bp-pulse"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when
test="$defaultEffectiveTime and ($cholesterol-ldl or $cholesterol-hdl or $cholesterol-total)">
<xsl:variable name="thingXml">
<xsl:call-template name="Organizer_To_cholesterol-profile">
<xsl:with-param name="organizer" select="."/>
<xsl:with-param name="effectiveTime" select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowed-observation-ids"
select="$allowed-observation-ids"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="things" select="msxsl:node-set($thingXml)"/>
<xsl:choose>
<xsl:when test="$things">
<xsl:copy-of select="$things"/>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="ignore-items"
select="$cholesterol-ldl | $cholesterol-hdl | $cholesterol-total"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$defaultEffectiveTime and ($pef or $fev1 or $fev6)">
<xsl:variable name="thingXml">
<xsl:call-template name="Organizer_To_peak-flow">
<xsl:with-param name="organizer" select="."/>
<xsl:with-param name="effectiveTime" select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowed-observation-ids"
select="$allowed-observation-ids"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="things" select="msxsl:node-set($thingXml)"/>
<xsl:choose>
<xsl:when test="$things">
<xsl:copy-of select="$things"/>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="ignore-items" select="$pef | $fev1 | $fev6"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime"
select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ObservationResults_To_Things">
<xsl:with-param name="observations"
select="cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:with-param name="defaultEffectiveTime" select="$defaultEffectiveTime"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
<xsl:with-param name="allowVitalSignFallback"
select="$allowVitalSignFallback"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="Organizer_To_blood-pressure">
<xsl:param name="organizer"/>
<xsl:param name="effectiveTime"/>
<xsl:param name="narrative-block"/>
<xsl:param name="allowed-observation-ids"/>
<xsl:variable name="observations"
select="$organizer/cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:variable name="bp-systolic-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-systolic"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-systolic"
select="msxsl:node-set($bp-systolic-nodes)[1]/cda:observation"/>
<xsl:variable name="bp-diastolic-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-diastolic"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-diastolic"
select="msxsl:node-set($bp-diastolic-nodes)[1]/cda:observation"/>
<xsl:variable name="bp-pulse-nodes">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/blood-pressure-pulse"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bp-pulse" select="msxsl:node-set($bp-pulse-nodes)[1]/cda:observation"/>
<xsl:variable name="try">
<thing>
<type-id>ca3c57f4-f4c1-4e15-be67-0a3caf5414ed</type-id>
<data-xml>
<blood-pressure>
<when>
<xsl:call-template name="DateTimeFromCCDEffectiveTime">
<xsl:with-param name="effectiveTime" select="$effectiveTime"/>
</xsl:call-template>
</when>
<xsl:choose>
<xsl:when
test="$bp-systolic/cda:value/@xsi:type = 'PQ' and&#xD;&#xA; number($bp-systolic/cda:value/@value) &gt; 0 and&#xD;&#xA; h:lc($bp-systolic/cda:value/@unit) = h:lc($v_measure/millimeters-mercury/import) or h:lc($bp-systolic/cda:value/@unit) = h:lc($v_measure/millimeters-mercury/ucum)">
<systolic>
<xsl:call-template name="ToInteger">
<xsl:with-param name="value"
select="$bp-systolic/cda:value/@value"/>
</xsl:call-template>
</systolic>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when
test="$bp-diastolic/cda:value/@xsi:type = 'PQ' and&#xD;&#xA; number($bp-diastolic/cda:value/@value) &gt; 0 and&#xD;&#xA; h:lc($bp-diastolic/cda:value/@unit) = h:lc($v_measure/millimeters-mercury/import) or h:lc($bp-diastolic/cda:value/@unit) = h:lc($v_measure/millimeters-mercury/ucum)">
<diastolic>
<xsl:call-template name="ToInteger">
<xsl:with-param name="value"
select="$bp-diastolic/cda:value/@value"/>
</xsl:call-template>
</diastolic>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Throw"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if
test="$bp-pulse/cda:value/@xsi:type = 'PQ' and&#xD;&#xA; number($bp-pulse/cda:value/@value) &gt; 0 and&#xD;&#xA; h:lc($bp-pulse/cda:value/@unit) = h:lc($v_measure/per-minute/import) or h:lc($bp-pulse/cda:value/@unit) = h:lc($v_measure/per-minute/ucum)">
<pulse>
<xsl:value-of select="$bp-pulse/cda:value/@value"/>
</pulse>
</xsl:if>
</blood-pressure>
<xsl:call-template name="AddCommonSection"/>
</data-xml>
</thing>
</xsl:variable>
<xsl:call-template name="Finally">
<xsl:with-param name="fragment" select="$try"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="Organizer_To_cholesterol-profile">
<xsl:param name="organizer"/>
<xsl:param name="effectiveTime"/>
<xsl:param name="narrative-block"/>
<xsl:param name="allowed-observation-ids"/>
<xsl:variable name="observations"
select="$organizer/cda:component/cda:observation[./cda:templateId/@root = $allowed-observation-ids]"/>
<xsl:variable name="ldl">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-ldl"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cholesterol-ldl" select="msxsl:node-set($ldl)[1]/cda:observation"/>
<xsl:variable name="hdl">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-hdl"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cholesterol-hdl" select="msxsl:node-set($hdl)[1]/cda:observation"/>
<xsl:variable name="total">
<xsl:call-template name="GetMatchingObservation">
<xsl:with-param name="observations" select="$observations"/>
<xsl:with-param name="concept" select="$v_vitals/cholesterol-total"/>
<xsl:with-param name="narrative-block" select="$narrative-block"/>
</xsl:call-template>
</xsl:variable>