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

PSJPDRIP.m

Go to the documentation of this file.
PSJPDRIP ;BIR/MV-MAIN DRIVER PADE INVENTORY REPORT  ;18 JUN 96 / 2:58 PM
 ;;5.0;INPATIENT MEDICATIONS;**317**;16 DEC 97;Build 130
 ;
 ; Reference to ^%ZISC is supported by DBIA 10089.
 ; Reference to ^XLFDT is supported by DBIA 10103.
 ; Reference to ^DG(40.8 is supported by DBIA 728.
 ; Reference to ^PSDRUG is supported by DBIA 2192.
 ; Reference to ^VA(200 is supported by DBIA 10060.
 Q
 ;
EN(PSJINP) ; Write PADE Inventory Report
 ; Required : ^TMP("PSJPDRIN",$J global array containing report data in delimited format.
 ;            PSJINP array
 ;            PSJINP("PADEV")         = PADE device(s) (pointer to PADE DISPENSING DEVICE #58.63) selected by user
 ;            PSJINP("PSDRG")         = Drug(s) (pointer to DRUG #50) selected by user
 ;            PSJINP("PSJCSUB")       = CS Federal Schedule(s) selected by user
 ;            PSJINP("PSJDEV",CABIEN) = Pointer to PADE DISPENSING DEVICE (#58.63) file
 ;            PSJINP("PSJDELM")       = (D)elimited or formatted (R)eport, selected by user
 ;            PSJINP("PSJDIV")        = Division (pointer to MEDICAL CENTER DIVISION #40.8) selected by user
 ;            PSJINP("PSJPSYS"        = PADE INVENTORY SYSTEM (#58.601) selected by user
 ;            PSJINP("PSJSUM"         = (S)ummary or (D)etail report, selected by user
 ;
 N PSJDELIM,PSJQUIT,PSJIOSL,PSPGTOT,LNCNT,PSJPTOT,DTOUT,DUOUT,DA,DIC,X,Y,DIR,DR
 S PSJIOSL=$S($G(IOSL):IOSL-5,1:20)
 S PSJDELIM=$G(PSJINP("PSJDELM"))
 U IO
 I PSJDELIM="D" D DELIM(.PSJINP)
 I PSJDELIM="R" D FORMAT(.PSJINP)
 Q
 ;
DELIM(PSJINP) ; Output delimited report
 N PSJPGTOT,PSJPCNT
 S PSJPTOT=1,PSJPCNT=1
 D RHEAD^PSJPDRIP(.PSJINP,PSJPTOT,PSJPCNT)
 S LNCNT=0 F  S LNCNT=$O(^TMP("PSJPDRIN",$J,LNCNT)) Q:'LNCNT!$G(PSJQUIT)  D
 .W !,^TMP("PSJPDRIN",$J,LNCNT)
 D ^%ZISC
 D EXIT
 Q
 ;
FORMAT(PSJINP) ; Output formatted report
 N CABNAME,PSJPGTOT,PSJPCNT
 S PSJPCNT=1,PSJPGTOT=$$PGTOT()
 D RHEAD^PSJPDRIP(.PSJINP,PSJPCNT,PSJPGTOT)
 S LNCNT=0 F  S LNCNT=$O(^TMP("PSJPDRIN",$J,LNCNT)) Q:'LNCNT!$G(PSJQUIT)  D
 .N LINE,PSCOL
 .S LINE=$G(^TMP("PSJPDRIN",$J,LNCNT))
 .D SETCOLS(.PSJINP,.PSCOL)
 .I $G(PSJINP("PSJSUM"))="S" I $L($P(LINE,"^"))>1 S CABNAME=$P(LINE,"^")
 .W !?PSCOL(1),$P(LINE,"^"),?PSCOL(2),$P(LINE,"^",2),?PSCOL(3),$P(LINE,"^",3),?PSCOL(4),$P(LINE,"^",4),?PSCOL(5),$P(LINE,"^",5),?PSCOL(6),$P(LINE,"^",6)
 .N CABCONT
 .Q:($Y<(PSJIOSL))
 .I ($G(PSJINP("PSJSUM"))="S") I $G(CABNAME)]"" I ($P(LINE,"^")]"")!($P(LINE,"^",2)]"") D
 ..N NXT S NXT=+$O(^TMP("PSJPDRIN",$J,LNCNT))
 ..S NXT=$P($G(^TMP("PSJPDRIN",$J,NXT)),"^") S:NXT="" CABCONT=CABNAME_"(cont) "
 .D CONT(.PSJPCNT,.PSJQUIT,LNCNT)
 .Q:$G(PSJQUIT)
 .D RHEAD(.PSJINP,PSJPCNT,PSJPGTOT,$G(CABCONT))
 I '$G(PSJQUIT) D CONT(.PSJPCNT,.PSJQUIT,$O(^TMP("PSJPDRIN",$J,9999999),-1)+1)
 D ^%ZISC
 D EXIT
 Q
 ;
RHEAD(PSJINP,PSJPCNT,PSJPGTOT,CABCONT) ; Report Header
 N PSPGCNT,PSJDIV,CSCHED,PSJTMP,PADECAB,PADEDRG,PSJII,PSJCABS,PSJSUM
 S PSJPGTOT=$S($G(PSJPGTOT):+$G(PSJPGTOT),1:1)
 S PSJDIV=$G(PSJINP("PSJDIV"))
 S PSPGTOT=$G(PSJINP("PSPGTOT")),PSPGCNT=1
 S PSJSUM=$G(PSJINP("PSJSUM"))
 W @IOF
 W !,"Run Date: "_$P($TR($$FMTE^XLFDT($$NOW^XLFDT,2),"@"," "),":",1,2)
 W ?27,"PADE On Hand Amounts Report ",$S(($G(PSJSUM)="S"):"(Summary)",1:"(Detail)")
 W ?66,"Page ",PSJPCNT," of ",PSJPGTOT
 W !,"Run By: ",$P($G(^VA(200,+$G(DUZ),0)),"^")
 W ?35,"Division: ",$E($$DIVSTR^PSJPDRTR(.PSJINP),1,44)
 S CSCHED=$$CSCHED(.PSJINP)
 W !,"CS/Non-CS: ",$S($G(PSJINP("PSJCSUB"))="N":"N",1:$G(CSCHED))
 S PSJCABS=$$CABSTR(.PSJINP)
 W !,"PADE"_$S(PSJCABS[",":"s: ",1:": "),PSJCABS
 S PADEDRG=$$DRGSTR(.PSJINP)
 W !,"ITEM"_$S(PADEDRG[",":"(s): ",1:": "),PADEDRG
 D:($G(PSJINP("PSJSUM"))="S") SUMHEAD(.PSJINP,$G(CABCONT))
 D:($G(PSJINP("PSJSUM"))="D") DETHEAD(.PSJINP)
 Q
 ;
SUMHEAD(PSJINP,CABCONT) ; Summary specific header
 N DASHES,BLANK,PSJCOL
 I $G(PSJINP("PSJDELM"))="D" D  Q
 .W !,"PADE^ITEM^UNIT^QTY"
 D SETCOLS(.PSJINP,.PSJCOL)
 S $P(DASHES,"-",80)="-"
 S $P(BLANK," ",80)=""
 W !,DASHES
 W !?2,"ITEM",?PSJCOL(3)-1,"UNIT",?PSJCOL(4)+1,"QTY"
 W !,DASHES
 W !,$S($G(CABCONT)]"":CABCONT,1:BLANK)
 Q
 ;
DETHEAD(PSJINP) ; Detail specific header
 N DASHES,PSJCOL
 I $G(PSJINP("PSJDELM"))="D" D  Q
 .W !,"ITEM^UNIT^QTY^PADE^ITEM LOCATION"
 D SETCOLS(.PSJINP,.PSJCOL)
 S $P(DASHES,"-",80)="-"
 W !,DASHES
 W !,"ITEM",?PSJCOL(2),"UNIT",?PSJCOL(3)," QTY",?PSJCOL(4),"PADE",?PSJCOL(5),"ITEM LOCATION"
 W !,DASHES
 Q
 ;
EXIT ; Clean up.
 K ^TMP("PSJPDRIN",$J)
 Q
 ;
POCKDRG(PSJPSYS,PSJCAB,DRUG,DRWPCK) ; Get Drawer.Pocket location of DRUG in PSJCAB cabinet
 ;
 N CABIEN,DRGIEN,DRWIEN,DRWNAM,PCKIEN,PCKNAM,ND,LOCNAM,PSJII
 Q:'$G(PSJPSYS)!'$G(PSJCAB)!'$G(PSJCAB)
 S CABIEN=$$FIND1^DIC(58.6011,","_PSJPSYS_",","MXQ",+$G(PSJCAB),,,"ERR")
 S DRWIEN=0 F  S DRWIEN=$O(^PS(58.601,PSJPSYS,"DEVICE",CABIEN,"DRAWER",DRWIEN)) Q:'DRWIEN  S DRWNAM=$P(^(DRWIEN,0),"^") D
 .S PCKIEN=0 F  S PCKIEN=$O(^PS(58.601,PSJPSYS,"DEVICE",CABIEN,"DRAWER",DRWIEN,"SUB",PCKIEN)) Q:'PCKIEN  S ND=^(PCKIEN,0) I $P(ND,"^",5)=DRUG D
 ..N LOCNAM,SUBID
 ..S SUBID=$P(ND,"^",4) S:SUBID["~~" SUBID=$P(SUBID,"~~") S:SUBID="" SUBID="N/A"
 ..S PCKNAM=DRWNAM_"_"_SUBID_"_"_$P(ND,"^",3)
 ..F PSJII=1:1:$L(PCKNAM,"_") D
 ...N TMPLOC S TMPLOC=$P(PCKNAM,"_",PSJII)
 ...S TMPLOC=$S(TMPLOC="~~":"N/A",1:TMPLOC)
 ...S LOCNAM=$G(LOCNAM)_TMPLOC_"_"
 ..S:$E(LOCNAM,$L(LOCNAM))="_" LOCNAM=$E(LOCNAM,1,$L(LOCNAM)-1)
 ..S DRWPCK(DRUG,LOCNAM)=$P(ND,"^",2)
 Q
 ;
CONT(PGCNT,PSJQUIT,TMPLN) ; Press return to continue
 N DIR
 I ($E($G(IOST))="C") W ! D  Q:$G(PSJQUIT)
 .I '$O(^TMP("PSJPDRIN",$J,TMPLN)) S DIR("A")="End of Report. Press Return to continue" S PSJQUIT=1
 .S DIR(0)="E"
 .D ^DIR K DIR
 .I $G(DTOUT)!$G(DUOUT) S PSJQUIT=1
 .W @IOF
 S PGCNT=$G(PGCNT)+1
 Q
 ;
PGTOT() ; Return calculated number of pages for this report
 N PGTOT,LN,PSJSL,INT,HDRPAD,HDR,HDRWRAP,SCHWRAP,PADEWRAP,DRGWRAP,PSJAVAIL,HDRTOP
 S PSJIOSL=$S($G(PSJIOSL):PSJIOSL,1:20)
 S LN=$O(^TMP("PSJPDRIN",$J,999999999),-1)
 S SCHWRAP=($L($$CSCHED(.PSJINP))+10)/80
 S:SCHWRAP#1 SCHWRAP=(SCHWRAP\1)+1
 S PADEWRAP=($L($$CABSTR(.PSJINP))+6)/80
 S:PADEWRAP#1 PADEWRAP=(PADEWRAP\1)+1
 S DRGWRAP=($L($$DRGSTR(.PSJINP))+7)/80
 S:DRGWRAP#1 DRGWRAP=(DRGWRAP\1)+1
 S HDRWRAP=SCHWRAP+PADEWRAP+DRGWRAP
 S HDRTOP=$S($G(PSJINP("PSJSUM"))="D":5,1:6)
 S HDRPAD=(HDRTOP+HDRWRAP)
 ; How many lines are availabe for actual report data, after header and footer are taken into account?
 ; If less than five lines per page for report data, set to 5 (longer page length needed)
 S PSJAVAIL=PSJIOSL-HDRPAD
 ; Determine how many pages will be needed to print the total lines in ^TMP("PSJPDRIN", 
 ; using the available area (PSJAVAIL) on each page
 S PGTOT=LN\PSJAVAIL
 ;S PSJLASTP=LN#PSJAVAIL
 S:LN#PSJAVAIL PGTOT=PGTOT+1
 ;
 Q PGTOT
 ;
CSCHED(PSJINP) ; Return string of CS Federal Schedules from array PSJINP("PSJCSUB",SCHEDULE)
 N CSCHED N PSJTMP
 S CSCHED=$G(PSJINP("PSJCSUB")) I '(CSCHED="N") S CSCHED="CS (" D
 .I $G(PSJINP("PSJCSUB"))["ALL" S CSCHED=PSJINP("PSJCSUB") Q
 .S PSJTMP="" F  S PSJTMP=$O(PSJINP("PSJCSUB",PSJTMP)) Q:PSJTMP=""  S CSCHED=CSCHED_PSJTMP_","
 .I $E(CSCHED,$L(CSCHED))="," S CSCHED=$E(CSCHED,1,$L(CSCHED)-1)_")"
 Q CSCHED
 ;
CABSTR(PSJINP) ; Return string of PADE cabinets from array PSJINP("PADEV",CABINET)
 N CABSTR N PSJTMP,PSJII,PSJDONE
 S PSJTMP=0 F PSJII=0:1 S PSJTMP=$O(PSJINP("PADEV",PSJTMP)) Q:'PSJTMP!$G(PSJDONE)  D
 .I $G(PSJINP("PADEV"))="ALL" S CABSTR="ALL",PSJDONE=1 Q
 .I $L($G(CABSTR))+$L($P($G(^PS(58.63,+PSJTMP,0)),"^"))>140 S CABSTR=CABSTR_" >> more..." S PSJDONE=1 Q
 .S CABSTR=$S(PSJII:$G(CABSTR)_",",1:"")_$P($G(^PS(58.63,+PSJTMP,0)),"^")
 Q CABSTR
 ;
DRGSTR(PSJINP) ; Return string of PADE drugs selected by user from PSJINP("PSDRG",DRUG IEN)
 N PADEDRG,PSJTMP,PSJII,PSJDONE
 S PADEDRG="",PSJTMP="" F PSJII=0:1 S PSJTMP=$O(PSJINP("PSDRG",PSJTMP)) Q:'PSJTMP!$G(PSJDONE)  D
 .I $G(PSJINP("PSDRG"))="ALL" S PADEDRG="ALL",PSJDONE=1 Q
 .S PADEDRG=$S(PSJII:(PADEDRG_","),1:"")_$P($G(^PSDRUG(+PSJTMP,0)),"^")
 .I $L(PADEDRG)>187 S PADEDRG=PADEDRG_" > more..." S PSJDONE=1 Q
 S:$E(PADEDRG,$L(PADEDRG)) PADEDRG=$E(PADEDRG,1,$L(PADEDRG)=1)
 Q PADEDRG
 ;
SETCOLS(PSJINP,COL) ; Set column widths
 I $G(PSJINP("PSJSUM"))="S" D
 .S COL(1)=0,COL(2)=2,COL(3)=50,COL(4)=60,COL(5)=68,COL(6)=74
 I $G(PSJINP("PSJSUM"))="D" D
 .S COL(1)=0,COL(2)=38,COL(3)=48,COL(4)=53,COL(5)=64,COL(6)=75
 Q
 ;
TRANSTR(PSJINP) ; Return string of transaction types selected
 N TRANS,TMP,II,PATFLG
 S PATFLG=$$PTTRFLG^PSJPDRU1(.PSJINP)
 S TRANS=""
 I $G(PSJINP("PSJTRANS"))="ALL"&(PATFLG=1) Q "ALL"
 I $G(PSJINP("PSJTRANS"))="ALL"&(PATFLG=2) Q "ALL PATIENT TRANSACTIONS"
 I $G(PSJINP("PSJTRANS"))="ALL"&'PATFLG Q "ALL NON-PATIENT TRANSACTIONS"
 S TMP="" F II=0:1 S TMP=$O(PSJINP("PSJTRANS",TMP)) Q:TMP=""  S TRANS=$S(II:TRANS_","_PSJINP("PSJTRANS",TMP),1:PSJINP("PSJTRANS",TMP))
 Q TRANS
 ;
CABST(PSJPSYS,PSJPADE) ; Return PADE Status : (I)=Inactive or null
 N STATUS,PADIEN
 Q:'$G(PSJPSYS) ""
 Q:$G(PSJPADE)="" ""
 S PADIEN=$$FIND1^DIC(58.63,,,PSJPADE)
 Q:'PADIEN ""
 S STATUS=$P($G(^PS(58.63,+PADIEN,0)),"^",4)
 S STATUS=$S(STATUS="I":"(I)",1:"")
 Q STATUS
 ;
XALL(IN) ; Convert partial ^ALL to ALL
 N OUT
 S OUT=IN
 I ($E(IN)'="^")!(IN="^") Q OUT
 S OUT=$$ENLU^PSGMI(OUT)
 I $E(OUT,1,$L(OUT))=$E("^ALL",1,$L(OUT)) D
 .S OUT="ALL"
 .K DUOUT,DTOUT
 Q OUT
 ;
CONT2(PGCNT,PSJQUIT,PSJEND) ; Press return to continue
 N DIR
 I ($E($G(IOST))="C") W ! D  Q:$G(PSJQUIT)
 .I $G(PSJEND) S DIR("A")="End of Report. Press Return to continue" S PSJQUIT=1
 .S:'$D(DIR("A")) DIR("A")="Press Return to continue or '^' to exit"
 .S DIR(0)="FO"
 .D ^DIR K DIR
 .I $G(DTOUT)!$G(DUOUT) S PSJQUIT=1
 .W @IOF
 S PGCNT=$G(PGCNT)+1
 Q
 ;
CNVTYP(INTYP,PSJOUT) ; Convert Transaction Types to external format from raw HL7
 N TTCNT,PSJOUTE K PSJOUT
 S TTCNT=0 F  S TTCNT=$O(INTYP(TTCNT)) Q:'TTCNT  D
 .N TTNAME,TTCODE S TTNAME=INTYP(TTCNT)
 .S TTCODE=$$EXTT^PSJPDRUT(TTNAME)
 .I TTCODE]"" S PSJOUT(TTCODE)=TTNAME
 .Q
 .I $E(INTYP(TTCNT))="D" S PSJOUT("V")="VEND",PSJOUT("I")="ISSUE" Q
 .I $E(INTYP(TTCNT))="L" S PSJOUT("L")="LOAD" Q
 .I $E(INTYP(TTCNT))="F" S PSJOUT("F")="FILL" Q
 .I $E(INTYP(TTCNT))="U" S PSJOUT("U")="UNLOAD" Q
 .I $E(INTYP(TTCNT))="B" S PSJOUT("B")="EMPTY BIN" Q
 .I $E(INTYP(TTCNT))="C" S PSJOUT("C")="COUNT" Q
 .I $E(INTYP(TTCNT))="R" S PSJOUT("R")="RETURN" Q
 .I $E(INTYP(TTCNT))="W" S PSJOUT("W")="WASTE" Q
 .I $E(INTYP(TTCNT))="E" S PSJOUT("E")="EXPIRED" Q
 .I INTYP(TTCNT)="Destock" S PSJOUT("D")="DESTOCK" Q
 Q
 ;
ALLSCHED(PSJCSUB,SCHLST) ; Return all CS Federal Schedules in PSJCSUB(SCHEDULE)
 N SCHED,SCNT
 F SCNT=1:1:$L(SCHLST,";") S SCHED=$P(SCHLST,";",SCNT),PSJCSUB($P(SCHED,":"))=$P(SCHED,":",2)
 Q
 ;
DIV(PSJDIV,PSJSTOP) ; Get Division
 N DIC,X,Y,PSJDONE,PSDIVLST,PSJDIC
 S DIC("S")="I $D(^PS(58.63,""D"",+Y))"
 S PSJSTOP=0
 D LIST^DIC(40.8,,,"P",,,,,DIC("S"),,"PSDIVLST")
 S PSJDIC=0 F  S PSJDIC=$O(PSDIVLST("DILIST",PSJDIC)) Q:'PSJDIC  D
 .S PSDIVLST=+$G(PSDIVLST("DILIST",PSJDIC,0))
 .S PSDIVLST("PSJDIV",PSDIVLST)=""
 S PSJDIV="" K PSJDONE,PSJDIV
 S DIC("S")="I $D(^PS(58.63,""D"",+Y))"
 D DIV^PSJPDRUT(.PSJDIV,.PSJSTOP)
 Q