C0CMXP	  ; GPL - MXML based XPath utilities;12/04/09  17:05
 ;;0.1;C0C;nopatch;noreleasedate
 ;Copyright 2009 George Lilly.  Licensed under the terms of the GNU
 ;General Public License See attached copy of the License.
 ;
 ;This program is free software; you can redistribute it and/or modify
 ;it under the terms of the GNU General Public License as published by
 ;the Free Software Foundation; either version 2 of the License, or
 ;(at your option) any later version.
 ;
 ;This program is distributed in the hope that it will be useful,
 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;GNU General Public License for more details.
 ;
 ;You should have received a copy of the GNU General Public License along
 ;with this program; if not, write to the Free Software Foundation, Inc.,
 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 ;
 Q
 ;
TEST	;
 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
 K GARY
 W $$FTG^%ZISH("/home/vademo2/EHR/p/","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
 S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DocID: ",C0CDOCID
 S REDUX="//ContinuityOfCareRecord/Body"
 D XPATH(1,"/","GIDX","GARY",,REDUX)
 Q
 ;
TEST2	;
 S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
 D XPATH(1,"/","GIDX","GARY","",REDUX)
 Q
 ;
TEST3
 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
 K GARY,GTMP,GIDX
 K @C0CXMLIN
 W $$FTG^%ZISH("/home/vademo2/CCR/","SampleCCDDocument.xml",$NA(@C0CXMLIN@(1)),3)
 D CLEANARY("GTMP",C0CXMLIN) ; REMOVE CONTROL CHARACTERS
 K @C0CXMLIN
 M @C0CXMLIN=GTMP
 K GTMP
 D STRIPTXT("GTMP",C0CXMLIN)
 K @C0CXMLIN
 M @C0CXMLIN=GTMP
 K GTMP
 S C0CDOCID=$$PARSCCD(C0CXMLIN,"W") W !,"DocID: ",C0CDOCID
 S REDUX="//ClinicalDocument/component/structuredBody"
 D FINDTID ; FIND THE TEMPLATE IDS
 D FINDALT ; FIND ALTERNATE TAGS
 D SETCBK ; SET THE CALLBACK ROUTINE FOR TAGS
 D XPATH(1,"/","GIDX","GARY",,REDUX)
 K C0CCBK("TAG")
 D SEPARATE("GARY2","GARY") ; SEPARATE FOR EASIER BROWSING
 ;S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DOCID: ",C0CDOCID  ;CALL REGULAR PARSER
 ;D XPATH(1,"/","GIDX2","GARY2",,REDUX)
 Q
 ;
TEST4 ; TEST OF OUTPUTING AN XML FILE FROM THE DOM .. this one is the CCR
 ;
 D TEST ; SET UP THE DOM
 D START^C0CMXMLB($$TAG(1),,"G")
 D NDOUT($$FIRST(1))
 D END^C0CMXMLB ;END THE DOCUMENT
 M ZCCR=^TMP("MXMLBLD",$J)
 ZWR ZCCR
 Q
 ;
TEST5 ; SAME AS TEST4, BUT THIS TIME THE CCD
 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
 K GARY,GTMP,GIDX
 K @C0CXMLIN
 W $$FTG^%ZISH("/home/vademo2/CCR/","SampleCCDDocument.xml",$NA(@C0CXMLIN@(1)),3)
 D CLEANARY("GTMP",C0CXMLIN) ; REMOVE CONTROL CHARACTERS
 K @C0CXMLIN
 M @C0CXMLIN=GTMP
 K GTMP
 D STRIPTXT("GTMP",C0CXMLIN)
 K @C0CXMLIN
 M @C0CXMLIN=GTMP
 K GTMP
 S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DOCID: ",C0CDOCID  ;CALL REGULAR PARSER
 ;D XPATH(1,"/","GIDX2","GARY2",,REDUX)
 D OUTXML("ZCCD",C0CDOCID)
 ;D START^C0CMXMLB($$TAG(1),,"G")
 ;D NDOUT($$FIRST(1))
 ;D END^C0CMXMLB ;END THE DOCUMENT
 ;M ZCCD=^TMP("MXMLBLD",$J)
 ZWR ZCCD(1:30)
 Q
 ; 
MKTPLATE(INXML,OUTT) ;MAKE A TEMPLATE FROM INXML, RETURNED IN OUTT
 ; BOTH PASSED BY NAME
 ;
 S C0CDOCID=$$PARSE(INXML,"C0CMKT")
 S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID)) 
 N ZI S ZI=""
 F  S ZI=$O(@C0CDOM@(ZI)) Q:ZI=""  D  ; FOR EACH NODE IN THE DOM
 . W !,ZI,$$TAG(ZI)
 Q
 ;
UPDIE	; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
 K ZERR
 D CLEAN^DILF
 D UPDATE^DIE("","C0CFDA","","ZERR")
 I $D(ZERR) D  ;
 . W "ERROR",!
 . ZWR ZERR
 . B
 K C0CFDA
 Q
 ;
