Index: ccr2ccd-xslt/trunk/make/ccr_qrda.xsl
===================================================================
--- ccr2ccd-xslt/trunk/make/ccr_qrda.xsl	(revision 981)
+++ ccr2ccd-xslt/trunk/make/ccr_qrda.xsl	(revision 991)
@@ -2716,2 +2716,807 @@
     </xsl:template>
 </xsl:stylesheet>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Procedures">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.10.20.1.12"/>
+                                <code code="47519-4" codeSystem="2.16.840.1.113883.6.1"/>
+                                <title>Procedures</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Code</th>
+                                                <th>Description</th>
+                                                <th>Location</th>
+                                                <th>Substance</th>
+                                                <th>Method</th>
+                                                <th>Position</th>
+                                                <th>Site</th>
+                                                <th>Status</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                                <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <table>
+                                                        <tbody>
+                                                            <xsl:apply-templates select="a:DateTime"/>
+                                                        </tbody>
+                                                    </table>
+                                                    <td>
+                                                        <xsl:apply-templates select="a:Description/a:Code"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Locations/a:Location">
+                                                            <xsl:value-of select="a:Description/a:Text"/>
+                                                            <xsl:if test="a:Actor">
+                                                                (<xsl:call-template name="actorName">
+                                                                    <xsl:with-param name="objID" select="a:Actor/a:ActorID"/>
+                                                                </xsl:call-template>
+                                                                <xsl:if test="a:Actor/a:ActorRole/a:Text">
+                                                                    <xsl:text xml:space="preserve"> - </xsl:text><xsl:value-of select="a:ActorRole/a:Text"/>)
+                                                                </xsl:if>
+                                                            </xsl:if>)
+                                                            <xsl:if test="position() != last()">
+                                                                <br/>
+                                                            </xsl:if>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Substance">
+                                                            <xsl:value-of select="a:Text"/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Method/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Position/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Site/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                    <entry typeCode="DRIV">
+                                        <procedure classCode="PROC" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.17" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.29" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.19" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- <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>
+
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <xsl:call-template name="ccdStatusProcedure">
+                                                <xsl:with-param name="status" select="a:Status"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Method">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Method"/>
+                                                    <xsl:with-param name="nodeName" select="'approachSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Site">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Site"/>
+                                                    <xsl:with-param name="nodeName" select="'targetSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Practitioners/a:Practitioner">
+                                                <xsl:call-template name="ccdPerformer">
+                                                    <xsl:with-param name="ccrActorReference" select="a:Practitioners/a:Practitioner[1]"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+                                        </procedure>
+                                    </entry>
+                                </xsl:for-each>
+                            </section>
+                        </component>
+                    </xsl:if>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Procedures">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.10.20.1.12"/>
+                                <code code="47519-4" codeSystem="2.16.840.1.113883.6.1"/>
+                                <title>Procedures</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Code</th>
+                                                <th>Description</th>
+                                                <th>Location</th>
+                                                <th>Substance</th>
+                                                <th>Method</th>
+                                                <th>Position</th>
+                                                <th>Site</th>
+                                                <th>Status</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                                <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <table>
+                                                        <tbody>
+                                                            <xsl:apply-templates select="a:DateTime"/>
+                                                        </tbody>
+                                                    </table>
+                                                    <td>
+                                                        <xsl:apply-templates select="a:Description/a:Code"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Locations/a:Location">
+                                                            <xsl:value-of select="a:Description/a:Text"/>
+                                                            <xsl:if test="a:Actor">
+                                                                (<xsl:call-template name="actorName">
+                                                                    <xsl:with-param name="objID" select="a:Actor/a:ActorID"/>
+                                                                </xsl:call-template>
+                                                                <xsl:if test="a:Actor/a:ActorRole/a:Text">
+                                                                    <xsl:text xml:space="preserve"> - </xsl:text><xsl:value-of select="a:ActorRole/a:Text"/>)
+                                                                </xsl:if>
+                                                            </xsl:if>)
+                                                            <xsl:if test="position() != last()">
+                                                                <br/>
+                                                            </xsl:if>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Substance">
+                                                            <xsl:value-of select="a:Text"/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Method/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Position/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Site/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                    <entry typeCode="DRIV">
+                                        <procedure classCode="PROC" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.17" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.29" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.19" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- <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>
+
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <xsl:call-template name="ccdStatusProcedure">
+                                                <xsl:with-param name="status" select="a:Status"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Method">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Method"/>
+                                                    <xsl:with-param name="nodeName" select="'approachSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Site">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Site"/>
+                                                    <xsl:with-param name="nodeName" select="'targetSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Practitioners/a:Practitioner">
+                                                <xsl:call-template name="ccdPerformer">
+                                                    <xsl:with-param name="ccrActorReference" select="a:Practitioners/a:Practitioner[1]"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+                                        </procedure>
+                                    </entry>
+                                </xsl:for-each>
+                            </section>
+                        </component>
+                    </xsl:if>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Problems">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.3.88.11.83.103" assigningAuthorityName="HITSP/C83"/>
+                                <templateId root="1.3.6.1.4.1.19376.1.5.3.1.3.6" assigningAuthorityName="IHE PCC"/>
+                                <templateId root="2.16.840.1.113883.10.20.1.11" assigningAuthorityName="HL7 CCD"/>
+                                <code code="11450-4" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Problem list"/>
+                                <title>Problems</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Code</th>
+                                                <th>Description</th>
+                                                <th>Status</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Problems/a:Problem">
+                                                <tr>
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <table>
+                                                            <tbody>
+                                                                <xsl:apply-templates select="a:DateTime"/>
+                                                            </tbody>
+                                                        </table>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:apply-templates select="a:Description/a:Code"/>
+                                                    </td>
+                                                    <td>
+														<xsl:attribute name="ID">
+															<xsl:value-of select="a:CCRDataObjectID"></xsl:value-of>
+														</xsl:attribute>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Problems/a:Problem">
+                                    <entry typeCode="DRIV">
+                                        <act classCode="ACT" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.10.20.1.27"/>
+                                            <!-- Problem act template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <code nullFlavor="NA"/>
+
+                                            <xsl:call-template name="ccdPerformer">
+                                                <xsl:with-param name="ccrActorReference" select="a:Source/a:Actor"/>
+                                            </xsl:call-template>
+
+                                            <entryRelationship typeCode="SUBJ">
+                                                <observation classCode="OBS" moodCode="EVN">
+                                                    <templateId root="2.16.840.1.113883.10.20.1.28" assigningAuthorityName="CCD"/>
+                                                    <!--Problem observation template-->
+
+                                                    <!-- <id> -->
+                                                    <xsl:call-template name="ccdID">
+                                                        <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                                        <xsl:with-param name="suffix"></xsl:with-param>
+                                                    </xsl:call-template>
+
+                                                    <code code="55607006" displayName="Problem" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT"/>
+
+                                                    <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:call-template>
+
+                                                    <xsl:call-template name="ccdStatus">
+                                                        <xsl:with-param name="ccrStatus" select="a:Status"/>
+                                                    </xsl:call-template>
+                                                </observation>
+                                            </entryRelationship>
+
+                                        </act>
+                                    </entry>
+                                </xsl:for-each>
+                            </section>
+                        </component>
+                    </xsl:if>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Procedures">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.10.20.1.12"/>
+                                <code code="47519-4" codeSystem="2.16.840.1.113883.6.1"/>
+                                <title>Procedures</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Code</th>
+                                                <th>Description</th>
+                                                <th>Location</th>
+                                                <th>Substance</th>
+                                                <th>Method</th>
+                                                <th>Position</th>
+                                                <th>Site</th>
+                                                <th>Status</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                                <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <table>
+                                                        <tbody>
+                                                            <xsl:apply-templates select="a:DateTime"/>
+                                                        </tbody>
+                                                    </table>
+                                                    <td>
+                                                        <xsl:apply-templates select="a:Description/a:Code"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Locations/a:Location">
+                                                            <xsl:value-of select="a:Description/a:Text"/>
+                                                            <xsl:if test="a:Actor">
+                                                                (<xsl:call-template name="actorName">
+                                                                    <xsl:with-param name="objID" select="a:Actor/a:ActorID"/>
+                                                                </xsl:call-template>
+                                                                <xsl:if test="a:Actor/a:ActorRole/a:Text">
+                                                                    <xsl:text xml:space="preserve"> - </xsl:text><xsl:value-of select="a:ActorRole/a:Text"/>)
+                                                                </xsl:if>
+                                                            </xsl:if>)
+                                                            <xsl:if test="position() != last()">
+                                                                <br/>
+                                                            </xsl:if>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Substance">
+                                                            <xsl:value-of select="a:Text"/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Method/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Position/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Site/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Procedures/a:Procedure">
+                                    <entry typeCode="DRIV">
+                                        <procedure classCode="PROC" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.3.88.11.83.17" assigningAuthorityName="HITSP C83"/>
+                                            <templateId root="2.16.840.1.113883.10.20.1.29" assigningAuthorityName="CCD"/>
+                                            <templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.19" assigningAuthorityName="IHE PCC"/>
+
+                                            <!-- <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>
+
+                                            <text>
+                                                <reference>
+                                                    <xsl:attribute name="value">
+                                                        <xsl:text>#</xsl:text>
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+                                                </reference>
+                                            </text>
+
+                                            <xsl:call-template name="ccdStatusProcedure">
+                                                <xsl:with-param name="status" select="a:Status"/>
+                                            </xsl:call-template>
+
+                                            <xsl:call-template name="ccdDateTime">
+                                                <xsl:with-param name="dt" select="a:DateTime"/>
+                                            </xsl:call-template>
+
+                                            <xsl:if test="a:Method">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Method"/>
+                                                    <xsl:with-param name="nodeName" select="'approachSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Site">
+                                                <xsl:call-template name="ccdCodedValue">
+                                                    <xsl:with-param name="ccrCodedDescription" select="a:Site"/>
+                                                    <xsl:with-param name="nodeName" select="'targetSiteCode'"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+
+                                            <xsl:if test="a:Practitioners/a:Practitioner">
+                                                <xsl:call-template name="ccdPerformer">
+                                                    <xsl:with-param name="ccrActorReference" select="a:Practitioners/a:Practitioner[1]"/>
+                                                </xsl:call-template>
+                                            </xsl:if>
+                                        </procedure>
+                                    </entry>
+                                </xsl:for-each>
+                            </section>
+                        </component>
+                    </xsl:if>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Problems">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.3.88.11.83.103" assigningAuthorityName="HITSP/C83"/>
+                                <templateId root="1.3.6.1.4.1.19376.1.5.3.1.3.6" assigningAuthorityName="IHE PCC"/>
+                                <templateId root="2.16.840.1.113883.10.20.1.11" assigningAuthorityName="HL7 CCD"/>
+                                <code code="11450-4" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Problem list"/>
+                                <title>Problems</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Code</th>
+                                                <th>Description</th>
+                                                <th>Status</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Problems/a:Problem">
+                                                <tr>
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <table>
+                                                            <tbody>
+                                                                <xsl:apply-templates select="a:DateTime"/>
+                                                            </tbody>
+                                                        </table>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:apply-templates select="a:Description/a:Code"/>
+                                                    </td>
+                                                    <td>
+														<xsl:attribute name="ID">
+															<xsl:value-of select="a:CCRDataObjectID"></xsl:value-of>
+														</xsl:attribute>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Problems/a:Problem">
+                                    <entry typeCode="DRIV">
+                                        <act classCode="ACT" moodCode="EVN">
+                                            <templateId root="2.16.840.1.113883.10.20.1.27"/>
+                                            <!-- Problem act template -->
+
+                                            <!-- <id> -->
+                                            <xsl:call-template name="ccdID">
+                                                <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                            </xsl:call-template>
+
+                                            <code nullFlavor="NA"/>
+
+                                            <xsl:call-template name="ccdPerformer">
+                                                <xsl:with-param name="ccrActorReference" select="a:Source/a:Actor"/>
+                                            </xsl:call-template>
+
+                                            <entryRelationship typeCode="SUBJ">
+                                                <observation classCode="OBS" moodCode="EVN">
+                                                    <templateId root="2.16.840.1.113883.10.20.1.28" assigningAuthorityName="CCD"/>
+                                                    <!--Problem observation template-->
+
+                                                    <!-- <id> -->
+                                                    <xsl:call-template name="ccdID">
+                                                        <xsl:with-param name="ccrObjectID" select="a:CCRDataObjectID"/>
+                                                        <xsl:with-param name="suffix"></xsl:with-param>
+                                                    </xsl:call-template>
+
+                                                    <code code="55607006" displayName="Problem" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT"/>
+
+                                                    <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:call-template>
+
+                                                    <xsl:call-template name="ccdStatus">
+                                                        <xsl:with-param name="ccrStatus" select="a:Status"/>
+                                                    </xsl:call-template>
+                                                </observation>
+                                            </entryRelationship>
+
+                                        </act>
+                                    </entry>
+                                </xsl:for-each>
+                            </section>
+                        </component>
+                    </xsl:if>
+                    <xsl:if test="a:ContinuityOfCareRecord/a:Body/a:Encounters">
+                        <component>
+                            <section>
+                                <templateId root="2.16.840.1.113883.3.88.11.83.127" assigningAuthorityName="HITSP/C83"/>
+                                <templateId root="1.3.6.1.4.1.19376.1.5.3.1.1.5.3.3" assigningAuthorityName="IHE PCC"/>
+                                <templateId root="2.16.840.1.113883.10.20.1.3" assigningAuthorityName="HL7 CCD"/>
+                                <!--Encounters section template-->
+                                <code code="46240-8" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="History of encounters"/>
+                                <title>Encounters</title>
+                                <text>
+                                    <table>
+                                        <tbody>
+                                            <tr>
+                                                <th>Type</th>
+                                                <th>Date</th>
+                                                <th>Location</th>
+                                                <th>Status</th>
+                                                <th>Practitioner</th>
+                                                <th>Description</th>
+                                                <th>Indications</th>
+                                                <th>Source</th>
+                                            </tr>
+                                            <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Encounters/a:Encounter">
+                                                <tr>
+                                                    <xsl:attribute name="id">
+                                                        <xsl:value-of select="a:CCRDataObjectID"/>
+                                                    </xsl:attribute>
+
+                                                    <td>
+                                                        <xsl:value-of select="a:Type/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="date:format-date">
+                                                            <xsl:with-param name="date-time" select="a:DateTime/a:ExactDateTime"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Locations/a:Location">
+                                                            <xsl:value-of select="a:Description/a:Text"/>
+                                                            <xsl:call-template name="actorName">
+                                                                <xsl:with-param name="objID" select="a:Actor/a:ActorID"/>
+                                                            </xsl:call-template>
+                                                            <br/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Status/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Practitioners/a:Practitioner">
+                                                            <xsl:call-template name="actorName">
+                                                                <xsl:with-param name="objID" select="a:ActorID"/>
+                                                            </xsl:call-template>
+                                                            <br/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:value-of select="a:Description/a:Text"/>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:for-each select="a:Indications/a:Indication">
+                                                            <xsl:call-template name="problemDescription">
+                                                                <xsl:with-param name="objID" select="a:InternalCCRLink/a:LinkID"/>
+                                                            </xsl:call-template>
+                                                            <br/>
+                                                        </xsl:for-each>
+                                                    </td>
+                                                    <td>
+                                                        <xsl:call-template name="actorName">
+                                                            <xsl:with-param name="objID" select="a:Source/a:Actor/a:ActorID"/>
+                                                        </xsl:call-template>
+                                                    </td>
+                                                </tr>
+                                            </xsl:for-each>
+                                        </tbody>
+                                    </table>
+                                </text>
+                                <xsl:for-each select="/a:ContinuityOfCareRecord/a:Body/a:Encounters/a:Encounter">
+                                    <entry typeCode="DRIV">
+                                        <encounter classCode="ENC" moodCode="EVN">
+                                            <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>
+                    </xsl:if>
