Changeset 574 for ccr/trunk/p


Ignore:
Timestamp:
Oct 13, 2009, 8:38:21 PM (15 years ago)
Author:
George Lilly
Message:

with Wally's changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccr/trunk/p/C0CMXML.m

    r573 r574  
    1 C0CMXML   ; ERX/GPL - MXML based XPath utilities; 10/11/09
    2  ;;0.1;C0P;nopatch;noreleasedate
    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  Q
    21  ;
    22 TEST ;
    23  S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
    24  W $$FTG^%ZISH("/home/vademo2/EHR/p/","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
    25  S C0CDOCID=$$PARSE(C0CXMLIN)
    26  S REDUX="//ContinuityOfCareRecord/Body"
    27  D XPATH(1,"/","GIDX","GARY",,REDUX)
    28  Q
    29  ;
    30 TEST2 ;
    31  S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
    32  D XPATH(1,"/","GIDX","GARY","",REDUX)
    33  Q
    34  ;
    35 XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
    36  ; THE XPATH INDEX ZXIDX, PASSED BY NAME
    37  ; THE XPATH ARRAY XPARY, PASSED BY NAME
    38  ; ZOID IS THE STARTING OID
    39  ; ZPATH IS THE STARTING XPATH, USUALLY "/"
    40  ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
    41  ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
    42  I $G(ZREDUX)="" S ZREDUX=""
    43  N NEWPATH
    44  N NEWNUM S NEWNUM=""
    45  I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
    46  S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
    47  I $G(ZREDUX)'="" D  ; REDUX PROVIDED?
    48  . N GT S GT=$P(NEWPATH,ZREDUX,2)
    49  . I GT'="" S NEWPATH=GT
    50  S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
    51  N GD S GD=$$DATA(ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
    52  I GD'="" S @ZXPARY@(NEWPATH)=GD ; IF YES, ADD IT TO THE XPATH ARRAY
    53  N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
    54  I ZFRST'=0 D  ; THERE IS A CHILD
    55  . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
    56  . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
    57  N GNXT S GNXT=$$NXTSIB(ZOID)
    58  I GNXT'=0 D  ;
    59  . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
    60  Q
    61  ;
    62 PARSE(INXML,INDOC) ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
    63  ; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
    64  ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
    65  ;Q $$EN^MXMLDOM(INXML)
    66  Q $$EN^MXMLDOM(INXML,"D")
    67  ;
    68 ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
    69  N ZN
    70  S ZN=$$NXTSIB(ZOID)
    71  I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
    72  Q 0
    73  ;
    74 FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
    75  Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
    76  ;
    77 TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
    78  Q $$NAME^MXMLDOM(C0CDOCID,ZOID)
    79  ;
    80 NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
    81  Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
    82  ;
    83 DATA(ZOID) ; RETURNS DATA FOR THE NODE
    84  N ZT,ZN S ZT=""
    85  S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
    86  Q $G(@C0CDOM@(ZOID,"T",1))
    87  S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,"ZT")
    88  I $G(ZT) ZWR ZT
    89  Q $G(ZT)
    90  ;
     1C0CMXML   ; ERX/GPL - MXML based XPath utilities;10/13/09  17:05
     2        ;;0.1;C0P;nopatch;noreleasedate
     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        Q
     21        ;
     22TEST    ;
     23        S C0CXMLIN=$NA(^TMP("C0CMXML",$J)) K GARY
     24        W $$FTG^%ZISH("FORT$:","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
     25        S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DocID: ",C0CDOCID
     26        S REDUX="//ContinuityOfCareRecord/Body"
     27        D XPATH(1,"/","GIDX","GARY",,REDUX)
     28        Q
     29        ;
     30TEST2   ;
     31        S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
     32        D XPATH(1,"/","GIDX","GARY","",REDUX)
     33        Q
     34        ;
     35XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX)      ; RECURSIVE ROUTINE TO POPULATE
     36        ; THE XPATH INDEX ZXIDX, PASSED BY NAME
     37        ; THE XPATH ARRAY XPARY, PASSED BY NAME
     38        ; ZOID IS THE STARTING OID
     39        ; ZPATH IS THE STARTING XPATH, USUALLY "/"
     40        ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
     41        ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
     42        I $G(ZREDUX)="" S ZREDUX=""
     43        N NEWPATH
     44        N NEWNUM S NEWNUM=""
     45        I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
     46        S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
     47        I $G(ZREDUX)'="" D  ; REDUX PROVIDED?
     48        . N GT S GT=$P(NEWPATH,ZREDUX,2)
     49        . I GT'="" S NEWPATH=GT
     50        S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
     51        N GD S GD=$$DATA(ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
     52        I GD'="" S @ZXPARY@(NEWPATH)=GD ; IF YES, ADD IT TO THE XPATH ARRAY
     53        N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
     54        I ZFRST'=0 D  ; THERE IS A CHILD
     55        . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
     56        . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
     57        N GNXT S GNXT=$$NXTSIB(ZOID)
     58        I GNXT'=0 D  ;
     59        . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
     60        Q
     61        ;
     62PARSE(INXML,INDOC)      ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
     63        ; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
     64        ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
     65        ;Q $$EN^MXMLDOM(INXML)
     66        Q $$EN^MXMLDOM(INXML,"W")
     67        ;
     68ISMULT(ZOID)    ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
     69        N ZN
     70        S ZN=$$NXTSIB(ZOID)
     71        I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
     72        Q 0
     73        ;
     74FIRST(ZOID)     ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
     75        Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
     76        ;
     77TAG(ZOID)       ; RETURNS THE XML TAG FOR THE NODE
     78        Q $$NAME^MXMLDOM(C0CDOCID,ZOID)
     79        ;
     80NXTSIB(ZOID)    ; RETURNS THE NEXT SIBLING
     81        Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
     82        ;
     83DATA(ZOID)      ; RETURNS DATA FOR THE NODE
     84        N ZT,ZN S ZT=""
     85        ;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
     86        ;Q $G(@C0CDOM@(ZOID,"T",1))
     87        S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,"ZT")
     88        ;I $D(ZT) ZWR ZT
     89        Q $G(ZT(1))
     90        ;
Note: See TracChangeset for help on using the changeset viewer.