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

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

CCD processing checks for missing sections

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