Index: ccr2ccd-xslt/trunk/ccr_ccd.xsl
===================================================================
--- ccr2ccd-xslt/trunk/ccr_ccd.xsl	(revision 811)
+++ ccr2ccd-xslt/trunk/ccr_ccd.xsl	(revision 814)
@@ -303,6 +303,10 @@
                         <component>
                             <section>
-                                <templateId root="2.16.840.1.113883.10.20.1.1"/>
-                                <code code="42348-3" codeSystem="2.16.840.1.113883.6.1"/>
+                                <templateId root="2.16.840.1.113883.10.20.1.1" assigningAuthorityName="HL7 CCD"/>
+                                <templateId root="2.16.840.1.113883.3.88.11.83.116" assigningAuthorityName="HITSP/C83"/>
+                                <templateId root="1.3.6.1.4.1.19376.1.5.3.1.3.35" assigningAuthorityName="IHE PCC"/>
+                                <templateId root="1.3.6.1.4.1.19376.1.5.3.1.3.34" assigningAuthorityName="IHE PCC"/>
+                                <!--Advance Directives section template-->
+                                <code code="42348-3" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Advance directives"/>
                                 <title>Advance Directives</title>
                                 <text>
@@ -318,4 +322,7 @@
                                             <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:AdvanceDirectives/a:AdvanceDirective">
                                                 <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
                                                     <td>
                                                         <xsl:value-of select="a:Type/a:Text"/>
@@ -327,4 +334,9 @@
                                                     </td>
                                                     <td>
+                                                        <xsl:attribute name="id">
+                                                            <xsl:value-of select="a:CCRDataObjectID"/>
+                                                            <xsl:text>:Narrative</xsl:text>
+                                                        </xsl:attribute>
+
                                                         <xsl:value-of select="a:Description/a:Text"/>
                                                     </td>
@@ -341,6 +353,79 @@
                                         </tbody>
                                     </table>
-
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:AdvanceDirectives/a:AdvanceDirective">
+                                    <entry typeCode="DRIV">
+                                        <observation classCode="OBS" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.12" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.17" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.13" assigningAuthorityName="IHE PCC"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.13.7" assigningAuthorityName="IHE PCC"/>
+                                            <!-- Advance directive observation template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <statusCode code="completed"/>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Description"/>
+                                                <xsl:with-param name="originalTextReference">
+                                                    <xsl:text>#</xsl:text>
+                                                    <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    <xsl:text>:Narrative</xsl:text>
+                                                </xsl:with-param>
+                                            </xsl:call-template>
+
+                                            <participant typeCode="VRF">
+                                                <templateId root="2.16.840.1.113883.10.20.1.58"/>
+                                                <!--Verification of an advance directive observation template -->
+                                                <time nullFlavor="UNK"/>
+                                                <xsl:call-template name="ccdParticipantRoleActor">
+                                                    <xsl:with-param name="ccrActorObjectID" select="a:Source[1]/a:ActorID"/>
+                                                </xsl:call-template>
+                                            </participant>
+
+                                            <xsl:if test="a:ReferenceID">
+                                                <reference typeCode="REFR">
+                                                    <externalDocument>
+                                                        <templateId root="2.16.840.1.113883.10.20.1.36"/>
+                                                        <!-- Advance directive reference template -->
+                                                        <xsl:variable name="referenceID" select="a:ReferenceID"/>
+                                                        <!-- <id> -->
+                                                        <xsl:call-template name="ccdID">
+                                                            <xsl:with-param name="ccrObjectID" select="$referenceID"/>
+                                                        </xsl:call-template>
+                                                        <code code="371538006" codeSystem="2.16.840.1.113883.6.96" displayName="Advance directive"/>
+                                                        <xsl:variable name="reference" select="/a:ContinuityOfCareRecord/a:References/a:Reference[a:ReferenceObjectID=$referenceID]"/>
+                                                        <text>
+                                                            <xsl:attribute name="mediaType">
+                                                                <xsl:value-of select="$reference/a:Type/a:Text"/>
+                                                            </xsl:attribute>
+                                                            <reference>
+                                                                <xsl:value-of select="$reference/a:Location[1]/a:Description/a:Text"/>
+                                                            </reference>
+                                                        </text>
+                                                    </externalDocument>
+                                                </reference>
+                                            </xsl:if>
+                                        </observation>
+                                    </entry>
+
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -832,8 +917,7 @@
                                                             <xsl:with-param name="ccrCodedDescription" select="a:Product/a:ProductName"/>
                                                             <xsl:with-param name="nodeName" select="'code'"/>
