source: ccr/trunk/p/C0CIN.m@ 587

Last change on this file since 587 was 584, checked in by George Lilly, 15 years ago

new import processing

File size: 3.7 KB
Line 
1C0CIN ; 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 ;
23EN(INXML,SOURCE,C0CDFN) ; IMPORT A CCR, PASSED BY NAME INXML
24 ; FILE UNDER SOURCE, WHICH IS A POINTER TO THE CCR SOURCE FILE
25 ; FOR PATIENT C0CDFN
26 ;N C0CXP
27 S C0CINB=$NA(^TMP("C0CIN",$J,"VARS",C0CDFN))
28 S C0CDOCID=$$PARSE^C0CMXML(INXML) ;W !,"DocID: ",C0CDOCID
29 ;S REDUX="//ContinuityOfCareRecord/Body"
30 S REDUX=""
31 D XPATH^C0CMXML(1,"/","C0CIDX","C0CXP",,REDUX)
32 ;D INDEX^C0CXPATH(INXML,"C0CXP",-1) ; GENERATE XPATHS FROM THE CCR
33 ;N ZI,ZJ,ZK
34 S ZI=""
35 F S ZI=$O(C0CXP(ZI)) Q:ZI="" D ; FOR EACH XPATH
36 . D DEMUX("ZJ",ZI) ;
37 . W ZJ,!
38 . S ZK=$P(ZJ,"^",3) ; PULL OUT THE XPATH
39 . S ZM=$P(ZJ,"^",1) ; PULL OUT THE MULTIPLE
40 . S ZS=$P(ZJ,"^",2) ; PULL OUT THE SUBMULTIPLE
41 . S C0CDICN=$O(^C0CDIC(170,"XPATH",ZK,""))
42 . I C0CDICN="" D Q ;
43 . . W "MISSING XPATH:",!,ZK,! ; OOPS, XPATH NOT IN C0CDIC
44 . . S MISSING(ZK)=""
45 . ;D GETS^DIQ(170,C0CDICN_",","*",,"C0CFDA")
46 . S C0CVAR=$$GET1^DIQ(170,C0CDICN_",",.01) ; VARIABLE NAME
47 . S C0CSEC=$$GET1^DIQ(170,C0CDICN_",",12) ;ELEMENT TYPE
48 . W C0CSEC,":",C0CVAR,!
49 Q
50 ;
51GETACCR(AOUT,C0CDFN) ; EXTRACT A CCR FOR PATIENT ADFN AND PUT IT IN ARRAY AOUT
52 ;PASSED BY NAME
53 N ZT
54 D CCRRPC^C0CCCR(.ZT,C0CDFN,"LABLIMIT:T-1000")
55 M @AOUT=ZT
56 Q
57 ;
58DEMUX(OUTX,INX) ;PARSES XPATH PASSED BY VALUE IN INX TO REMOVE [x] MULTIPLES
59 ; RETURNS OUTX: MULTIPLE^SUBMULTIPLE^XPATH
60 N ZX,ZY,ZZ,ZZ1,ZMULT,ZSUB
61 S (ZMULT,ZSUB)=""
62 S ZX=$P(INX,"[",2)
63 I ZX'="" D ; THERE IS A [x] MULTIPLE
64 . S ZY=$P(INX,"[",1) ;FIRST PART OF XPATH
65 . S ZMULT=$P(ZX,"]",1) ; NUMBER OF THE MULTIPLE
66 . S ZX=ZY_$P(ZX,"]",2) ; REST OF THE XPATH
67 . I $P(ZX,"[",2)'="" D ; A SUB MULTIPLE EXISTS
68 . . S ZZ=$P(ZX,"[",1) ; FIRST PART OF XPATH
69 . . S ZX=$P(ZX,"[",2) ; DELETE THE [
70 . . S ZSUB=$P(ZX,"]",1) ; NUMBER OF THE SUBMULTIPLE
71 . . S ZX=ZZ_$P(ZX,"]",2) ; REST OF THE XPATH
72 E S ZX=INX ;NO MULTIPLE HERE
73 S @OUTX=ZMULT_"^"_ZSUB_"^"_ZX ;RETURN MULTIPLE^SUBMULTIPLE^XPATH
74 Q
75 ;
76TEST64 ;TEST BASE64 DECODING FOR IMPORTING CCR FROM THE NHIN
77 W $$FTG^%ZISH("/tmp/","base64_encoded_ccr.txt","G64(1)",1)
78 S G=G64(1)
79 S ZI=""
80 F S ZI=$O(G64(1,"OVF",ZI)) Q:ZI="" D ; FOR EVERY OVERFLOW RECORD
81 . S G=G_G64(1,"OVF",ZI) ;HOPE IT'S NOT TOO BIG
82 S G2=$$DECODE^RGUTUU(G)
83 Q
84 ;
85NORMAL(OUTXML,INXML) ;NORMALIZES AN XML STRING PASSED BY NAME IN INXML
86 ; INTO AN XML ARRAY RETURNED IN OUTXML, ALSO PASSED BY NAME
87 ;
88 N ZI,ZN,ZTMP
89 S ZN=1
90 S @OUTXML@(ZN)=$P(@INXML,"><",ZN)_">"
91 S ZN=ZN+1
92 F S @OUTXML@(ZN)="<"_$P(@INXML,"><",ZN) Q:$P(@INXML,"><",ZN+1)="" D ;
93 . S @OUTXML@(ZN)=@OUTXML@(ZN)_">"
94 . S ZN=ZN+1
95 Q
96 ;
97CLEANCR(OUTXML,INXML) ; USE $C(10) TO SEPARATE THE STRING INXML INTO
98 ;AN ARRAY OUTXML(n) OUTXML AND INXML PASSED BY NAME
99 N ZX,ZY,ZN
100 S ZX=1,ZN=1
101 F S ZY=$F(@INXML,$C(10),ZX) Q:ZY=0 D ;
102 . S @OUTXML@(ZN)=$E(G2,ZX,ZY-2)
103 . I @OUTXML@(ZN)'="" S ZN=ZN+1
104 . S ZX=ZY
105 Q
106 ;
107
Note: See TracBrowser for help on using the repository browser.