Index: /ccr2ccd-xslt/trunk/templates/address.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/address.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/address.xsl	(revision 759)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="urn:astm-org:CCR" xmlns:fo="http://www.w3.org/1999/XSL/Format">
+    <xsl:template name="address">
+        <xsl:param name="actorID"/>
+        <xsl:variable name="actor" select="/a:ContinuityOfCareRecord/a:Actors/a:Actor[a:ActorObjectID=$actorID]"/>
+        <td>
+            <table class="internal" cellpadding="0" cellspacing="0">
+                <tr>
+                    <td valign="top">
+                        <xsl:for-each select="$actor/a:Address">
+                            <xsl:if test="a:Type">
+                                <b>
+                                    <xsl:value-of select="a:Type/a:Text"/>:
+                                </b>
+                                <br/>
+                            </xsl:if>
+                            <xsl:if test="a:Line1">
+                                <xsl:value-of select="a:Line1"/>
+                                <br/>
+                            </xsl:if>
+                            <xsl:if test="a:Line2">
+                                <xsl:value-of select="a:Line2"/>
+                                <br/>
+                            </xsl:if>
+                            <xsl:if test="a:City">
+                                <xsl:value-of select="a:City"/>,<xsl:text xml:space="preserve"> </xsl:text>
+                            </xsl:if>
+                            <xsl:value-of select="a:State"/>
+                            <xsl:text xml:space="preserve"> </xsl:text>
+                            <xsl:value-of select="a:PostalCode"/>
+                            <br/>
+                        </xsl:for-each>
+                    </td>
+                    <td valign="top">
+                        <xsl:for-each select="a:Telephone">
+                            <xsl:if test="a:Type/a:Text">
+                                <xsl:value-of select="a:Type/a:Text"/> Phone:<xsl:text xml:space="preserve"> </xsl:text>
+                            </xsl:if>
+                            <xsl:value-of select="a:Value"/>
+                        </xsl:for-each>
+                        <xsl:for-each select="a:EMail">
+                            Email:<xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="a:Value"/>
+                        </xsl:for-each>
+                    </td>
+                </tr>
+            </table>
+        </td>
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccdcodedvalue.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccdcodedvalue.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccdcodedvalue.xsl	(revision 759)
@@ -0,0 +1,58 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="a">
+
+    <xsl:import href="cdavocablookup.xsl"/>
+    <xsl:import href="HL7OIDLookup.xsl"/>
+
+    <xsl:template name="ccdCodedValue">
+        <xsl:param name="ccrCodedDescription"/>
+        <xsl:param name="type"/>
+        <xsl:param name="domain"/>
+        <xsl:param name="nodeName">value</xsl:param>
+
+        <xsl:element name="{$nodeName}">
+            <xsl:if test="$type">
+                <xsl:attribute name="xsi:type">
+                    <xsl:value-of select="$type"/>
+                </xsl:attribute>
+            </xsl:if>
+            <xsl:attribute name="displayName">
+                <xsl:value-of select="$ccrCodedDescription/a:Text"/>
+            </xsl:attribute>
+            <xsl:choose>
+                <xsl:when test="$ccrCodedDescription/a:Code">
+                    <xsl:attribute name="code">
+                        <xsl:value-of select="$ccrCodedDescription/a:Code/a:Value"/>
+                    </xsl:attribute>
+                    <xsl:attribute name="codeSystemName">
+                        <xsl:value-of select="$ccrCodedDescription/a:Code/a:CodingSystem"/>
+                    </xsl:attribute>
+                    <xsl:attribute name="codeSystem">
+                        <xsl:call-template name="HL7OIDLookup">
+                            <xsl:with-param name="name" select="$ccrCodedDescription/a:Code/a:CodingSystem"/>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                </xsl:when>
+                <xsl:when test="$domain">
+                    <xsl:attribute name="code">
+                        <xsl:call-template name="CDAVocabularyLookup">
+                            <xsl:with-param name="domain" select="$domain"/>
+                            <xsl:with-param name="ccrDescription" select="$ccrCodedDescription/a:Text"/>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                    <xsl:attribute name="codeSystemName">
+                        <xsl:call-template name="CDAVocabularyCodeSystemNameLookup">
+                            <xsl:with-param name="domain" select="$domain"/>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                    <xsl:attribute name="codeSystemName">
+                        <xsl:call-template name="CDAVocabularyCodeSystemLookup">
+                            <xsl:with-param name="domain" select="$domain"/>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:element>
+
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccddatetime.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccddatetime.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccddatetime.xsl	(revision 759)
@@ -0,0 +1,141 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="a date">
+    <!-- Converts the CCR DateTime to CCD effectiveTime.  Only ExactDateTime is supported (both alone and in DateTimeRange). -->
+    <xsl:import href="../lib/date.format-date.template.xsl"/>
+    <xsl:template name="ccdDateTime">
+        <xsl:param name="dt"/>
+        <xsl:param name="type"/>
+        <xsl:if test="$dt">
+            <xsl:if test="$dt[1]/a:ExactDateTime">
+                <effectiveTime>
+                    <xsl:if test="$type">
+                        <xsl:attribute name="xsi:type">
+                            <xsl:value-of select="$type"></xsl:value-of>
+                        </xsl:attribute>
+                    </xsl:if>
+                    <low>
+                        <xsl:attribute name="value">
+                            <xsl:call-template name="date:format-date">
+                                <xsl:with-param name="date-time">
+                                    <xsl:value-of select="$dt[1]/a:ExactDateTime"/>
+                                </xsl:with-param>
+                                <xsl:with-param name="pattern">yyyyMMdd</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </low>
+                    <high nullFlavor="UNK"/>
+                </effectiveTime>
+            </xsl:if>
+            <xsl:if test="$dt[1]/a:DateTimeRange">
+                <effectiveTime>
+                    <low>
+                        <xsl:attribute name="value">
+                            <xsl:call-template name="date:format-date">
+                                <xsl:with-param name="date-time">
+                                    <xsl:value-of select="$dt[1]/a:DateTimeRange/a:BeginRange/a:ExactDateTime"/>
+                                </xsl:with-param>
+                                <xsl:with-param name="pattern">yyyyMMdd</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </low>
+                    <high>
+                        <xsl:attribute name="value">
+                            <xsl:call-template name="date:format-date">
+                                <xsl:with-param name="date-time">
+                                    <xsl:value-of select="$dt[1]/a:DateTimeRange/a:EndRange/a:ExactDateTime"/>
+                                </xsl:with-param>
+                                <xsl:with-param name="pattern">yyyyMMdd</xsl:with-param>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                    </high>
+                </effectiveTime>
+            </xsl:if>
+        </xsl:if>
+    </xsl:template>
+
+    <xsl:template name="dateTime" match="a:DateTime">
+        <xsl:param name="dt" select="."/>
+        <xsl:param name="fmt">MMM dd, yyyy</xsl:param>
+        <xsl:for-each select="$dt">
+            <tr>
+                <xsl:if test="$dt/a:Type/a:Text">
+                    <td>
+                        <xsl:value-of select="a:Type/a:Text"/>:
+                    </td>
+                </xsl:if>
+                <xsl:choose>
+                    <xsl:when test="a:ExactDateTime">
+                        <td>
+                            <xsl:call-template name="date:format-date">
+                                <xsl:with-param name="date-time">
+                                    <xsl:value-of select="a:ExactDateTime"/>
+                                </xsl:with-param>
+                                <xsl:with-param name="pattern" select="$fmt"/>
+                            </xsl:call-template>
+                        </td>
+                    </xsl:when>
+                    <xsl:when test="$dt/a:Age">
+                        <td>
+                            <xsl:value-of select="$dt/a:Age/a:Value"/>
+                            <xsl:text xml:space="preserve"> </xsl:text>
+                            <xsl:value-of select="$dt/a:Age/a:Units/a:Unit"/>
+                        </td>
+                    </xsl:when>
+                    <xsl:when test="$dt/a:ApproximateDateTime">
+                        <td>
+                            <xsl:value-of select="$dt/a:ApproximateDateTime/a:Text"/>
+                        </td>
+                    </xsl:when>
+                    <xsl:when test="$dt/a:DateTimeRange">
+                        <td>
+                            <xsl:for-each select="$dt/a:DateTimeRange/a:BeginRange">
+                                <xsl:choose>
+                                    <xsl:when test="$dt/a:ExactDateTime">
+                                        <xsl:call-template name="date:format-date">
+                                            <xsl:with-param name="date-time">
+                                                <xsl:value-of select="$dt/a:ExactDateTime"/>
+                                            </xsl:with-param>
+                                            <xsl:with-param name="pattern" select="$fmt"/>
+                                        </xsl:call-template>
+                                    </xsl:when>
+                                    <xsl:when test="$dt/a:Age">
+                                        <xsl:value-of select="$dt/a:Age/a:Value"/>
+                                        <xsl:text xml:space="preserve"> </xsl:text>
+                                        <xsl:value-of select="$dt/a:Age/a:Units/a:Unit"/>
+                                    </xsl:when>
+                                    <xsl:when test="$dt/a:ApproximateDateTime">
+                                        <xsl:value-of select="$dt/a:ApproximateDateTime/a:Text"/>
+                                    </xsl:when>
+                                    <xsl:otherwise/>
+                                </xsl:choose>
+                            </xsl:for-each><xsl:text xml:space="preserve"> </xsl:text>
+                            -<xsl:text xml:space="preserve"> </xsl:text>
+                            <xsl:for-each select="$dt/a:DateTimeRange/a:EndRange">
+                                <xsl:choose>
+                                    <xsl:when test="$dt/a:ExactDateTime">
+                                        <xsl:call-template name="date:format-date">
+                                            <xsl:with-param name="date-time">
+                                                <xsl:value-of select="$dt/a:ExactDateTime"/>
+                                            </xsl:with-param>
+                                            <xsl:with-param name="pattern" select="$fmt"/>
+                                        </xsl:call-template>
+                                    </xsl:when>
+                                    <xsl:when test="$dt/a:Age">
+                                        <xsl:value-of select="$dt/a:Age/a:Value"/>
+                                        <xsl:text xml:space="preserve"> </xsl:text>
+                                        <xsl:value-of select="$dt/a:Age/a:Units/a:Unit"/>
+                                    </xsl:when>
+                                    <xsl:when test="$dt/a:ApproximateDateTime">
+                                        <xsl:value-of select="$dt/a:ApproximateDateTime/a:Text"/>
+                                    </xsl:when>
+                                    <xsl:otherwise/>
+                                </xsl:choose>
+                            </xsl:for-each>
+                        </td>
+                    </xsl:when>
+                    <xsl:otherwise/>
+                </xsl:choose>
+            </tr>
+        </xsl:for-each>
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccdentity.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccdentity.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccdentity.xsl	(revision 759)
@@ -0,0 +1,173 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:date="http://exslt.org/dates-and-times" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="a date">
+
+    <xsl:import href="actor.xsl"/>
+    <xsl:import href="ccdcodedvalue.xsl"/>
+    <xsl:import href="ccddatetime.xsl"/>
+    <xsl:import href="cdavocablookup.xsl"/>
+
+    <xsl:template name="ccdEntity">
+        <xsl:param name="ccrActorObjectID"/>
+        <xsl:param name="personNodeName">assignedPerson</xsl:param>
+
+        <xsl:variable name="CCRActor" select="//a:ContinuityOfCareRecord/a:Actors/a:Actor[a:ActorObjectID=$ccrActorObjectID]"/>
+
+        <id>
+            <xsl:choose>
+                <xsl:when test="$CCRActor/a:IDs">
+                    <xsl:attribute name="extension">
+                        <xsl:value-of select="$CCRActor/a:IDs[1]/a:ID"/>
+                    </xsl:attribute>
+                    <xsl:attribute name="root">
+                        <xsl:value-of select="$CCRActor/a:IDs[1]/a:Type/a:Text"/>
+                    </xsl:attribute>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:attribute name="extension">
+                        <xsl:value-of select="$CCRActor/a:ActorObjectID"/>
+                    </xsl:attribute>
+                    <xsl:attribute name="root">
+                        <xsl:text>CCR Actor ID</xsl:text>
+                    </xsl:attribute>
+                </xsl:otherwise>
+            </xsl:choose>
+        </id>
+
+        <xsl:if test="$CCRActor/a:Organization">
+            <xsl:value-of select="$CCRActor/a:Organization/a:Name"></xsl:value-of>
+        </xsl:if>
+
+        <addr>
+            <xsl:choose>
+                <xsl:when test="$CCRActor/a:Address">
+                    <xsl:attribute name="use">
+                        <xsl:call-template name="CDAVocabularyLookup">
+                            <xsl:with-param name="domain" select="'telecommunicationsAddressUse'"/>
+                            <xsl:with-param name="ccrDescription" select="$CCRActor/a:Address/a:Type/a:Text"/>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                    <streetAddressLine>
+                        <xsl:value-of select="$CCRActor/a:Address[1]/a:Line1"/>
+                    </streetAddressLine>
+                    <city>
+                        <xsl:value-of select="$CCRActor/a:Address[1]/a:City"/>
+                    </city>
+                    <state>
+                        <xsl:value-of select="$CCRActor/a:Address[1]/a:State"/>
+                    </state>
+                    <postalcode>
+                        <xsl:value-of select="$CCRActor/a:Address[1]/a:PostalCode"/>
+                    </postalcode>
+                </xsl:when>
+                <xsl:otherwise>
+                    <streetAddressLine/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </addr>
+
+        <telecom>
+            <xsl:if test="$CCRActor/a:Telephone">
+                <xsl:attribute name="use">
+                    <xsl:call-template name="CDAVocabularyLookup">
+                        <xsl:with-param name="domain" select="'telecommunicationsAddressUse'"/>
+                        <xsl:with-param name="ccrDescription" select="$CCRActor/a:Telephone/a:Type/a:Text"/>
+                    </xsl:call-template>
+                </xsl:attribute>
+                <xsl:attribute name="value">
+                    <xsl:text>tel:+1-</xsl:text>
+                    <xsl:value-of select="$CCRActor/a:Telephone[1]/a:Value"/>
+                </xsl:attribute>
+            </xsl:if>
+
+        </telecom>
+
+        <xsl:if test="$CCRActor/a:Email">
+            <telecom>
+                <xsl:choose>
+                    <xsl:when test="$CCRActor/a:Telephone">
+                        <xsl:attribute name="use">
+                            <xsl:call-template name="CDAVocabularyLookup">
+                                <xsl:with-param name="domain" select="'telecommunicationsAddressUse'"/>
+                                <xsl:with-param name="ccrDescription" select="$CCRActor/a:Telephone/a:Type/a:Text"/>
+                            </xsl:call-template>
+                        </xsl:attribute>
+                        <xsl:attribute name="value">
+                            <xsl:text>mailto:</xsl:text>
+                            <xsl:value-of select="$CCRActor/a:Email[1]/a:Value"/>
+                        </xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:attribute name="value">Unknown</xsl:attribute>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </telecom>
+        </xsl:if>
+
+        <xsl:element name="{$personNodeName}">
+            <name>
+                <xsl:call-template name="actorName">
+                    <xsl:with-param name="objID" select="$ccrActorObjectID"/>
+                </xsl:call-template>
+            </name>
+
+            <xsl:if test="a:Person/a:Gender">
+                
+                    <xsl:call-template name="ccdCodedValue">
+                        <xsl:with-param name="ccrCodedDescription" select="a:Person/a:Gender"/>
+                        <xsl:with-param name="domain" select="'AdministrativeGender'"/>
+                        <xsl:with-param name="nodeName" select="'administrativeGenderCode'"/>
+                    </xsl:call-template>
+
+                
+            </xsl:if>
+
+            <xsl:if test="a:Person/a:DateOfBirth">
+                <birthTime>
+                    <xsl:attribute name="value">
+                        <xsl:call-template name="date:format-date">
+                            <xsl:with-param name="date-time">
+                                <xsl:value-of select="a:Person/a:DateOfBirth/a:ExactDateTime"/>
+                            </xsl:with-param>
+                            <xsl:with-param name="pattern">yyyyMMddhhmmss</xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:attribute>
+                </birthTime>
+            </xsl:if>
+        </xsl:element>
+
+        <xsl:if test="$ccrActorObjectID=/a:ContinuityOfCareRecord/a:Patient[1]/a:ActorID">
+            <xsl:if test="/a:ContinuityOfCareRecord/a:Body/a:SocialHistory/a:SocialHistoryElement[a:Type/a:Text='Marital Status']">
+                
+                    <xsl:call-template name="ccdCodedValue">
+                        <xsl:with-param name="ccrCodedDescription" select="/a:ContinuityOfCareRecord/a:Body/a:SocialHistory/a:SocialHistoryElement[a:Type/a:Text='Marital Status']/a:Description"></xsl:with-param>
+                        <xsl:with-param name="domain" select="'MaritalStatus'"/>
+                        <xsl:with-param name="nodeName" select="'maritalStatusCode'"/>
+                    </xsl:call-template>
+                
+            </xsl:if>
+
+            <xsl:if test="/a:ContinuityOfCareRecord/a:Body/a:SocialHistory/a:SocialHistoryElement[a:Type/a:Text='Language']">
+                <languageCommunication>
+                    <templateId root="2.16.840.1.113883.3.88.11.83.2" assigningAuthorityName="HITSP/C83"/>
+                    <templateId root="1.3.6.1.4.1.19376.1.5.3.1.2.1" assigningAuthorityName="IHE/PCC"/>
+                    
+                        <xsl:call-template name="ccdCodedValue">
+                            <xsl:with-param name="ccrCodedDescription" select="/a:ContinuityOfCareRecord/a:Body/a:SocialHistory/a:SocialHistoryElement[a:Type/a:Text='Language']/a:Description"></xsl:with-param>
+                            <xsl:with-param name="domain" select="'HumanLanguage'"/>
+                            <xsl:with-param name="nodeName" select="'languageCode'"/>
+                        </xsl:call-template>
+                    
+                </languageCommunication>
+            </xsl:if>
+        </xsl:if>
+
+        <xsl:if test="/a:ContinuityOfCareRecord/a:Actors/a:Actor[a:ActorObjectID=$ccrActorObjectID]/a:InternalCCRLink[a:LinkRelationship='Organization']">
+            <representedOrganization>
+                <xsl:call-template name="ccdEntity">
+                    <xsl:with-param name="ccrActorObjectID" select="/a:ContinuityOfCareRecord/a:Actors/a:Actor[a:ActorObjectID=$ccrActorObjectID]/a:InternalCCRLink[a:LinkRelationship='Organization']/a:LinkID"></xsl:with-param>
+                </xsl:call-template>
+            </representedOrganization>
+        </xsl:if>
+
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccdid.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccdid.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccdid.xsl	(revision 759)
@@ -0,0 +1,15 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="a">
+    <xsl:template name="ccdID">
+        <xsl:param name="ccrObjectID"/>
+        <xsl:param name="suffix"></xsl:param>
+    
+        <id>
+            <xsl:attribute name="root">
+                <xsl:value-of select="$ccrObjectID"></xsl:value-of>
+                <xsl:value-of select="$suffix"></xsl:value-of>
+            </xsl:attribute>
+            <xsl:attribute name="extension">CCR Object ID</xsl:attribute>
+        </id>
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccdmedicationfrequency.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccdmedicationfrequency.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccdmedicationfrequency.xsl	(revision 759)
@@ -0,0 +1,56 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="a">
+    <xsl:template name="ccdMedicationFrequency">
+        <xsl:param name="frequency"/>
+        <xsl:if test="$frequency">
+            <xsl:choose>
+                <xsl:when test="$frequency/a:Value='qd'">
+                    <effectiveTime xsi:type="PIVL_TS" operator="A">
+                        <xsl:attribute name="institutionSpecified">true</xsl:attribute>
+                        <period>
+                            <xsl:attribute name="value">24</xsl:attribute>
+                            <xsl:attribute name="unit">h</xsl:attribute>
+                        </period>
+                    </effectiveTime>
+                </xsl:when>
+                <xsl:when test="$frequency/a:Value='bid'">
+                    <effectiveTime xsi:type="PIVL_TS" operator="A">
+                        <xsl:attribute name="institutionSpecified">true</xsl:attribute>
+                        <period>
+                            <xsl:attribute name="value">12</xsl:attribute>
+                            <xsl:attribute name="unit">h</xsl:attribute>
+                        </period>
+                    </effectiveTime>
+                </xsl:when>
+                <xsl:when test="$frequency/a:Value='tid'">
+                    <effectiveTime xsi:type="PIVL_TS" operator="A">
+                        <xsl:attribute name="institutionSpecified">true</xsl:attribute>
+                        <period>
+                            <xsl:attribute name="value">8</xsl:attribute>
+                            <xsl:attribute name="unit">h</xsl:attribute>
+                        </period>
+                    </effectiveTime>
+                </xsl:when>
+                <xsl:when test="$frequency/a:Value='qid'">
+                    <effectiveTime xsi:type="PIVL_TS" operator="A">
+                        <xsl:attribute name="institutionSpecified">true</xsl:attribute>
+                        <period>
+                            <xsl:attribute name="value">6</xsl:attribute>
+                            <xsl:attribute name="unit">h</xsl:attribute>
+                        </period>
+                    </effectiveTime>
+                </xsl:when>
+                <xsl:when test="$frequency/a:Value='qam'">
+                    <effectiveTime xsi:type='EIVL' operator='A'>
+                        <event code='ACM'/>
+                    </effectiveTime>
+                </xsl:when>
+                <xsl:when test="$frequency/a:Value='qpm'">
+                    <effectiveTime xsi:type='EIVL' operator='A'>
+                        <event code='PCV'/>
+                    </effectiveTime>
+                </xsl:when>
+            </xsl:choose>
+        </xsl:if>
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/ccdstatus.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/ccdstatus.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/ccdstatus.xsl	(revision 759)
@@ -0,0 +1,63 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:hl7-org:v3" xmlns:a="urn:astm-org:CCR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="a">
+
+    <xsl:import href="ccdcodedvalue.xsl"/>
+    
+    <xsl:template name="ccdStatus">
+        <xsl:param name="ccrStatus"/>
+
+        <entryRelationship typeCode="REFR">
+            <observation classCode="OBS" moodCode="EVN">
+                <templateId root="2.16.840.1.113883.10.20.1.50"/>
+                <!-- Problem status observation template -->
+                <code code="33999-4" codeSystem="2.16.840.1.113883.6.1" displayName="Status"/>
+                <statusCode code="completed"/>
+                <xsl:call-template name="ccdCodedValue">
+                    <xsl:with-param name="ccrCodedDescription" select="$ccrStatus"/>
+                </xsl:call-template>
+            </observation>
+        </entryRelationship>
+    </xsl:template>
+    
+    <xsl:template name="ccdStatusObservation">
+        <xsl:param name="status"/>
+        <xsl:variable name="statusText" select="$status/a:Text"></xsl:variable>
+        <xsl:choose>
+            <xsl:when test="$statusText='Active'">
+                <xsl:call-template name="ccdStatusElement">
+                    <xsl:with-param name="statusCode" select="'55561003'"></xsl:with-param>
+                    <xsl:with-param name="statusDisplayName" select="$statusText"></xsl:with-param>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$statusText='Inactive'">
+                <xsl:call-template name="ccdStatusElement">
+                    <xsl:with-param name="statusCode" select="'73425007'"></xsl:with-param>
+                    <xsl:with-param name="statusDisplayName" select="$statusText"></xsl:with-param>
+                </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$statusText='Chronic'">
+                <xsl:call-template name="ccdStatusElement">
+                    <xsl:with-param name="statusCode" select="'90734009'"></xsl:with-param>
+                    <xsl:with-param name="statusDisplayName" select="$statusText"></xsl:with-param>
+                </xsl:call-template>
+            </xsl:when>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template name="ccdStatusElement">
+        <xsl:param name="statusCode"/>
+        <xsl:param name="statusDisplayName"/>
+        <value>
+            <xsl:attribute name="xsi:type">CE</xsl:attribute>
+            <xsl:attribute name="code">
+                <xsl:value-of select="$statusCode"></xsl:value-of>
+            </xsl:attribute>
+            <xsl:attribute name="codeSystem">2.16.840.1.113883.6.96</xsl:attribute>
+            <xsl:attribute name="displayName">
+                <xsl:value-of select="$statusDisplayName"></xsl:value-of>
+            </xsl:attribute>
+        </value>
+    </xsl:template>
+
+</xsl:stylesheet>
+
Index: /ccr2ccd-xslt/trunk/templates/cdavocablookup.xsl
===================================================================
--- /ccr2ccd-xslt/trunk/templates/cdavocablookup.xsl	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/cdavocablookup.xsl	(revision 759)
@@ -0,0 +1,21 @@
+﻿<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:template name="CDAVocabularyLookup">
+        <xsl:param name="domain"/>
+        <xsl:param name="ccrDescription"/>
+
+        <xsl:value-of select="document('cdavocabmap.xml')/domains/domain[@name=$domain]/item[ccrdescription=$ccrDescription]/cdacode"/>
+    </xsl:template>
+
+    <xsl:template name="CDAVocabularyCodeSystemNameLookup">
+        <xsl:param name="domain"/>
+        
+        <xsl:value-of select="document('cdavocabmap.xml')/domains/domain[@name=$domain]/@codeSystemName"/>
+    </xsl:template>
+
+    <xsl:template name="CDAVocabularyCodeSystemLookup">
+        <xsl:param name="domain"/>
+
+        <xsl:value-of select="document('cdavocabmap.xml')/domains/domain[@name=$domain]/@codeSystem"/>
+    </xsl:template>
+</xsl:stylesheet>
Index: /ccr2ccd-xslt/trunk/templates/cdavocabmap.xml
===================================================================
--- /ccr2ccd-xslt/trunk/templates/cdavocabmap.xml	(revision 759)
+++ /ccr2ccd-xslt/trunk/templates/cdavocabmap.xml	(revision 759)
@@ -0,0 +1,106 @@
+﻿<?xml version="1.0" encoding="utf-8" ?>
+<domains>
+    <domain name="telecommunicationsAddressUse">
+        <item>
+            <ccrdescription>Home</ccrdescription>
+            <cdadescription>home address</cdadescription>
+            <cdacode>H</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Primary Home</ccrdescription>
+            <cdadescription>primary home</cdadescription>
+            <cdacode>HP</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Vacation Home</ccrdescription>
+            <cdadescription>primary home</cdadescription>
+            <cdacode>HV</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Office</ccrdescription>
+            <cdadescription>office</cdadescription>
+            <cdacode>WP</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Mobile</ccrdescription>
+            <cdadescription>mobile contact</cdadescription>
+            <cdacode>MC</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Pager</ccrdescription>
+            <cdadescription>pager</cdadescription>
+            <cdacode>PG</cdacode>
+        </item>
+    </domain>
+    <domain name="HumanLanguage" codeSystemName="IETF RFC 1766">
+        <item>
+        <ccrdescription>English</ccrdescription>
+        <cdacode>en-us</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Spanish</ccrdescription>
+            <cdacode>es</cdacode>
+        </item>
+        <item>
+            <ccrdescription>French</ccrdescription>
+            <cdacode>fr</cdacode>
+        </item>
+        <item>
+            <ccrdescription>German</ccrdescription>
+            <cdacode>de</cdacode>
+        </item>
+    </domain>
+    <domain name="MaritalStatus" codeSystemName="HL7 Marital status" codeSystem="2.16.840.1.113883.5.2">
+        <item>
+            <ccrdescription>Annulled</ccrdescription>
+            <cdacode>A</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Divorced</ccrdescription>
+            <cdacode>D</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Interlocutory</ccrdescription>
+            <cdacode>I</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Separated</ccrdescription>
+            <cdacode>L</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Married</ccrdescription>
+            <cdacode>M</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Polygamous</ccrdescription>
+            <cdacode>P</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Single</ccrdescription>
+            <cdacode>S</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Domestic Partner</ccrdescription>
+            <cdacode>T</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Widowed</ccrdescription>
+            <cdacode>W</cdacode>
+        </item>
+    </domain>
+    <domain name="AdministrativeGender" codeSystemName="HL7 Administrative Gender" codeSystem="2.16.840.1.113883.5.1">
+        <item>
+            <ccrdescription>Female</ccrdescription>
+            <cdacode>F</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Male</ccrdescription>
+            <cdacode>M</cdacode>
+        </item>
+        <item>
+            <ccrdescription>Undifferentiated</ccrdescription>
+            <cdacode>UN</cdacode>
+        </item>
+    </domain>
+
+    </domains>