-                                                            <xsl:with-param name="domain" select="'RouteOfAdministration'"/>
                                                         </xsl:call-template>
                                                         <name>
-                                                            <xsl:value-of select="a:Product/a:BrandName/a:Text"></xsl:value-of>
+                                                            <xsl:value-of select="a:Product/a:BrandName/a:Text"/>
                                                         </name>
                                                     </manufacturedMaterial>
@@ -865,4 +949,7 @@
                                             <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Immunizations/a:Immunization">
                                                 <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
                                                     <td>
                                                         <xsl:apply-templates select="a:Product/a:ProductName/a:Code"/>
@@ -884,4 +971,9 @@
                                                     </td>
                                                     <td>
+                                                        <xsl:attribute name="id">
+                                                            <xsl:value-of select="a:CCRDataObjectID"/>
+                                                            <xsl:text>:Site</xsl:text>
+                                                        </xsl:attribute>
+
                                                         <xsl:value-of select="a:Directions/a:Direction/a:Site/a:Text"/>
                                                     </td>
@@ -896,4 +988,76 @@
                                     </table>
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Immunizations/a:Immunization">
+                                    <entry typeCode="DRIV">
+                                        <substanceAdministration classCode="SBADM" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.10.20.1.24" assigningAuthorityName="CCD"/>
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.13" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.12" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- Medication activity template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <code code="IMMUNIZ" codeSystem="2.16.840.1.113883.5.4" codeSystemName="HL7 ActCode"/>
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <statusCode code='completed'/>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                                <xsl:with-param name="type" select="'IVL_TS'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Directions/a:Direction/a:Route"/>
+                                                <xsl:with-param name="nodeName" select="'routeCode'"/>
+                                                <xsl:with-param name="domain" select="'RouteOfAdministration'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Directions/a:Direction/a:Site">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Directions/a:Direction/a:Site"/>
+                                                    <xsl:with-param name="nodeName" select="'approachSiteCode'"/>
+                                                    <xsl:with-param name="originalTextReference">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                        <xsl:text>:Site</xsl:text>
+                                                    </xsl:with-param>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <consumable>
+                                                <manufacturedProduct>
+                                                    <templateId root="2.16.840.1.113883.3.88.11.83.8.2" assigningAuthorityName="HITSP C83"/>
+                                                    <templateId root="2.16.840.1.113883.10.20.1.53" assigningAuthorityName="CCD"/>
+                                                    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.2" assigningAuthorityName="IHE PCC"/>
+
+                                                    <!-- Product template -->
+
+                                                    <manufacturedMaterial>
+                                                        <xsl:call-template name="ccdCodedValue">
+                                                            <xsl:with-param name="ccrCodedDescription" select="a:Product/a:ProductName"/>
+                                                            <xsl:with-param name="nodeName" select="'code'"/>
+                                                        </xsl:call-template>
+                                                        <name>
+                                                            <xsl:value-of select="a:Product/a:BrandName/a:Text"/>
+                                                        </name>
+                                                    </manufacturedMaterial>
+                                                </manufacturedProduct>
+                                            </consumable>
+
+                                        </substanceAdministration>
+                                    </entry>
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -916,4 +1080,8 @@
                                             <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:VitalSigns/a:Result">
                                                 <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+
                                                     <td>
                                                         <xsl:value-of select="a:Description/a:Text"/>
