source: ccr/trunk/p/C0CCCD.m@ 1724

Last change on this file since 1724 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

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