source: ccr/trunk/p/GPLCCD.m@ 242

Last change on this file since 242 was 134, checked in by George Lilly, 16 years ago

cleaning up needless writes - make conditional on DEBUG

File size: 11.8 KB
Line 
1GPLCCD ; CCDCCR/GPL - CCD MAIN PROCESSING; 6/6/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 ;Copyright 2008 WorldVistA. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 ; EXPORT A CCR
21 ;
22EXPORT ; EXPORT ENTRY POINT FOR CCR
23 ; Select a patient.
24 S DIC=2,DIC(0)="AEMQ" D ^DIC
25 I Y<1 Q ; EXIT
26 S DFN=$P(Y,U,1) ; SET THE PATIENT
27 D XPAT(DFN,"","") ; EXPORT TO A FILE
28 Q
29 ;
30XPAT(DFN,DIR,FN) ; EXPORT ONE PATIENT TO A FILE
31 ; DIR IS THE DIRECTORY, DEFAULTS IF NULL TO ^TMP("GPLCCR","ODIR")
32 ; FN IS FILE NAME, DEFAULTS IF NULL
33 ; N CCDGLO
34 D CCDRPC(.CCDGLO,DFN,"CCD","","","")
35 S OARY=$NA(^TMP("GPLCCR",$J,DFN,"CCD",1))
36 S ONAM=FN
37 I FN="" S ONAM="PAT_"_DFN_"_CCD_V1.xml"
38 S ODIRGLB=$NA(^TMP("GPLCCR","ODIR"))
39 I '$D(@ODIRGLB) D ; IF NOT ODIR HAS BEEN SET
40 . S @ODIRGLB="/home/glilly/CCROUT"
41 . ;S @ODIRGLB="/home/cedwards/"
42 . ;S @ODIRGLB="/opt/wv/p/"
43 S ODIR=DIR
44 I DIR="" S ODIR=@ODIRGLB
45 N ZY
46 S ZY=$$OUTPUT^GPLXPATH(OARY,ONAM,ODIR)
47 W $P(ZY,U,2)
48 Q
49 ;
50CCDRPC(CCRGRTN,DFN,CCRPART,TIME1,TIME2,HDRARY) ;RPC ENTRY POINT FOR CCR OUTPUT
51 ; CCRGRTN IS RETURN ARRAY PASSED BY NAME
52 ; DFN IS PATIENT IEN
53 ; CCRPART IS "CCR" FOR ENTIRE CCR, OR SECTION NAME FOR A PART
54 ; OF THE CCR BODY.. PARTS INCLUDE "PROBLEMS" "VITALS" ETC
55 ; TIME1 IS STARTING TIME TO INCLUDE - NULL MEANS ALL
56 ; TIME2 IS ENDING TIME TO INCLUDE TIME IS FILEMAN TIME
57 ; - NULL MEANS NOW
58 ; HDRARY IS THE HEADER ARRAY DEFINING THE "FROM" AND
59 ; "TO" VARIABLES
60 ; IF NULL WILL DEFAULT TO "FROM" ORGANIZATION AND "TO" DFN
61 I '$D(DEBUG) S DEBUG=0
62 N CCD S CCD=0 ; FLAG FOR PROCESSING A CCD
63 I CCRPART="CCD" S CCD=1 ; WE ARE PROCESSING A CCD
64 S TGLOBAL=$NA(^TMP("GPLCCR",$J,"TEMPLATE")) ; GLOBAL FOR STORING TEMPLATE
65 I CCD S CCDGLO=$NA(^TMP("GPLCCR",$J,DFN,"CCD")) ; GLOBAL FOR THE CCD
66 E S CCDGLO=$NA(^TMP("GPLCCR",$J,DFN,"CCR")) ; GLOBAL FOR BUILDING THE CCR
67 S ACTGLO=$NA(^TMP("GPLCCR",$J,DFN,"ACTORS")) ; GLOBAL FOR ALL ACTORS
68 ; TO GET PART OF THE CCR RETURNED, PASS CCRPART="PROBLEMS" ETC
69 S CCRGRTN=$NA(^TMP("GPLCCR",$J,DFN,CCRPART)) ; RTN GLO NM OF PART OR ALL
70 I CCD D LOAD^GPLCCD1(TGLOBAL) ; LOAD THE CCR TEMPLATE
71 E D LOAD^GPLCCR0(TGLOBAL) ; LOAD THE CCR TEMPLATE
72 D CP^GPLXPATH(TGLOBAL,CCDGLO) ; COPY THE TEMPLATE TO CCR GLOBAL
73 N CAPSAVE,CAPSAVE2 ; FOR HOLDING THE CCD ROOT LINES
74 S CAPSAVE=@TGLOBAL@(3) ; SAVE THE CCD ROOT
75 S CAPSAVE2=@TGLOBAL@(@TGLOBAL@(0)) ; SAVE LAST LINE OF CCD
76 S @CCDGLO@(3)="<ContinuityOfCareRecord>" ; CAP WITH CCR ROOT
77 S @TGLOBAL@(3)=@CCDGLO@(3) ; CAP THE TEMPLATE TOO
78 S @CCDGLO@(@CCDGLO@(0))="</ContinuityOfCareRecord>" ; FINISH CAP
79 S @TGLOBAL@(@TGLOBAL@(0))="</ContinuityOfCareRecord>" ; FINISH CAP TEMP
80 ;
81 ; DELETE THE BODY, ACTORS AND SIGNATURES SECTIONS FROM GLOBAL
82 ; THESE WILL BE POPULATED AFTER CALLS TO THE XPATH ROUTINES
83 D REPLACE^GPLXPATH(CCDGLO,"","//ContinuityOfCareRecord/Body")
84 D REPLACE^GPLXPATH(CCDGLO,"","//ContinuityOfCareRecord/Actors")
85 I 'CCD D REPLACE^GPLXPATH(CCDGLO,"","//ContinuityOfCareRecord/Signatures")
86 I DEBUG F I=1:1:@CCDGLO@(0) W @CCDGLO@(I),!
87 ;
88 I 'CCD D HDRMAP(CCDGLO,DFN,HDRARY) ; MAP HEADER VARIABLES
89 ; MAPPING THE PATIENT PORTION OF THE CDA HEADER
90 S ZZX="//ContinuityOfCareRecord/recordTarget/patientRole/patient"
91 D QUERY^GPLXPATH(CCDGLO,ZZX,"ACTT1")
92 D PATIENT^GPLACTOR("ACTT1",DFN,"ACTORPATIENT_"_DFN,"ACTT2") ; MAP PATIENT
93 I DEBUG D PARY^GPLXPATH("ACTT2")
94 D REPLACE^GPLXPATH(CCDGLO,"ACTT2",ZZX)
95 I DEBUG D PARY^GPLXPATH(CCDGLO)
96 K ACTT1 K ACCT2
97 ; MAPPING THE PROVIDER ORGANIZATION,AUTHOR,INFORMANT,CUSTODIAN CDA HEADER
98 ; FOR NOW, THEY ARE ALL THE SAME AND RESOLVE TO ORGANIZATION
99 D ORG^GPLACTOR(CCDGLO,DFN,"ACTORPATIENTORGANIZATION","ACTT2") ; MAP ORG
100 D CP^GPLXPATH("ACTT2",CCDGLO)
101 ;
102 K ^TMP("GPLCCR",$J,"CCRSTEP") ; KILL GLOBAL PRIOR TO ADDING TO IT
103 S CCRXTAB=$NA(^TMP("GPLCCR",$J,"CCRSTEP")) ; GLOBAL TO STORE CCR STEPS
104 D INITSTPS(CCRXTAB) ; INITIALIZED CCR PROCESSING STEPS
105 N I,XI,TAG,RTN,CALL,XPATH,IXML,OXML,INXML,CCRBLD
106 F I=1:1:@CCRXTAB@(0) D ; PROCESS THE CCR BODY SECTIONS
107 . S XI=@CCRXTAB@(I) ; CALL COPONENTS TO PARSE
108 . S RTN=$P(XI,";",2) ; NAME OF ROUTINE TO CALL
109 . S TAG=$P(XI,";",1) ; LABEL INSIDE ROUTINE TO CALL
110 . S XPATH=$P(XI,";",3) ; XPATH TO XML TO PASS TO ROUTINE
111 . D QUERY^GPLXPATH(TGLOBAL,XPATH,"INXML") ; EXTRACT XML TO PASS
112 . S IXML="INXML"
113 . I CCD D SHAVE(IXML) ; REMOVE ALL BUT REPEATING PARTS OF TEMPLATE SECTION
114 . S OXML=$P(XI,";",4) ; ARRAY FOR SECTION VALUES
115 . ; W OXML,!
116 . S CALL="D "_TAG_"^"_RTN_"(IXML,DFN,OXML)" ; SETUP THE CALL
117 . W "RUNNING ",CALL,!
118 . X CALL
119 . I @OXML@(0)'=0 D ; THERE IS A RESULT
120 . . I CCD D QUERY^GPLXPATH(TGLOBAL,XPATH,"ITMP") ; XML TO UNSHAVE WITH
121 . . I CCD D UNSHAVE("ITMP",OXML)
122 . . I CCD D UNMARK^GPLXPATH(OXML) ; REMOVE THE CCR MARKUP FROM SECTION
123 . ; NOW INSERT THE RESULTS IN THE CCR BUFFER
124 . D INSERT^GPLXPATH(CCDGLO,OXML,"//ContinuityOfCareRecord/Body")
125 . I DEBUG F GPLI=1:1:@OXML@(0) W @OXML@(GPLI),!
126 ; NEED TO ADD BACK IN ACTOR PROCESSING AFTER WE FIGURE OUT LINKAGE
127 ; D ACTLST^GPLCCR(CCDGLO,ACTGLO) ; GEN THE ACTOR LIST
128 ; D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","ACTT")
129 ; D EXTRACT^GPLACTOR("ACTT",ACTGLO,"ACTT2")
130 ; D INSINNER^GPLXPATH(CCDGLO,"ACTT2","//ContinuityOfCareRecord/Actors")
131 N I,J,DONE S DONE=0
132 F I=0:0 D Q:DONE ; DELETE UNTIL ALL EMPTY ELEMENTS ARE GONE
133 . S J=$$TRIM^GPLXPATH(CCDGLO) ; DELETE EMPTY ELEMENTS
134 . W "TRIMMED",J,!
135 . I J=0 S DONE=1 ; DONE WHEN TRIM RETURNS FALSE
136 I CCD D ; TURN THE BODY INTO A CCD COMPONENT
137 . N I
138 . F I=1:1:@CCDGLO@(0) D ; SEARCH THROUGH THE ENTIRE ARRAY
139 . . I @CCDGLO@(I)["<Body>" D ; REPLACE BODY MARKUP
140 . . . S @CCDGLO@(I)="<component><structuredBody>" ; WITH CCD EQ
141 . . I @CCDGLO@(I)["</Body>" D ; REPLACE BODY MARKUP
142 . . . S @CCDGLO@(I)="</structuredBody></component>"
143 S @CCDGLO@(3)=CAPSAVE ; UNCAP - TURN IT BACK INTO A CCD
144 S @CCDGLO@(@CCDGLO@(0))=CAPSAVE2 ; UNCAP LAST LINE
145 Q
146 ;
147INITSTPS(TAB) ; INITIALIZE CCR PROCESSING STEPS
148 ; TAB IS PASSED BY NAME
149 W "TAB= ",TAB,!
150 ; ORDER FOR CCR IS PROBLEMS,FAMILYHISTORY,SOCIALHISTORY,MEDICATIONS,VITALSIGNS,RESULTS,HEALTHCAREPROVIDERS
151 D PUSH^GPLXPATH(TAB,"EXTRACT;GPLPROBS;//ContinuityOfCareRecord/Body/Problems;^TMP(""GPLCCR"",$J,DFN,""PROBLEMS"")")
152 ;D PUSH^GPLXPATH(TAB,"EXTRACT;GPLMEDS;//ContinuityOfCareRecord/Body/Medications;^TMP(""GPLCCR"",$J,DFN,""MEDICATIONS"")")
153 I 'CCD D PUSH^GPLXPATH(TAB,"EXTRACT;GPLVITAL;//ContinuityOfCareRecord/Body/VitalSigns;^TMP(""GPLCCR"",$J,DFN,""VITALS"")")
154 Q
155 ;
156SHAVE(SHXML) ; REMOVES THE 2-6 AND N-1 AND N-2 LINES FROM A COMPONENT
157 ; NEEDED TO EXPOSE THE REPEATING PARTS FOR GENERATION
158 N SHTMP,SHBLD ; TEMP ARRAY AND BUILD LIST
159 W SHXML,!
160 W @SHXML@(1),!
161 D QUEUE^GPLXPATH("SHBLD",SHXML,1,1) ; THE FIRST LINE IS NEEDED
162 D QUEUE^GPLXPATH("SHBLD",SHXML,7,@SHXML@(0)-3) ; REPEATING PART
163 D QUEUE^GPLXPATH("SHBLD",SHXML,@SHXML@(0),@SHXML@(0)) ; LAST LINE
164 D PARY^GPLXPATH("SHBLD") ; PRINT BUILD LIST
165 D BUILD^GPLXPATH("SHBLD","SHTMP") ; BUILD EDITED SECTION
166 D CP^GPLXPATH("SHTMP",SHXML) ; COPY RESULT TO PASSED ARRAY
167 Q
168 ;
169UNSHAVE(ORIGXML,SHXML) ; REPLACES THE 2-6 AND N-1 AND N-2 LINES FROM TEMPLATE
170 ; NEEDED TO RESTORM FIXED TOP AND BOTTOM OF THE COMPONENT XML
171 N SHTMP,SHBLD ; TEMP ARRAY AND BUILD LIST
172 W SHXML,!
173 W @SHXML@(1),!
174 D QUEUE^GPLXPATH("SHBLD",ORIGXML,1,6) ; FIRST 6 LINES OF TEMPLATE
175 D QUEUE^GPLXPATH("SHBLD",SHXML,2,@SHXML@(0)-1) ; INS ALL BUT FIRST/LAST
176 D QUEUE^GPLXPATH("SHBLD",ORIGXML,@ORIGXML@(0)-2,@ORIGXML@(0)) ; FROM TEMP
177 D PARY^GPLXPATH("SHBLD") ; PRINT BUILD LIST
178 D BUILD^GPLXPATH("SHBLD","SHTMP") ; BUILD EDITED SECTION
179 D CP^GPLXPATH("SHTMP",SHXML) ; COPY RESULT TO PASSED ARRAY
180 Q
181 ;
182HDRMAP(CXML,DFN,IHDR) ; MAP HEADER VARIABLES: FROM, TO ECT
183 N VMAP S VMAP=$NA(^TMP("GPLCCR",$J,DFN,"HEADER"))
184 ; K @VMAP
185 S @VMAP@("DATETIME")=$$FMDTOUTC^CCRUTIL($$NOW^XLFDT,"DT")
186 I IHDR="" D ; HEADER ARRAY IS NOT PROVIDED, USE DEFAULTS
187 . S @VMAP@("ACTORPATIENT")="ACTORPATIENT_"_DFN
188 . S @VMAP@("ACTORFROM")="ACTORORGANIZATION_"_DUZ ; FROM DUZ - ???
189 . S @VMAP@("ACTORFROM2")="ACTORSYSTEM_1" ; SECOND FROM IS THE SYSTEM
190 . S @VMAP@("ACTORTO")="ACTORPATIENT_"_DFN ; FOR TEST PURPOSES
191 . S @VMAP@("PURPOSEDESCRIPTION")="CEND PHR" ; FOR TEST PURPOSES
192 . S @VMAP@("ACTORTOTEXT")="Patient" ; FOR TEST PURPOSES
193 . ; THIS IS THE USE CASE FOR THE PHR WHERE "TO" IS THE PATIENT
194 I IHDR'="" D ; HEADER VALUES ARE PROVIDED
195 . D CP^GPLXPATH(IHDR,VMAP) ; COPY HEADER VARIABLES TO MAP ARRAY
196 N CTMP
197 D MAP^GPLXPATH(CXML,VMAP,"CTMP")
198 D CP^GPLXPATH("CTMP",CXML)
199 Q
200 ;
201ACTLST(AXML,ACTRTN) ; RETURN THE ACTOR LIST FOR THE XML IN AXML
202 ; AXML AND ACTRTN ARE PASSED BY NAME
203 ; EACH ACTOR RECORD HAS 3 PARTS - IE IF OBJECTID=ACTORPATIENT_2
204 ; P1= OBJECTID - ACTORPATIENT_2
205 ; P2= OBJECT TYPE - PATIENT OR PROVIDER OR SOFTWARE
206 ;OR INSTITUTION
207 ; OR PERSON(IN PATIENT FILE IE NOK)
208 ; P3= IEN RECORD NUMBER FOR ACTOR - 2
209 N I,J,K,L
210 K @ACTRTN ; CLEAR RETURN ARRAY
211 F I=1:1:@AXML@(0) D ; SCAN ALL LINES
212 . I @AXML@(I)?.E1"<ActorID>".E D ; THERE IS AN ACTOR THIS LINE
213 . . S J=$P($P(@AXML@(I),"<ActorID>",2),"</ActorID>",1)
214 . . W "<ActorID>=>",J,!
215 . . I J'="" S K(J)="" ; HASHING ACTOR
216 . . ; TO GET RID OF DUPLICATES
217 S I="" ; GOING TO $O THROUGH THE HASH
218 F J=0:0 D Q:$O(K(I))="" ;
219 . S I=$O(K(I)) ; WALK THROUGH THE HASH OF ACTORS
220 . S $P(L,U,1)=I ; FIRST PIECE IS THE OBJECT ID
221 . S $P(L,U,2)=$P($P(I,"ACTOR",2),"_",1) ; ACTOR TYPE
222 . S $P(L,U,3)=$P(I,"_",2) ; IEN RECORD NUMBER FOR ACTOR
223 . D PUSH^GPLXPATH(ACTRTN,L) ; ADD THE ACTOR TO THE RETURN ARRAY
224 Q
225 ;
226TEST ; RUN ALL THE TEST CASES
227 D TESTALL^GPLUNIT("GPLCCR")
228 Q
229 ;
230ZTEST(WHICH) ; RUN ONE SET OF TESTS
231 N ZTMP
232 D ZLOAD^GPLUNIT("ZTMP","GPLCCR")
233 D ZTEST^GPLUNIT(.ZTMP,WHICH)
234 Q
235 ;
236TLIST ; LIST THE TESTS
237 N ZTMP
238 D ZLOAD^GPLUNIT("ZTMP","GPLCCR")
239 D TLIST^GPLUNIT(.ZTMP)
240 Q
241 ;
242 ;;><TEST>
243 ;;><PROBLEMS>
244 ;;>>>K GPL S GPL=""
245 ;;>>>D CCRRPC^GPLCCR(.GPL,"2","PROBLEMS","","","")
246 ;;>>?@GPL@(@GPL@(0))["</Problems>"
247 ;;><VITALS>
248 ;;>>>K GPL S GPL=""
249 ;;>>>D CCRRPC^GPLCCR(.GPL,"2","VITALS","","","")
250 ;;>>?@GPL@(@GPL@(0))["</VitalSigns>"
251 ;;><CCR>
252 ;;>>>K GPL S GPL=""
253 ;;>>>D CCRRPC^GPLCCR(.GPL,"2","CCR","","","")
254 ;;>>?@GPL@(@GPL@(0))["</ContinuityOfCareRecord>"
255 ;;><ACTLST>
256 ;;>>>K GPL S GPL=""
257 ;;>>>D CCRRPC^GPLCCR(.GPL,"2","CCR","","","")
258 ;;>>>D ACTLST^GPLCCR(GPL,"ACTTEST")
259 ;;><ACTORS>
260 ;;>>>D ZTEST^GPLCCR("ACTLST")
261 ;;>>>D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","G2")
262 ;;>>>D EXTRACT^GPLACTOR("G2","ACTTEST","G3")
263 ;;>>?G3(G3(0))["</Actors>"
264 ;;><TRIM>
265 ;;>>>D ZTEST^GPLCCR("CCR")
266 ;;>>>W $$TRIM^GPLXPATH(CCDGLO)
267 ;;><CCD>
268 ;;>>>K GPL S GPL=""
269 ;;>>>D CCRRPC^GPLCCR(.GPL,"2","CCD","","","")
270 ;;>>?@GPL@(@GPL@(0))["</ContinuityOfCareRecord>"
271 ;;></TEST>
Note: See TracBrowser for help on using the repository browser.