source: ccr/trunk/p/C0CCCR.m@ 1742

Last change on this file since 1742 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/C0CCCR.m1290
    /ccr/branches/ohum/p/C0CCCR.m1291-1543
    /ccr/branches/ohum/p/p/C0CCCR.m1287-1289
File size: 12.0 KB
RevLine 
[1544]1C0CCCR ; CCDCCR/GPL - CCR MAIN PROCESSING; 6/6/08
[1586]2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
[1544]3 ;Copyright 2008,2009 George Lilly, University of Minnesota.
4 ;
[1586]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.
[1544]9 ;
[1586]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.
[1544]14 ;
[1586]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/>.
[1544]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 ;OHUM/RUT 3120109 commented
26 ;;OHUM/RUT 3120102 To take inputs from user for date limits and notes
27 ;D ^C0CVALID
28 ;;OHUM/RUT
29 ;OHUM/RUT
30 D XPAT(DFN) ; EXPORT TO A FILE
31 Q
32 ;
33XPAT(DFN,XPARMS,DIR,FN) ; EXPORT ONE PATIENT TO A FILE
34 ; DIR IS THE DIRECTORY, DEFAULTS IF NULL TO ^TMP("C0CCCR","ODIR")
35 ; FN IS FILE NAME, DEFAULTS IF NULL
36 N CCRGLO,UDIR,UFN
37 S C0CNRPC=1 ; FLAG FOR NOT AN RPC CALL - FOR DEBUGGING THE RPC
38 I '$D(DIR) S UDIR=""
39 E S UDIR=DIR
40 I '$D(FN) S UFN="" ; IF FILENAME IS NOT PASSED
41 E S UFN=FN
42 I '$D(XPARMS) S XPARMS=""
43 N C0CRTN ; RETURN ARRAY
44 D CCRRPC(.C0CRTN,DFN,XPARMS,"CCR")
45 S OARY=$NA(^TMP("C0CCUR",$J,DFN,"CCR",1))
46 S ONAM=UFN
47 I UFN="" S ONAM="PAT_"_DFN_"_CCR_V1_0_0.xml"
48 S ODIRGLB=$NA(^TMP("C0CCCR","ODIR"))
49 S ^TMP("C0CCCR","FNAME",DFN)=ONAM ; FILE NAME FOR BATCH USE
50 I $D(^TMP("GPLCCR","ODIR")) S @ODIRGLB=^TMP("GPLCCR","ODIR")
51 I '$D(@ODIRGLB) D ; IF NOT ODIR HAS BEEN SET
52 . W "Warning.. please set ^TMP(""C0CCCR"",""ODIR"")=""output path""",! Q
53 . ;S @ODIRGLB="/home/glilly/CCROUT"
54 . ;S @ODIRGLB="/home/cedwards/"
55 . S @ODIRGLB="/opt/wv/p/"
56 S ODIR=UDIR
57 I UDIR="" S ODIR=@ODIRGLB
58 N ZY
59 S ZY=$$OUTPUT^C0CXPATH(OARY,ONAM,ODIR)
60 W !,$P(ZY,U,2),!
61 Q
62 ;
63DCCR(DFN) ; DISPLAY A CCR THAT HAS JUST BEEN EXTRACTED
64 ;
65 N G1
66 S G1=$NA(^TMP("C0CCUR",$J,DFN,"CCR"))
67 I $D(@G1@(0)) D ; CCR EXISTS
68 . D PARY^C0CXPATH(G1)
69 E W "CCR NOT CREATED, RUN D XPAT^C0CCCR(DFN,"""","""") FIRST",!
70 Q
71 ;
72CCRRPC(CCRGRTN,DFN,CCRPARMS,CCRPART) ;RPC ENTRY POINT FOR CCR OUTPUT
73 ; CCRGRTN IS RETURN ARRAY PASSED BY REFERENCE
74 ; DFN IS PATIENT IEN
75 ; CCRPART IS "CCR" FOR ENTIRE CCR, OR SECTION NAME FOR A PART
76 ; OF THE CCR BODY.. PARTS INCLUDE "PROBLEMS" "VITALS" ETC
77 ; CCRPARMS ARE PARAMETERS THAT AFFECT THE EXTRACTION
78 ; IN THE FORM "PARM1:VALUE1^PARM2:VALUE2"
79 ; EXAMPLE: "LABLIMIT:T-60" TO LIMIT LAB EXTRACTION TO THE LAST 60 DAYS
80 ; SEE C0CPARMS FOR A COMPLETE LIST OF SUPPORTED PARAMETERS
81 K ^TMP("C0CCCR",$J) ; CLEAN UP THE GLOBAL BEFORE WE USE IT
82 M ^TMP("C0CSAV",$J)=^TMP($J) ; SAVING CALLER'S TMP SETTINGS
83 K ^TMP($J) ; START CLEAN
84 I '$D(DEBUG) S DEBUG=0
85 S CCD=0 ; NEED THIS FLAG TO DISTINGUISH FROM CCD
86 I '$D(CCRPARMS) S CCRPARMS=""
87 I '$D(CCRPART) S CCRPART="CCR"
88 I '$D(C0CNRPC) S ^TMP("C0CRPC",$H,"CALL",DFN)=""
89 D SET^C0CPARMS(CCRPARMS) ;SET PARAMETERS WITH CCRPARMS AS OVERRIDES
90 I '$D(TESTVIT) S TESTVIT=0 ; FLAG FOR TESTING VITALS
91 I '$D(TESTLAB) S TESTLAB=0 ; FLAG FOR TESTING RESULTS SECTION
92 I '$D(TESTALERT) S TESTALERT=1 ; FLAG FOR TESTING ALERTS SECTION
93 I '$D(TESTMEDS) S TESTMEDS=0 ; FLAG FOR TESTING C0CMED SECTION
94 S TGLOBAL=$NA(^TMP("C0CCCR",$J,"TEMPLATE")) ; GLOBAL FOR STORING TEMPLATE
95 S CCRGLO=$NA(^TMP("C0CCUR",$J,DFN,"CCR")) ; GLOBAL FOR BUILDING THE CCR
96 S ACTGLO=$NA(^TMP("C0CCCR",$J,DFN,"ACTORS")) ; GLOBAL FOR ALL ACTORS
97 ; TO GET PART OF THE CCR RETURNED, PASS CCRPART="PROBLEMS" ETC
98 ;M CCRGRTN=^TMP("C0CCCR",$J,DFN,CCRPART) ; RTN GLOBAL OF PART OR ALL
99 D LOAD^C0CCCR0(TGLOBAL) ; LOAD THE CCR TEMPLATE
100 D CP^C0CXPATH(TGLOBAL,CCRGLO) ; COPY THE TEMPLATE TO CCR GLOBAL
101 ;
102 ; DELETE THE BODY, ACTORS AND SIGNATURES SECTIONS FROM GLOBAL
103 ; THESE WILL BE POPULATED AFTER CALLS TO THE XPATH ROUTINES
104 D REPLACE^C0CXPATH(CCRGLO,"","//ContinuityOfCareRecord/Body")
105 D REPLACE^C0CXPATH(CCRGLO,"","//ContinuityOfCareRecord/Actors")
106 D REPLACE^C0CXPATH(CCRGLO,"","//ContinuityOfCareRecord/Signatures")
107 D REPLACE^C0CXPATH(CCRGLO,"","//ContinuityOfCareRecord/Comments")
108 I DEBUG F I=1:1:@CCRGLO@(0) W @CCRGLO@(I),!
109 ;
110 D HDRMAP(CCRGLO,DFN) ; MAP HEADER VARIABLES
111 ;
112 K ^TMP("C0CCCR",$J,"CCRSTEP") ; KILL GLOBAL PRIOR TO ADDING TO IT
113 S CCRXTAB=$NA(^TMP("C0CCCR",$J,"CCRSTEP")) ; GLOBAL TO STORE CCR STEPS
114 D INITSTPS(CCRXTAB) ; INITIALIZED CCR PROCESSING STEPS
115 N PROCI,XI,TAG,RTN,CALL,XPATH,IXML,OXML,INXML,CCRBLD
116 F PROCI=1:1:@CCRXTAB@(0) D ; PROCESS THE CCR BODY SECTIONS
117 . S XI=@CCRXTAB@(PROCI) ; CALL COPONENTS TO PARSE
118 . S RTN=$P(XI,";",2) ; NAME OF ROUTINE TO CALL
119 . S TAG=$P(XI,";",1) ; LABEL INSIDE ROUTINE TO CALL
120 . S XPATH=$P(XI,";",3) ; XPATH TO XML TO PASS TO ROUTINE
121 . D QUERY^C0CXPATH(TGLOBAL,XPATH,"INXML") ; EXTRACT XML TO PASS
122 . S IXML="INXML"
123 . S OXML=$P(XI,";",4) ; ARRAY FOR SECTION VALUES
124 . ; K @OXML ; KILL EXPECTED OUTPUT ARRAY
125 . ; W OXML,!
126 . S CALL="D "_TAG_"^"_RTN_"(IXML,DFN,OXML)" ; SETUP THE CALL
127 . W "RUNNING ",CALL,!
128 . X CALL
129 . ; NOW INSERT THE RESULTS IN THE CCR BUFFER
130 . I $G(@OXML@(0))>0 D ; THERE IS A RESULT
131 . . D INSERT^C0CXPATH(CCRGLO,OXML,"//ContinuityOfCareRecord/Body")
132 . . I DEBUG F C0CI=1:1:@OXML@(0) W @OXML@(C0CI),!
133 N ACTT,ATMP,ACTT2,ATMP2 ; TEMPORARY ARRAY SYMBOLS FOR ACTOR PROCESSING
134 D ACTLST^C0CCCR(CCRGLO,ACTGLO) ; GEN THE ACTOR LIST
135 D QUERY^C0CXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","ACTT")
136 D EXTRACT^C0CACTOR("ACTT",ACTGLO,"ACTT2")
137 D INSINNER^C0CXPATH(CCRGLO,"ACTT2","//ContinuityOfCareRecord/Actors")
138 K ACTT,ACTT2
139 ;D QUERY^C0CXPATH(TGLOBAL,"//ContinuityOfCareRecord/Comments","CMTT")
140 ;D EXTRACT^C0CCMT("CMTT",DFN,"CMTT2")
141 ;D INSINNER^C0CXPATH(CCRGLO,"CMTT2","//ContinuityOfCareRecord/Comments")
142 ; gpl - turned off Comments for Certification
143 K CMTT,CMTT2
144 N TRIMI,J,DONE S DONE=0
145 F TRIMI=0:0 D Q:DONE ; DELETE UNTIL ALL EMPTY ELEMENTS ARE GONE
146 . S J=$$TRIM^C0CXPATH(CCRGLO) ; DELETE EMPTY ELEMENTS
147 . I DEBUG W "TRIMMED",J,!
148 . I J=0 S DONE=1 ; DONE WHEN TRIM RETURNS FALSE
149 ;S CCRGRTN=$NA(^TMP("C0CCCR",$J,DFN,CCRPART)) ; RTN GLOBAL OF PART OR ALL
150 I CCRPART="CCR" M CCRGRTN=@CCRGLO ; ENTIRE CCR
151 E M CCRGRTN=^TMP("C0CCCR",$J,DFN,CCRPART) ; RTN GLOBAL OF PART
152 I '$D(C0CNRPC) S ^TMP("C0CRPC",$H,"RESULT",CCRGRTN(0))=""
153 K ^TMP("C0CCCR",$J) ; BEGIN TO CLEAN UP
154 K ^TMP($J) ; REALLY CLEAN UP
155 M ^TMP($J)=^TMP("C0CSAV",$J) ; RESTORE CALLER'S $J
156 Q
157 ;
158INITSTPS(TAB) ; INITIALIZE CCR PROCESSING STEPS
159 ; TAB IS PASSED BY NAME
160 I DEBUG W "TAB= ",TAB,!
161 ; ORDER FOR CCR IS PROBLEMS,FAMILYHISTORY,SOCIALHISTORY,MEDICATIONS,VITALSIGNS,RESULTS,HEALTHCAREPROVIDERS
162 D PUSH^C0CXPATH(TAB,"EXTRACT;C0CPROBS;//ContinuityOfCareRecord/Body/Problems;^TMP(""C0CCCR"",$J,DFN,""PROBLEMS"")")
163 I TESTALERT D PUSH^C0CXPATH(TAB,"EXTRACT;C0CALERT;//ContinuityOfCareRecord/Body/Alerts;^TMP(""C0CCCR"",$J,DFN,""ALERTS"")")
164 D PUSH^C0CXPATH(TAB,"EXTRACT;C0CMED;//ContinuityOfCareRecord/Body/Medications;^TMP(""C0CCCR"",$J,DFN,""MEDICATIONS"")")
165 D PUSH^C0CXPATH(TAB,"MAP;C0CIMMU;//ContinuityOfCareRecord/Body/Immunizations;^TMP(""C0CCCR"",$J,DFN,""IMMUNE"")")
166 I TESTVIT D PUSH^C0CXPATH(TAB,"EXTRACT;C0CVIT2;//ContinuityOfCareRecord/Body/VitalSigns;^TMP(""C0CCCR"",$J,DFN,""VITALS"")")
167 E D PUSH^C0CXPATH(TAB,"EXTRACT;C0CVITAL;//ContinuityOfCareRecord/Body/VitalSigns;^TMP(""C0CCCR"",$J,DFN,""VITALS"")")
168 D PUSH^C0CXPATH(TAB,"MAP;C0CLABS;//ContinuityOfCareRecord/Body/Results;^TMP(""C0CCCR"",$J,DFN,""RESULTS"")")
169 D PUSH^C0CXPATH(TAB,"EXTRACT;C0CPROC;//ContinuityOfCareRecord/Body/Procedures;^TMP(""C0CCCR"",$J,DFN,""PROCEDURES"")")
170 ;D PUSH^C0CXPATH(TAB,"EXTRACT;C0CENC;//ContinuityOfCareRecord/Body/Encounters;^TMP(""C0CCCR"",$J,DFN,""ENCOUNTERS"")")
171 ; gpl - turned off Encounters for Certification
172 ;OHUM/RUT 3120109 Changed the condition
173 ;;OHUM/RUT 3111228 Condition for Notes ; It should be included or not
174 ;;I ^TMP("C0CCCR","TIULIMIT")'="" D PUSH^C0CXPATH(TAB,"EXTRACT;C0CENC;//ContinuityOfCareRecord/Body/Encounters;^TMP(""C0CCCR"",$J,DFN,""ENCOUNTERS"")")
175 I $P(^C0CPARM(1,2),"^",3)=1 D PUSH^C0CXPATH(TAB,"EXTRACT;C0CENC;//ContinuityOfCareRecord/Body/Encounters;^TMP(""C0CCCR"",$J,DFN,""ENCOUNTERS"")")
176 ;;OHUM/RUT
177 ;OHUM/RUT
178 Q
179 ;
180HDRMAP(CXML,DFN) ; 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 D ; ALWAYS MAP THESE VARIABLES
186 . S @VMAP@("CCRDOCOBJECTID")=$$UUID^C0CUTIL ; UUID FOR THIS CCR
187 . S @VMAP@("ACTORPATIENT")="ACTORPATIENT_"_DFN
188 . S @VMAP@("ACTORFROM")="ACTORPROVIDER_"_DUZ ; FROM DUZ - FROM PROVIDER
189 . ;S @VMAP@("ACTORFROM")="ACTORORGANIZATION_"_DUZ ; FROM DUZ - ???
190 . S @VMAP@("ACTORFROM2")="ACTORSYSTEM_1" ; SECOND FROM IS THE SYSTEM
191 . S @VMAP@("ACTORTO")="ACTORPATIENT_"_DFN ; FOR TEST PURPOSES
192 . S @VMAP@("PURPOSEDESCRIPTION")="CEND PHR" ; FOR TEST PURPOSES
193 . S @VMAP@("ACTORTOTEXT")="Patient" ; FOR TEST PURPOSES
194 . ; THIS IS THE USE CASE FOR THE PHR WHERE "TO" IS THE PATIENT
195 ;I IHDR'="" D ; HEADER VALUES ARE PROVIDED
196 ;. D CP^C0CXPATH(IHDR,VMAP) ; COPY HEADER VARIABLES TO MAP ARRAY
197 N CTMP
198 D MAP^C0CXPATH(CXML,VMAP,"CTMP")
199 D CP^C0CXPATH("CTMP",CXML)
200 N HRIMVARS ;
201 S HRIMVARS=$NA(^TMP("C0CRIM","VARS",DFN,"HEADER")) ; TO PERSIST VARS
202 M @HRIMVARS@(1)=@VMAP ; PERSIST THE HEADER VARIABLES IN RIM TABLE
203 S @HRIMVARS@(0)=1 ; ONLY ONE SET OF HEADERS PER PATIENT
204 Q
205 ;
206ACTLST(AXML,ACTRTN) ; RETURN THE ACTOR LIST FOR THE XML IN AXML
207 ; AXML AND ACTRTN ARE PASSED BY NAME
208 ; EACH ACTOR RECORD HAS 3 PARTS - IE IF OBJECTID=ACTORPATIENT_2
209 ; P1= OBJECTID - ACTORPATIENT_2
210 ; P2= OBJECT TYPE - PATIENT OR PROVIDER OR SOFTWARE
211 ;OR INSTITUTION
212 ; OR PERSON(IN PATIENT FILE IE NOK)
213 ; P3= IEN RECORD NUMBER FOR ACTOR - 2
214 N I,J,K,L
215 K @ACTRTN ; CLEAR RETURN ARRAY
216 F I=1:1:@AXML@(0) D ; FIRST FIX MISSING LINKS
217 . I @AXML@(I)?.E1"_<".E D ;
218 . . N ZA,ZB
219 . . S ZA=$P(@AXML@(I),">",1)_">"
220 . . S ZB="<"_$P(@AXML@(I),"<",3)
221 . . S @AXML@(I)=ZA_"ACTORORGANIZATION_1"_ZB
222 F I=1:1:@AXML@(0) D ; SCAN ALL LINES
223 . I @AXML@(I)?.E1"<ActorID>".E D ; THERE IS AN ACTOR THIS LINE
224 . . S J=$P($P(@AXML@(I),"<ActorID>",2),"</ActorID>",1)
225 . . I $G(LINKDEBUG) W "<ActorID>=>",J,!
226 . . I J'="" S K(J)="" ; HASHING ACTOR
227 . I @AXML@(I)?.E1"<LinkID>".E D ; THERE IS AN ACTOR THIS LINE
228 . . S J=$P($P(@AXML@(I),"<LinkID>",2),"</LinkID>",1)
229 . . I $G(LINKDEBUG) W "<LinkID>=>",J,!
230 . . I J'="" S K(J)="" ; HASHING ACTOR
231 . . ; TO GET RID OF DUPLICATES
232 S I="" ; GOING TO $O THROUGH THE HASH
233 F J=0:0 D Q:$O(K(I))=""
234 . S I=$O(K(I)) ; WALK THROUGH THE HASH OF ACTORS
235 . S $P(L,U,1)=I ; FIRST PIECE IS THE OBJECT ID
236 . S $P(L,U,2)=$P($P(I,"ACTOR",2),"_",1) ; ACTOR TYPE
237 . S $P(L,U,3)=$P(I,"_",2) ; IEN RECORD NUMBER FOR ACTOR
238 . D PUSH^C0CXPATH(ACTRTN,L) ; ADD THE ACTOR TO THE RETURN ARRAY
239 Q
240 ;
241TEST ; RUN ALL THE TEST CASES
242 D TESTALL^C0CUNIT("C0CCCR")
243 Q
244 ;
245ZTEST(WHICH) ; RUN ONE SET OF TESTS
246 N ZTMP
247 D ZLOAD^C0CUNIT("ZTMP","C0CCCR")
248 D ZTEST^C0CUNIT(.ZTMP,WHICH)
249 Q
250 ;
251TLIST ; LIST THE TESTS
252 N ZTMP
253 D ZLOAD^C0CUNIT("ZTMP","C0CCCR")
254 D TLIST^C0CUNIT(.ZTMP)
255 Q
256 ;
257 ;;><TEST>
258 ;;><PROBLEMS>
259 ;;>>>K C0C S C0C=""
260 ;;>>>D CCRRPC^C0CCCR(.C0C,"2","PROBLEMS","")
261 ;;>>?@C0C@(@C0C@(0))["</Problems>"
262 ;;><VITALS>
263 ;;>>>K C0C S C0C=""
264 ;;>>>D CCRRPC^C0CCCR(.C0C,"2","VITALS","")
265 ;;>>?@C0C@(@C0C@(0))["</VitalSigns>"
266 ;;><CCR>
267 ;;>>>K C0C S C0C=""
268 ;;>>>D CCRRPC^C0CCCR(.C0C,"2","CCR","")
269 ;;>>?@C0C@(@C0C@(0))["</ContinuityOfCareRecord>"
270 ;;><ACTLST>
271 ;;>>>K C0C S C0C=""
272 ;;>>>D CCRRPC^C0CCCR(.C0C,"2","CCR","")
273 ;;>>>D ACTLST^C0CCCR(C0C,"ACTTEST")
274 ;;><ACTORS>
275 ;;>>>D ZTEST^C0CCCR("ACTLST")
276 ;;>>>D QUERY^C0CXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","G2")
277 ;;>>>D EXTRACT^C0CACTOR("G2","ACTTEST","G3")
278 ;;>>?G3(G3(0))["</Actors>"
279 ;;><TRIM>
280 ;;>>>D ZTEST^C0CCCR("CCR")
281 ;;>>>W $$TRIM^C0CXPATH(CCRGLO)
282 ;;><ALERTS>
283 ;;>>>S TESTALERT=1
284 ;;>>>K C0C S C0C=""
285 ;;>>>D CCRRPC^C0CCCR(.C0C,"2","ALERTS","")
286 ;;>>?@C0C@(@C0C@(0))["</Alerts>"
Note: See TracBrowser for help on using the repository browser.