Added TRIM^GPLXPATH to delete empty elements from output
This commit is contained in:
parent
3905fdb162
commit
92d871bf9d
|
@ -70,6 +70,11 @@ CCRRPC(CCRGRTN,DFN,CCRPART,TIME1,TIME2,HDRARY) ;RPC ENTRY POINT FOR CCR OUTPUT
|
||||||
D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","ACTT")
|
D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","ACTT")
|
||||||
D EXTRACT^GPLACTORS("ACTT",ACTGLO,"ACTT2")
|
D EXTRACT^GPLACTORS("ACTT",ACTGLO,"ACTT2")
|
||||||
D INSINNER^GPLXPATH(CCRGLO,"ACTT2","//ContinuityOfCareRecord/Actors")
|
D INSINNER^GPLXPATH(CCRGLO,"ACTT2","//ContinuityOfCareRecord/Actors")
|
||||||
|
N I,J,DONE S DONE=0
|
||||||
|
F I=0:0 D Q:DONE ; DELETE UNTIL ALL EMPTY ELEMENTS ARE GONE
|
||||||
|
. S J=$$TRIM^GPLXPATH(CCRGLO) ; DELETE EMPTY ELEMENTS
|
||||||
|
. W "TRIMMED",J,!
|
||||||
|
. I J=0 S DONE=1 ; DONE WHEN TRIM RETURNS FALSE
|
||||||
Q
|
Q
|
||||||
;
|
;
|
||||||
INITSTPS(TAB) ; INITIALIZE CCR PROCESSING STEPS
|
INITSTPS(TAB) ; INITIALIZE CCR PROCESSING STEPS
|
||||||
|
@ -159,4 +164,7 @@ TLIST ; LIST THE TESTS
|
||||||
;;>>>D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","G2")
|
;;>>>D QUERY^GPLXPATH(TGLOBAL,"//ContinuityOfCareRecord/Actors","G2")
|
||||||
;;>>>D EXTRACT^GPLACTORS("G2","ACTTEST","G3")
|
;;>>>D EXTRACT^GPLACTORS("G2","ACTTEST","G3")
|
||||||
;;>>?G3(G3(0))["</Actors>"
|
;;>>?G3(G3(0))["</Actors>"
|
||||||
|
;;><TRIM>
|
||||||
|
;;>>>D ZTEST^GPLCCR("CCR")
|
||||||
|
;;>>>W $$TRIM^GPLXPATH(CCRGLO)
|
||||||
;;></TEST>
|
;;></TEST>
|
||||||
|
|
52
p/GPLXPATH.m
52
p/GPLXPATH.m
|
@ -332,25 +332,39 @@ MAP(IXML,INARY,OXML) ; SUBSTITUTE @@X@@ VARS IN IXML WITH VALUES IN INARY
|
||||||
;
|
;
|
||||||
TRIM(THEXML) ; TAKES OUT ALL NULL ELEMENTS
|
TRIM(THEXML) ; TAKES OUT ALL NULL ELEMENTS
|
||||||
; THEXML IS PASSED BY NAME
|
; THEXML IS PASSED BY NAME
|
||||||
N I,J,TMPXML,DEL
|
N I,J,TMPXML,DEL,FOUND
|
||||||
F I=1:1:@THEXML@(0) D ; LOOP THROUGH ENTIRE ARRAY
|
S FOUND=0
|
||||||
. I @THEXML@(I)'["><" D PUSH("TMPXML",@THEXML@(I))
|
W "DELETING EMPTY ELEMENTS",!
|
||||||
D INDEX("TMPXML") ; MAKE AN XPATH INDEX
|
F I=1:1:(@THEXML@(0)-1) D ; LOOP THROUGH ENTIRE ARRAY
|
||||||
S I="" S I=$O(TMPXML(I))
|
. S J=@THEXML@(I)
|
||||||
F K=0:0 D Q:I="" ; NOW LOOK FOR EMPTY SECTIONS
|
. N JM,JP ; JMINUS AND JPLUS
|
||||||
. I I["//" D ;
|
. S JM=@THEXML@(I-1) ; LINE BEFORE
|
||||||
. . W I,TMPXML(I),!
|
. S JP=@THEXML@(I+1) ; LINE AFTER
|
||||||
. . S J=$P(TMPXML(I),"^",1)
|
. S JPX=$TR(JP,"/","") ; REMOVE THE SLASH
|
||||||
. . I J+1=$P(TMPXML(I),"^",2) D ;
|
. I J=JPX D ; AN EMPTY ELEMENT ON TWO LINES
|
||||||
. . . W I,!
|
. . W I,J,JP,!
|
||||||
. . . S DEL(J)=""
|
. . S FOUND=1 ; FOUND SOMETHING TO BE DELETED
|
||||||
. . . S DEL(J+1)=""
|
. . S DEL(I)="" ; SET LINE TO DELETE
|
||||||
. S I=$O(TMPXML(I))
|
. . S DEL(I+1)="" ; SET NEXT LINE TO DELETE
|
||||||
F I=1:1:TMPXML(0) D ;
|
. I J["><" D ; AN EMPTY ELEMENT ON ONE LINE
|
||||||
. I '$D(DEL(I))
|
. . W I,J,!
|
||||||
. D PUSH("TMPXML2",TMPXML(I))
|
. . S FOUND=1 ; FOUND SOMETHING TO BE DELETED
|
||||||
D CP("TMPXML2",THEXML)
|
. . S DEL(I)="" ; SET THE EMPTY LINE UP TO BE DELETED
|
||||||
Q
|
. . I JM=JPX D ;
|
||||||
|
. . . W I,JM_J_JPX,!
|
||||||
|
. . . S DEL(I-1)=""
|
||||||
|
. . . S DEL(I+1)="" ; SET THE SURROUNDING LINES FOR DEL
|
||||||
|
; . I J'["><" D PUSH("TMPXML",J)
|
||||||
|
I FOUND D ; NEED TO DELETE THINGS
|
||||||
|
. F I=1:1:@THEXML@(0) D ; COPY ARRAY LEAVING OUT DELELTED LINES
|
||||||
|
. . I '$D(DEL(I)) D ; IF THE LINE IS NOT DELETED
|
||||||
|
. . . D PUSH("TMPXML",@THEXML@(I)) ; COPY TO TMPXML ARRAY
|
||||||
|
. ZWR DEL
|
||||||
|
. D CP("TMPXML",THEXML) ; REPLACE THE XML WITH THE COPY
|
||||||
|
Q FOUND
|
||||||
|
;
|
||||||
|
NXTCHLD(HANDLE,NODE,CUR) ; RETURNS THE NEXT CHILD OR "" IF NONE
|
||||||
|
Q $$CHILD^MXMLDOM(HANDLE,NODE,CUR)
|
||||||
;
|
;
|
||||||
PARY(GLO) ;PRINT AN ARRAY
|
PARY(GLO) ;PRINT AN ARRAY
|
||||||
N I
|
N I
|
||||||
|
|
Loading…
Reference in New Issue