updates for XML handling

This commit is contained in:
george 2009-06-01 18:24:15 +00:00
parent b5e4659b49
commit 206c726dcb
1 changed files with 62 additions and 29 deletions

View File

@ -113,7 +113,7 @@ VDX2XPG(OUTXPG,INVDX) ; CONVERT AN VDX ARRAY TO XPG
. S ZW=$E(ZI,3,$L(ZI)) ; STRIP OFF INITIAL //
. S ZW2=$P(ZW,"/",1)
. F ZK=1:1:$L(ZW,"/") D PUSH("ZA",$P(ZW,"/",ZK))
. ZWR ZA
. ;ZWR ZA
. S ZW2=ZA(1)
. F ZK=2:1:ZA(0) D ;
. . S ZW2=ZW2_""","""_ZA(ZK)
@ -128,7 +128,7 @@ XML2XPG(OUTXPG,INXML) ; CONVERT AN XML ARRAY, PASSED BY NAME TO AN XPG ARRAY
; XPG MEANS XPATH GLOBAL AND HAS THE FORM @OUTXPG@("X1","X2","X3")=VALUE
;
;N G1
D INDEX(INXML,"G1") ; PRODUCES A VDX ARRAY IN G1
D INDEX(INXML,"G1",1) ; PRODUCES A VDX ARRAY IN G1, NO INDEX IS PRODUCED
D VDX2XPG(OUTXPG,"G1") ; CONVERTS THE VDX ARRAY TO XPG FORM
Q
;
@ -136,26 +136,53 @@ DO
D XPG2XML("^GPL2B","^GPL2A")
Q
;
XPG2XML(OUTXML,INXPG,NUM) ;
; OUTPUT XML FROM AN XPG FILE
I '$D(NUM) D ; FIRST TIME THROUGH
. K @OUTXML
. S NUM=1
. S ZA=""
S G=INXPG
S G=@G I G="" Q ;
F D ; S G=$Q(@G) Q:G="" D ;
. F ZI=1:1:$QL(G) D ;
. . I ZI<$QL(G) D ;
. . . S ZB=$QS(G,ZI)
. . . I ZA(ZA(0))'=ZB D ZXO(ZB)
. . . E D ZXC(ZB)
. . S ZV=""
. . S G2=$QS(G,ZI)
. . I ZI=$QL(G) S ZV=@G
. . W G2," ",ZV
. S G=@G I G="" Q ;
. W !
T1 ; TEST OUT THESE ROUTINES
D XML2XPG("G2","^GPL")
D XPG2XML("G3","G2")
K ^GPLOUT
M ^GPLOUT=G3
W $$OUTPUT^C0CXPATH("^GPLOUT(1)","GPLTEST.xml","/home/vademo2/EHR/p")
Q
;
XPG2XML(OUTXML,INXPG) ;
N C0CN,FWD,ZA,G,GA,ZQ
S ZQ=0 ; QUIT FLAG
F Q:ZQ=1 D ; LOOP THROUGH EVERYTHING
. I '$D(C0CN) D ; FIRST TIME THROUGH
. . K @OUTXML ; MAKE SURE OUTPUT ARRAY IS CLEAR
. . S FWD=1 ; START OUT GOING FORWARD THROUGH SUBSCRIPTS
. . S G=$Q(@INXPG) ; THIS ONE
. . S GN=$Q(@G) ; NEXT ONE
. . S C0CN=1 ; SUBSCRIPT COUNT
. . S ZQ=0 ; QUIT FLAG
. . D ZXO("?xml version=""1.0"" encoding=""UTF-8""?") ;MAKE IT REAL XML
. . I $QS(G,1)="ContinuityOfCareRecord" D ;
. . . D ZXO("?xml-stylesheet type=""text/xsl"" href=""ccr.xsl""?") ; HACK TO MAKE THE CCR STYLESHEET WORK
. I FWD D ; GOING FORWARDS
. . I C0CN<$QL(G) D ; NOT A DATA NODE
. . . S ZA=$QS(G,C0CN) ; PULL OUT THE SUBSCRIPT
. . . D ZXO(ZA) ; AND OPEN AN XML ELEMENT
. . . I @OUTXML@(@OUTXML@(0))="<ContinuityOfCareRecord>" D ;
. . . . S @OUTXML@(@OUTXML@(0))="<ContinuityOfCareRecord xmlns=""urn:astm-org:CCR"">"
. . . S C0CN=C0CN+1 ; MOVE TO THE NEXT ONE
. . E D ; AT THE DATA NODE
. . . S ZA=$QS(G,C0CN) ; PULL OUT THE SUBSCRIPT
. . . D ZXVAL(ZA,@G) ; OUTPUT <X>VAL</X> FOR DATA NODE
. . . S FWD=0 ; GO BACKWARDS
. I 'FWD D ;GOING BACKWARDS
. . S GN=$Q(@G) ;NEXT XPATH
. . ;W "NEXT!",GN,!
. . S C0CN=C0CN-1 ; PREVIOUS SUBSCRIPT
. . I GN'="" D ;
. . . I $QS(G,C0CN)'=$QS(GN,C0CN) D ; NEED TO CLOSE OFF ELEMENT
. . . . D ZXC($QS(G,C0CN)) ;
. . . E I GN'="" D ; MORE ELEMENTS AT THIS LEVEL
. . . . S G=$Q(@G) ; ADVANCE TO NEW XPATH
. . . . S C0CN=C0CN+1 ; GET READY TO PROCESS NEXT SUBSCRIPT
. . . . S FWD=1 ; GOING FORWARD NOW
. I (GN="")&(C0CN=1) D Q ; WHEN WE ARE ALL DONE
. . D ZXC($QS(G,C0CN)) ; LAST ONE
. . S ZQ=1 ; QUIT NOW
Q
;
ZXO(WHAT)
@ -172,26 +199,31 @@ ZXVAL(WHAT,VAL)
D PUSH(OUTXML,"<"_WHAT_">"_VAL_"</"_WHAT_">")
Q
;
INDEX(ZXML,VDX) ; parse the XML in ZXML and produce an XPATH index
INDEX(IZXML,VDX,NOINX) ; parse the XML in IZXML and produce an XPATH index
; GPL 5/24/09 AND OPTIONALLY PRODUCE THE VDX ARRAY PASSED BY NAME
; @VDX@("XPATH")=VALUE
; ex. @ZXML@("XPATH")=FIRSTLINE^LASTLINE
; ex. @IZXML@("XPATH")=FIRSTLINE^LASTLINE
; WHERE FIRSTLINE AND LASTLINE ARE THE BEGINNING AND ENDING OF THE
; XML SECTION
; ZXML IS PASSED BY NAME
; IZXML IS PASSED BY NAME
; IF NOINX IS SET TO 1, NO INDEX WILL BE GENERATED, BUT THE VDX WILL BE
N I,LINE,FIRST,LAST,CUR,TMP,MDX,FOUND,CURVAL,DVDX,LCNT
N C0CSTK ; LEAVE OUT FOR DEBUGGING
I '$D(@ZXML@(0)) D ; IF COUNT NOT IN NODE 0 COUNT THEM
I '$D(NOINX) S NOINX=0 ; IF NOT PASSED, GENERATE AN INDEX
N ZXML
I NOINX S ZXML=$NA(^TMP("C0CINDEX",$J)) ; TEMP PLACE FOR INDEX TO DISCARD
E S ZXML=IZXML ; PLACE FOR INDEX TO KEEP
I '$D(@IZXML@(0)) D ; IF COUNT NOT IN NODE 0 COUNT THEM
. S I="",LCNT=0
. F S I=$O(@ZXML@(I)) Q:I="" S LCNT=LCNT+1
E S LCNT=@ZXML@(0) ; LINE COUNT PASSED IN ARRAY
. F S I=$O(@IZXML@(I)) Q:I="" S LCNT=LCNT+1
E S LCNT=@IZXML@(0) ; LINE COUNT PASSED IN ARRAY
I LCNT=0 D Q ; NO XML PASSED
. W "ERROR IN XML FILE",!
S DVDX=0 ; DEFAULT DO NOT PRODUCE VDX INDEX
I $D(VDX) S DVDX=1 ; IF NAME PASSED, DO VDX
S C0CSTK(0)=0 ; INITIALIZE STACK
F I=1:1:LCNT D ; PROCESS THE ENTIRE ARRAY
. S LINE=@ZXML@(I)
. S LINE=@IZXML@(I)
. ;W LINE,!
. S FOUND=0 ; INTIALIZED FOUND FLAG
. I LINE?.E1"<!".E S FOUND=1 ; SKIP OVER COMMENTS
@ -239,6 +271,7 @@ INDEX(ZXML,VDX) ; parse the XML in ZXML and produce an XPATH index
. . . . S @ZXML@(MDX)=I_"^" ; INSERT INTO THE INDEX
S @ZXML@("INDEXED")=""
S @ZXML@("//")="1^"_LCNT ; ROOT XPATH
I NOINX K @ZXML ; DELETE UNWANTED INDEX
Q
;
QUERY(IARY,XPATH,OARY) ; RETURNS THE XML ARRAY MATCHING THE XPATH EXPRESSION