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

BLRGMENU.m

Go to the documentation of this file.
  1. BLRGMENU ; IHS/OIT/MKK - GENERIC MENU DRIVER ; 17-Oct-2014 09:22 ; MKK
  1. ;;5.2;IHS LABORATORY;**1022,1033,1034**;NOV 01, 1997;Build 88
  1. ;;
  1. ;; The main array is the BLRMMENU array. It's format is
  1. ;; BLRMMENU(CNT,RTN,MENUDISP)
  1. ;; where CNT = # of Item
  1. ;; RTN = Full routine name, including Entry Points
  1. ;; MENUDISP = Menu display string
  1. ;;
  1. ;; The BLRMMENU array is added to by using ADDTMENU.
  1. ;;
  1. ;; The calling routines must ensure that BLRMMENU is intialized before
  1. ;; using the ADDTMENU call.
  1. ;;
  1. EEP ; Ersatz EP
  1. D ^XBCLS
  1. W !!!,$C(7),$C(7),$C(7)
  1. W !!
  1. W $$SHOUTMSG("USE LABEL")
  1. W !!
  1. W !,$C(7),$C(7),$C(7),!
  1. Q
  1. ;
  1. ; Display up to 4 Header lines
  1. I $G(HD1)="" Q ; Must be at least 1 HEADER line
  1. ;
  1. I $G(IOM)="" D HOME^%ZIS ; Reset screen variables, if need be
  1. ;
  1. NEW HEADER,HDCNT,MMSEL,MAX ; NEW variables so they don't hang around.
  1. ;
  1. F D Q:MMSEL'>0 ; "Infinite loop"
  1. . D MAINHEAD ; Set up MAIN header array
  1. . ;
  1. . S:HDCNT<3 HEADER(HDCNT)="MAIN MENU"
  1. . S:HDCNT>2 HEADER(HDCNT)=$$CJ^XLFSTR("MAIN MENU",IOM)
  1. . ;
  1. . D BLRGSHSH ; Generic Header
  1. . D DISPMENU ; Display the BLRMMENU array
  1. . D GOFORIT ; Select & Do menu item
  1. ;
  1. Q ; Exit
  1. ;
  1. ; Display up to 4 Header lines in FileMan format
  1. I $G(HD1)="" Q ; Must be at least 1 HEADER line
  1. ;
  1. I $G(IOM)="" D HOME^%ZIS
  1. NEW HEADER,HDCNT,MMSEL,MAX,STR,STR2
  1. ;
  1. F D Q:MMSEL'>0 ; "Infinite loop"
  1. . D MAINHEAD
  1. . D BLRGSHSH
  1. . D DISPMEFM ; Display BLRMMENU array in FileMan format
  1. . D GOFORIT
  1. ;
  1. Q ; Exit
  1. ;
  1. ; Set up Main Menu driver heading
  1. MAINHEAD ; ; EP
  1. K HEADER
  1. S HEADER(1)=HD1
  1. S HDCNT=2
  1. S:$G(HD2)'="" HEADER(2)=HD2,HDCNT=HDCNT+1
  1. S:$G(HD3)'="" HEADER(3)=HD3,HDCNT=HDCNT+1
  1. S:$G(HD4)'="" HEADER(4)=HD4,HDCNT=HDCNT+1
  1. ;
  1. S MAX=$G(BLRMMENU(-1)) ; Maximum # of menu items
  1. Q
  1. ;
  1. ; Select Item and try to do it
  1. GOFORIT ; EP
  1. NEW STR,STR2
  1. ;
  1. S MMSEL=$$SELITEM ; Select the Item from the menu
  1. I MMSEL<1 Q ; If zero, just RETURN
  1. ;
  1. W !
  1. S STR=$P($G(BLRMMENU(MMSEL)),"|",1) ; Get routine "string"
  1. I STR="" Q ; If routine = Null, just RETURN
  1. ;
  1. ; If routine string is of the form LABEL^ROUTINE, then have to make
  1. ; sure to test the existance of the ROUTINE and not the LABEL^ROUTINE.
  1. ; This is the reason for the code involving the STR2 variable.
  1. S STR2=$P($P(STR,"^",2),"(",1)
  1. I STR2="" Q ; If no routine Name, skip
  1. ;
  1. Q:$L($T(@STR))<1 ; IHS/MSC/MKK - LR*5.2*1033 - If Line Label doesn't exist, skip
  1. ;
  1. I $$EXIST^%R(STR2_".INT") D @STR ; If routine exists, do it
  1. Q
  1. ;
  1. ; Select Item Function
  1. SELITEM() ; EP
  1. D ^XBFMK ; Kernel call cleans up FILEMAN vars
  1. S DIR("A")="Select"
  1. S DIR(0)="NO^1:"_MAX
  1. S DIR("T")=30 ; IHS/MSC/MKK - LR*5.2*1033
  1. D ^DIR
  1. Q +$G(Y)
  1. ;
  1. ; Add Menu Items to BLRMMENU array
  1. ; RTN = Routine
  1. ; DISPSTR = Display String
  1. ADDTMENU(RTN,DISPSTR) ; EP
  1. I $G(RTN)="" Q
  1. I $G(DISPSTR)="" Q
  1. ;
  1. NEW MAX
  1. S MAX=1+$O(BLRMMENU(""),-1)
  1. S BLRMMENU(MAX)=RTN_"|"_DISPSTR
  1. ;
  1. S BLRMMENU(-1)=MAX ; Special node
  1. Q
  1. ;
  1. ; Display BLRMMENU array -- Tab positions are hardcoded
  1. DISPMENU ; EP
  1. NEW ITEM
  1. NEW CNT,TAB ; IHS/MSC/MKK - LR*5.2*1033
  1. ;
  1. S ITEM=0
  1. S CNT=1,TAB(1)=3,TAB(2)=42 ; IHS/MSC/MKK - LR*5.2*1033
  1. ; F S ITEM=$O(BLRMMENU(ITEM)) Q:ITEM="" D
  1. ; . I ITEM#2'=0 D
  1. ; .. W ?4,$J(ITEM,2),") "
  1. ; .. W $E($P($G(BLRMMENU(ITEM)),"|",2),1,31)
  1. ; . I ITEM#2=0 D
  1. ; .. W ?41,$J(ITEM,2),") "
  1. ; .. W $E($P($G(BLRMMENU(ITEM)),"|",2),1,31)
  1. ; .. W !
  1. ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1033
  1. F S ITEM=$O(BLRMMENU(ITEM)) Q:ITEM="" D
  1. . W ?TAB(CNT),$J(ITEM,2),") "
  1. . W $E($P($G(BLRMMENU(ITEM)),"|",2),1,33)
  1. . S CNT=CNT+1
  1. . I CNT>2 W ! S CNT=1
  1. . ; ----- END IHS/MSC/MKK - LR*5.2*1033
  1. W !
  1. Q
  1. ;
  1. ; Display BLRMMENU array in FileMan format
  1. DISPMEFM ; EP
  1. NEW ITEM
  1. ;
  1. S ITEM=0
  1. F S ITEM=$O(BLRMMENU(ITEM)) Q:ITEM="" D
  1. . W ?4,ITEM
  1. . ; W ?9,$E($P($G(BLRMMENU(ITEM)),"|",2),1,53)
  1. . W ?9,$E($P($G(BLRMMENU(ITEM)),"|",2),1,70) ; IHS/MSC/MKK - LR*5.2*1033
  1. . W !
  1. W !
  1. Q
  1. ;
  1. ; New Page with just Header & Date & Time
  1. HEADERDT ; EP
  1. BLRGSHSH ; EP
  1. NEW J,TMPLN ; Temporary Line
  1. NEW RMPSOS ; RPMS' Operating System
  1. NEW TIMELEN,TIMESTR
  1. ;
  1. I IOST["C-VT" D ^XBCLS ; Clear sceen and home cursor
  1. I IOST'["C-VT" W @IOF ; Form Feed if not terminal
  1. ;
  1. W $$CJ^XLFSTR($$LOC^XBFUNC,IOM),! ; Location
  1. ;
  1. S TMPLN=$$CJ^XLFSTR(HEADER(1),IOM) ; Center string
  1. S $E(TMPLN,1,13)="Date:"_$$HTE^XLFDT($H,"2DZ") ; Today's Date
  1. S $E(TMPLN,IOM-15)=$J("Time:"_$$NOWTIME,16) ; Current Time
  1. S TMPLN=$$TRIM^XLFSTR(TMPLN,"R"," ") ; Trim extra spaces
  1. W TMPLN,!
  1. ;
  1. I $G(HEADER(2))'="" D
  1. . S TMPLN=$$CJ^XLFSTR(HEADER(2),IOM)
  1. . S:$G(BLRVERN)'="" $E(TMPLN,(IOM-10))=$J(BLRVERN,11) ; Version number
  1. . S TMPLN=$$TRIM^XLFSTR(TMPLN,"R"," ")
  1. . ; If BLRVERN2 variable exists, put it in HEADER array, if room
  1. . I $L($G(BLRVERN2)),$TR($E(TMPLN,1,$L(BLRVERN2)+2)," ")="" S $E(TMPLN,1,$L(BLRVERN2))=BLRVERN2 ; IHS/MSC/MKK - LR*5.2*1033
  1. . W TMPLN,!
  1. ;
  1. ; Other Header lines, iff they exist
  1. F J=3:1 Q:$G(HEADER(J))="" D
  1. . W $G(HEADER(J)),!
  1. ;
  1. W $TR($J("",IOM)," ","-"),! ; Dashed Line
  1. ;
  1. S LINES=J+2 ; Re-intialize # lines
  1. ;
  1. Q
  1. ;
  1. ; Header with Date/Time & Page Numbers
  1. BLRGHWPN(PG,QFLG,HEADONE) ; EP
  1. D HEDPGNUM
  1. Q
  1. ;
  1. ; HEaDer with PaGe Number & date/time
  1. HEADERPG(PG,QFLG,HEADONE) ; EP
  1. D HEDPGNUM
  1. Q
  1. ;
  1. ; HEaDer with PaGe NUMber & date & time
  1. HEDPGNUM ; ; EP
  1. NEW J,TMPLN
  1. NEW TIMELEN,TIMESTR
  1. ;
  1. ; Check "Print Header Once" Flag
  1. I $E($G(HEADONE),1,1)="Y"&(PG>0) S QFLG="HO" Q
  1. ;
  1. I IOST["C-VT"&(PG>0) D I $G(QFLG)="Q" Q ; If Fileman quit, then skip
  1. . D ^XBFMK
  1. . W !
  1. . S DIR(0)="E",(X,Y)=""
  1. . S DIR("T")=30 ; IHS/OIT/MKK - LR*5.2*1032
  1. . D ^DIR
  1. . I $G(X)="^" S QFLG="Q"
  1. ;
  1. I IOST["C-VT" D ^XBCLS ; If terminal, clear sceen & home cursor
  1. I IOST'["C-VT" W @IOF ; Form Feed if not terminal
  1. ;
  1. W $$CJ^XLFSTR($$LOC^XBFUNC,IOM),! ; Location
  1. ;
  1. S PG=PG+1 ; Increment Page Number
  1. S TMPLN=$$CJ^XLFSTR(HEADER(1),IOM) ; Center Header string
  1. S $E(TMPLN,1,13)="Date:"_$$NOWDATE ; Today's Date
  1. S $E(TMPLN,IOM-10)=$J("Page "_PG,11) ; Page Number
  1. S TMPLN=$$TRIM^XLFSTR(TMPLN,"R"," ") ; Trim extra spaces
  1. W TMPLN,!
  1. ;
  1. S TMPLN=$$CJ^XLFSTR(HEADER(2),IOM)
  1. S TIMESTR="Time:"_$$NOWTIME ; Current Time
  1. S TIMELEN=$L(TIMESTR) ; Length of string
  1. S $E(TMPLN,1,TIMELEN)=TIMESTR
  1. S:$G(BLRVERN)'="" $E(TMPLN,(IOM-10))=$J(BLRVERN,11) ; Version number
  1. S TMPLN=$$TRIM^XLFSTR(TMPLN,"R"," ")
  1. W TMPLN,!
  1. ;
  1. ; F J=3:1 Q:$G(HEADER(J))="" D
  1. ; . W $G(HEADER(J)),!
  1. ;
  1. ; ----- BEGIN IHS/OIT/MKK - LR*5.2*1032
  1. ; If BLRVERN2 variable exists, put it in HEADER array, if room
  1. I $G(HEADER(3))'="" D
  1. . S TMPLN=HEADER(3)
  1. . I $G(BLRVERN2)'="",$TR($E(TMPLN,1,$L(BLRVERN2)+1)," ")="" S $E(TMPLN,1,$L(BLRVERN2))=BLRVERN2 ; Label
  1. . S TMPLN=$$TRIM^XLFSTR(TMPLN,"R"," ")
  1. . W TMPLN,!
  1. ;
  1. ; Other Header lines, iff they exist
  1. F J=4:1 Q:$G(HEADER(J))="" D
  1. . W $G(HEADER(J)),!
  1. ; ----- END IHS/OIT/MKK - LR*5.2*1032
  1. ;
  1. ;
  1. W $TR($J("",IOM)," ","-"),! ; Dashed line
  1. ;
  1. S LINES=J+2
  1. ;
  1. Q
  1. ;
  1. ; Generic "Press Any Key"
  1. BLRGPGR(TAB) ; EP
  1. NEW TABSTR
  1. I $G(TAB)'="" S TABSTR=$J("",TAB)_"Press RETURN Key"
  1. I $G(TAB)="" S TABSTR="Press RETURN Key"
  1. ;
  1. W ! ; Blank line
  1. D ^XBFMK
  1. S DIR(0)="E",(X,Y)=""
  1. S DIR("A")=TABSTR
  1. D ^DIR
  1. I $G(X)="^" S QFLG="Q" ; If Fileman quit, then set Quit Flag
  1. ;
  1. Q
  1. ;
  1. ; Generic "Press Any Key"
  1. PRESSKEY(TAB) ; EP
  1. NEW TABSTR
  1. S TABSTR=$J("",+$G(TAB))_"Press RETURN Key"
  1. W ! ; Blank line
  1. D ^XBFMK
  1. S DIR(0)="E",(X,Y)=""
  1. S DIR("A")=TABSTR
  1. D ^DIR
  1. I $G(X)="^" S QFLG="Q" ; If Fileman quit, then set Quit Flag
  1. ;
  1. Q
  1. ;
  1. ; NOW DATE in MM/DD/YY format
  1. NOWDATE() ; EP
  1. Q $$HTE^XLFDT($H,"2DZ")
  1. ;
  1. ; NOW TIME in xx:xx AM/PM format
  1. NOWTIME() ; EP
  1. Q $$UP^XLFSTR($P($$HTE^XLFDT($H,"2MPZ")," ",2,3))
  1. ;
  1. ; Return a string like >>>> STR <<<<
  1. SHOUTMSG(STR,RM) ; EP
  1. NEW HALFLEN,J,STRLEN,TMPSTR
  1. ;
  1. I $G(RM)="" S RM=IOM
  1. ;
  1. S HALFLEN=(RM\2)-(($L(STR)+2)\2)
  1. S TMPSTR=$TR($J("",HALFLEN)," ",">")
  1. S TMPSTR=TMPSTR_" "_STR_" "
  1. S STRLEN=$L(TMPSTR)
  1. F J=STRLEN:1:(RM-1) S TMPSTR=TMPSTR_"<"
  1. Q TMPSTR
  1. ;
  1. HEADONE(HD1) ; EP -- Asks if user wants only 1 header line
  1. D ^XBFMK
  1. S DIR("A")="One Header Line ONLY"
  1. S DIR("B")="NO"
  1. S DIR(0)="YO"
  1. D ^DIR
  1. S HD1=$S(+$G(Y)=1:"YES",1:"NO")
  1. Q
  1. ;
  1. ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1033
  1. ; TAB = Beginning Column
  1. ; STR = String to display
  1. ; MAX = # of characters
  1. LINEWRAP(TAB,STR,MAX) ; EP - If line too long, wrap it.
  1. Q:$L($G(STR))<1
  1. ;
  1. NEW LINE,LM,ONGO,SPACE,STR1,STR2,WRAPSTR
  1. ;
  1. S WRAPSTR="",NEEDSP=0
  1. ;
  1. S STR=$$TRIM^XLFSTR(STR,"LR"," ") ; Get rid of leading & trailing blanks
  1. ;
  1. ; Determine if the length of any space-delmited piece of the string > MAX
  1. F SPACE=1:1:$L(STR," ") S:$L($P(STR," ",SPACE))>MAX NEEDSP=NEEDSP+1
  1. ;
  1. ; If $L(STR)> MAX and has no spaces, or the $L of any space-delimited
  1. ; piece of STR > MAX, then setup spaces every MAX characters so that
  1. ; the ^DIWP routine will "wrap" STR so that no piece's $L is > MAX.
  1. I NEEDSP!((STR'[$C(32)&($L(STR)>MAX))) D
  1. . S ONGO=STR
  1. . F Q:$L(ONGO)<MAX D
  1. .. S STR1=$E(ONGO,1,MAX)
  1. .. S STR2=$E(ONGO,(MAX+1),(MAX*2))
  1. .. S WRAPSTR=WRAPSTR_STR1_" "_STR2
  1. .. S ONGO=$E(ONGO,((MAX*2)+1),$L(ONGO))
  1. .. S:$L(ONGO) WRAPSTR=WRAPSTR_" "
  1. . S:$L(ONGO) WRAPSTR=WRAPSTR_ONGO
  1. ;
  1. ; If WRAPSTR exists, trim trailing spaces
  1. S:$L(WRAPSTR) WRAPSTR=$$TRIM^XLFSTR(WRAPSTR,"R"," ")
  1. ;
  1. S X=$S($L(WRAPSTR):WRAPSTR,1:STR)
  1. ;
  1. ; Use FileMan DIWP routine to "wrap" string, if necessary.
  1. K ^UTILITY($J,"W")
  1. S LM=2
  1. S DIWL=LM,DIWR="",DIWF="C"_MAX
  1. D ^DIWP
  1. ;
  1. ; Use loop to output result without extra line feed
  1. S LINE=0
  1. F S LINE=$O(^UTILITY($J,"W",LM,LINE)) Q:LINE<1 D
  1. . W:LINE=1 ?TAB
  1. . I LINE>1 W !,?TAB S LINES=1+$G(LINES)
  1. . W $$TRIM^XLFSTR($G(^UTILITY($J,"W",LM,LINE,0)),"L",$C(9))
  1. ;
  1. K ^UTILITY($J,"W")
  1. Q
  1. ;
  1. DASH(LEN) ; EP - Dashed Characters
  1. W $TR($J("",LEN)," ","-")
  1. Q ""
  1. ;
  1. ;
  1. BUILDHED(STR,NOCENTER) ; EP - Build the HEADER array
  1. NEW CURLINE
  1. ;
  1. S NOCENTER=$G(NOCENTER,1)
  1. ;
  1. S CURLINE=+$O(HEADER("A"),-1)+1
  1. I CURLINE<3!(NOCENTER) S HEADER(CURLINE)=STR Q
  1. ;
  1. S HEADER(CURLINE)=$$CJ^XLFSTR(STR,IOM)
  1. Q
  1. ;
  1. ; ----- END IHS/MSC/MKK - LR*5.2*1033
  1. ;
  1. ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1034
  1. SHOWBOX(MSG,LM,RM) ; EP - Display Message in a "box"
  1. NEW CRTLINE,J,MAXIT,AROUND
  1. ;
  1. S RM=$G(RM,IOM)
  1. S LM=$G(LM,0)
  1. S RM=RM-LM
  1. ;
  1. S MAXIT="@"
  1. F J=1:1:$L(MSG) S MAXIT=MAXIT_$E(MSG,J,J)_"@"
  1. S AROUND=$TR($J("",8+$L(MAXIT))," ","@")
  1. S MAXIT="@@!!"_$TR(MAXIT," ","@")_"!!@@"
  1. ;
  1. W !!
  1. F J=1,2 W ?LM,$TR($J("",RM)," ","*"),!
  1. W ?LM,$TR($$CJ^XLFSTR(AROUND,RM)," @","* "),!
  1. W ?LM,$TR($$CJ^XLFSTR(MAXIT,RM)," @","* "),!
  1. W ?LM,$TR($$CJ^XLFSTR(AROUND,RM)," @","* "),!
  1. F J=1,2 W ?LM,$TR($J("",RM)," ","*"),!
  1. Q
  1. ;
  1. COLHEAD(MSG,WIDTH,DASHER) ; EP - COLumn HEADer String
  1. NEW COLSTR
  1. ;
  1. S DASHER=$G(DASHER,"=")
  1. S COLSTR="@"_$TR(MSG," ","@")_"@"
  1. Q $TR($$CJ^XLFSTR(COLSTR,WIDTH)," @",DASHER_" ")
  1. ;
  1. ; ----- END IHS/MSC/MKK - LR*5.2*1034