Index: ccr/trunk/p/C0CXPATH.m
===================================================================
--- ccr/trunk/p/C0CXPATH.m	(revision 515)
+++ ccr/trunk/p/C0CXPATH.m	(revision 528)
@@ -114,5 +114,5 @@
  . 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  ;
@@ -129,5 +129,5 @@
  ;
  ;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
@@ -137,24 +137,51 @@
  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
  ;
@@ -173,17 +200,22 @@
  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",!
@@ -192,5 +224,5 @@
  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
@@ -240,4 +272,5 @@
  S @ZXML@("INDEXED")=""
  S @ZXML@("//")="1^"_LCNT ; ROOT XPATH
+ I NOINX K @ZXML ; DELETE UNWANTED INDEX
  Q
  ;