@@ -946,4 +1114,33 @@
                                     </table>
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:VitalSigns/a:Result">
+                                    <entry typeCode="DRIV">
+                                        <organizer classCode="CLUSTER" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.10.20.1.32" assigningAuthorityName="CCD"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.35" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.13.1" assigningAuthorityName="IHE PCC"/>
+                                            <!-- Vital signs organizer template -->
+
+                                            <xsl:variable name="testDate" select="a:DateTime"/>
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <code code="46680005" codeSystem="2.16.840.1.113883.6.96" displayName="Vital signs" codeSystemName="SNOMED CT"/>
+                                            <statusCode code="completed"/>
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="$testDate"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdObservation">
+                                                <xsl:with-param name="ccrTestNode" select="a:Test[1]"/>
+                                                <xsl:with-param name="testDate" select="$testDate"/>
+                                            </xsl:call-template>
+
+                                        </organizer>
+                                    </entry>
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -1039,5 +1236,4 @@
                                                 <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
                                             </xsl:call-template>
-
 
                                             <xsl:call-template name="ccdCodedValue">
@@ -1135,4 +1331,36 @@
                                     </table>
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:SocialHistory/a:SocialHistoryElement">
+                                    <entry typeCode="DRIV">
+                                        <observation classCode="OBS" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.19" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.33" assigningAuthorityName="CCD"/>
+                                            <!-- Social history observation template -->
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+                                            <statusCode code="completed"/>
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+                                            <entryRelationship typeCode="SUBJ" inversionInd="true">
+                                                <observation classCode="OBS" moodCode="EVN">
+                                                    <templateId root="2.16.840.1.113883.10.20.1.41"/>
+                                                    <!-- Episode observation template -->
+                                                    <statusCode code="completed"/>
+                                                    <entryRelationship typeCode="SAS">
+                                                        <observation classCode="OBS" moodCode="EVN">
+                                                            <xsl:call-template name="ccdCodedValue">
+                                                                <xsl:with-param name="ccrCodedDescription" select="a:Description"/>
+                                                                <xsl:with-param name="nodeName" select="'code'"/>
+                                                            </xsl:call-template>
+                                                        </observation>
+                                                    </entryRelationship>
+                                                </observation>
+                                            </entryRelationship>
+                                        </observation>
+                                    </entry>
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -1297,5 +1525,5 @@
 
                                                     <xsl:for-each select="a:Test">
-                                                        <xsl:call-template name="labObservation">
+                                                        <xsl:call-template name="ccdObservation">
                                                             <xsl:with-param name="ccrTestNode" select="."/>
                                                             <xsl:with-param name="testDate" select="$testDate"/>
@@ -1307,9 +1535,8 @@
                                             </xsl:when>
                                             <xsl:otherwise>
-                                                <xsl:call-template name="labObservation">
+                                                <xsl:call-template name="ccdObservation">
                                                     <xsl:with-param name="ccrTestNode" select="a:Test[1]"/>
                                                     <xsl:with-param name="testDate" select="$testDate"/>
                                                 </xsl:call-template>
-
                                             </xsl:otherwise>
                                         </xsl:choose>
