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

PSBOPM.m

Go to the documentation of this file.
PSBOPM ;BIRMINGHAM/BSR - BCMA OIT HISTORY ;Sep 02, 2020@15:05:53
 ;;3.0;BAR CODE MED ADMIN;**3,9,13,17,40,70,72,83,82**;Mar 2004;Build 27
 ;;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ; Reference/IA
 ; File 50.7/2880
 ; File 52.6/436
 ; File 52.7/437
 ; File 200/10060
 ; EN^PSJBCMA1/2829
 ;
 ;*70 - reset PSBCLINORD = 2 to signify combined orders report
 ;*83 - add Give info associated with a Remove and print
 ;
EN ;
 N PSBHDR,DFN,PSBGBL,X1,X2,PSBSTRT,PSBSTOP,PSBCOM,PSBSPC
 S PSBGBL="^TMP(""PSBO"",$J,""B"")"
 F  S PSBGBL=$Q(@PSBGBL) Q:PSBGBL=""  Q:$QS(PSBGBL,2)'=$J  Q:$QS(PSBGBL,1)'["PSBO"  D
 .S DFN=$QS(PSBGBL,5)
 I '$G(DFN) W !,("Error: No Patient IEN")  Q
 S PSBSTRT=$P(PSBRPT(.1),U,6)+$P(PSBRPT(.1),U,7)
 S PSBSTOP=$P(PSBRPT(.1),U,8)+$P(PSBRPT(.1),U,9)
 S PSBCOM=$P(PSBRPT(.2),"^",8)   ;COMMENT FLAG 1 MEANS YES
 I PSBSTRT="0" D
 .D NOW^%DTC S PSBSTOP=%
 .S X1=((PSBSTOP)\1) S X2=-$$GET^XPAR("ALL","PSB MED HIST DAYS BACK")
 .S:X2'<0 X2=-30 D C^%DTC  S PSBSTRT=X
 .S PSBCOM=$$GET^XPAR("ALL","PSB RPT INCL COMMENTS")
 D OUT(DFN,PSBSTRT,PSBSTOP,PSBORDNM)
 Q
 ;
OUT(DFN,PSBSTRT,PSBSTOP,PSBORDNM)        ;
 D CLEANALL ;CLEAN UP VARIABLES AND TMP ARRAY
 N PSBOR
 ;
 ;IF PSBORDNM DOESN'T CONTAIN A "U" OR A "V", SKIP THE ORDER LOOKUP
 S PSBOR=1
 I PSBORDNM'["U",PSBORDNM'["V" D
 .S:'$$GETORD^PSBOPM1(.PSBORDNM) PSBOR=0
 .I 'PSBOR&(PSBORDNM]"") S TMP("PSBOIS",$J,PSBORDNM)=""
 I PSBOR D
 .D GETORDN
 .D GETOIS
 D GETADSO ;  GET ALL ADDITIVES AND SOLUTIONS
 D FINDIENS^PSBOPM1 ; FIND EVERY MED LOG ENTRIES THAT SHOULD BE ON THE RPT
 D PREOUT ;   WRITE DATA TO GLOBAL
 D WRITEOT ;
 D CLEANSUM ; CLEAN UP AND LEAVE LIST OF IENS FOR THE REPORT.
 Q
 ;
GETORDN ;
 K ^TMP("PSJ1",$J)
 D EN^PSJBCMA1(DFN,PSBORDNM,1)
 Q
 ;
GETOIS  ; LOAD PSBOIS(#) WITH ALL OF THE ORDERABLE ITEMS
 N PSBOI,XXX,XXY,PSBADD,PSBSOL
 I PSBORDNM["U" D
 .;GET UNIT DOSE ORDERS
 .I $D(^TMP("PSJ1",$J,2)) D
 ..S PSBOI=$P(^TMP("PSJ1",$J,2),"^")
 ..S PSBOI=$S(PSBOI["U":$TR(PSBOI,"U",""),PSBOI["V":$TR(PSBOI,"V",""),1:PSBOI)
 ..S TMP("PSBOIS",$J,PSBOI)=""
 ;
 ;IV ORDERS NEED TO USE THE ADDITIVE AND SOLUTION NUMBER TO BACK
 ;TRACK TO THE OI ASSOCIATED WITH IT
 I PSBORDNM["V" D
 .;GET ADDITIVES OFF THE ORDER
 .I $G(^TMP("PSJ1",$J,850,0))  D
 ..S XXX="" F  S XXX=$O(^TMP("PSJ1",$J,850,XXX)) Q:XXX=""  D
 ...S XXY="" F  S XXY=$O(^TMP("PSJ1",$J,850,XXX,XXY)) Q:XXY=""  D
 ....S PSBADD=$P(^TMP("PSJ1",$J,850,XXX,XXY),"^")
 ....;CONVERT ADDITIVE TO ORDERABLE ITEM AND ADD TO LIST
 ....S TMP("PSBOIS",$J,$$OFROMA(PSBADD))=""
 .;   GET SOLUTIONS OFF THE ORDER
 .I $G(^TMP("PSJ1",$J,950,0))  D
 ..S XXX="" F  S XXX=$O(^TMP("PSJ1",$J,950,XXX)) Q:XXX=""  D
 ...S XXY="" F  S XXY=$O(^TMP("PSJ1",$J,950,XXX,XXY)) Q:XXY=""  D
 ....S PSBSOL=$P(^TMP("PSJ1",$J,950,XXX,XXY),"^")
 ....I $G(^TMP("PSJ1",$J,850,0)) Q:$$GET1^DIQ(52.7,PSBSOL_",",18)'="YES"  ; PSB*3.0*82 rbd Do not do pre-mix when additive present
 ....;
 ....;CONVERT SOLUTIOIN TO ORDERABLE ITEM AND ADD TO LIST
 ....S TMP("PSBOIS",$J,$$OFROMS(PSBSOL))=""
 Q
 ;
OFROMA(PSBADD) ;GET ORDERABLE ITEM FROM AN ADDITIVE
 Q $$GET1^DIQ(52.6,PSBADD_",",15,"I")
 ;
OFROMS(PSBSOL) ; GET ORDERABLE ITEM FROM A SOLUTION
 Q $$GET1^DIQ(52.7,PSBSOL_",",9,"I")
 ;
GETADSO ; GET ALL ADDITIVES FOR ALL ORDERABLE ITEMS
 N PSBAOUT,PSBSOUT,XA,XB
 S XA="" F  S XA=$O(TMP("PSBOIS",$J,XA)) Q:XA=""  D
 .D LIST^DIC(52.6,"","@;15I","QPI","","","","AOI","","","PSBAOUT")
 .S XB=0 F  S XB=$O(PSBAOUT("DILIST",XB)) Q:XB=""  D
 ..I $P(PSBAOUT("DILIST",XB,0),"^",2)=XA D
 ...S TMP("PSBADDS",$J,$P(PSBAOUT("DILIST",XB,0),"^",1))=""
 K PSBAOUT
 ; GET ALL SOLUTIONS FOR ALL ORDERABLE ITEMS
 S XA="" F  S XA=$O(TMP("PSBOIS",$J,XA)) Q:XA=""  D
 .D LIST^DIC(52.7,"","@;9I","QPI","","","","AOI","","","PSBSOUT")
 .S XB=0 F  S XB=$O(PSBSOUT("DILIST",XB)) Q:XB=""  D
 ..I $P(PSBSOUT("DILIST",XB,0),"^",2)=XA D
 ...S TMP("PSBSOLS",$J,$P(PSBSOUT("DILIST",XB,0),"^",1))=""
 K PSBSOUT
 Q
 ;
PREOUT ;
 N I,TYP,XDT,PSBIEN,PSBIENS
 F TYP="UD","ADD","SOL"  D
 .Q:'$D(TMP("PSBIENS",$J,TYP))
 .S XDT="" F  S XDT=$O(TMP("PSBIENS",$J,TYP,XDT),-1) Q:XDT=""  D
 ..S I="" F  S I=$O(TMP("PSBIENS",$J,TYP,XDT,I)) Q:I=""  D
 ...I TYP="UD" Q:$D(TMP("PSBIENS",$J,"ADD",XDT,I))  Q:$D(TMP("PSBIENS",$J,"SOL",XDT,I))
 ...S PSBIEN=I
 ...S PSBIENS=PSBIEN_","
 ...D OUTPUT(TYP)
 Q
 ;
OUTPUT(TYP) ;
 N GIVE,G1,G2,G3,G4
 ; added new local variables for PSB*3.0*82 rbd - also New'ing W & PSBUNK variables
 N PSBUNK,W,W2,W22LINE,W22NUM,W22TEXT,W3,WCURSTAT,WINIT,WNAME
 N WNPIEN,WOLDSTAT,WSUB9,WSUB9BY,WSUB9CNT,WSUB9DT,WUO,PSBNODE,PSBY,PSBDD
 S PSBSPC=$J("",80)
 ; PSB*3.0*82 rbd - more room for LOCATION; chg'ed 20 to 25
 S W=" "_$E($$GET1^DIQ(53.79,PSBIENS,.02)_PSBSPC,1,25)_" "
 I $TR(W," ")="",$$MME^PSBOML(+PSBIENS) S W=" MME/UNKNOWN LOCATION      "
 ; PSB*3.0*82 rbd - do not output status/sch type abbrevs anymore
 ;S W=W_$S($P(^PSB(53.79,PSBIEN,0),U,9)="":"?? ",1:$E($P(^PSB(53.79,PSBIEN,0),U,9)_"  ",1,2)_" ")
 S PSBUNK=0 S:$P(^PSB(53.79,PSBIEN,0),U,9)="" PSBUNK=1
 ;S W=W_$E($P($G(^PSB(53.79,PSBIEN,.1)),U,2)_PSBSPC,1,2)_"  "
 ; PSB*3.0*82 rbd - Status & Schedule Type spelled out now (unabbreviated)
 S WCURSTAT=$S(PSBUNK:"Unknown Status",1:$P($G(^PSB(53.79,PSBIEN,0)),U,9))
 S W=W_$E($$STATUS(WCURSTAT)_PSBSPC,1,23)_" "
 S W=W_$E($$SCHED($P($G(^PSB(53.79,PSBIEN,.1)),U,2))_PSBSPC,1,19)_" "
 S W=W_$E($E($$GET1^DIQ(53.79,PSBIENS,.06),1,18)_PSBSPC,1,21)_" "
 ;*83 body site info
 N SITE
 S SITE=$$GET1^DIQ(53.79,PSBIENS,.18)
 S:SITE="" SITE=$$GET1^DIQ(53.79,PSBIENS,.16)
 ;S W=W_SITE    ; PSB*3*82 rbd Site Info will now go on the next line with the Medication
 ;
 D ADD(W,TYP)
 ; PSB*3.0*82 rbd - put By/Body Site on line with 1st med; keep legend of Initials & Name also
 S WINIT=$$GETINIT^PSBCSUTX(PSBIEN,"I")
 S WNAME=$$GETINIT^PSBCSUTX(PSBIEN,"N")
 I WINIT]"",WNAME]"" S ^TMP("PSB_WINITNAM",$J,WINIT,WNAME)=""
 S W=" "_$E(WINIT_PSBSPC,1,25)_" " ;Get initials of who took action, PSB*3*72 - ln/spacing chg'ed PSB*3*82 rbd
 ;S W=$J("",56)
 ; PSB*3.0*82 rbd find all audit history not just associated Give for Removal
 ;I $P(^PSB(53.79,PSBIEN,0),U,9)="RM" D
 ;.S GIVE=$$FINDGIVE^PSBUTL(PSBIEN)
 ;.S G1=$E($P(GIVE,U,3)_PSBSPC,1,3)
 ;.S G2=$E($P($G(^PSB(53.79,PSBIEN,.1)),U,2)_PSBSPC,1,4)
 ;.S G3=$P(GIVE,U),G3=$E($$UP^XLFSTR($$FMTE^XLFDT(G3,1)),1,18)_$J("",4)
 ;.S G4=$E($P(GIVE,U,2)_PSBSPC,1,6)
 ;.S W=$J("",21)
 ;.S W2=G1_G2_G3_G4
 I $G(^PSB(53.79,PSBIEN,.9,1,0))]"" D
 .S WSUB9CNT=""
 .F  S WSUB9CNT=$O(^PSB(53.79,PSBIEN,.9,WSUB9CNT),-1) Q:WSUB9CNT=0  D
 ..S WSUB9=$G(^PSB(53.79,PSBIEN,.9,WSUB9CNT,0)) I WSUB9]"" D
 ...I $P(WSUB9,U,3)["ACTION STATUS Set to" D
 ....S WSUB9BY=$P($P(WSUB9,U,3),"'",4),WSUB9DT=$P(WSUB9,U)
 ....S WOLDSTAT=$E($P(WSUB9,U,4),1,3)
 ....S:WOLDSTAT="REM" WOLDSTAT="RM"
 ....S:WOLDSTAT'="RM" WOLDSTAT=$E(WOLDSTAT)
 ....S W2(WSUB9CNT)=$$STATUS(WOLDSTAT)_U_WSUB9DT_U_WSUB9BY
 ....I WSUB9BY]"" D   ; keep legend of init/name PSB*3.0*82 rbd
 .....S WNPIEN=$P(WSUB9,U,5)
 .....S WNAME=$$GET1^DIQ(200,WNPIEN,.01)
 .....I WNAME]"" S ^TMP("PSB_WINITNAM",$J,WSUB9BY,WNAME)=""
 ;
 F PSBNODE=.5,.6,.7 D
 .S PSBDD=$S(PSBNODE=.5:53.795,PSBNODE=.6:53.796,1:53.797)
 .F PSBY=0:0 S PSBY=$O(^PSB(53.79,PSBIEN,PSBNODE,PSBY)) Q:'PSBY  D  ;Include units ordered for IV's
 ..; PSB*3.0*82 rbd Send in Units Ordered also to WRAPMEDS
 ..;D:PSBDD=53.795 WRAPMEDS(W,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.01),$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.03),$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.04),TYP)  ;insert W to Wrapmeds tag *83
 ..;D:PSBDD=53.796!(PSBDD=53.797) WRAPMEDS(W,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.01)_" - "_$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.02),$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.03),$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.04),TYP)  ;insert W to wrapmeds *83
 ..S WUO=$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.02)
 ..D:PSBDD=53.795 WRAPMEDS(W,SITE,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.01),$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.03),WUO,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.04),TYP)  ;insert W to Wrapmeds tag *83
 ..I PSBDD=53.796!(PSBDD=53.797) D
 ...D WRAPMEDS(W,SITE,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.01)_" - "_WUO,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.03),WUO,$$GET1^DIQ(PSBDD,PSBY_","_PSBIENS,.04),TYP)  ;insert W to wrapmeds *83
 ; PSB*3.0*82 rbd Add audit info as its own line
 S WSUB9CNT=$O(W2(""),-1) I WSUB9CNT?1N.N K W2(WSUB9CNT)
 S WSUB9CNT="" F  S WSUB9CNT=$O(W2(WSUB9CNT),-1) Q:WSUB9CNT=""  D
 .S WSUB9=W2(WSUB9CNT),W3=$J("",27),W3=W3_"(Previous Status: "_$E($P(WSUB9,U)_PSBSPC,1,23)
 .S W3=W3_"  At "_$$UP^XLFSTR($$FMTE^XLFDT($P(WSUB9,U,2),1))_"  By "
 .S W3=W3_$P(WSUB9,U,3)_")" D ADD(W3,TYP)
 ; PSB*3.0*82 rbd Add in PRN Effectiveness info.
 S W=$E($$GET1^DIQ(53.79,PSBIENS,.21)_PSBSPC,1,27)_" "
 I $TR(W," ")]"" D
 .S W=" " D ADD(W,TYP)
 .S W="     "_$E($$GET1^DIQ(53.79,PSBIENS,.21)_PSBSPC,1,27)_" "
 .S W22LINE=$$GET1^DIQ(53.79,PSBIENS,.22)
 .D WRAP2(W22LINE,25,.W22TEXT)
 .S W=W_$E(W22TEXT(1)_PSBSPC,1,27)_" "
 .S W=W_$E($$GET1^DIQ(53.79,PSBIENS,.23)_PSBSPC,1,29)_" "
 .S W=W_$E($$GET1^DIQ(53.79,PSBIENS,.24)_PSBSPC,1,29)
 .D ADD(W,TYP)
 .I W22TEXT>1 F W22NUM=2:1:W22TEXT D
 ..D ADD($J("",33)_W22TEXT(W22NUM),TYP)
 I PSBCOM=1 D COMNTS   ;GETS COMMENTS
 D ADD("",TYP)
 Q
 ;
