Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: RORTSK10

RORTSK10.m

Go to the documentation of this file.
  1. RORTSK10 ;HCIOFO/SG - REPORT RETRIEVING UTILITIES ; 11/14/06 1:11pm
  1. ;;1.5;CLINICAL CASE REGISTRIES;**1**;Feb 17, 2006;Build 24
  1. ;
  1. Q
  1. ;
  1. ;***** TRACES THE PATH FROM THE ELEMENT TO THE ROOT
  1. ;
  1. ; IEN IEN of the report element
  1. ;
  1. ; .STACK Reference to a local variable where the path will
  1. ; be stored to.
  1. ;
  1. ; STACK Number of elements in the path (n)
  1. ; STACK(i) Identifiers of the elements (i=1 - the source
  1. ; element; i=n - the root element)
  1. ; ^1: IEN of the report element
  1. ; ^2: Where exactly the rendering process
  1. ; has stopped (see $$XMLSTR for details)
  1. ; ^3: IEN of the text line
  1. ;
  1. PATH(IEN,STACK) ;
  1. K STACK S STACK=0
  1. F D Q:IEN'>0
  1. . S STACK=STACK+1,STACK(STACK)=IEN
  1. . S:'$P(IEN,U,2) $P(STACK(STACK),U,2)=4
  1. . S IEN=$P($G(@RORSRC@(+IEN,0)),U,2)
  1. Q
  1. ;
  1. ;***** RENDERS THE REPORT INTO XML
  1. ;
  1. ; ROR8DST Closed root of the destination buffer
  1. ;
  1. ; TASK Task number
  1. ;
  1. ; [.SORT] Sort modes for the report
  1. ;
  1. ; [.FROM] Where to start/continue the rendering process
  1. ; ^1: IEN of the report element
  1. ; ^2: Where exactly the rendering process has stopped
  1. ; (see the $$XMLSTR function for details)
  1. ; ^3: IEN of the text line (if the 2nd piece = 3)
  1. ;
  1. ; You must not make any assumptions about structure of
  1. ; this parameter (it can be changed at any time without
  1. ; warning). The only exception is the IEN of the report
  1. ; element. You can assign a positive value to this
  1. ; parameter before the call to start the rendering from
  1. ; the corresponding element.
  1. ;
  1. ; [MAXSIZE] Either the maximum number of lines to retrieve or
  1. ; the maximum size of the output in bytes (append the
  1. ; "B" to the number). By default (if $G(MAXSIZE)'>0,)
  1. ; the whole report (starting from the point indicated
  1. ; by the FROM parameter if it is defined) is retrieved.
  1. ;
  1. ; Examples:
  1. ; 500 Retrieve no more than 500 lines
  1. ; 4096B Retrieve no more than 4Kb
  1. ;
  1. ; NOTE: If the "B" suffix is used, the size of the retrieved
  1. ; portion of the document can be somewhat bigger than
  1. ; MAXSIZE! The last line of the chunk is not truncated
  1. ; even if the size will be bigger than MAXSIZE.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ; >0 Number of rendered lines
  1. ;
  1. ; If the maximum size (MAXSIZE) is reached, the identifiers
  1. ; of the last item (it has not been added to the output buffer) are
  1. ; returned via the FROM parameter. The next call of the function will
  1. ; continue the rendering process starting from that item.
  1. ;
  1. XMLREP(ROR8DST,TASK,SORT,FROM,MAXSIZE) ;
  1. N RORNUM ; Number of rendered lines of the report
  1. N RORSIZE ; Size of the output (in bytes)
  1. N RORSORT ; Sort modes for the report
  1. N RORSTACK ; Path from the FROM element to the root
  1. N RORSRC ; Closed root of the source report data
  1. ;
  1. N DIR,I,RC,SORTFLD,SORTLST K @ROR8DST
  1. S RORSRC=$$ROOT^DILFD(798.87,","_TASK_",",1)
  1. ;--- Setup the size limits
  1. S (RORNUM,RORSIZE)=0
  1. S MAXSIZE=$$UP^XLFSTR($G(MAXSIZE))
  1. I MAXSIZE["B" S RORNUM(1)=0,RORSIZE(1)=+MAXSIZE
  1. E S RORNUM(1)=+MAXSIZE,RORSIZE(1)=0
  1. ;--- Setup the starting point
  1. I $G(FROM)>0 D
  1. . S:$P(FROM,U,2)'>0 $P(FROM,U,2)=1
  1. . D PATH(FROM,.RORSTACK)
  1. E S I=$$XMLSTR("<?xml version=""1.0""?>")
  1. ;--- Setup the sorting
  1. S (FROM,I)=""
  1. F S I=$O(SORT(I)) Q:I="" D
  1. . S SORTLST=$P(SORT(I),"=") Q:SORTLST=""
  1. . S SORTFLD=$P($P(SORT(I),"=",2),":") Q:SORTFLD=""
  1. . S DIR=$S($P(SORT(I),":",2)?1"D".1"ESC":-1,1:1)
  1. . S RORSORT($$XEC^RORTSK11(SORTLST))=$$XEC^RORTSK11(SORTFLD)_U_DIR
  1. ;--- Get the report
  1. S RC=$$XMLREPI(0,0)
  1. S:RC>0 FROM=$P(RC,U,2)_U_$P(RC,U)_U_$P(RC,U,3)
  1. Q $S(RC'<0:RORNUM,1:RC)
  1. ;
  1. ;***** RECURSIVELY RENDERS THE REPORT INTO XML
  1. ;
  1. ; PARENT IEN of the parent element
  1. ; PELC Type of the parent element
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ; >0 Number of rendered lines has reached the limit
  1. ; (see the $$XMLSTR function for details)
  1. ;
  1. XMLREPI(PARENT,PELC) ;
  1. N RORIEN ; IEN of the report element being processed
  1. ;
  1. N BUF,DIR,LC,ELEMENT,I,LINE,MODE,RC,SVC,TMP,VAL,XREF
  1. I $G(PELC)>0 D
  1. . S BUF=$G(RORSORT(PELC)),SVC=+$P(BUF,U),DIR=$S($P(BUF,U,2)<0:-1,1:1)
  1. E S SVC=0,DIR=1
  1. S XREF=$NA(@RORSRC@("APSV",PARENT,SVC))
  1. ;--- Use order of creation if the xref is not available
  1. S:$D(@XREF)<10 XREF=$NA(@RORSRC@("APSV",PARENT,0))
  1. ;--- Determine the starting point (FROM)
  1. I $G(RORSTACK)>0 S RC=0 D Q:RC RC
  1. . S RORIEN=+$P(RORSTACK(RORSTACK),U)
  1. . S MODE=+$P(RORSTACK(RORSTACK),U,2)
  1. . S LINE=+$P(RORSTACK(RORSTACK),U,3)
  1. . S RORSTACK=RORSTACK-1
  1. . S I=+$O(@RORSRC@("APSR",RORIEN,SVC,""))
  1. . I I>0 D
  1. . . S TMP=+$P($G(@RORSRC@(I,0)),U,3)
  1. . . S VAL=$$SORTBY^RORDD01(TMP,$G(@RORSRC@(I,1)))
  1. . E S VAL=" "
  1. . S RORIEN=$O(@RORSRC@("APSV",PARENT,SVC,VAL,RORIEN),-DIR)
  1. . S VAL=$O(@RORSRC@("APSV",PARENT,SVC,VAL),-DIR)
  1. E K RORSTACK S (LINE,MODE)=0,(RORIEN,VAL)=""
  1. ;--- Render the report elements
  1. S RC=0
  1. F S VAL=$O(@XREF@(VAL),DIR) Q:VAL="" D Q:RC
  1. . F S RORIEN=$O(@XREF@(VAL,RORIEN),DIR) Q:RORIEN="" D S MODE=0 Q:RC
  1. . . S TMP=$G(@RORSRC@(RORIEN,0)) Q:$P(TMP,U,4)
  1. . . S ELC=+$P(TMP,U) Q:ELC'>0
  1. . . S ELEMENT=$P(^ROR(799.31,ELC,0),U)
  1. . . S I=0,BUF="<"_ELEMENT
  1. . . ;--- Render the attributes of the element
  1. . . F S I=$O(@RORSRC@(RORIEN,2,I)) Q:I'>0 D
  1. . . . S TMP=$P(@RORSRC@(RORIEN,2,I,0),U)
  1. . . . S BUF=BUF_" "_$P(^ROR(799.31,TMP,0),U)
  1. . . . S TMP=$G(@RORSRC@(RORIEN,2,I,1))
  1. . . . S BUF=BUF_"="""_$$XMLENC^RORUTL03(TMP)_""""
  1. . . ;--- Append the SORT attribute(s) to a table
  1. . . D:$D(RORSORT(ELC))
  1. . . . S TMP=+$P(RORSORT(ELC),U) Q:TMP'>0
  1. . . . S BUF=BUF_" SORT="""_$P(^ROR(799.31,TMP,0),U)_""""
  1. . . . S TMP=+$P(RORSORT(ELC),U,2)
  1. . . . S:TMP<0 BUF=BUF_" SORTDESC=""1"""
  1. . . ;--- Leaf element (without children)
  1. . . I $D(@RORSRC@("APSV",RORIEN))<10 D Q
  1. . . . ;--- <ELEMENT...>VALUE</ELEMENT>
  1. . . . S TMP=$G(@RORSRC@(RORIEN,1))
  1. . . . I TMP'="" D:MODE'>2 Q
  1. . . . . S BUF=BUF_">"_$$XMLENC^RORUTL03(TMP)_"</"_ELEMENT_">"
  1. . . . . S RC=$$XMLSTR(BUF,2)
  1. . . . ;--- <ELEMENT.../>
  1. . . . S I=$O(@RORSRC@(RORIEN,3,0))
  1. . . . I I'>0 S:MODE'>2 RC=$$XMLSTR(BUF_"/>",2) Q
  1. . . . ;--- <ELEMENT...>
  1. . . . ; TEXT
  1. . . . ;--- </ELEMENT>
  1. . . . I MODE'>3 D Q:RC
  1. . . . . S:MODE'>1 RC=$$XMLSTR(BUF_">",1)
  1. . . . . S:LINE>0 I=LINE,LINE=0
  1. . . . . F Q:RC D S I=$O(@RORSRC@(RORIEN,3,I)) Q:I'>0
  1. . . . . . S RC=$$XMLSTR($G(@RORSRC@(RORIEN,3,I,0)),3,I)
  1. . . . S RC=$$XMLSTR("</"_ELEMENT_">",5)
  1. . . ;--- Parent element and all children (recursively)
  1. . . I MODE'>4 D Q:RC
  1. . . . I MODE'>1 S RC=$$XMLSTR(BUF_">",1) Q:RC
  1. . . . S RC=$$XMLREPI(RORIEN,ELC)
  1. . . S RC=$$XMLSTR("</"_ELEMENT_">",5)
  1. . S RORIEN=""
  1. Q RC
  1. ;
  1. ;***** APPENDS THE STRING TO THE OUTPUT BUFFER
  1. ;
  1. ; STR String that should be appended to the document
  1. ; TYPE Type of the rendered item
  1. ; [LINE] IEN of the text line
  1. ;
  1. ; Return Values:
  1. ; 0 Ok
  1. ; >0 Number of rendered lines has reached the limit
  1. ; ^1: Where exactly the rendering process has stopped
  1. ; 1 Opening tag
  1. ; 2 Single value
  1. ; 3 Multiline text value
  1. ; 4 Nested tag
  1. ; 5 Closing tag
  1. ; ^2: IEN of the report element
  1. ; ^3: IEN of the text line (if the 1st piece = 3)
  1. ;
  1. XMLSTR(STR,TYPE,LINE) ;
  1. N SL S SL=$L(STR)+2
  1. I RORNUM(1)>0 Q:RORNUM'<RORNUM(1) TYPE_U_RORIEN_U_$G(LINE)
  1. I RORSIZE(1)>0 Q:RORSIZE'<RORSIZE(1) TYPE_U_RORIEN_U_$G(LINE)
  1. S RORNUM=RORNUM+1,@ROR8DST@(RORNUM)=STR
  1. S RORSIZE=RORSIZE+SL
  1. Q 0
  1. ;
  1. ;*****
  1. XREFNODE(TASK,PARENT,SORT) ;
  1. N NODE
  1. S NODE=$$ROOT^DILFD(798.87,","_TASK_",",1)
  1. S SORT=$$XEC^RORTSK11(SORT)
  1. Q $S(SORT>0:$NA(@NODE@("APSV",PARENT,SORT)),1:"")