@@ -1371,4 +1598,53 @@
                                     </table>
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Payers/a:Payer">
+                                    <entry typeCode="DRIV">
+                                        <act classCode="ACT" moodCode="DEF">
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.17" assigningAuthorityName="IHE PCC"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.20" assigningAuthorityName="CCD"/>
+                                            <!-- Coverage entry template -->
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+                                            <code code="48768-6" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Payment sources"/>
+                                            <statusCode code="completed"/>
+                                            <entryRelationship typeCode="COMP">
+                                                <act classCode="ACT" moodCode="EVN">
+                                                    <templateId root="2.16.840.1.113883.3.88.11.83.5" assigningAuthorityName="HITSP C83"/>
+                                                    <templateId root="2.16.840.1.113883.10.20.1.26" assigningAuthorityName="CCD"/>
+                                                    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.18" assigningAuthorityName="IHE PCC"/>
+                                                    <!--Insurance provider template -->
+                                                    <id>
+                                                        <xsl:attribute name="root">
+                                                            <xsl:value-of select="a:IDs[1]/a:ID"/>
+                                                        </xsl:attribute>
+                                                        <xsl:attribute name="extension">
+                                                            <xsl:value-of select="a:IDs[1]/a:Type/a:Text"/>
+                                                        </xsl:attribute>
+                                                    </id>
+
+                                                    <!-- <code> -->
+                                                    <xsl:call-template name="ccdCodedValue">
+                                                        <xsl:with-param name="ccrCodedDescription" select="a:Description"/>
+                                                        <xsl:with-param name="nodeName" select="'code'"/>
+                                                    </xsl:call-template>
+
+                                                    <statusCode code="completed"/>
+
+                                                    <xsl:call-template name="ccdPerformer">
+                                                        <xsl:with-param name="ccrActorReference" select="a:PaymentProvider"/>
+                                                    </xsl:call-template>
+
+                                                    <participant typeCode="HLD">
+                                                        <xsl:call-template name="ccdParticipantRoleActor">
+                                                            <xsl:with-param name="ccrActorReference" select="a:Subscriber"/>
+                                                        </xsl:call-template>
+                                                    </participant>
+                                                </act>
+                                            </entryRelationship>
+                                        </act>
+                                    </entry>
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -1498,4 +1774,253 @@
                                     </xsl:if>
                                 </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:PlanOfCare/a:Plan/a:OrderRequest/a:Procedures/a:Procedure">
