source: ccr/trunk/p/GPLCCR.m@ 362

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

beginnings of CCR ELEMENTS fileman file support

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