STATUS(STATABBR) ; Give a full status from abbr - PSB*3.0*82 rbd
 Q:STATABBR="G" "Given" Q:STATABBR="I" "Infusing"
 Q:STATABBR="S" "Stopped" Q:STATABBR="C" "Completed"
 Q:STATABBR="H" "Held" Q:STATABBR="R" "Refused"
 Q:STATABBR="RM" "Removed" Q:STATABBR="M" "Missing Dose Requested"
 Q ""
 ;
SCHED(SCHABBR) ; Give a full schedule type from abbr - PSB*3.0*82 rbd
 Q:SCHABBR="C" "Continuous" Q:SCHABBR="P" "PRN"
 Q:SCHABBR="O" "One Time" Q:SCHABBR="OC" "On Call"
 Q ""
 ;
COMNTS  ;
 N Z,CNT,PSBCMNT,PSBINIT,PSBNAME,PSBPRREC,XT,XBR   ; PSB*3.0*82 rbd keep legend of init/name
 S Z="",CNT=0
 I $D(^PSB(53.79,PSBIEN,.3,0)) D
 .D ADD("",TYP)
 .D ADD($J("",27)_"Comments: "_$$MAKELINE("-",81),TYP)  ; PSB*3.0*82 rbd Move Comments to align with Medication
 .S XT="" F  S XT=$O(^PSB(53.79,PSBIEN,.3,XT),-1) Q:XT=""  I XT'=0  D   ; PSB*3.0*82 rbd reverse chronological for comments also
 ..D:CNT=1 ADD("",TYP)
 ..; PSB*3.0*82 rbd keep legend of init/name
 ..;S Y=$P(^PSB(53.79,PSBIEN,.3,XT,0),"^",3) D DD^%DT S XBR=Y
 ..S PSBCMNT=$G(^PSB(53.79,PSBIEN,.3,XT,0))
 ..S Y=$P(PSBCMNT,"^",3) D DD^%DT S XBR=Y
 ..S PSBPRREC=$G(^VA(200,+$P(PSBCMNT,"^",2),0))
 ..S PSBINIT=$P(PSBPRREC,"^",2)
 ..S PSBNAME=$P(PSBPRREC,"^",1)
 ..I PSBINIT]"",PSBNAME]"" D
 ...S ^TMP("PSB_WINITNAM",$J,PSBINIT,PSBNAME)=""
 ..;S Z=XBR_"   "_$P(^VA(200,$P(^PSB(53.79,PSBIEN,.3,XT,0),"^",2),0),"^",2)
 ..S Z=XBR_"   "_PSBINIT
 ..D WRAP($P(^PSB(53.79,PSBIEN,.3,XT,0),"^",1),Z,PSBIEN)
 ..S CNT=1
 .D ADD($J("",37)_$$MAKELINE("-",81),TYP)  ; PSB*3.0*82 rbd Move Comments to align with Medication
 Q
 ;