+                                    <entry typeCode="DRIV">
+                                        <observation classCode="OBS" moodCode="RQO">
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.1.20.3.1"/>
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <!-- <code> -->
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Description"/>
+                                                <xsl:with-param name="nodeName" select="'code'"/>
+                                            </xsl:call-template>
+
+                                            <statusCode code="new"/>
+
+                                            <effectiveTime>
+                                                <xsl:choose>
+                                                    <xsl:when test="a:DateTime">
+                                                        <xsl:call-template name="ccdDateTime">
+                                                            <xsl:with-param name="dt" select="a:DateTime"/>
+                                                        </xsl:call-template>
+                                                    </xsl:when>
+                                                    <xsl:when test="a:Interval">
+                                                        <xsl:attribute name="xsi:type">PIVL_TS</xsl:attribute>
+                                                        <xsl:attribute name="operator">A</xsl:attribute>
+                                                        <xsl:attribute name="institutionSpecified">true</xsl:attribute>
+                                                        <period>
+                                                            <xsl:attribute name="value">
+                                                                <xsl:value-of select="a:Interval/a:Value"/>
+                                                            </xsl:attribute>
+                                                            <xsl:attribute name="unit">
+                                                                <xsl:value-of select="a:Interval/a:Units/a:Unit"/>
+                                                            </xsl:attribute>
+                                                        </period>
+                                                    </xsl:when>
+                                                </xsl:choose>
+                                            </effectiveTime>
+                                        </observation>
+                                    </entry>
+                                </xsl:for-each>
+
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:PlanOfCare/a:Plan/a:OrderRequest/a:Medications/a:Medication">
+                                    <entry typeCode="DRIV">
+                                        <substanceAdministration classCode="SBADM" moodCode="INT">
+                                            <templateId root="2.16.840.1.113883.10.20.1.24" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.1" assigningAuthorityName="IHE PCC"/>
+
+                                            <!--Medication activity template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <statusCode code='completed'/>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                                <xsl:with-param name="type" select="'IVL_TS'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdMedicationFrequency">
+                                                <xsl:with-param name="frequency" select="a:Directions/a:Direction/a:Frequency"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Directions/a:Direction/a:Route"/>
+                                                <xsl:with-param name="nodeName" select="'routeCode'"/>
+                                                <xsl:with-param name="domain" select="'RouteOfAdministration'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Directions/a:Direction/a:Dose">
+                                                <doseQuantity>
+                                                    <low>
+                                                        <xsl:attribute name="value">
+                                                            <xsl:value-of select="a:Directions/a:Direction/a:Dose/a:Value"></xsl:value-of>
+                                                        </xsl:attribute>
+                                                        <xsl:attribute name="unit">
+                                                            <xsl:value-of select="a:Directions/a:Direction/a:Dose/a:Unit"></xsl:value-of>
+                                                        </xsl:attribute>
+                                                    </low>
+                                                    <high>
+                                                        <xsl:attribute name="value">
+                                                            <xsl:value-of select="a:Directions/a:Direction/a:Dose/a:Value"></xsl:value-of>
+                                                        </xsl:attribute>
+                                                        <xsl:attribute name="unit">
+                                                            <xsl:value-of select="a:Directions/a:Direction/a:Dose/a:Unit"></xsl:value-of>
+                                                        </xsl:attribute>
+                                                    </high>
+                                                </doseQuantity>
+                                            </xsl:if>
+                                            <consumable>
+                                                <manufacturedProduct>
+                                                    <templateId root="2.16.840.1.113883.3.88.11.83.8.2" assigningAuthorityName="HITSP C83"/>
+                                                    <templateId root="2.16.840.1.113883.10.20.1.53" assigningAuthorityName="CCD"/>
+                                                    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.2" assigningAuthorityName="IHE PCC"/>
+
+                                                    <!-- Product template -->
+
+                                                    <manufacturedMaterial>
+                                                        <xsl:call-template name="ccdCodedValue">
+                                                            <xsl:with-param name="ccrCodedDescription" select="a:Product/a:ProductName"/>
+                                                            <xsl:with-param name="nodeName" select="'code'"/>
+                                                        </xsl:call-template>
+                                                        <name>
+                                                            <xsl:value-of select="a:Product/a:BrandName/a:Text"/>
+                                                        </name>
+                                                    </manufacturedMaterial>
+                                                </manufacturedProduct>
+                                            </consumable>
+                                        </substanceAdministration>
+                                    </entry>
+                                </xsl:for-each>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:PlanOfCare/a:Plan/a:OrderRequest/a:Immunizations/a:Immunization">
+
+                                    <entry typeCode="DRIV">
+                                        <substanceAdministration classCode="SBADM" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.10.20.1.24" assigningAuthorityName="CCD"/>
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.13" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.12" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- Medication activity template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <code code="IMMUNIZ" codeSystem="2.16.840.1.113883.5.4" codeSystemName="HL7 ActCode"/>
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <statusCode code='completed'/>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                                <xsl:with-param name="type" select="'IVL_TS'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Directions/a:Direction/a:Route"/>
+                                                <xsl:with-param name="nodeName" select="'routeCode'"/>
+                                                <xsl:with-param name="domain" select="'RouteOfAdministration'"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Directions/a:Direction/a:Site">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Directions/a:Direction/a:Site"/>
+                                                    <xsl:with-param name="nodeName" select="'approachSiteCode'"/>
+                                                    <xsl:with-param name="originalTextReference">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                        <xsl:text>:Site</xsl:text>
+                                                    </xsl:with-param>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <consumable>
+                                                <manufacturedProduct>
+                                                    <templateId root="2.16.840.1.113883.3.88.11.83.8.2" assigningAuthorityName="HITSP C83"/>
+                                                    <templateId root="2.16.840.1.113883.10.20.1.53" assigningAuthorityName="CCD"/>
+                                                    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.2" assigningAuthorityName="IHE PCC"/>
+
+                                                    <!-- Product template -->
+
+                                                    <manufacturedMaterial>
+                                                        <xsl:call-template name="ccdCodedValue">
+                                                            <xsl:with-param name="ccrCodedDescription" select="a:Product/a:ProductName"/>
+                                                            <xsl:with-param name="nodeName" select="'code'"/>
+                                                        </xsl:call-template>
+                                                        <name>
+                                                            <xsl:value-of select="a:Product/a:BrandName/a:Text"/>
+                                                        </name>
+                                                    </manufacturedMaterial>
+                                                </manufacturedProduct>
+                                            </consumable>
+
+                                        </substanceAdministration>
+                                    </entry>
+                                </xsl:for-each>
+
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:PlanOfCare/a:Plan/a:OrderRequest/a:Encounters/a:Encounter">
+                                    <entry typeCode="DRIV">
+                                        <encounter classCode="ENC" moodCode="INT">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.16" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.21" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.14" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- Encounter activity template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdCodedValue">
+                                                <xsl:with-param name="ccrCodedDescription" select="a:Description"/>
+                                                <xsl:with-param name="nodeName" select="'code'"/>
+                                            </xsl:call-template>
+
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Practitioners[1]/a:Practitioner">
+                                                <xsl:call-template name="ccdPerformer">
+                                                    <xsl:with-param name="ccrActorReference" select="a:Practitioners/a:Practitioner[1]"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Locations[1]/a:Location">
+                                                <participant typeCode="LOC">
+                                                    <templateId root="2.16.840.1.113883.10.20.1.45"/>
+                                                    <!-- Location participation template -->
+                                                    <xsl:choose>
+                                                        <xsl:when test="a:Locations[1]/a:Location/a:ActorID">
+                                                            <xsl:call-template name="ccdParticipantRoleActor">
+                                                                <xsl:with-param name="ccrActorObjectID" select="a:Locations[1]/a:Location/a:ActorID"/>
+                                                            </xsl:call-template>
+                                                        </xsl:when>
+                                                        <xsl:otherwise>
+                                                            <xsl:call-template name="ccdParticipantRoleCodedDescription">
+                                                                <xsl:with-param name="ccrCodedDescription" select="a:Locations[1]/a:Location/a:Description"/>
+                                                            </xsl:call-template>
+                                                        </xsl:otherwise>
+                                                    </xsl:choose>
+                                                </participant>
+                                            </xsl:if>
+                                        </encounter>
+                                    </entry>
+                                </xsl:for-each>
                             </section>
                         </component>
