<xsl:template match="xs:complexType">
<xsl:variable name="complexTypeR2" select="."/>
<xsl:variable name="complexTypeR2-name" select="@name"/>
<!-- TODO: fix duplicate entry more intelligently -->
<xsl:variable name="complexTypeR2-class" select="$mappingTable//map[@cdar2=$complexTypeR2-name][1]/@class"/>
<xsl:variable name="complexTypeR3-name" select="$mappingTable//map[@cdar2=$complexTypeR2-name][1]/@cdar3"/>
<xsl:variable name="complexTypeR3">
<xsl:choose>
<xsl:when test="starts-with($complexTypeR3-name,'POCD_MT000040UV.')">
<xsl:copy-of select="document($cdar3pocdXsd)//xs:complexType[@name=$complexTypeR3-name]"/>
</xsl:when>
<xsl:when test="starts-with($complexTypeR3-name,'COCT_MT980000UV.')">
<xsl:copy-of select="document($cdar3csXsd)//xs:complexType[@name=$complexTypeR3-name]"/>
</xsl:when>
<xsl:when test="starts-with($complexTypeR3-name,'COCT_MT990000UV.')">
<xsl:copy-of select="document($cdar3partXsd)//xs:complexType[@name=$complexTypeR3-name]"/>
</xsl:when>
<xsl:otherwise>
<xsl:message>Cannot map complexType '
<xsl:value-of select="$complexTypeR2-name"/>' to '
<xsl:value-of select="$complexTypeR3-name"/>'. Unknown source file.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="clinicalStatement" as="xs:string*" select="('POCD_MT000040.Act','POCD_MT000040.Encounter','POCD_MT000040.Organizer','POCD_MT000040.Observation','POCD_MT000040.ObservationMedia','POCD_MT000040.Procedure','POCD_MT000040.RegionOfInterest','POCD_MT000040.SubstanceAdministration','POCD_MT000040.Supply')"/>
<!-- Contains the list of datatyped element names that are valid for this complexType based on the RIM -->
<xsl:variable name="allElementsDatatype" as="xs:string*" select="$rimClassesDTr2//class[@name=$complexTypeR2-class]/attribute/@name"/>
<!-- Contains the list of association element names that are valid for this complexType based on the CDAr2 -->
<xsl:variable name="allElementsAssociation" as="xs:string*" select=".//xs:element[starts-with(@type,'POCD_MT000040.')]/@name"/>
<xsl:text>
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:comment>
<xsl:value-of select="$complexTypeR2-name"/>
</xsl:comment>
<xsl:text>
</xsl:text>
<xsl:element name="xsl:template">
<xsl:attribute name="match" select="'*'"/>
<xsl:attribute name="mode" select="@name"/>
<xsl:variable name="elementNameMap">
<wrap>
<map cdar2="POCD_MT000040.AssignedAuthor.assignedAuthoringDevice" cdar3="assignedDevice"/>
<map cdar2="POCD_MT000040.Birthplace.place" cdar3="birthplace"/>
<map cdar2="POCD_MT000040.ClinicalDocument.participant" cdar3="participation1"/>
<map cdar2="POCD_MT000040.Component2.nonXMLBody" cdar3="nonStructuredBody"/>
<map cdar2="POCD_MT000040.Component4.organizer" cdar3="observation"/>
<map cdar2="POCD_MT000040.Consumable.manufacturedProduct" cdar3="role"/>
<map cdar2="POCD_MT000040.Entry.organizer" cdar3="observation"/>
<map cdar2="POCD_MT000040.EntryRelationship.organizer" cdar3="observation"/>
<map cdar2="POCD_MT000040.Organizer.component" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Act.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Act.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Act.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Act.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Encounter.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Encounter.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Encounter.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Encounter.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.HealthCareFacility.location" cdar3="playingPlace"/>
<map cdar2="POCD_MT000040.HealthCareFacility.serviceProviderOrganization" cdar3="scopingOrganization"/>
<map cdar2="POCD_MT000040.ManufacturedProduct.manufacturedLabeledDrug" cdar3="playingManufacturedMaterial"/>
<map cdar2="POCD_MT000040.ManufacturedProduct.manufacturedMaterial" cdar3="playingManufacturedMaterial"/>
<map cdar2="POCD_MT000040.ManufacturedProduct.manufacturerOrganization" cdar3="scopingOrganization"/>
<map cdar2="POCD_MT000040.Organizer.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Organizer.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Organizer.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Organizer.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Observation.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Observation.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Observation.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Observation.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Observation.referenceRange" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.ObservationMedia.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.ObservationMedia.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.ObservationMedia.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.ObservationMedia.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Participant2.participantRole" cdar3="role"/>
<map cdar2="POCD_MT000040.Performer2.assignedEntity" cdar3="role"/>
<map cdar2="POCD_MT000040.Precondition.criterion" cdar3="observation"/>
<map cdar2="POCD_MT000040.Procedure.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Procedure.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Procedure.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Procedure.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Product.manufacturedProduct" cdar3="role"/>
<map cdar2="POCD_MT000040.Reference.externalAct" cdar3="act"/>
<map cdar2="POCD_MT000040.Reference.externalDocument" cdar3="document"/>
<map cdar2="POCD_MT000040.Reference.externalObservation" cdar3="observation"/>
<map cdar2="POCD_MT000040.Reference.externalProcedure" cdar3="procedure"/>
<map cdar2="POCD_MT000040.ReferenceRange.observationRange" cdar3="observation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.RegionOfInterest.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.RegionOfInterest.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.RegionOfInterest.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Specimen.specimenRole" cdar3="role"/>
<map cdar2="POCD_MT000040.SpecimenRole.specimenPlayingEntity" cdar3="playingEntity"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.consumable" cdar3="participation"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.SubstanceAdministration.reference" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Supply.entryRelationship" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Supply.author" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.informant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.participant" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.performer" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.subject" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.precondition" cdar3="outboundRelationship"/>
<map cdar2="POCD_MT000040.Supply.product" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.specimen" cdar3="participation"/>
<map cdar2="POCD_MT000040.Supply.reference" cdar3="outboundRelationship"/>
</wrap>
</xsl:variable>
<!-- First loop through all possible attributes in the RIM. Some exist both in R2 and R3, others in R3 but
not in R2 (only as extension), and finally some may be both extensions in R2 and R3 (headers)
- When exist in both or in neither handle datatype and leave namespace, resp. hl7 or some other
- When exist in R3 but not in R2, handle namespace conversion
-->
<xsl:if test="count($allElementsDatatype)>0">
<xsl:text>
</xsl:text>
<xsl:comment>Loop through attributes with a datatype based on RIM order</xsl:comment>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:for-each select="$rimClassesDTr2//class[@name=$complexTypeR2-class]/attribute">
<xsl:variable name="nm" select="@name"/>
<xsl:variable name="dtr1" select="@dtr1"/>
<xsl:variable name="dtr2" select="@dtr2"/>
<xsl:variable name="isInCDAr2" select="exists($complexTypeR2//xs:element[@name=$nm])" as="xs:boolean"/>
<xsl:variable name="isInCDAr3" select="exists($complexTypeR3//xs:element[@name=$nm])" as="xs:boolean"/>
<xsl:variable name="cdar2dt">
<xsl:choose>
<xsl:when test="not($isInCDAr2)">
<xsl:value-of select="$dtr1"/>
</xsl:when>
<xsl:when test="$complexTypeR2//xs:element[@name=$nm]/@type='POCD_MT000040.RegionOfInterest.value'">
<xsl:value-of select="'INT'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$complexTypeR2//xs:element[@name=$nm]/@type"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cdar3dt" select="if ($isInCDAr3) then ($complexTypeR3//xs:element[@name=$nm]/@type) else ($dtr2)"/>
<xsl:choose>
<!-- informant.time and author.time map differently under entry than the other occurences -->
<xsl:when test="($complexTypeR2-name='POCD_MT000040.Author' and $nm='time') or ($complexTypeR2-name='POCD_MT000040.Informant12' and $nm='time')">
<xsl:element name="xsl:choose">
<xsl:element name="xsl:when">
<xsl:attribute name="test" select="'ancestor::hl7:entry'"/>
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="concat('dt-',$cdar2dt,'-to-IVL_TS')"/>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'in'"/>
<xsl:attribute name="select" select="concat('hl7:',$nm)"/>
</xsl:element>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'convertNamespace'"/>
<xsl:attribute name="select" select="'false()'"/>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:element name="xsl:otherwise">
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="concat('dt-',$cdar2dt,'-to-',$cdar3dt)"/>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'in'"/>
<xsl:attribute name="select" select="concat('hl7:',$nm)"/>
</xsl:element>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'convertNamespace'"/>
<xsl:attribute name="select" select="'false()'"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.Organizer' and $nm='effectiveTime'">
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="concat('dt-',$cdar2dt,'-to-QSET_TS')"/>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'in'"/>
<xsl:attribute name="select" select="concat('hl7:',$nm)"/>
</xsl:element>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'convertNamespace'"/>
<xsl:attribute name="select" select="'false()'"/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedCustodian' and $nm='id'">
<xsl:comment>patch for moved attribute</xsl:comment>
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="'dt-II-to-DSET_II'"/>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'in'"/>
<xsl:attribute name="select" select="'hl7:representedCustodianOrganization/hl7:id'"/>
</xsl:element>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'convertNamespace'"/>
<xsl:attribute name="select" select="'false()'"/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="not($complexTypeR2-name='POCD_MT000040.CustodianOrganization' and $nm='id')">
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="concat('dt-',$cdar2dt,'-to-',$cdar3dt)"/>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'in'"/>
<xsl:attribute name="select" select="if ($isInCDAr2) then (concat('hl7:',$nm)) else (concat('*:',$nm))"/>
</xsl:element>
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'convertNamespace'"/>
<xsl:attribute name="select" select="if ($isInCDAr3) then 'true()' else'false()'"/>
</xsl:element>
<xsl:choose>
<xsl:when test="$cdar2dt='CS' and $cdar3dt='CD' and $nm='languageCode'">
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'codeSystem'"/>
<xsl:attribute name="select" select="'$oidHumanLanguage'"/>
</xsl:element>
</xsl:when>
<xsl:when test="$cdar2dt='CS' and $cdar3dt='CD' and $nm='signatureCode'">
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'codeSystem'"/>
<xsl:attribute name="select" select="'$oidParticipationSignature'"/>
</xsl:element>
</xsl:when>
<!-- Only applicable to RegionOfInterest code (CIRCLE, ELLIPSE, POINT, POLY) -->
<xsl:when test="$cdar2dt='CS' and $cdar3dt='CD' and $nm='code'">
<xsl:element name="xsl:with-param">
<xsl:attribute name="name" select="'codeSystem'"/>
<xsl:attribute name="select" select="'$oidActCode'"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:comment>Skipping mapping of '
<xsl:value-of select="concat($complexTypeR2-name,'.',$nm)"/>', because there is no matching '
<xsl:value-of select="concat($complexTypeR3-name,'.',$nm)"/>'</xsl:comment>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:if test="count($allElementsAssociation)>0">
<xsl:if test="count($allElementsDatatype)=0">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:comment>Loop through all official complexTypes from CDAr2 schema</xsl:comment>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:for-each select=".//xs:element[starts-with(@type,'POCD_MT000040.')]">
<xsl:variable name="cdar2name" select="@name"/>
<xsl:variable name="cdar2type" select="@type"/>
<xsl:variable name="cdar3name" select="if ($elementNameMap//map[@cdar2=concat($complexTypeR2-name,'.',$cdar2name)]) then ($elementNameMap//map[@cdar2=concat($complexTypeR2-name,'.',$cdar2name)]/@cdar3) else ($cdar2name)"/>
<xsl:choose>
<xsl:when test="$cdar2type='POCD_MT000040.RegionOfInterest.value'"/>
<xsl:when test="$complexTypeR3//xs:element[@name=$cdar3name] or count(index-of($infrastructureRoot,$cdar2name))>0">
<xsl:variable name="ctr3sub" select="$complexTypeR3//xs:element[@name=$cdar2name]/@type"/>
<xsl:choose>
<!--
<xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId" minOccurs="0"/>
<xs:element name="templateId" type="POCD_MT000040.InfrastructureRoot.templateId" minOccurs="0" maxOccurs="unbounded"/>
-->
<xsl:when test="$cdar2name='realmCode'"/>
<xsl:when test="$cdar2type='POCD_MT000040.InfrastructureRoot.typeId'"/>
<xsl:when test="$cdar2type='POCD_MT000040.InfrastructureRoot.templateId'"/>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.ClinicalDocument' and $cdar2name='componentOf'"/>
<xsl:otherwise>
<xsl:variable name="hasNegationInd" select="exists(document($cdar2pocdXsd)//xs:complexType[@name=$cdar2type]/xs:attribute[@name='negationInd'])"/>
<xsl:element name="xsl:for-each">
<xsl:attribute name="select" select="concat('hl7:',$cdar2name)"/>
<xsl:element name="xsl:element">
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="$cdar2type='POCD_MT000040.Organizer'">
<xsl:text>{if (@classCode='CLUSTER') then ('composition') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.Author' and $cdar2name='assignedAuthor'">
<xsl:text>{if (ancestor::hl7:entry) then ('role') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedAuthor' and $cdar2name='assignedPerson'">
<xsl:text>{if (ancestor::hl7:entry) then ('playingPerson') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedAuthor' and $cdar2name='assignedAuthoringDevice'">
<xsl:text>{if (ancestor::hl7:entry) then ('playingDevice') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedAuthor' and $cdar2name='representedOrganization'">
<xsl:text>{if (ancestor::hl7:entry) then ('scopingOrganization') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedEntity' and $cdar2name='assignedPerson'">
<xsl:text>{if (ancestor::hl7:entry) then ('playingPerson') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.AssignedEntity' and $cdar2name='representedOrganization'">
<xsl:text>{if (ancestor::hl7:entry) then ('scopingOrganization') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.Informant12' and $cdar2name='assignedEntity'">
<xsl:text>{if (ancestor::hl7:entry) then ('role') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.Informant12' and $cdar2name='relatedEntity'">
<xsl:text>{if (ancestor::hl7:entry) then ('role') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.Subject' and $cdar2name='relatedSubject'">
<xsl:text>{if (ancestor::hl7:entry) then ('role') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.RelatedSubject' and $cdar2name='subject'">
<xsl:text>{if (ancestor::hl7:entry) then ('playingPerson') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:when test="$complexTypeR2-name='POCD_MT000040.RelatedEntity' and $cdar2name='relatedPerson'">
<xsl:text>{if (ancestor::hl7:entry) then ('playingPerson') else ('</xsl:text>
<xsl:value-of select="$cdar3name"/>
<xsl:text>')}</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$cdar3name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="namespace" select="'urn:hl7-org:v3'"/>
<!-- Start of attributes -->
<xsl:call-template name="handleSpecificAttributes">
<xsl:with-param name="in" select="concat($complexTypeR2-name,'.',$cdar2name)"/>
</xsl:call-template>
<xsl:element name="xsl:copy-of">
<xsl:attribute name="select" select="'@nullFlavor|@typeCode|@classCode|@moodCode|@determinerCode|@inversionInd'"/>
</xsl:element>
<xsl:if test="$hasNegationInd">
<xsl:element name="xsl:if">
<xsl:attribute name="test" select="'self::node()[@negationInd]'"/>
<xsl:element name="xsl:attribute">
<xsl:attribute name="name" select="'actionNegationInd'"/>
<xsl:attribute name="select" select="'@negationInd'"/>
</xsl:element>
</xsl:element>
</xsl:if>
<xsl:if test="$cdar2name='organizer'">
<xsl:element name="xsl:if">
<xsl:attribute name="test">
<xsl:text>@classCode='CLUSTER'</xsl:text>
</xsl:attribute>
<xsl:element name="xsl:attribute">
<xsl:attribute name="name" select="'classCode'"/>
<xsl:attribute name="select">
<xsl:text>'COMPOSITION'</xsl:text>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:if>
<!-- End of attributes -->
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="'infrastructureRootElements'"/>
</xsl:element>
<!-- Do ActRelationship stuff -->
<xsl:call-template name="handleSpecificElements">
<xsl:with-param name="in" select="concat($complexTypeR2-name,'.',$cdar2name)"/>
</xsl:call-template>
<xsl:element name="xsl:apply-templates">
<xsl:attribute name="select" select="'self::*'"/>
<xsl:attribute name="mode" select="$cdar2type"/>
</xsl:element>
<!-- End of elements -->
</xsl:element>
</xsl:element>
<!-- Filthy hack ... somehow in CDAr3 the component and componentOf are switched, so wait until we have component, and then append componentOf -->
<xsl:if test="$complexTypeR2-name='POCD_MT000040.ClinicalDocument' and $cdar2name='component'">
<xsl:variable name="hcdar2name" select="'componentOf'"/>
<xsl:variable name="hcdar3name" select="if ($elementNameMap//map[@cdar2=concat($complexTypeR2-name,'.',$hcdar2name)]) then ($elementNameMap//map[@cdar2=concat($complexTypeR2-name,'.',$hcdar2name)]/@cdar3) else ($hcdar2name)"/>
<xsl:variable name="hctsub" select="'POCD_MT000040.Component1'"/>
<xsl:element name="xsl:for-each">
<xsl:attribute name="select" select="concat('hl7:',$hcdar2name)"/>
<xsl:element name="xsl:element">
<xsl:attribute name="name" select="$hcdar3name"/>
<xsl:attribute name="namespace" select="'urn:hl7-org:v3'"/>
<!-- Start of attributes -->
<xsl:call-template name="handleSpecificAttributes">
<xsl:with-param name="in" select="concat($complexTypeR2-name,'.',$hcdar2name)"/>
</xsl:call-template>
<xsl:element name="xsl:copy-of">
<xsl:attribute name="select" select="'@nullFlavor|@typeCode|@classCode|@moodCode|@determinerCode|@inversionInd'"/>
</xsl:element>
<xsl:element name="xsl:if">
<xsl:attribute name="test" select="'self::node()[@negationInd]'"/>
<xsl:element name="xsl:attribute">
<xsl:attribute name="name" select="'actionNegationInd'"/>
<xsl:attribute name="select" select="'@negationInd'"/>
</xsl:element>
</xsl:element>
<!-- End of attributes -->
<xsl:element name="xsl:call-template">
<xsl:attribute name="name" select="'infrastructureRootElements'"/>
</xsl:element>
<!-- Do ActRelationship stuff -->
<xsl:call-template name="handleSpecificElements">
<xsl:with-param name="in" select="concat($complexTypeR2-name,'.',$hcdar2name)"/>
</xsl:call-template>
<xsl:element name="xsl:apply-templates">
<xsl:attribute name="select" select="'self::*'"/>
<xsl:attribute name="mode" select="$hctsub"/>
</xsl:element>
<!-- End of elements -->
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:comment>Skipping mapping of '
<xsl:value-of select="concat($complexTypeR2-name,'.',$cdar2name)"/>', because there is no matching '
<xsl:value-of select="concat($complexTypeR3-name,'.',$cdar3name)"/>'</xsl:comment>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:comment>Run through complexTypes in extensions</xsl:comment>
<xsl:text>
</xsl:text>
<xsl:element name="xsl:apply-templates">
<xsl:attribute name="select">
<xsl:text>*[not(namespace-uri()='urn:hl7-org:v3')]</xsl:text>
<xsl:if test="count($allElementsDatatype)>0">
<xsl:text>[not(local-name()=(</xsl:text>
<xsl:for-each select="$allElementsDatatype">
<xsl:text>'</xsl:text>
<xsl:value-of select="."/>
<xsl:text>'</xsl:text>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>))]</xsl:text>
</xsl:if>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template> |