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

PSOUTLA2.m

Go to the documentation of this file.
  1. PSOUTLA2 ;BHAM ISC/GSN-Pharmacy utility program cont. ;6/6/05 12:19pm
  1. ;;7.0;OUTPATIENT PHARMACY;**210**;DEC 1997
  1. Q
  1. ;
  1. WORDWRAP(STR,IEN,GL,LM) ;Wraps words at spaces normally and will breakup long
  1. ; words at a delimiter & wrap at those break points
  1. ; Input: STR - a text string
  1. ; IEN - ien of global
  1. ; GL - global root
  1. ; LM - left margin
  1. ; Output: Populated global (usually in ^TMP)
  1. ;
  1. ; When a long word is encountered, i.e. text with no spaces, an
  1. ; attempt will be made to locate a delimiter & break the line there.
  1. ; If it can't find a valid delimiter without a restricted scenario,
  1. ; i.e. a number like 1,000 , then it will be forced to break at the
  1. ; End of Line (EOL).
  1. ;
  1. ; Delimiters searched for and order they are picked for use:
  1. ; preferred: , ;
  1. ; alternate: : =
  1. ; do not use: - . ) ( / (to critical, used in dosing)
  1. ; example: "TAKE 1/2-1 TAB(7.5MG) TABLET(S)"
  1. ;
  1. ; Key Variables: WORD - current word from text string
  1. ; WORD1 - 1st part of word that will fit
  1. ; WORD2 - 2nd part of word for new line
  1. ; WORD0 - remnant that won't fit on the new line
  1. ;
  1. N QQ,DL,DLM,WD,LL,TL,UL,MAXLN,LSTD,CURD,GWRD,LC,WORD0,WORD,WORD1,WORD2
  1. S IEN=+$G(IEN),@GL@(IEN,0)=$G(@GL@(IEN,0)),WORD0=""
  1. ;loop thru words, quit if no more words & no remnants - i.e. WORD0
  1. F QQ=1:1 S WORD=$P(STR," ",QQ) D Q:(QQ'<$L(STR," "))&(WORD0="")
  1. . ;if remnant exists, prepend to next Word
  1. . S:WORD0]"" WORD=WORD0_WORD,WORD0=""
  1. . ;wrap short words at spaces, check if last char is already a space
  1. . S GWRD=@GL@(IEN,0)
  1. . S LC=$E(@GL@(IEN,0),$L(GWRD))
  1. . I LC=" ",$L(GWRD_WORD)<81 S @GL@(IEN,0)=@GL@(IEN,0)_WORD Q
  1. . I LC'=" ",$L(GWRD_" "_WORD)<81 S @GL@(IEN,0)=@GL@(IEN,0)_" "_WORD Q
  1. . I $L(WORD)<20,$L(LM+1+$L(WORD))<81 D Q
  1. . . S WORD1="",WORD2=WORD,DLM="" D ADDWORDS S WORD0=WORD2 Q
  1. . ;
  1. . ;word>80, so wrap long words @ a specific delimiter, if found
  1. . S MAXLN=79-$L(@GL@(IEN,0))
  1. . ;search backwards & pick 1st dl > 1 count of preferred delims
  1. . F DL=";","," S DL($L(WORD,DL))=DL
  1. . S DL=$O(DL(DL),-1) S DLM=$S(DL>1:DL(DL),1:"")
  1. . I DLM="" F DL="=",":" S DL($L(WORD,DL))=DL D ;try these alt delims
  1. . . S DL=$O(DL(DL),-1) S DLM=$S(DL>1:DL(DL),1:"")
  1. . ;
  1. . ;no good delimiter, will have to break at end of line
  1. . I DLM="" D Q
  1. . . S WORD1=$E(WORD,1,MAXLN),WORD2=$E(WORD,MAXLN+1,$L(WORD))
  1. . . D ADDWORDS S WORD0=WORD2
  1. . ;
  1. . ;good delimiter, will break at last dlm that fits within maxln
  1. . S (LSTD,LL)=0,CURD=1 F TL=0:0 S CURD=$F(WORD,DLM,CURD) Q:'CURD D
  1. . . S TL=TL+1
  1. . . S WD(TL)=CURD_"^"_$E(WORD,CURD-2,CURD)
  1. . . S:CURD<MAXLN LSTD=CURD,LL=TL
  1. . ;special check of "," embedded in a number e.g. 1,000
  1. . ;backup to previous delimiter if pattern match
  1. . I DLM="," F UL=LL:-1:0 Q:$P($G(WD(UL)),"^",2)'?1N1","1N
  1. . I DLM=",",+$G(WD(UL))<LSTD S LSTD=+$G(WD(UL))
  1. . ;
  1. . ;'LSTD usually means no valid Dlm's found in Word, but if line
  1. . ;found to have some valid Dlm's later in the Word, then go ahead
  1. . ;defer entire string to next line via Addwords Api
  1. . I 'LSTD,TL>LL,$P($G(WD(TL)),"^",2)'?1N1","1N D Q
  1. . . S WORD1="",WORD2=WORD D ADDWORDS S WORD0=WORD2
  1. . ;
  1. . ;no valid Dlm's found in word, can't determine a word, break @EOL
  1. . I 'LSTD,$L(WORD)>(MAXLN) D Q
  1. . . S WORD1=$E(WORD,1,MAXLN),WORD2=$E(WORD,MAXLN+1,$L(WORD))
  1. . . D ADDWORDS S WORD0=WORD2
  1. . ;no valid Dlm's found in word, and can add Word to curr line
  1. . I 'LSTD,$L(WORD)'>(MAXLN) S @GL@(IEN,0)=@GL@(IEN,0)_WORD Q
  1. . ;
  1. . ;valid Dlm's & location found indicated by SS
  1. . I LSTD D Q
  1. . . S WORD1=$E(WORD,1,LSTD-1),WORD2=$E(WORD,LSTD,$L(WORD))
  1. . . D ADDWORDS S WORD0=WORD2
  1. Q
  1. ;
  1. ADDWORDS ;Add words to curr line and to a new line
  1. N CH
  1. ;if last character is the DLM or a " ", then don't add a space when
  1. ;adding Word1 to current line
  1. S CH=$E(@GL@(IEN,0),$L(@GL@(IEN,0)))
  1. I (CH=DLM)!(CH=" ") D
  1. . S @GL@(IEN,0)=@GL@(IEN,0)_WORD1
  1. E D
  1. . S @GL@(IEN,0)=@GL@(IEN,0)_" "_WORD1
  1. ;create new line to hold Word2
  1. S IEN=IEN+1,$P(@GL@(IEN,0)," ",LM+1)=" "
  1. S MAXLN=79-$L(@GL@(IEN,0))
  1. ;word2 won't fit, quit for further wrapping
  1. Q:$L(WORD2)>(80-LM)
  1. ;word2 will fit add it
  1. S @GL@(IEN,0)=@GL@(IEN,0)_WORD2,WORD2=""
  1. Q