PSAUNI ;BIR/LTL-Unlinked Drugs in the ITEM MASTER file ;7/23/97
 ;;3.0; DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**15**; 10/24/97
 ;
 ;References to ^PSDRUG("AB" are covered by IA #2095
 ;References to ^PRC( are covered by IA #214
 ;
 ;Check ITEM FILE for unlinked drugs
 ;This report lists each active drug in the ITEM MASTER FILE that has not
 ;yet been linked to an entry in the DRUG FILE. If you enter a date from
 ;which to begin, only items that have been purchased since that date
 ;will be listed.
 ;
 N DIR,PSA,PSADT,X,Y D DT^DICRW
 S DIR(0)="D^::AEX",DIR("A")="Please enter oldest purchase date to include",DIR("B")="T-12M",DIR("?")="I will check each active drug to make sure it has been purchased since this date" W ! D ^DIR K DIR I 'Y S PSAOUT=1 G END
 S PSADT=Y X ^DD("DD") S PSADT(1)=Y
DEV ;asks device and queueing info
 K I,IO("Q") N %ZIS,DTOUT,DUOUT,IOP,POP,PSAOUT S %ZIS="Q" W ! D ^%ZIS I POP W !,"NO DEVICE SELECTED OR REPORT PRINTED!" S PSAOUT=1 G END
 I $D(IO("Q")) N ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK S ZTRTN="START^PSAUNI",ZTSAVE("PSA*")="",ZTDESC="Active, Unlinked Drug Report" D ^%ZTLOAD,HOME^%ZIS S PSAOUT=1 G END
START ;compiles and prints data for report
 N PSALN,PSAPG S (PSA,PSAPG,PSAOUT)=0 D HEADER
LOOP F  S PSA=$O(^PRC(441,PSA)) G:'PSA!(PSAOUT) END D:$Y+10>IOSL HEADER I $P($G(^PRC(441,+PSA,0)),U,3)=6505,'$G(^PRC(441,+PSA,3)),$O(^PRC(441,+PSA,4,0)),'$O(^PSDRUG("AB",PSA,"")) D
 .W:$E(IOST,1,2)="C-" "."
 .S PSA(1)=0
 .F  S PSA(1)=$O(^PRC(441,+PSA,4,PSA(1))) Q:'PSA(1)!('$O(^PRC(441,+PSA,4,PSA(1),1,0)))  D  Q:$G(PSA(3))
 ..S PSA(2)=0 F  S PSA(2)=$O(^PRC(441,+PSA,4,PSA(1),1,PSA(2))) Q:'PSA(2)  I $P($G(^PRC(442,+$G(^PRC(441,+PSA,4,PSA(1),1,PSA(2),0)),1)),U,15)>PSADT D  Q
 ...W !!,"ITEM #: ",PSA,"  ",$P($G(^PRC(441,+PSA,0)),U,2),!!,"NSN: ",$P($G(^(0)),U,5),?25,"LAST VENDOR ORDERED: ",$E($P($G(^PRC(440,+$P($G(^PRC(441,+PSA,0)),U,4),0)),U),1,30)
 ...W !!,"NDC: ",$P($G(^PRC(441,+PSA,2,+$P($G(^PRC(441,+PSA,0)),U,4),0)),U,5)
 ...S PSA(3)=1
 ...W ?20,"LONG DESCRIPTION: "
 ...I $L(^PRC(441,+PSA,1,1,0))<40,'$O(^PRC(441,+PSA,1,1)) W $G(^PRC(441,+PSA,1,1,0)),! Q
 ...K ^UTILITY($J,"W") S DIWL=40,DIWR=80,DIWF="W"
 ...S PSA(4)=0
 ...F  S PSA(4)=$O(^PRC(441,+PSA,1,PSA(4))) Q:'PSA(4)  S X=$G(^PRC(441,+PSA,1,PSA(4),0)) D ^DIWP D ^DIWW
END I $E(IOST)'="C" W @IOF
 I $E(IOST,1,2)="C-",'PSAOUT W !! 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,"UNLINKED ITEM MASTER file DRUGS PURCHASED SINCE ",PSADT(1),?70,"PAGE: "_PSAPG,!,PSALN,!!
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSAUNI   2865     printed  Sep 23, 2025@19:26:45                                                                                                                                                                                                      Page 2
PSAUNI    ;BIR/LTL-Unlinked Drugs in the ITEM MASTER file ;7/23/97
 +1       ;;3.0; DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**15**; 10/24/97
 +2       ;
 +3       ;References to ^PSDRUG("AB" are covered by IA #2095
 +4       ;References to ^PRC( are covered by IA #214
 +5       ;
 +6       ;Check ITEM FILE for unlinked drugs
 +7       ;This report lists each active drug in the ITEM MASTER FILE that has not
 +8       ;yet been linked to an entry in the DRUG FILE. If you enter a date from
 +9       ;which to begin, only items that have been purchased since that date
 +10      ;will be listed.
 +11      ;
 +12       NEW DIR,PSA,PSADT,X,Y
           DO DT^DICRW
 +13       SET DIR(0)="D^::AEX"
           SET DIR("A")="Please enter oldest purchase date to include"
           SET DIR("B")="T-12M"
           SET DIR("?")="I will check each active drug to make sure it has been purchased since this date"
           WRITE !
           DO ^DIR
           KILL DIR
           IF 'Y
               SET PSAOUT=1
               GOTO END
 +14       SET PSADT=Y
           XECUTE ^DD("DD")
           SET PSADT(1)=Y
DEV       ;asks device and queueing info
 +1        KILL I,IO("Q")
           NEW %ZIS,DTOUT,DUOUT,IOP,POP,PSAOUT
           SET %ZIS="Q"
           WRITE !
           DO ^%ZIS
           IF POP
               WRITE !,"NO DEVICE SELECTED OR REPORT PRINTED!"
               SET PSAOUT=1
               GOTO END
 +2        IF $DATA(IO("Q"))
               NEW ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK
               SET ZTRTN="START^PSAUNI"
               SET ZTSAVE("PSA*")=""
               SET ZTDESC="Active, Unlinked Drug Report"
               DO ^%ZTLOAD
               DO HOME^%ZIS
               SET PSAOUT=1
               GOTO END
START     ;compiles and prints data for report
 +1        NEW PSALN,PSAPG
           SET (PSA,PSAPG,PSAOUT)=0
           DO HEADER
LOOP       FOR 
               SET PSA=$ORDER(^PRC(441,PSA))
               if 'PSA!(PSAOUT)
                   GOTO END
               if $Y+10>IOSL
                   DO HEADER
               IF $PIECE($GET(^PRC(441,+PSA,0)),U,3)=6505
                   IF '$GET(^PRC(441,+PSA,3))
                       IF $ORDER(^PRC(441,+PSA,4,0))
                           IF '$ORDER(^PSDRUG("AB",PSA,""))
                               Begin DoDot:1
 +1                                if $EXTRACT(IOST,1,2)="C-"
                                       WRITE "."
 +2                                SET PSA(1)=0
 +3                                FOR 
                                       SET PSA(1)=$ORDER(^PRC(441,+PSA,4,PSA(1)))
                                       if 'PSA(1)!('$ORDER(^PRC(441,+PSA,4,PSA(1),1,0)))
                                           QUIT 
                                       Begin DoDot:2
 +4                                        SET PSA(2)=0
                                           FOR 
                                               SET PSA(2)=$ORDER(^PRC(441,+PSA,4,PSA(1),1,PSA(2)))
                                               if 'PSA(2)
                                                   QUIT 
                                               IF $PIECE($GET(^PRC(442,+$GET(^PRC(441,+PSA,4,PSA(1),1,PSA(2),0)),1)),U,15)>PSADT
                                                   Begin DoDot:3
 +5                                                    WRITE !!,"ITEM #: ",PSA,"  ",$PIECE($GET(^PRC(441,+PSA,0)),U,2),!!,"NSN: ",$PIECE($GET(^(0)),U,5),?25,"LAST VENDOR ORDERED: ",$EXTRACT($PIECE($GET(^PRC(440,+$PIECE($GET(^PRC(441,+PSA,0)),U,4),0)),U),1
,30)
 +6                                                    WRITE !!,"NDC: ",$PIECE($GET(^PRC(441,+PSA,2,+$PIECE($GET(^PRC(441,+PSA,0)),U,4),0)),U,5)
 +7                                                    SET PSA(3)=1
 +8                                                    WRITE ?20,"LONG DESCRIPTION: "
 +9                                                    IF $LENGTH(^PRC(441,+PSA,1,1,0))<40
                                                           IF '$ORDER(^PRC(441,+PSA,1,1))
                                                               WRITE $GET(^PRC(441,+PSA,1,1,0)),!
                                                               QUIT 
 +10                                                   KILL ^UTILITY($JOB,"W")
                                                       SET DIWL=40
                                                       SET DIWR=80
                                                       SET DIWF="W"
 +11                                                   SET PSA(4)=0
 +12                                                   FOR 
                                                           SET PSA(4)=$ORDER(^PRC(441,+PSA,1,PSA(4)))
                                                           if 'PSA(4)
                                                               QUIT 
                                                           SET X=$GET(^PRC(441,+PSA,1,PSA(4),0))
                                                           DO ^DIWP
                                                           DO ^DIWW
                                                   End DoDot:3
                                                   QUIT 
                                       End DoDot:2
                                       if $GET(PSA(3))
                                           QUIT 
                               End DoDot:1
END        IF $EXTRACT(IOST)'="C"
               WRITE @IOF
 +1        IF $EXTRACT(IOST,1,2)="C-"
               IF 'PSAOUT
                   WRITE !!
                   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,"UNLINKED ITEM MASTER file DRUGS PURCHASED SINCE ",PSADT(1),?70,"PAGE: "_PSAPG,!,PSALN,!!
 +4        QUIT