WRAP(SIZE,ZP,BRIEN)         ;
 ; PSB*3.0*82 rbd Massaged Comments to possibly be 4 lines using new WRAP2 API
 ;D ADD($J("",56)_ZP,TYP)
 ;D ADD($J("",56)_$E(SIZE,1,75),TYP)
 ;I $L(SIZE)>75 D ADD($J("",56)_$E(SIZE,76,150),TYP)
 N SIZE2,SIZE2NUM D WRAP2(SIZE,50,.SIZE2),ADD($J("",37)_ZP_"   "_SIZE2(1),TYP)
 I SIZE2>1 F SIZE2NUM=2:1:SIZE2 D
 .D ADD($J("",66)_SIZE2(SIZE2NUM),TYP)
 Q
 ;
 ; PSB*3.0*82 rbd Put in place more robust wrapping API
WRAP2(TEXTLINE,MAX,TEXT) ; Splits Text into TEXT array
 N I,J S J=0 K TEXT
 I $L(TEXTLINE)'>MAX S J=J+1,TEXT(J)=TEXTLINE G WRQ
WR0 ;   Loop for Remaining Text
 S I=$F(TEXTLINE," ")
 I ('I)!(I>(MAX+2)) D
 .S J=J+1,TEXT(J)=$E(TEXTLINE,1,MAX)
 .S TEXTLINE=$E(TEXTLINE,MAX+1,999)
 I $L(TEXTLINE)>MAX F I=(MAX+1):-1:1 I $E(TEXTLINE,I)=" " D  Q
 .S J=J+1,TEXT(J)=$E(TEXTLINE,1,I-1)
 .S TEXTLINE=$E(TEXTLINE,I+1,999)
 G:$L(TEXTLINE)>MAX WR0
 S:$L(TEXTLINE) J=J+1,TEXT(J)=TEXTLINE
WRQ ;   Quit Wrap
 S TEXT=J
 Q
 ; end new API for PSB*3*82 rbd
HEADA ;
 W !
 ; PSB*3.0*82 rbd - Expand fields and include new fields
 ;W "Location",?21,"St Sch Administration Date",?50,"By",?61,"Body Site",?96,"Units",?112,"Units of"     ;*83
 W ?1,"Location",?27,"Status",?51,"Schedule Type"
 W ?71,"Administration Date",?98,"Units",?109,"Units",?121,"Units of"
 W !?1,"By",?27,"Medication & Dosage",?71,"Body Site"
 W ?97,"Ordered",?109,"GIVEN",?122,"Admin"
 W !!?5,"PRN Reason",?33,"PRN Effectiveness",?61,"Effectiveness Entered By"
 W ?91,"Effectiveness Entered"
 W !
 W $$MAKELINE("-",132)
 Q
 ;
ADD(XE,TYP)  ;
 S ^TMP("PSB",$J,TYP,$O(^TMP("PSB",$J,TYP,""),-1)+1)=XE
 Q
 ;
 ; PSB*3.0*82 rbd Send in Units Ordered as well
WRAPMEDS(W,SITE,MED,UG,UO,UOA,TYP)  ;insert parm W (possible RM string) to print on line 1 *83
 ;MED IS NOT WRAPPED: MAX LENGTH IN PSDRUG/52.6/52.7 IS 40
 ;UG/UOA MAX AT 30/40 AND WILL BE WRAPPED AT 15 EACH
 ;THIS WILL CREATE UPTO 3 LINES
 S MED=$S($L(MED)>40:$E(MED_$J("",80),1,80),1:$E(MED_$J("",40),1,40)) ;Add wrapping for med/units ordered
 N UGWRAP,PSBMED1,PSBMED41,PSBMED81,PSBCNT,UOWRAP,CNTX,CNTXX,UOA1,UOA16,UOA31,UOAX   ; PSB*3.0*82 rbd Added Units Ordered
 S (CNTX,UOA1,UOA16,UOA31,PSBMED1,PSBMED41,PSBMED81)=""
 I +$G(UG)?1"."1.N S UG=0_+UG
 I +$G(UO)?1"."1.N S UO=0_+UO   ; PSB*3.0*82 rbd Units Ordered added
 F CNT=1:15:45  D
 .S PSBCNT=$S(CNT=1:1,CNT=16:41,CNT=31:81,1:120)
 .D PARSEM(MED,PSBCNT)
 .D PARSE(UOA,CNT)
 .S UGWRAP=$E(UG,CNT,(CNT+14))
 .; PSB*3.0*82 rbd Units Ordered & Site handling next 3 lines of code
 .S UOWRAP=$E(UO,CNT,(CNT+14))
 .I CNT=1 D ADD(W_$E(MED_PSBSPC,1,43)_" "_$E(SITE_PSBSPC,1,25)_"   "_$$PAD(UOWRAP,11)_" "_$$PAD(UGWRAP,11)_" "_$$PAD(UOA1,11),TYP)
 .I (CNT>1),($L(UGWRAP)>0!$L(@("UOA"_CNT))>0) D ADD($J("",99)_$$PAD(UOWRAP,11)_" "_$$PAD(UGWRAP,11)_" "_$$PAD(@("UOA"_CNT),11),TYP)
 Q
 ;
PAD(X,CNT) ;
 Q $E(X_$J("",CNT),1,CNT)
WRITEOT ;
 N TPE,PSTRTA,PSTP
 S Y=$P(PSBSTRT,".",1)  D D^DIQ  S PSTRTA=Y
 S Y=$P(PSBSTOP,".",1)  D D^DIQ  S PSTP=Y
 S PSBHDR(1)="MEDICATION HISTORY for "_PSTRTA_"  to  "_PSTP
 I '$D(TMP("PSBIENS",$J)) D ADD("<<<< NO HISTORY FOUND FOR THIS TIME FRAME >>>>","UD")
 S TPE="" F  S TPE=$O(^TMP("PSB",$J,TPE)) Q:TPE=""  D
 .D MEDS(TPE)
 .N PSBCLINORD,EX S PSBCLINORD=2 D PT^PSBOHDR(DFN,.PSBHDR),HEADA     ;*70
 .S EX="" F  S EX=$O(^TMP("PSB",$J,TPE,EX)) Q:EX=""  D
 ..I $Y>(IOSL-5) D
 ...W $$PTFTR^PSBOHDR()
 ...D PT^PSBOHDR(DFN,.PSBHDR),HEADA
 ..W !,$G(^TMP("PSB",$J,TPE,EX))
 ; PSB*3.0*82 rbd Keep legend of initials & names
 W !!,"Initial - Name Legend"
 S WINIT="" F  S WINIT=$O(^TMP("PSB_WINITNAM",$J,WINIT)) Q:WINIT=""  D
 .S WNAME="" F  S WNAME=$O(^TMP("PSB_WINITNAM",$J,WINIT,WNAME)) Q:WNAME=""  D
 ..W !,$E(WINIT_PSBSPC,1,10)_WNAME
 K ^TMP("PSB_WINITNAM",$J)
 W $$PTFTR^PSBOHDR()
 Q
 ;
FTR() ;
 I (IOSL<100) F  Q:$Y>(IOSL-10)  W !
 W !,$TR($J("",IOM)," ","=")
 S X="Ward: "_PSBHDR("WARD")_"  Room-Bed: "_PSBHDR("ROOM")
 W !,PSBHDR("NAME"),?(IOM-11\2),PSBHDR("SSN"),?(IOM-$L(X)),X
 Q ""
 ;
MEDS(TYP) ;
 N MED,XA,XB,DPTR,DRG,FLE,SBSC
 S MED="",XB=3,DRG=""
 S PSBHDR(3)="MEDICATIONS SEARCH LIST:"
 S XA="" F  S XA=$O(TMP("PSBOIS",$J,XA)) Q:XA=""  D
 .S MED=$$GET1^DIQ(50.7,XA,.01)
 .I $L(PSBHDR(XB)_" "_MED)>IOM D
 ..S XB=XB+1,PSBHDR(XB)="                         "_MED
 .E  S PSBHDR(XB)=PSBHDR(XB)_$S($L(PSBHDR(XB))<26:" ",1:"; ")_MED
 S XA=999 F  S XA=$O(PSBHDR(XA),-1) Q:XA=XB  K PSBHDR(XA)
 I TYP'="" D
 .I TYP["UD" S TYP="UNIT DOSE",SBSC="PSBOIS",FLE=50.7
 .I TYP["AD" S TYP="ADDITIVE",SBSC="PSBADDS",FLE=52.6
 .I TYP["SO" S TYP="SOLUTION",SBSC="PSBSOLS",FLE=52.7
 .S DPTR="" F  S DPTR=$O(TMP(SBSC,$J,DPTR)) Q:DPTR=""  I TMP(SBSC,$J,DPTR) D
 ..S DRG=$$GET1^DIQ(FLE,DPTR,.01)
 ..S PSBHDR($O(PSBHDR(999),-1)+1)=$S(TYP="UNIT DOSE":"",1:"SEARCH FOR "_TYP_": "_DRG)
 .K TMP(SBSC,$J)
 Q
 ;
CLEANALL        ; KILL ALL TMP LEVELS USED VARIABLES
 K ^TMP("PSB",$J),^TMP("PSJ1",$J),TMP("PSBOIS",$J),TMP("PSBADDS",$J),TMP("PSBSOLS",$J),TMP("PSBIENS",$J),TMP("ARY",$J),DRG,DPTR,PSBOR,FLE,SBSC,TPE
 Q
 ;
CLEANSUM        ; KILLL ALL BUT THE "PSBIENS" LEVEL
 K ^TMP("PSB",$J),^TMP("PSJ1",$J),TMP("PSBIENS",$J),TMP("PSBOIS",$J),TMP("PSBADDS",$J),TMP("PSBSOLS",$J)
 Q
MAKELINE(X,CNT) ;LINE OF WHAT'S PASSED IN CNT TIMES
 N Y,Z
 S Y=""
 F Z=1:1:CNT S Y=Y_X
 Q Y
 ;
PARSE(X,CNT) ;Split text for wrapping.
 S CNTX="UOA"_CNT,@CNTX=@CNTX_$E(X,CNT,(CNT+14)),UOAX=""
 F  S:$F(@CNTX,", ",+UOAX)>0 UOAX=$F(@CNTX,", ",+UOAX)  Q:'$F(@CNTX,", ",+UOAX)
 I UOAX<1 F  S:$F(@CNTX," ",+UOAX)>0 UOAX=$F(@CNTX," ",+UOAX)  Q:'$F(@CNTX," ",+UOAX)
 I UOAX>1,(($L(UOA)-(CNT+14))>0) S CNTXX=$E(@CNTX,1,UOAX-1),@("UOA"_(CNT+15))=$E(@CNTX,UOAX,UOAX+14),@CNTX=CNTXX
 Q
 ;
PARSEM(PSBMED,PSBCNT) ;Split text for wrapping meds, PSB*3*72
 N PSBCNTX,PSBMEDX,PSBMEDX,PSBCNTXX
 S PSBCNTX="PSBMED"_PSBCNT,@PSBCNTX=@PSBCNTX_$E(PSBMED,PSBCNT,(PSBCNT+39)),PSBMEDX=""
 F  S:$F(@PSBCNTX,", ",+PSBMEDX)>0 PSBMEDX=$F(@PSBCNTX,", ",+PSBMEDX)  Q:'$F(@PSBCNTX,", ",+PSBMEDX)
 I PSBMEDX<1 F  S:$F(@PSBCNTX," ",+PSBMEDX)>0 PSBMEDX=$F(@PSBCNTX," ",+PSBMEDX)  Q:'$F(@PSBCNTX," ",+PSBMEDX)
 I PSBMEDX>1,(($L(MED)-(PSBCNT+39))>0) S PSBCNTXX=$E(@PSBCNTX,1,PSBMEDX-1),@("PSBMED"_(PSBCNT+40))=$E(@PSBCNTX,PSBMEDX,PSBMEDX+39),@PSBCNTX=PSBCNTXX
 Q