GPLCCD0 ; CCDCCR/GPL - CCD TEMPLATE AND ACCESS ROUTINES; 6/7/08
 ;;0.1;CCDCCR;nopatch;noreleasedate
 ;Copyright 2008 WorldVistA.  Licensed under the terms of the GNU
 ;General Public License See attached copy of the License.
 ;
 ;This program is free software; you can redistribute it and/or modify
 ;it under the terms of the GNU General Public License as published by
 ;the Free Software Foundation; either version 2 of the License, or
 ;(at your option) any later version.
 ;
 ;This program is distributed in the hope that it will be useful,
 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;GNU General Public License for more details.
 ;
 ;You should have received a copy of the GNU General Public License along
 ;with this program; if not, write to the Free Software Foundation, Inc.,
 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 ;
          W "This is a CCD TEMPLATE with processing routines",!
          W !
          Q
          ;
ZT(ZARY,BAT,LINE) ; private routine to add a line to the ZARY array
          ; ZARY IS PASSED BY NAME
          ; BAT is a string identifying the section
          ; LINE is a test which will evaluate to true or false
          ; I '$G(@ZARY) D
          . S @ZARY@(0)=0 ; initially there are no elements
          . W "GOT HERE LOADING "_LINE,!
          N CNT ; count of array elements
          S CNT=@ZARY@(0) ; contains array count
          S CNT=CNT+1 ; increment count
          S @ZARY@(CNT)=LINE ; put the line in the array
          ; S @ZARY@(BAT,CNT)="" ; index the test by battery
          S @ZARY@(0)=CNT ; update the array counter
          Q
          ;
ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
          ; ZARY IS PASSED BY NAME
          ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
          ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
          K @ZARY S @ZARY=""
          S @ZARY@(0)=0 ; initialize array count
          N LINE,LABEL,BODY
          N INTEST S INTEST=0 ; switch for in the TEMPLATE section
          N SECTION S SECTION="[anonymous]" ; NO section LABEL
          ;
          N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE=""  D
          . I LINE?." "1";<TEMPLATE>".E S INTEST=1 ; entering section
          . I LINE?." "1";</TEMPLATE>".E S INTEST=0 ; leaving section
          . I INTEST  D  ; within the section
          . . I LINE?." "1";><".E  D  ; sub-section name found
          . . . S SECTION=$P($P(LINE,";><",2),">",1) ; pull out name
          . . I LINE?." "1";;".E  D  ; line found
          . . . D ZT(ZARY,SECTION,$P(LINE,";;",2)) ; put the line in the array
          Q
          ;
LOAD(ARY) ; LOAD A CCR TEMPLATE INTO ARY PASSED BY NAME
          D ZLOAD(ARY,"GPLCCD0")
          ; ZWR @ARY
          Q
          ;