@@ -2184,5 +2709,7 @@
                     </xsl:when>
                     <xsl:otherwise>
-                        <xsl:attribute name="value">Unknown</xsl:attribute>
+                        <xsl:attribute name="value">
+                            <xsl:text>Unknown</xsl:text>
+                        </xsl:attribute>
                     </xsl:otherwise>
                 </xsl:choose>
@@ -2207,4 +2734,5 @@
         <xsl:param name="domain"/>
         <xsl:param name="nodeName">value</xsl:param>
+        <xsl:param name="originalTextReference"/>
 
         <xsl:element name="{$nodeName}">
@@ -2259,7 +2787,14 @@
                 </xsl:when>
                 <xsl:otherwise>
-                    <xsl:attribute name="displayName">
+                    <originalText>
                         <xsl:value-of select="$ccrCodedDescription/a:Text"/>
-                    </xsl:attribute>
+                        <xsl:if test="$originalTextReference">
+                            <reference>
+                                <xsl:attribute name="value">
+                                    <xsl:value-of select="$originalTextReference"/>
+                                </xsl:attribute>
+                            </reference>
+                        </xsl:if>
+                    </originalText>
                 </xsl:otherwise>
             </xsl:choose>
@@ -2448,5 +2983,5 @@
     </xsl:template>
 
-    <xsl:template name="labObservation">
+    <xsl:template name="ccdObservation">
         <xsl:param name="ccrTestNode"/>
         <xsl:param name="testDate"/>
@@ -2457,4 +2992,5 @@
                 <templateId root="2.16.840.1.113883.10.20.1.31" assigningAuthorityName="CCD"/>
                 <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.13" assigningAuthorityName="IHE PCC"/>
+
                 <!-- Result observation template -->
 
