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