;<TEMPLATE>
;;<?xml version="1.0"?>
;;<?xml-stylesheet type="text/xsl" href="CCD.xsl"?>
;;<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 CDA.xsd">
;;<typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040"/>
;;<templateId root="2.16.840.1.113883.10.20.1"/>
;;<id root="db734647-fc99-424c-a864-7e3cda82e703"/>
;;<code code="34133-9" codeSystem="2.16.840.1.113883.6.1" displayName="Summarization of episode note"/>
;;<title>< value="DOCTITLE"/>@@DOCTITLE@@Good Health Clinic Continuity of Care Document</title>
;;<effectiveTime value="@@EFFECTIVETIME@@20000407130000+0500"/>
;;<confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25"/>
;;<languageCode code="en-US"/>
;;<recordTarget>
;;<patientRole>
;;<id extension="996-756-495" root="2.16.840.1.113883.19.5"/>
;;<patient>
;;<name>
;;<given>@@PATIENTGIVENNAME@@</given>
;;<family>@@PATIENTFAMILYNAME@@</family>
;;<suffix>@@PATIENTNAMESUFFIX@@</suffix>
;;</name>
;;<administrativeGenderCode code="@@PATIENTGENDER@@M" codeSystem="2.16.840.1.113883.5.1"/>
;;<birthTime value="@@PATIENTDATEOFBIRTH@@19320924"/>
;;</patient>
;;<providerOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@SITENAME@@Good Health Clinic</name>
;;</providerOrganization>
;;</patientRole>
;;</recordTarget>
;;<author>
;;<time value="20000407130000+0500"/>
;;<assignedAuthor>
;;<id root="20cf14fb-b65c-4c8c-a54d-b0cca834c18c"/>
;;<assignedPerson>
;;<name><prefix>Dr.</prefix><given>@@AUTHORGIVENNAME@@Robert</given><family>@@AUTHORFAMILYNAME@@Dolin</family></name>
;;</assignedPerson>
;;<representedOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@AUTHORSITE@@Good Health Clinic</name>
;;</representedOrganization>
;;</assignedAuthor>
;;</author>
;;<informant>
;;<assignedEntity>
;;<id nullFlavor="NI"/>
;;<representedOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@INFORMANTORG@@Good Health Clinic</name>
;;</representedOrganization>
;;</assignedEntity>
;;</informant>
;;<custodian>
;;<assignedCustodian>
;;<representedCustodianOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@CUSTODIANORG@@Good Health Clinic</name>
;;</representedCustodianOrganization>
;;</assignedCustodian>
;;</custodian>
;;<legalAuthenticator>
;;<time value="20000407130000+0500"/>
;;<signatureCode code="S"/>
;;<assignedEntity>
;;<id nullFlavor="NI"/>
;;<representedOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@LEGALORG@@Good Health Clinic</name>
;;</representedOrganization>
;;</assignedEntity>
;;</legalAuthenticator>
;;<participant typeCode="IND">
;;<associatedEntity classCode="GUAR">
;;<id root="4ff51570-83a9-47b7-91f2-93ba30373141"/>
;;<addr>
;;<streetAddressLine>@@GUARSTREET@@17 Daws Rd.</streetAddressLine>
;;<city>@@GUARCITY@@Blue Bell</city>
;;<state>@@GUARSTATE@@MA</state>
;;<postalCode>@@GUARZIP@@02368</postalCode>
;;</addr>
;;<telecom value="tel:@@GUARTELE@@(888)555-1212"/>
;;<associatedPerson>
;;<name>
;;<given>@@GUARGIVENNAME@@Kenneth</given>
;;<family>@@GUARFAMILYNAME@@Ross</family>
;;</name>
;;</associatedPerson>
;;</associatedEntity>
;;</participant>
;;<participant typeCode="IND">
;;<associatedEntity classCode="NOK">
;;<id root="4ac71514-6a10-4164-9715-f8d96af48e6d"/>
;;<code code="65656005" codeSystem="2.16.840.1.113883.6.96" displayName="@@NOKRELATION@@Biiological mother"/>
;;<telecom value="tel:@@NOKTELE@@(999)555-1212"/>
;;<associatedPerson>
;;<name>
;;<given>@@NOKGIVENNAME@@Henrietta</given>
;;<family>@@NOKFAMILYNAME@@Levin</family>
;;</name>
;;</associatedPerson>
;;</associatedEntity>
;;</participant>
;;<documentationOf>
;;<serviceEvent classCode="PCPR">
;;<effectiveTime><low value="@@DOCPERIODLOW@@19320924"/><high value="@@DOCPERIODHIGH@@20000407"/></effectiveTime>
;;<performer typeCode="PRF">
;;<functionCode code="PCP" codeSystem="2.16.840.1.113883.5.88"/>
;;<time><low value="@@PCPPERIODLOW@@1990"/><high value='@@PCPPERIODHIGH@@20000407'/></time>
;;<assignedEntity>
;;<id root="20cf14fb-b65c-4c8c-a54d-b0cca834c18c"/>
;;<assignedPerson>
;;<name><prefix>@@PCPNAMEPREFIX@@Dr.</prefix><given>@@PCPNAMEGIVEN@@Robert</given><family>@@PCPNAMEFAMILY@@Dolin</family></name>
;;</assignedPerson>
;;<representedOrganization>
;;<id root="2.16.840.1.113883.19.5"/>
;;<name>@@PCPORG@@Good Health Clinic</name>
;;</representedOrganization>
;;</assignedEntity>
;;</performer>
;;</serviceEvent>
;;</documentationOf>
;;<component>
;;<structuredBody>
;;<component>
;;<section>
;;<templateId root='2.16.840.1.113883.10.20.1.13'/>
;;<code code="48764-5" codeSystem="2.16.840.1.113883.6.1"/>
;;<title>Summary Purpose</title>
;;<text>Transfer of care</text>
;;<entry typeCode="DRIV">
;;<act classCode="ACT" moodCode="EVN">
;;<templateId root='2.16.840.1.113883.10.20.1.30'/>
;;<code code="23745001" codeSystem="2.16.840.1.113883.6.96" displayName="Documentation procedure"/>
;;<statusCode code="completed"/>
;;<entryRelationship typeCode="RSON">
;;<act classCode="ACT" moodCode="EVN">
;;<code code="308292007" codeSystem="2.16.840.1.113883.6.96" displayName="@@DOCPURPOSE@@Transfer of care"/>
;;<statusCode code="completed"/>
;;</act>
;;</entryRelationship>
;;</act>
;;</entry>
;;</section>
;;</component>
;;<component>
;;<section>
;;<templateId root="2.16.840.1.113883.10.20.1.14"/>
;;<code code="30954-2" codeSystem="2.16.840.1.113883.6.1"/>
;;<entry typeCode="DRIV">
;;<organizer classCode="BATTERY" moodCode="EVN">
;;<templateId root="2.16.840.1.113883.10.20.1.32"/>
;;<id root="7d5a02b0-67a4-11db-bd13-0800200c9a66"/>
;;<code code="@@BATTERYCODE@@43789009" codeSystem="@@BATTERYSYSTEM@@2.16.840.1.113883.6.96" displayName="@@BATTERYNAME@@CBC WO DIFFERENTIAL"/>
;;<statusCode code="completed"/>
;;<effectiveTime value="@@BATTERYTIME@@200003231430"/>
;;<component>
;;<observation classCode="OBS" moodCode="EVN">
;;<templateId root="2.16.840.1.113883.10.20.1.31"/>
;;<id root="107c2dc0-67a5-11db-bd13-0800200c9a66"/>
;;<code code="@@COMPONENTCODE@@30313-1" codeSystem="@@COMPONENTSYSTEM@@2.16.840.1.113883.6.1" displayName="@@COMPONENTNAME@@HGB"/>
;;<statusCode code="completed"/>
;;<effectiveTime value="@@COMPONENTTIME@@200003231430"/>
;;<value xsi:type="@@COMPONENTTYPE@@PQ" value="@@COMPONENTVALUE@13.2" unit="@@COMPONENTUNIT@@g/dl"/>
;;<interpretationCode code="N" codeSystem="2.16.840.1.113883.5.83"/>
;;<referenceRange>
;;<value="OBSERVATIONRANGE"/>
;;<observationRange>
;;<text>@@OBSRANGETEXT@@M 13-18 g/dl; F 12-16 g/dl</text>
;;</observationRange>
;;</referenceRange>
;;</observation>
;;</component>
;;</organizer>
;;</entry>
;;</section>
;;</component>
;;</structuredBody>
;;</component>
;;</ClinicalDocument>
;</TEMPLATE>
