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