1 | C0CIN ; CCDCCR/GPL - CCR IMPORT utilities; 9/20/08
|
---|
2 | ;;1.0;C0C;;Sep 20, 2009;
|
---|
3 | ;Copyright 2009 George Lilly. 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 | W "This is the CCR Import Utility Library ",!
|
---|
21 | Q
|
---|
22 | ;
|
---|
23 | TEST ; TESTS BOTH ROUTINES AT ONCE
|
---|
24 | N ZI,ZJ
|
---|
25 | S ZI="/home/vademo2/CCR" ;directory purposely leaving off the trailing /
|
---|
26 | S ZJ="PAT_358_CCR_V1_0_21.xml" ; random test patient
|
---|
27 | D RPCFIN(.GPL,358,"GPLTEST","CCR",ZJ,ZI)
|
---|
28 | Q
|
---|
29 | ;
|
---|
30 | RPCAIN(RTN,DFN,SOURCE,TYPE,ARY) ; ARRAY IN RPC - ACCEPT AN XML DOCUMENT
|
---|
31 | ; AND STORE IT IN THE INCOMING XML FILE
|
---|
32 | ; RETURNS THE IEN OF THE RECORD OR TEXT IF THERE IS AN ERROR
|
---|
33 | I $G(DFN)="" S RTN="DFN NOT DEFINED" Q ;
|
---|
34 | N C0CXF S C0CXF=175 ; FILE NUMBER FOR INCOMING XML FILE
|
---|
35 | N C0CFDA,ZX
|
---|
36 | S C0CFDA(C0CXF,"+1,",.01)=DFN ; PATIENT
|
---|
37 | S C0CFDA(C0CXF,"+1,",1)=$$NOW^XLFDT ;DATE
|
---|
38 | S C0CFDA(C0CXF,"+1,",2)=TYPE ;TYPE
|
---|
39 | S C0CFDA(C0CXF,"+1,",3)=$$ADDSRC(SOURCE) ;SOURCE
|
---|
40 | S C0CFDA(C0CXF,"+1,",7)="NEW" ; STATUS OF NEW FOR NOT PROCESSED
|
---|
41 | D UPDIE ; CREATE THE RECORD
|
---|
42 | S ZX=C0CIEN(1) ; CAPTURE THE RECORD NUMBER
|
---|
43 | D WP^DIE(C0CXF,ZX_",",4,,ARY,"ZERR")
|
---|
44 | ;W "RECORD:",ZX,!
|
---|
45 | S RTN=ZX ; RETURN IEN OF THE XML FILE
|
---|
46 | Q
|
---|
47 | ;
|
---|
48 | ADDSRC(ZSRC) ;EXTRISIC TO ADD A SOURCE TO THE CCR SOURCE FILE
|
---|
49 | ; RETURNS RECORD NUMBER. IF SOURCE EXISTS, JUST RETURNS IT'S RECORD NUMBER
|
---|
50 | ;
|
---|
51 | N ZX,ZF,C0CFDA
|
---|
52 | S ZF=171.401 ; FILE NUMBER FOR CCR SOURCE FILE
|
---|
53 | S C0CFDA(ZF,"?+1,",.01)=ZSRC
|
---|
54 | D UPDIE
|
---|
55 | Q $O(^C0C(171.401,"B",ZSRC,""))
|
---|
56 | ;
|
---|
57 | RPCFIN(RTN,DFN,SOURCE,TYPE,FN,FP) ; FILE IN RPC - READ AN XML DOCUMENT
|
---|
58 | ; FROM A HOST FILE AND STORE IT IN THE INCOMING XML FILE
|
---|
59 | N ZX,ZTMP
|
---|
60 | I $E($RE(FP))'="/" S ZX=FP_"/"
|
---|
61 | E S ZX=FP
|
---|
62 | S ZX=ZX_FN
|
---|
63 | D LOAD("ZTMP",ZX)
|
---|
64 | I '$D(ZTMP) D Q ; NO LUCK
|
---|
65 | . W "FILE NOT LOADED",!
|
---|
66 | D RPCAIN(.RTN,DFN,SOURCE,TYPE,"ZTMP")
|
---|
67 | N C0CFDA
|
---|
68 | S C0CFDA(175,RTN_",",5)=FN ; FILE NAME
|
---|
69 | S C0CFDA(175,RTN_",",6)=FP ; FILE PATH
|
---|
70 | D UPDIE ; UPDATE WITH FILE NAME AND PATH
|
---|
71 | Q
|
---|
72 | ;
|
---|
73 | RPCLIST(RTN,DFN) ; CCR LIST - LIST XML DOCUMENTS FOR PATIENT DFN
|
---|
74 | ; THAT ARE STORED IN THE INCOMING XML FILE
|
---|
75 | ; RETURNS AN ARRAY OF THE FORM
|
---|
76 | ; RTN(x)="IEN^DATE^TYPE^SOURCE^STATUS" WHERE
|
---|
77 | ; IEN IS THE RECORD NUMBER OF THE XML DOCUMENT
|
---|
78 | ; DATE IS THE DATE THE DOCUMENT WAS STORED IN THE FILE
|
---|
79 | ; TYPE IS "CCD" OR "CCR" OR "OTHER"
|
---|
80 | ; SOURCE IS THE NAME OF THE DOCUMENT SOURCE FROM THE CCR SOURCE FILE
|
---|
81 | ; STATUS IS THE STATUS OF THE DOCUMENT (VALUES TO BE DEFINED)
|
---|
82 | N ZF S ZF=175 ; FILE NUMBER OF INCOMING XML FILE
|
---|
83 | N ZI S ZI=""
|
---|
84 | N ZN S ZN=0
|
---|
85 | F S ZI=$O(^C0CIN("B",DFN,ZI),-1) Q:ZI="" D ; FOR EACH RECORD FOR THIS PATIENT
|
---|
86 | . S ZN=ZN+1 ;INCREMENT COUNT OF RETURN ARRAY
|
---|
87 | . S $P(RTN(ZN),"^",1)=ZI ; IEN OF RECORD
|
---|
88 | . S $P(RTN(ZN),"^",2)=$$GET1^DIQ(ZF,ZI_",",1,"E") ;DATE
|
---|
89 | . S $P(RTN(ZN),"^",3)=$$GET1^DIQ(ZF,ZI_",",2,"E") ;TYPE
|
---|
90 | . S $P(RTN(ZN),"^",4)=$$GET1^DIQ(ZF,ZI_",",3,"E") ;SOURCE
|
---|
91 | . S $P(RTN(ZN),"^",5)=$$GET1^DIQ(ZF,ZI_",",7,"I") ; STATUS
|
---|
92 | Q
|
---|
93 | ;
|
---|
94 | RPCDOC(RTN,IEN) ; RETRIEVE DOCUMENT NUMBER IEN FROM THE INCOMING XML FILE
|
---|
95 | ; RETURNED IN ARRAY RTN
|
---|
96 | N ZI
|
---|
97 | S ZI=$$GET1^DIQ(175,IEN_",",4,,"RTN")
|
---|
98 | Q
|
---|
99 | ;
|
---|
100 | EN(INXML,SOURCE,C0CDFN) ; IMPORT A CCR, PASSED BY NAME INXML
|
---|
101 | ; FILE UNDER SOURCE, WHICH IS A POINTER TO THE CCR SOURCE FILE
|
---|
102 | ; FOR PATIENT C0CDFN
|
---|
103 | ;N C0CXP
|
---|
104 | S C0CINB=$NA(^TMP("C0CIN",$J,"VARS",C0CDFN))
|
---|
105 | S C0CDOCID=$$PARSE^C0CMXML(INXML) ;W !,"DocID: ",C0CDOCID
|
---|
106 | ;S REDUX="//ContinuityOfCareRecord/Body"
|
---|
107 | S REDUX=""
|
---|
108 | D XPATH^C0CMXML(1,"/","C0CIDX","C0CXP",,REDUX)
|
---|
109 | ;D INDEX^C0CXPATH(INXML,"C0CXP",-1) ; GENERATE XPATHS FROM THE CCR
|
---|
110 | ;N ZI,ZJ,ZK
|
---|
111 | S ZI=""
|
---|
112 | F S ZI=$O(C0CXP(ZI)) Q:ZI="" D ; FOR EACH XPATH
|
---|
113 | . D DEMUX^C0CMXP("ZJ",ZI) ;
|
---|
114 | . W ZJ,!
|
---|
115 | . S ZK=$P(ZJ,"^",3) ; PULL OUT THE XPATH
|
---|
116 | . S ZM=$P(ZJ,"^",1) ; PULL OUT THE MULTIPLE
|
---|
117 | . S ZS=$P(ZJ,"^",2) ; PULL OUT THE SUBMULTIPLE
|
---|
118 | . S C0CDICN=$O(^C0CDIC(170,"XPATH",ZK,""))
|
---|
119 | . I C0CDICN="" D Q ;
|
---|
120 | . . W "MISSING XPATH:",!,ZK,! ; OOPS, XPATH NOT IN C0CDIC
|
---|
121 | . . S MISSING(ZK)=""
|
---|
122 | . ;D GETS^DIQ(170,C0CDICN_",","*",,"C0CFDA")
|
---|
123 | . S C0CVAR=$$GET1^DIQ(170,C0CDICN_",",.01) ; VARIABLE NAME
|
---|
124 | . S C0CSEC=$$GET1^DIQ(170,C0CDICN_",",12) ;ELEMENT TYPE
|
---|
125 | . W C0CSEC,":",C0CVAR,!
|
---|
126 | Q
|
---|
127 | ;
|
---|
128 | GETACCR(AOUT,C0CDFN) ; EXTRACT A CCR FOR PATIENT ADFN AND PUT IT IN ARRAY AOUT
|
---|
129 | ;PASSED BY NAME
|
---|
130 | N ZT
|
---|
131 | D CCRRPC^C0CCCR(.ZT,C0CDFN,"LABLIMIT:T-1000")
|
---|
132 | M @AOUT=ZT
|
---|
133 | Q
|
---|
134 | ;
|
---|
135 | TEST64 ;TEST BASE64 DECODING FOR IMPORTING CCR FROM THE NHIN
|
---|
136 | W $$FTG^%ZISH("/tmp/","base64_encoded_ccr.txt","G64(1)",1)
|
---|
137 | S G=G64(1)
|
---|
138 | S ZI=""
|
---|
139 | F S ZI=$O(G64(1,"OVF",ZI)) Q:ZI="" D ; FOR EVERY OVERFLOW RECORD
|
---|
140 | . S G=G_G64(1,"OVF",ZI) ;HOPE IT'S NOT TOO BIG
|
---|
141 | S G2=$$DECODE^RGUTUU(G)
|
---|
142 | Q
|
---|
143 | ;
|
---|
144 | NORMAL(OUTXML,INXML) ;NORMALIZES AN XML STRING PASSED BY NAME IN INXML
|
---|
145 | ; INTO AN XML ARRAY RETURNED IN OUTXML, ALSO PASSED BY NAME
|
---|
146 | ;
|
---|
147 | N ZI,ZN,ZTMP
|
---|
148 | S ZN=1
|
---|
149 | S @OUTXML@(ZN)=$P(@INXML,"><",ZN)_">"
|
---|
150 | S ZN=ZN+1
|
---|
151 | F S @OUTXML@(ZN)="<"_$P(@INXML,"><",ZN) Q:$P(@INXML,"><",ZN+1)="" D ;
|
---|
152 | . S @OUTXML@(ZN)=@OUTXML@(ZN)_">"
|
---|
153 | . S ZN=ZN+1
|
---|
154 | Q
|
---|
155 | ;
|
---|
156 | CLEANCR(OUTXML,INXML) ; USE $C(10) TO SEPARATE THE STRING INXML INTO
|
---|
157 | ;AN ARRAY OUTXML(n) OUTXML AND INXML PASSED BY NAME
|
---|
158 | N ZX,ZY,ZN
|
---|
159 | S ZX=1,ZN=1
|
---|
160 | F S ZY=$F(@INXML,$C(10),ZX) Q:ZY=0 D ;
|
---|
161 | . S @OUTXML@(ZN)=$E(G2,ZX,ZY-2)
|
---|
162 | . I @OUTXML@(ZN)'="" S ZN=ZN+1
|
---|
163 | . S ZX=ZY
|
---|
164 | Q
|
---|
165 | ;
|
---|
166 | LOAD(ZRTN,filepath) ; load an xml file into the ZRTN array, passed by name
|
---|
167 | n i
|
---|
168 | D ;
|
---|
169 | . n zfile,zpath,ztmp,zok s (zfile,zpath,ztmp)=""
|
---|
170 | . s ztmp=$na(^TMP("C0CLOAD",$J))
|
---|
171 | . k @ztmp
|
---|
172 | . s zfile=$re($p($re(filepath),"/",1)) ;file name
|
---|
173 | . s zpath=$p(filepath,zfile,1) ; file path
|
---|
174 | . s zok=$$FTG^%ZISH(zpath,zfile,$NA(@ztmp@(1)),3) ; import the file incr sub 3
|
---|
175 | . m @ZRTN=@ztmp
|
---|
176 | . k @ztmp
|
---|
177 | . s i=$o(@ZRTN@(""),-1) ; highest line number
|
---|
178 | q
|
---|
179 | ;
|
---|
180 | UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
|
---|
181 | K ZERR,C0CIEN
|
---|
182 | D CLEAN^DILF
|
---|
183 | D UPDATE^DIE("","C0CFDA","C0CIEN","ZERR")
|
---|
184 | I $D(ZERR) D ;
|
---|
185 | . W "ERROR",!
|
---|
186 | . ZWR ZERR
|
---|
187 | . B
|
---|
188 | K C0CFDA
|
---|
189 | Q
|
---|
190 | ; |
---|