1 | GPLCCR ; CCDCCR/GPL - CCR 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 | ;
|
---|
22 | EXPORT ; 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 | ;
|
---|
30 | XPAT(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 CCRGLO
|
---|
34 | I '$D(DIR) S DIR=""
|
---|
35 | I '$D(FN) S FN=""
|
---|
36 | D CCRRPC(.CCRGLO,DFN,"CCR","","","")
|
---|
37 | S OARY=$NA(^TMP("GPLCCR",$J,DFN,"CCR",1))
|
---|
38 | S ONAM=FN
|
---|
39 | I FN="" S ONAM="PAT_"_DFN_"_CCR_V1.xml"
|
---|
40 | S ODIRGLB=$NA(^TMP("GPLCCR","ODIR"))
|
---|
41 | I '$D(@ODIRGLB) D ; IF NOT ODIR HAS BEEN SET
|
---|
42 | . ;S @ODIRGLB="/home/glilly/CCROUT"
|
---|
43 | . ;S @ODIRGLB="/home/cedwards/"
|
---|
44 | . S @ODIRGLB="/opt/wv/p/"
|
---|
45 | S ODIR=DIR
|
---|
46 | I DIR="" S ODIR=@ODIRGLB
|
---|
47 | N ZY
|
---|
48 | S ZY=$$OUTPUT^GPLXPATH(OARY,ONAM,ODIR)
|
---|
49 | W !,$P(ZY,U,2),!
|
---|
50 | Q
|
---|
51 | ;
|
---|
52 | DCCR(DFN) ; DISPLAY A CCR THAT HAS JUST BEEN EXTRACTED
|
---|
53 | ;
|
---|
54 | N G1
|
---|
55 | S G1=$NA(^TMP("GPLCCR",$J,DFN,"CCR"))
|
---|
56 | I $D(@G1@(0)) D ; CCR EXISTS
|
---|
57 | . D PARY^GPLXPATH(G1)
|
---|
58 | E W "CCR NOT CREATED, RUN D XPAT^GPLCCR(DFN,"""","""") FIRST",!
|
---|
59 | Q
|
---|
60 | ;
|
---|
61 | CCRRPC(CCRGRTN,DFN,CCRPART,TIME1,TIME2,HDRARY) ;RPC ENTRY POINT FOR CCR OUTPUT
|
---|
62 | ; CCRGRTN IS RETURN ARRAY PASSED BY NAME
|
---|
63 | ; DFN IS PATIENT IEN
|
---|
64 | ; CCRPART IS "CCR" FOR ENTIRE CCR, OR SECTION NAME FOR A PART
|
---|
65 | ; OF THE CCR BODY.. PARTS INCLUDE "PROBLEMS" "VITALS" ETC
|
---|
66 | ; TIME1 IS STARTING TIME TO INCLUDE - NULL MEANS ALL
|
---|
67 | ; TIME2 IS ENDING TIME TO INCLUDE TIME IS FILEMAN TIME
|
---|
68 | ; - NULL MEANS NOW
|
---|
69 | ; HDRARY IS THE HEADER ARRAY DEFINING THE "FROM" AND
|
---|
70 | ; "TO" VARIABLES
|
---|
71 | ; IF NULL WILL DEFAULT TO "FROM" DUZ AND "TO" DFN
|
---|
72 | I '$D(DEBUG) S DEBUG=0
|
---|
73 | S CCD=0 ; NEED THIS FLAG TO DISTINGUISH FROM CCD
|
---|
74 | I '$D(TESTLAB) S TESTLAB=0 ; FLAG FOR TESTING RESULTS SECTION
|
---|
75 | I '$D(TESTALERT) S TESTALERT=0 ; FLAG FOR TESTING ALERTS SECTION
|
---|
76 | I '$D(TESTMEDS) S TESTMEDS=0 ; FLAG FOR TESTING CCRMEDS SECTION
|
---|
77 | S TGLOBAL=$NA(^TMP("GPLCCR",$J,"TEMPLATE")) ; GLOBAL FOR STORING TEMPLATE
|
---|
78 | S CCRGLO=$NA(^TMP("GPLCCR",$J,DFN,"CCR")) ; GLOBAL FOR BUILDING THE CCR
|
---|
79 | S ACTGLO=$NA(^TMP("GPLCCR",$J,DFN,"ACTORS")) ; GLOBAL FOR ALL ACTORS
|
---|
80 | ; TO GET PART OF THE CCR RETURNED, PASS CCRPART="PROBLEMS" ETC
|
---|
81 | S CCRGRTN=$NA(^TMP("GPLCCR",$J,DFN,CCRPART)) ; RTN GLO NM OF PART OR ALL
|
---|
82 | D LOAD^GPLCCR0(TGLOBAL) ; LOAD THE CCR TEMPLATE
|
---|
83 | D CP^GPLXPATH(TGLOBAL,CCRGLO) ; COPY THE TEMPLATE TO CCR GLOBAL
|
---|
84 | ;
|
---|
85 | ; DELETE THE BODY, ACTORS AND SIGNATURES SECTIONS FROM GLOBAL
|
---|
86 | ; THESE WILL BE POPULATED AFTER CALLS TO THE XPATH ROUTINES
|
---|
87 | D REPLACE^GPLXPATH(CCRGLO,"","//ContinuityOfCareRecord/Body")
|
---|
88 | D REPLACE^GPLXPATH(CCRGLO,"","//ContinuityOfCareRecord/Actors")
|
---|
89 | D REPLACE^GPLXPATH(CCRGLO,"","//ContinuityOfCareRecord/Signatures")
|
---|
90 | I DEBUG F I=1:1:@CCRGLO@(0) W @CCRGLO@(I),!
|
---|
91 | ;
|
---|
92 | D HDRMAP(CCRGLO,DFN,HDRARY) ; MAP HEADER VARIABLES
|
---|
93 | ;
|
---|
94 | K ^TMP("GPLCCR",$J,"CCRSTEP") ; KILL GLOBAL PRIOR TO ADDING TO IT
|
---|
95 | S CCRXTAB=$NA(^TMP("GPLCCR",$J,"CCRSTEP")) ; GLOBAL TO STORE CCR STEPS
|
---|
96 | D INITSTPS(CCRXTAB) ; INITIALIZED CCR PROCESSING STEPS
|
---|
97 | N PROCI,XI,TAG,RTN,CALL,XPATH,IXML,OXML,INXML,CCRBLD
|
---|
98 | F PROCI=1:1:@CCRXTAB@(0) D ; PROCESS THE CCR BODY SECTIONS
|
---|
99 | . S XI=@CCRXTAB@(PROCI) ; CALL COPONENTS TO PARSE
|
---|
100 | . S RTN=$P(XI,";",2) ; NAME OF ROUTINE TO CALL
|
---|
101 | . S TAG=$P(XI,";",1) ; LABEL INSIDE ROUTINE TO CALL
|
---|
102 | . S XPATH=$P(XI,";",3) ; XPATH TO XML TO PASS TO ROUTINE
|
---|
103 | . D QUERY^GPLXPATH(TGLOBAL,XPATH,"INXML") ; EXTRACT XML TO PASS
|
---|
104 | . S IXML="INXML"
|
---|
105 | . S OXML=$P(XI,";",4) ; ARRAY FOR SECTION VALUES
|
---|
106 | . ; K @OXML ; KILL EXPECTED OUTPUT ARRAY
|
---|
107 | . ; W OXML,!
|
---|
108 | . S CALL="D "_TAG_"^"_RTN_"(IXML,DFN,OXML)" ; SETUP THE CALL
|
---|
109 | . I DEBUG W "RUNNING ",CALL,!
|
---|
110 | . X CALL
|
---|
111 | . ; NOW INSERT THE RESULTS IN THE CCR BUFFER
|
---|
112 | . I @OXML@(0)'=0 D ; THERE IS A RESULT
|
---|
113 | . . D INSERT^GPLXPATH(CCRGLO,OXML,"//ContinuityOfCareRecord/Body")
|
---|
114 | . . I DEBUG F GPLI=1:1:@OXML@(0) W @OXML@(GPLI),!
|
---|
115 | D ACTLST^GPLCCR(CCRGLO,ACTGLO) ; GEN THE ACTOR LIST
|
---|
116 | D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","ACTT")
|
---|
117 | D EXTRACT^GPLACTOR("ACTT",ACTGLO,"ACTT2")
|
---|
118 | D INSINNER^GPLXPATH(CCRGLO,"ACTT2","//ContinuityOfCareRecord/Actors")
|
---|
119 | N TRIMI,J,DONE S DONE=0
|
---|
120 | F TRIMI=0:0 D Q:DONE ; DELETE UNTIL ALL EMPTY ELEMENTS ARE GONE
|
---|
121 | . S J=$$TRIM^GPLXPATH(CCRGLO) ; DELETE EMPTY ELEMENTS
|
---|
122 | . I DEBUG W "TRIMMED",J,!
|
---|
123 | . I J=0 S DONE=1 ; DONE WHEN TRIM RETURNS FALSE
|
---|
124 | Q
|
---|
125 | ;
|
---|
126 | INITSTPS(TAB) ; INITIALIZE CCR PROCESSING STEPS
|
---|
127 | ; TAB IS PASSED BY NAME
|
---|
128 | I DEBUG W "TAB= ",TAB,!
|
---|
129 | ; ORDER FOR CCR IS PROBLEMS,FAMILYHISTORY,SOCIALHISTORY,MEDICATIONS,VITALSIGNS,RESULTS,HEALTHCAREPROVIDERS
|
---|
130 | D PUSH^GPLXPATH(TAB,"EXTRACT;GPLPROBS;//ContinuityOfCareRecord/Body/Problems;^TMP(""GPLCCR"",$J,DFN,""PROBLEMS"")")
|
---|
131 | I TESTMEDS D PUSH^GPLXPATH(TAB,"EXTRACT;CCRMEDS;//ContinuityOfCareRecord/Body/Medications;^TMP(""GPLCCR"",$J,DFN,""MEDICATIONS"")")
|
---|
132 | E D PUSH^GPLXPATH(TAB,"EXTRACT;GPLMEDS;//ContinuityOfCareRecord/Body/Medications;^TMP(""GPLCCR"",$J,DFN,""MEDICATIONS"")")
|
---|
133 | D PUSH^GPLXPATH(TAB,"EXTRACT;GPLVITAL;//ContinuityOfCareRecord/Body/VitalSigns;^TMP(""GPLCCR"",$J,DFN,""VITALS"")")
|
---|
134 | I TESTLAB D PUSH^GPLXPATH(TAB,"EXTRACT;GPLLABS;//ContinuityOfCareRecord/Body/Results;^TMP(""GPLCCR"",$J,DFN,""RESULTS"")")
|
---|
135 | I TESTALERT D PUSH^GPLXPATH(TAB,"EXTRACT;GPLALERT;//ContinuityOfCareRecord/Body/Alerts;^TMP(""GPLCCR"",$J,DFN,""ALERTS"")")
|
---|
136 | Q
|
---|
137 | ;
|
---|
138 | HDRMAP(CXML,DFN,IHDR) ; MAP HEADER VARIABLES: FROM, TO ECT
|
---|
139 | N VMAP S VMAP=$NA(^TMP("GPLCCR",$J,DFN,"HEADER"))
|
---|
140 | ; K @VMAP
|
---|
141 | S @VMAP@("DATETIME")=$$FMDTOUTC^CCRUTIL($$NOW^XLFDT,"DT")
|
---|
142 | I IHDR="" D ; HEADER ARRAY IS NOT PROVIDED, USE DEFAULTS
|
---|
143 | . S @VMAP@("ACTORPATIENT")="ACTORPATIENT_"_DFN
|
---|
144 | . S @VMAP@("ACTORFROM")="ACTORORGANIZATION_"_DUZ ; FROM DUZ - ???
|
---|
145 | . S @VMAP@("ACTORFROM2")="ACTORSYSTEM_1" ; SECOND FROM IS THE SYSTEM
|
---|
146 | . S @VMAP@("ACTORTO")="ACTORPATIENT_"_DFN ; FOR TEST PURPOSES
|
---|
147 | . S @VMAP@("PURPOSEDESCRIPTION")="CEND PHR" ; FOR TEST PURPOSES
|
---|
148 | . S @VMAP@("ACTORTOTEXT")="Patient" ; FOR TEST PURPOSES
|
---|
149 | . ; THIS IS THE USE CASE FOR THE PHR WHERE "TO" IS THE PATIENT
|
---|
150 | I IHDR'="" D ; HEADER VALUES ARE PROVIDED
|
---|
151 | . D CP^GPLXPATH(IHDR,VMAP) ; COPY HEADER VARIABLES TO MAP ARRAY
|
---|
152 | N CTMP
|
---|
153 | D MAP^GPLXPATH(CXML,VMAP,"CTMP")
|
---|
154 | D CP^GPLXPATH("CTMP",CXML)
|
---|
155 | Q
|
---|
156 | ;
|
---|
157 | ACTLST(AXML,ACTRTN) ; RETURN THE ACTOR LIST FOR THE XML IN AXML
|
---|
158 | ; AXML AND ACTRTN ARE PASSED BY NAME
|
---|
159 | ; EACH ACTOR RECORD HAS 3 PARTS - IE IF OBJECTID=ACTORPATIENT_2
|
---|
160 | ; P1= OBJECTID - ACTORPATIENT_2
|
---|
161 | ; P2= OBJECT TYPE - PATIENT OR PROVIDER OR SOFTWARE
|
---|
162 | ;OR INSTITUTION
|
---|
163 | ; OR PERSON(IN PATIENT FILE IE NOK)
|
---|
164 | ; P3= IEN RECORD NUMBER FOR ACTOR - 2
|
---|
165 | N I,J,K,L
|
---|
166 | K @ACTRTN ; CLEAR RETURN ARRAY
|
---|
167 | F I=1:1:@AXML@(0) D ; SCAN ALL LINES
|
---|
168 | . I @AXML@(I)?.E1"<ActorID>".E D ; THERE IS AN ACTOR THIS LINE
|
---|
169 | . . S J=$P($P(@AXML@(I),"<ActorID>",2),"</ActorID>",1)
|
---|
170 | . . I DEBUG W "<ActorID>=>",J,!
|
---|
171 | . . I J'="" S K(J)="" ; HASHING ACTOR
|
---|
172 | . . ; TO GET RID OF DUPLICATES
|
---|
173 | S I="" ; GOING TO $O THROUGH THE HASH
|
---|
174 | F J=0:0 D Q:$O(K(I))=""
|
---|
175 | . S I=$O(K(I)) ; WALK THROUGH THE HASH OF ACTORS
|
---|
176 | . S $P(L,U,1)=I ; FIRST PIECE IS THE OBJECT ID
|
---|
177 | . S $P(L,U,2)=$P($P(I,"ACTOR",2),"_",1) ; ACTOR TYPE
|
---|
178 | . S $P(L,U,3)=$P(I,"_",2) ; IEN RECORD NUMBER FOR ACTOR
|
---|
179 | . D PUSH^GPLXPATH(ACTRTN,L) ; ADD THE ACTOR TO THE RETURN ARRAY
|
---|
180 | Q
|
---|
181 | ;
|
---|
182 | TEST ; RUN ALL THE TEST CASES
|
---|
183 | D TESTALL^GPLUNIT("GPLCCR")
|
---|
184 | Q
|
---|
185 | ;
|
---|
186 | ZTEST(WHICH) ; RUN ONE SET OF TESTS
|
---|
187 | N ZTMP
|
---|
188 | D ZLOAD^GPLUNIT("ZTMP","GPLCCR")
|
---|
189 | D ZTEST^GPLUNIT(.ZTMP,WHICH)
|
---|
190 | Q
|
---|
191 | ;
|
---|
192 | TLIST ; LIST THE TESTS
|
---|
193 | N ZTMP
|
---|
194 | D ZLOAD^GPLUNIT("ZTMP","GPLCCR")
|
---|
195 | D TLIST^GPLUNIT(.ZTMP)
|
---|
196 | Q
|
---|
197 | ;
|
---|
198 | ;;><TEST>
|
---|
199 | ;;><PROBLEMS>
|
---|
200 | ;;>>>K GPL S GPL=""
|
---|
201 | ;;>>>D CCRRPC^GPLCCR(.GPL,"2","PROBLEMS","","","")
|
---|
202 | ;;>>?@GPL@(@GPL@(0))["</Problems>"
|
---|
203 | ;;><VITALS>
|
---|
204 | ;;>>>K GPL S GPL=""
|
---|
205 | ;;>>>D CCRRPC^GPLCCR(.GPL,"2","VITALS","","","")
|
---|
206 | ;;>>?@GPL@(@GPL@(0))["</VitalSigns>"
|
---|
207 | ;;><CCR>
|
---|
208 | ;;>>>K GPL S GPL=""
|
---|
209 | ;;>>>D CCRRPC^GPLCCR(.GPL,"2","CCR","","","")
|
---|
210 | ;;>>?@GPL@(@GPL@(0))["</ContinuityOfCareRecord>"
|
---|
211 | ;;><ACTLST>
|
---|
212 | ;;>>>K GPL S GPL=""
|
---|
213 | ;;>>>D CCRRPC^GPLCCR(.GPL,"2","CCR","","","")
|
---|
214 | ;;>>>D ACTLST^GPLCCR(GPL,"ACTTEST")
|
---|
215 | ;;><ACTORS>
|
---|
216 | ;;>>>D ZTEST^GPLCCR("ACTLST")
|
---|
217 | ;;>>>D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","G2")
|
---|
218 | ;;>>>D EXTRACT^GPLACTOR("G2","ACTTEST","G3")
|
---|
219 | ;;>>?G3(G3(0))["</Actors>"
|
---|
220 | ;;><TRIM>
|
---|
221 | ;;>>>D ZTEST^GPLCCR("CCR")
|
---|
222 | ;;>>>W $$TRIM^GPLXPATH(CCRGLO)
|
---|
223 | ;;><ALERTS>
|
---|
224 | ;;>>>S TESTALERT=1
|
---|
225 | ;;>>>K GPL S GPL=""
|
---|
226 | ;;>>>D CCRRPC^GPLCCR(.GPL,"2","ALERTS","","","")
|
---|
227 | ;;>>?@GPL@(@GPL@(0))["</Alerts>"
|
---|
228 |
|
---|