PSAVIN1 ;BIR/LTL-Physical Inventory Balance Review ;7/23/97
 ;;3.0; DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**15**; 10/24/97
 ;This routine reviews balances for a drug.
 ;
 ;References to $$DESCR^PRCPUX1 are covered by IA #259
 ;References to $$INVNAME^PRCPUX1 are covered by IA #259
 ;References to ^PSDRUG( are covered by IA #2095
 ;References to ^PRCP( are covered by IA #214
 ;
 N DIC,DIR,DTOUT,DUOUT,PSA,PSACNT,PSALOCN,PSAR,PSAU,PSAOUT,PSAT,X,Y S PSAOUT=1,PSAU=0
LOOK D ^PSADA I '$G(PSALOC) S PSAOUT=1 G END
 I '$O(^PSD(58.8,PSALOC,1,0)) W !!,"There are no drugs in ",PSALOCN G END
 W !!,"The balances displayed from a Primary Inventory Point are based on the most",!,"recent physical inventory and may NOT reflect accurate quantities when",!,"converted to the dispensing unit level."
 S PSACNT=0 W !!,"You may select one, several, or ^ALL drugs.",!
CHKD F  S DIC="^PSD(58.8,+PSALOC,1,",DIC(0)="AEMQ",DIC("A")="Please Select "_PSALOCN_"'s Drug: ",DIC("S")="I $S($G(^(""I"")):$G(^(""I""))>DT,1:1)" W ! D ^DIC K DIC G:X'="^ALL"&(Y<1)&('PSACNT) END Q:Y<0  S PSA(+Y)="",PSACNT=PSACNT+1
 I X="^ALL" F  S PSAU=$O(^PSD(58.8,+PSALOC,1,PSAU)) Q:'PSAU  S PSA(PSAU)=""
DEV ;asks device and queueing info
 K IO("Q") N %ZIS,IOP,POP S %ZIS="Q" W ! D ^%ZIS I POP W !,"NO DEVICE SELECTED OR OUTPUT PRINTED!" Q
 I $D(IO("Q")) N ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK S ZTRTN="START^PSAVIN1",ZTDESC="Drug balance review",ZTSAVE("PSA*")="" D ^%ZTLOAD,HOME^%ZIS S PSAOUT=1 G END
START ;compiles and prints output
 N %DT,PSALN,PSAR,PSAPG,PSARPDT S (PSAPG,PSAOUT)=0,Y=DT,PSAR="" X ^DD("DD") S PSARPDT=Y,PSAU(1)=$O(PSA(0)) D HEADER S PSAU=0
 F  S PSAU=$O(PSA(PSAU)) Q:'PSAU  D  Q:$G(PSAOUT)
LOOP .D:$Y+8>IOSL HEADER  Q:$G(PSAOUT)
 .I $G(PSAU(5))>1 W "Total of all Primary Inventory items: ",$G(PSAU(7)),!!
 .W !,$P($G(^PSDRUG(+PSAU,0)),U) K PSAU(5),PSAU(7)
 .W !!,$G(PSALOCN),"'s balance: ",$P($G(^PSD(58.8,+PSALOC,1,+PSAU,0)),U,4)," "
 .W $P($G(^PSDRUG(+PSAU,660)),U,8),!!
 .Q:'$O(^PSDRUG(+PSAU,441,0))
 .F PSAU(1)=0:0 S PSAU(1)=$O(^PSDRUG(+PSAU,441,PSAU(1))) Q:'PSAU(1)  D
 ..S PSAU(2)=$P($G(^PSDRUG(+PSAU,441,+PSAU(1),0)),U) Q:'PSAU(2)
 ..Q:'$O(^PRCP(445,"AE",+PSAU(2),0))
 ..F PSAU(3)=0:0 S PSAU(3)=$O(^PRCP(445,"AE",+PSAU(2),PSAU(3))) Q:'PSAU(3)  D:$O(^PSD(58.8,"P",PSAU(3),0))
 ...S PSAU(5)=$G(PSAU(5))+1
 ...W $$DESCR^PRCPUX1(PSAU(3),PSAU(2))
 ...W !!,$$INVNAME^PRCPUX1(PSAU(3)),"'s balance: "
 ...S PSAU(6)=$P($G(^PRCP(445,+PSAU(3),1,+PSAU(2),0)),U,7)*$S($P($G(^(0)),U,29):$P($G(^(0)),U,29),1:1) W PSAU(6)," ",$P($G(^(0)),U,28),!!
 ...S PSAU(7)=$G(PSAU(7))+PSAU(6)
 W:$G(PSAU(5))>1 "Total of all Primary Inventory items: ",$G(PSAU(7)),!!
END W:$E(IOST)'="C" @IOF
 I $E(IOST,1,2)="C-",'PSAOUT S DIR(0)="EA",DIR("A")="END OF REPORT!  Press <RET> to return to the menu." D ^DIR
 D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@" K IO("Q")
 Q
 I $E(IOST,1,2)'="P-",PSAPG S DIR(0)="E" D ^DIR K DIR I 'Y S PSAOUT=1 Q
 I $$S^%ZTLOAD W !!,"Task #",$G(ZTSK),", ",$G(ZTDESC)," was stopped by ",$P($G(^VA(200,+$G(DUZ),0)),U),"." S PSAOUT=1 Q
 W:$Y @IOF S $P(PSALN,"&",81)="",PSAPG=PSAPG+1 W !?2,"Physical Inventory Balance Review",?55,PSARPDT,?70,"PAGE: ",PSAPG,!,PSALN,!
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSAVIN1   3209     printed  Sep 23, 2025@19:27:16                                                                                                                                                                                                     Page 2
PSAVIN1   ;BIR/LTL-Physical Inventory Balance Review ;7/23/97
 +1       ;;3.0; DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**15**; 10/24/97
 +2       ;This routine reviews balances for a drug.
 +3       ;
 +4       ;References to $$DESCR^PRCPUX1 are covered by IA #259
 +5       ;References to $$INVNAME^PRCPUX1 are covered by IA #259
 +6       ;References to ^PSDRUG( are covered by IA #2095
 +7       ;References to ^PRCP( are covered by IA #214
 +8       ;
 +9        NEW DIC,DIR,DTOUT,DUOUT,PSA,PSACNT,PSALOCN,PSAR,PSAU,PSAOUT,PSAT,X,Y
           SET PSAOUT=1
           SET PSAU=0
LOOK       DO ^PSADA
           IF '$GET(PSALOC)
               SET PSAOUT=1
               GOTO END
 +1        IF '$ORDER(^PSD(58.8,PSALOC,1,0))
               WRITE !!,"There are no drugs in ",PSALOCN
               GOTO END
 +2        WRITE !!,"The balances displayed from a Primary Inventory Point are based on the most",!,"recent physical inventory and may NOT reflect accurate quantities when",!,"converted to the dispensing unit level."
 +3        SET PSACNT=0
           WRITE !!,"You may select one, several, or ^ALL drugs.",!
CHKD       FOR 
               SET DIC="^PSD(58.8,+PSALOC,1,"
               SET DIC(0)="AEMQ"
               SET DIC("A")="Please Select "_PSALOCN_"'s Drug: "
               SET DIC("S")="I $S($G(^(""I"")):$G(^(""I""))>DT,1:1)"
               WRITE !
               DO ^DIC
               KILL DIC
               if X'="^ALL"&(Y<1)&('PSACNT)
                   GOTO END
               if Y<0
                   QUIT 
               SET PSA(+Y)=""
               SET PSACNT=PSACNT+1
 +1        IF X="^ALL"
               FOR 
                   SET PSAU=$ORDER(^PSD(58.8,+PSALOC,1,PSAU))
                   if 'PSAU
                       QUIT 
                   SET PSA(PSAU)=""
DEV       ;asks device and queueing info
 +1        KILL IO("Q")
           NEW %ZIS,IOP,POP
           SET %ZIS="Q"
           WRITE !
           DO ^%ZIS
           IF POP
               WRITE !,"NO DEVICE SELECTED OR OUTPUT PRINTED!"
               QUIT 
 +2        IF $DATA(IO("Q"))
               NEW ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK
               SET ZTRTN="START^PSAVIN1"
               SET ZTDESC="Drug balance review"
               SET ZTSAVE("PSA*")=""
               DO ^%ZTLOAD
               DO HOME^%ZIS
               SET PSAOUT=1
               GOTO END
START     ;compiles and prints output
 +1        NEW %DT,PSALN,PSAR,PSAPG,PSARPDT
           SET (PSAPG,PSAOUT)=0
           SET Y=DT
           SET PSAR=""
           XECUTE ^DD("DD")
           SET PSARPDT=Y
           SET PSAU(1)=$ORDER(PSA(0))
           DO HEADER
           SET PSAU=0
 +2        FOR 
               SET PSAU=$ORDER(PSA(PSAU))
               if 'PSAU
                   QUIT 
               Begin DoDot:1
LOOP               if $Y+8>IOSL
                       DO HEADER
                   if $GET(PSAOUT)
                       QUIT 
 +1                IF $GET(PSAU(5))>1
                       WRITE "Total of all Primary Inventory items: ",$GET(PSAU(7)),!!
 +2                WRITE !,$PIECE($GET(^PSDRUG(+PSAU,0)),U)
                   KILL PSAU(5),PSAU(7)
 +3                WRITE !!,$GET(PSALOCN),"'s balance: ",$PIECE($GET(^PSD(58.8,+PSALOC,1,+PSAU,0)),U,4)," "
 +4                WRITE $PIECE($GET(^PSDRUG(+PSAU,660)),U,8),!!
 +5                if '$ORDER(^PSDRUG(+PSAU,441,0))
                       QUIT 
 +6                FOR PSAU(1)=0:0
                       SET PSAU(1)=$ORDER(^PSDRUG(+PSAU,441,PSAU(1)))
                       if 'PSAU(1)
                           QUIT 
                       Begin DoDot:2
 +7                        SET PSAU(2)=$PIECE($GET(^PSDRUG(+PSAU,441,+PSAU(1),0)),U)
                           if 'PSAU(2)
                               QUIT 
 +8                        if '$ORDER(^PRCP(445,"AE",+PSAU(2),0))
                               QUIT 
 +9                        FOR PSAU(3)=0:0
                               SET PSAU(3)=$ORDER(^PRCP(445,"AE",+PSAU(2),PSAU(3)))
                               if 'PSAU(3)
                                   QUIT 
                               if $ORDER(^PSD(58.8,"P",PSAU(3),0))
                                   Begin DoDot:3
 +10                                   SET PSAU(5)=$GET(PSAU(5))+1
 +11                                   WRITE $$DESCR^PRCPUX1(PSAU(3),PSAU(2))
 +12                                   WRITE !!,$$INVNAME^PRCPUX1(PSAU(3)),"'s balance: "
 +13                                   SET PSAU(6)=$PIECE($GET(^PRCP(445,+PSAU(3),1,+PSAU(2),0)),U,7)*$SELECT($PIECE($GET(^(0)),U,29):$PIECE($GET(^(0)),U,29),1:1)
                                       WRITE PSAU(6)," ",$PIECE($GET(^(0)),U,28),!!
 +14                                   SET PSAU(7)=$GET(PSAU(7))+PSAU(6)
                                   End DoDot:3
                       End DoDot:2
               End DoDot:1
               if $GET(PSAOUT)
                   QUIT 
 +15       if $GET(PSAU(5))>1
               WRITE "Total of all Primary Inventory items: ",$GET(PSAU(7)),!!
END        if $EXTRACT(IOST)'="C"
               WRITE @IOF
 +1        IF $EXTRACT(IOST,1,2)="C-"
               IF 'PSAOUT
                   SET DIR(0)="EA"
                   SET DIR("A")="END OF REPORT!  Press <RET> to return to the menu."
                   DO ^DIR
 +2        DO ^%ZISC
           if $DATA(ZTQUEUED)
               SET ZTREQ="@"
           KILL IO("Q")
 +3        QUIT 
 +1        IF $EXTRACT(IOST,1,2)'="P-"
               IF PSAPG
                   SET DIR(0)="E"
                   DO ^DIR
                   KILL DIR
                   IF 'Y
                       SET PSAOUT=1
                       QUIT 
 +2        IF $$S^%ZTLOAD
               WRITE !!,"Task #",$GET(ZTSK),", ",$GET(ZTDESC)," was stopped by ",$PIECE($GET(^VA(200,+$GET(DUZ),0)),U),"."
               SET PSAOUT=1
               QUIT 
 +3        if $Y
               WRITE @IOF
           SET $PIECE(PSALN,"&",81)=""
           SET PSAPG=PSAPG+1
           WRITE !?2,"Physical Inventory Balance Review",?55,PSARPDT,?70,"PAGE: ",PSAPG,!,PSALN,!
 +4        QUIT