From eadaf3c07068fd8fd69375f4a5fba3c87fab4c32 Mon Sep 17 00:00:00 2001 From: george Date: Sat, 27 Mar 2010 05:31:47 +0000 Subject: [PATCH] updates to XML processing --- p/C0CMXP.m | 32 ++++++++++++++++++++++++++++++++ p/C0CSOAP.m | 10 +++++++--- p/C0CXPATH.m | 24 ++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/p/C0CMXP.m b/p/C0CMXP.m index d0bef5b..fd83ce1 100644 --- a/p/C0CMXP.m +++ b/p/C0CMXP.m @@ -103,6 +103,38 @@ GETTEMP(OUTXML,TEMPID,FARY) ;GET THE TEMPLATE XML FROM TEMPLATE TEMPID . W "ERROR RETRIEVING TEMPLATE",! Q ; +COPYWP(ZFLD,ZSRCREC,ZDESTREC,ZSRCF,ZDESTF) ; COPIES A WORD PROCESSING FIELD + ; FROM ONE RECORD TO ANOTHER RECORD + ; ZFLD IS EITHER A NUMBERIC FIELD OR A NAME IN ZSRCF + ; ZSRCF IS THE SOURCE FILE, IN FILE REDIRECT FORMAT + ; IF ZSRCF IS OMMITED, THE DEFAULT C0C XML MISC FILE WILL BE ASSUMED + ; ZDESTF IS DESTINATION FILE. IF OMMITED, IS ASSUMED TO BE THE SAME + ; A ZSRCF + I '$D(ZSRCF) D ; + . S ZSRCF="ZSRCF" + . D INITFARY^C0CSOAP(ZSRCF) + I '$D(ZDESTF) D ; + . S ZDESTF="ZDESTF" + . M @ZDESTF=@ZSRCF + N ZSF,ZDF,ZSFREF,ZDFREF + S ZSF=@ZSRCF@("XML FILE NUMBER") + S ZSFREF=$$FILEREF^C0CRNF(ZSF) + S ZDF=@ZDESTF@("XML FILE NUMBER") + S ZDFREF=$$FILEREF^C0CRNF(ZDF) + N ZSIEN,ZDIEN + S ZSIEN=$O(@ZSFREF@("B",ZSRCREC,"")) + I ZSIEN="" W !,"ERROR SOURCE RECORD NOT FOUND" Q ; + S ZDIEN=$O(@ZDFREF@("B",ZDESTREC,"")) + I ZDIEN="" W !,"ERROR DESTINATION RECORD NOT FOUND" Q ; + N ZFLDNUM + I +ZFLD=0 S ZFLDNUM=@ZSRCF@(ZFLD) ; IF FIELD IS PASSED BY NAME + E S ZFLDNUM=ZFLD ; IF FIELD IS PASSED BY NUMBER + N ZWP,ZWPN + S ZWPN=$$GET1^DIQ(ZSF,ZSIEN_",",ZFLDNUM,,"ZWP") ; GET WP FROM SOURCE + I ZWPN'="ZWP" W !,"ERROR SOURCE FIELD EMPTY" Q ; + D WP^DIE(ZDF,ZDIEN_",",ZFLDNUM,,"ZWP") ; PUT WP FIELD TO DEST + Q + ; COMPILE(TID,UFARY) ; COMPILES AN XML TEMPLATE AND GENERATES XPATH BINDINGS ; UFARY IF SPECIFIED WILL REDIRECT THE XML FILE TO USE ; INTID IS THE IEN OF THE RECORD TO USE IN THE XML FILE diff --git a/p/C0CSOAP.m b/p/C0CSOAP.m index b738e67..fef9118 100644 --- a/p/C0CSOAP.m +++ b/p/C0CSOAP.m @@ -67,7 +67,7 @@ TESTSOAP ; D SOAP("GPL","ICD9","G") Q ; -SOAP(C0CRTN,C0CTID,C0CVA,C0CVOR,ALTXML) ; MAKES A SOAP CALL FOR +SOAP(C0CRTN,C0CTID,C0CVA,C0CVOR,ALTXML,IFARY) ; MAKES A SOAP CALL FOR ; TEMPLATE ID C0CTID ; RETURNS THE XML RESULT IN C0CRTN, PASSED BY NAME ; C0CVA IS PASSED BY NAME AND IS THE VARIABLE ARRAY TO PASS TO BIND @@ -109,7 +109,10 @@ NEW NOTNEW ; END ARTIFACTS ; - D INITFARY("C0CF") ; SET FILE NUMBER AND PARAMATERS + I '$D(IFARY) D INITFARY("C0CF") ; SET FILE NUMBER AND PARAMATERS + E D ; + . K C0CF + . M C0CF=@IFARY S C0CXF=C0CF("XML FILE NUMBER") ; FILE NUMBER FOR THE XML TEMPLATE FILE I +C0CTID=0 D ; A STRING WAS PASSED FOR THE TEMPLATE NAME . S C0CUTID=$$RESTID(C0CTID,"C0CF") ;RESOLVE TEMPLATE IEN FROM NAME @@ -138,10 +141,11 @@ NOTNEW . E M XML=@ALTXML ; use ALTXML instead I $G(C0CPROXY) S C0CURL=C0CPURL K C0CRSLT,C0CRHDR + B S ok=$$httpPOST^%zewdGTM(C0CURL,.XML,C0CMIME,.C0CRSLT,.HEADER,"",.gpl5,.C0CRHDR) K C0CRXML D NORMAL("C0CRXML","C0CRSLT(1)") ;RETURN XML IN AN ARRAY - N C0CFR S C0CFR=C0CF("REPLY TEMPLATE") + N C0CFR S C0CFR=$G(C0CF("REPLY TEMPLATE")) S C0CR=$$GET1^DIQ(C0CXF,C0CUTID_",",C0CFR,"I") ; REPLY TEMPLATE ; reply templates are optional and are specified by populating a ; template pointer in field 2.5 of the request template diff --git a/p/C0CXPATH.m b/p/C0CXPATH.m index 6c59dcd..e5bc26e 100644 --- a/p/C0CXPATH.m +++ b/p/C0CXPATH.m @@ -339,6 +339,8 @@ QUERY(IARY,XPATH,OARY) ; RETURNS THE XML ARRAY MATCHING THE XPATH EXPRESSION N FIRST,LAST ; FIRST AND LAST LINES OF ARRAY TO RETURN N TMP,I,J,QXPATH S FIRST=1 + I '$D(@IARY@(0)) D ; LINE COUNT NOT IN ZERO NODE + . S @IARY@(0)=$O(@IARY@("//"),-1) ; THIS SHOULD USUALLY WORK S LAST=@IARY@(0) ; FIRST AND LAST DEFAULT TO ROOT I XPATH'="//" D ; NOT A ROOT QUERY . S TMP=@IARY@(XPATH) ; LOOK UP LINE VALUES @@ -460,14 +462,16 @@ INSERT(INSXML,INSNEW,INSXPATH) ; INSERT INSNEW INTO INSXML AT THE N INSBLD,INSTMP I $G(DEBUG) W "DOING INSERT ",INSXML,INSNEW,INSXPATH,! I $G(DEBUG) F G1=1:1:@INSXML@(0) W @INSXML@(G1),! - I '$D(@INSXML@(0)) D ; INSERT INTO AN EMPTY ARRAY + I '$D(@INSXML@(1)) D ; INSERT INTO AN EMPTY ARRAY . D CP^C0CXPATH(INSNEW,INSXML) ; JUST COPY INTO THE OUTPUT - I $D(@INSXML@(0)) D ; IF ORIGINAL ARRAY IS NOT EMPTY + I $D(@INSXML@(1)) D ; IF ORIGINAL ARRAY IS NOT EMPTY + . I '$D(@INSXML@(0)) S @INSXML@(0)=$O(@INSXML@(""),-1) ;SET LENGTH . I $D(INSXPATH) D ; XPATH PROVIDED . . D QOPEN("INSBLD",INSXML,INSXPATH) ; COPY THE BEFORE . . I $G(DEBUG) D PARY^C0CXPATH("INSBLD") . I '$D(INSXPATH) D ; NO XPATH PROVIDED, OPEN AT ROOT . . D QOPEN("INSBLD",INSXML,"//") ; OPEN WITH ROOT XPATH + . I '$D(@INSNEW@(0)) S @INSNEW@(0)=$O(@INSNEW@(""),-1) ;SIZE OF XML . D QUEUE("INSBLD",INSNEW,1,@INSNEW@(0)) ; COPY IN NEW XML . I $D(INSXPATH) D ; XPATH PROVIDED . . D QCLOSE("INSBLD",INSXML,INSXPATH) ; CLOSE WITH XPATH @@ -532,6 +536,22 @@ REPLACE(REXML,RENEW,REXPATH) ; REPLACE THE XML AT THE XPATH POINT D CP("RTMP",REXML) ; COPY IN THE RESULT Q ; +DELETE(REXML,REXPATH) ; DELETE THE XML AT THE XPATH POINT + ; REXML IS PASSED BY NAME XPATH IS A VALUE + N REBLD,XFIRST,XLAST,OLD,XNODE,RETMP + S OLD=$NA(^TMP($J,"REPLACE_OLD")) + D QUERY(REXML,REXPATH,OLD) ; CREATE INDEX, TEST XPATH, MAKE OLD + S XNODE=@REXML@(REXPATH) ; PULL OUT FIRST AND LAST LINE PTRS + S XFIRST=$P(XNODE,"^",1) + S XLAST=$P(XNODE,"^",2) + D QUEUE("REBLD",REXML,1,XFIRST-1) ; THE BEFORE + D QUEUE("REBLD",REXML,XLAST+1,@REXML@(0)) ; THE REST + I $G(DEBUG) D PARY("REBLD") + D BUILD("REBLD","RTMP") + K @REXML ; KILL WHAT WAS THERE + D CP("RTMP",REXML) ; COPY IN THE RESULT + Q + ; MISSING(IXML,OARY) ; SEARTH THROUGH INXLM AND PUT ANY @@X@@ VARS IN OARY ; W "Reporting on the missing",! ; W OARY