source: WorldVistAEHR/trunk/r/CONTROLLED_SUBSTANCES-PSD/PSDESTP.m@ 1593

Last change on this file since 1593 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 7.1 KB
Line 
1PSDESTP ;BIR/BJW-Destroyed CS Drugs Report ; 28 Feb 98
2 ;;3.0; CONTROLLED SUBSTANCES ;**8,62**;13 Feb 97;Build 3
3 ;**Y2K compliance**,"P" added to date input string 2/9/98
4 ;*Y2K* chg to print four digit year in body of report
5 I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
6 I '$D(^XUSEC("PSJ RPHARM",DUZ)) W !!,"Please contact your Pharmacy Coordinator for access to",!,"the pending Controlled Substances destruction data.",!!,"PSJ RPHARM security key required.",! G END
7ASKD ;ask disp location
8 S PSDS=$P(PSDSITE,U,3),PSDSN=$P(PSDSITE,U,4)
9ASKV ;ask vault(s)
10 W !!,?5,"You may select a single VAULT, several VAULT(s),",!,?5,"or enter ^ALL to select all VAULT(s).",!
11 K DA,DIC D NOW^%DTC S (PSDT,Y)=X X ^DD("DD") S RPDT=Y
12 F S DIC=58.8,DIC("A")="Select VAULT: ",DIC(0)="QEA",DIC("S")="I $S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>PSDT:1,1:0),$P(^(0),""^"",2)'=""N"",$P(^(0),""^"",3)=+PSDSITE" D ^DIC K DIC Q:Y<0 S PSDVAU(+Y)=""
13ASKV2 ;
14 I '$O(PSDVAU(0))&(X'="^ALL") G END
15 I X="^ALL" F PSD=0:0 S PSD=$O(^PSD(58.8,PSD)) Q:'PSD I $S('$D(^PSD(58.8,PSD,"I")):1,'^("I"):1,+^("I")>PSDT:1,1:0),$P($G(^(0)),"^",2)'="N",$P($G(^(0)),"^",3)=+PSDSITE S PSDVAU(PSD)=""
16 S JJ=$O(PSDVAU(0)),JJ=$S($O(PSDVAU(JJ)):1,1:2)
17 S DIC="^DIC(4,",DR=.01,DA=+$P($G(^XMB(1,1,"XUS")),U,17),DIQ="PSD"
18 D EN^DIQ1 S PSD=PSD(4,DA,.01) K DIC,DR,DA,DIQ
19 S PSDSN=$S(JJ=1:PSD,1:$P($G(^PSD(58.8,+$O(PSDVAU(0)),0)),U)) K PSD
20DRUG ;ask drug
21 W !!,?5,"You may select a single drug, several drugs,",!,?5,"or enter ^ALL to select all drugs.",!!
22 W ! K DA,DIC
23 S PSDS=$O(PSDVAU(0))
24 I $O(PSDVAU(PSDS)) D G SKIP
25 .F S DIC=50,DIC(0)="QEAM",DIC("A")="SELECT DRUG: " D ^DIC K DIC Q:Y<0 S PSDRG(+Y)=""
26 F S DIC("W")="W:$P(^PSDRUG(Y,0),""^"",9) "" N/F"" I $P(^PSD(58.8,PSDS,1,Y,0),""^"",14)]"""",$P(^(0),""^"",14)'>DT W $C(7),"" *** INACTIVE ***""",DA(1)=+PSDS,DIC(0)="QEAM",DIC="^PSD(58.8,"_PSDS_",1," D ^DIC K DIC Q:Y<0 D
27 .S PSDRG(+Y)=""
28SKIP I '$D(PSDRG)&(X'="^ALL") G END
29 I X="^ALL" S ALL=1
30DATE ;ask date range
31 W ! K %DT S %DT="AEP",%DT("A")="Start with Date: " D ^%DT I Y<0 S PSDOUT=1 G END
32 S PSDSD=Y D D^DIQ S PSDATE=Y,%DT("A")="End with Date: " D ^%DT I Y<0 S PSDOUT=1 G END
33 I Y<PSDSD W !!,"The ending date of the range must be later than the starting date." G DATE
34 S PSDED=Y D D^DIQ S PSDATE=PSDATE_"^"_Y,PSDSD=PSDSD-.0001,PSDED=PSDED+.9999
35DEV ;select device
36 W !!,"This report is designed for a 80 column format.",!,"You may queue this report to print at a later time.",!!
37 S Y=$P($G(^PSD(58.8,+PSDS,2)),"^",9),C=$P(^DD(58.8,24,0),"^",2) D Y^DIQ S PSDEV=Y
38 K %ZIS,IOP,IO("Q"),POP S %ZIS="QM",%ZIS("B")=PSDEV D ^%ZIS I POP W !,"NO DEVICE SELECTED OR REPORT PRINTED!" G END
39 I $D(IO("Q")) K IO("Q"),ZTIO,ZTSAVE,ZTDTH,ZTSK S ZTRTN="START^PSDESTP",ZTDESC="Destroyed CS Drug Report" D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
40 U IO
41START ;start looping
42 K ^TMP("PSDESTP",$J)
43 D NOW^%DTC S Y=X X ^DD("DD") S RPDT=Y
44 K LN S (CNT,PG,PSDOUT,PSDTOT)=0,$P(LN,"-",80)=""
45 F PSD=PSDSD:0 S PSD=$O(^PSD(58.86,"AC",PSD)) Q:'PSD!(PSD>PSDED) S PSDS=0 F S PSDS=$O(^PSD(58.86,"AC",PSD,PSDS)) Q:'PSDS D:$D(PSDVAU(PSDS))
46 .F PSDR=0:0 S PSDR=$O(^PSD(58.86,"AC",PSD,PSDS,PSDR)) Q:'PSDR D
47 ..F PSDA=0:0 S PSDA=$O(^PSD(58.86,"AC",PSD,PSDS,PSDR,PSDA)) Q:'PSDA I $D(ALL)!($D(PSDRG(+PSDR))) D SET
48 I $D(ALL) F PSD=PSDSD:0 S PSD=$O(^PSD(58.86,"AD",PSD)) Q:'PSD!(PSD>PSDED) F S PSDS=$O(^PSD(58.86,"AD",PSD,PSDS)) Q:'PSDS D:$D(PSDVAU(PSDS))
49 .S PSDN="" F S PSDN=$O(^PSD(58.86,"AD",PSD,PSDS,PSDN)) Q:PSDN="" F PSDA=0:0 S PSDA=$O(^PSD(58.86,"AD",PSD,PSDS,PSDN,PSDA)) Q:'PSDA D SET
50 I CNT=0 D HDR W !!,?10,"*** NO CONTROLLED SUBSTANCE DESTRUCTIONS ***",!! G DONE
51PRINT ;prints data,L-6 added 8/24/95 accum summ.total,10/20/95 chgs made
52 D HDR
53 F PSDA=0:0 S PSDA=$O(^TMP("PSDESTP",$J,PSDA)) D:'PSDA GTOT Q:'PSDA!(PSDOUT) D:$Y+12>IOSL HDR Q:PSDOUT S PSDRN="" F S PSDRN=$O(^TMP("PSDESTP",$J,PSDA,PSDRN)) Q:PSDRN="" D
54 .I $Y+12>IOSL D HDR Q:PSDOUT
55 .S NODE=^TMP("PSDESTP",$J,PSDA,PSDRN)
56 .W !,"HOLDING #: ",PSDA,! S PVAULT=$P(NODE,U,9) W:JJ=1 "=> ",$P($G(^PSD(58.8,+PVAULT,0)),U),! W "Drug: ",PSDRN W ?60 W:$P(NODE,"^",8) "GS #: ",$P(NODE,U,8) W !,"Quantity: ",$P(NODE,"^"),!,"Cost of above Qty: ",$P(NODE,U,11)
57 .I $P(NODE,U,10)']"" S PSDTOT=$P(NODE,U,11)+PSDTOT
58 .I $P(NODE,U,6)']"" D
59 ..W !,"Date Destroyed: ",$P(NODE,U,3),!,"Destroyed By: ",$P(NODE,U,2),!,"Patient Returning Drug: ",$P(NODE,U,10),!
60 ..W:$P(NODE,U,4) "Comments: ",$P(NODE,U,4),!!
61 ..W:'$P(NODE,U,4) "Comments: ",$P(NODE,U,12),!!
62 .I $P(NODE,U,6)]"" D
63 ..W !,"Date/Time Cancelled: ",$P(NODE,U,5),!,"Cancelled By: ",$P(NODE,U,6),!,"Patient Returning Drug: ",$P(NODE,U,10),!,"Comments: ",$P(NODE,U,7),!!
64DONE ;
65 I $E(IOST)'="C" W @IOF
66 I $E(IOST,1,2)="C-",'PSDOUT W !! K DIR,DIRUT S DIR(0)="EA",DIR("A")="END OF REPORT! Press <RET> to return to the menu" D ^DIR K DIR
67END ;
68 K %,%DT,%H,%I,%ZIS,ALL,C,CNT,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,LN,NODE
69 K JJ,PG,PBACOM,PHARM,PHARMC,PHARMN,PHARMNC,POP,PPDU,PSD,PSDA,PSDATE,PSDCD,PSDCOMS,PSDCOM3,PSDED,PSDEV,PSDGS,PSDN,PSDPAT,PSDPATR,PSDPDU,PSDOUT,PSDR,PSDRG,PSDRN,PSDS,PSDTOT,PSDSD,PSDSN,PSDT,PSDTR,PSDVAU,PVAULT,PSDYR,PSDCYR
70 K QTY,RPDT,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
71 K ^TMP("PSDESTP",$J)
72 D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
73 Q
74HDR ;prints header information
75 I $E(IOST,1,2)="C-",PG W ! K DA,DIR S DIR(0)="E" D ^DIR K DIR I 'Y S PSDOUT=1 Q
76 S PG=PG+1 W:$Y @IOF W !,?70,"PAGE: ",PG,!,?15,"DESTROYED CS DRUGS REPORT for ",PSDSN
77 W !,?15,"Period From: ",$P(PSDATE,"^")," to: ",$P(PSDATE,"^",2),!,?15,"Run Date: ",RPDT,!!,"=> VAULT",!,LN,!
78 Q
79GTOT ;10/20/95 msg added,grand total,inserted 8/24/95
80 Q:PSDOUT
81 W !!!!?50,"Summary Total: ",PSDTOT
82 W !!!?15,"*** Drugs returned by a patient ARE NOT ADDED to Summary Total***"
83 Q
84SAVE ;saves variables for queueing
85 S (ZTSAVE("JJ"),ZTSAVE("PSDSD"),ZTSAVE("PSDED"),ZTSAVE("PSDATE"),ZTSAVE("PSDS"),ZTSAVE("PSDSN"),ZTSAVE("PSDTOT"))=""
86 S:$D(ALL) ZTSAVE("ALL")="" S:$D(PSDRG) ZTSAVE("PSDRG(")=""
87 S:$D(PSDVAU) ZTSAVE("PSDVAU(")=""
88 Q
89SET ;sets data;10/20/95 added bal.adj comms. PBACOM
90 S CNT=CNT+1
91 I '$D(PSDR) S PSDR="" ;<- JD *62
92 S (PSDGS,PBACOM)=""
93 S NODE=^PSD(58.86,PSDA,0),PSDRN=$S($G(^PSD(58.86,PSDA,1))]"":$G(^PSD(58.86,PSDA,1))_"*",$P($G(^PSDRUG(+PSDR,0)),"^")]"":$P($G(^PSDRUG(+PSDR,0)),"^"),1:"#"_PSDA_" DRUG NAME MISSING")
94 S PSDTR=$P(NODE,"^",9) I +PSDTR S PSDGS=$P($G(^PSD(58.81,PSDTR,0)),U,17),PBACOM=$P($G(^PSD(58.81,PSDTR,0)),U,16)
95 S QTY=$P(NODE,"^",3),PHARM=+$P(NODE,"^",10),PHARMN=$S($P($G(^VA(200,PHARM,0)),"^")]"":$P(^(0),"^"),1:"")
96 S PPDU=$P($G(^PSDRUG(+PSDR,660)),U,6),PSDPDU=$J(PPDU*QTY,1,3)
97 S Y=PSD X ^DD("DD") S PSDYR=$P(Y,",",2)
98 S PSDT=$E(PSD,4,5)_"/"_$E(PSD,6,7)_"/"_PSDYR
99 S PVAULT=+$P($G(^PSD(58.86,PSDA,0)),"^",7)
100 S PSDCOMS=$P($G(^PSD(58.86,PSDA,2)),"^")
101 S PSDCD=$P($G(^PSD(58.86,PSDA,3)),"^") I PSDCD S Y=PSDCD X ^DD("DD") S PSDCYR=$P(Y,",",2) S PSDCD=$E(PSDCD,4,5)_"/"_$E(PSDCD,6,7)_"/"_PSDCYR
102 S PHARMC=+$P($G(^PSD(58.86,PSDA,3)),"^",2),PHARMNC=$S($P($G(^VA(200,PHARMC,0)),"^")]"":$P(^(0),"^"),1:"")
103 S PSDCOM3=$P($G(^PSD(58.86,PSDA,3)),"^",3)
104 S PSDPAT=+$P(NODE,"^",13),PSDPATR=$S($P($G(^DPT(PSDPAT,0)),"^")]"":$P(^(0),"^"),1:"")
105 S ^TMP("PSDESTP",$J,PSDA,PSDRN)=QTY_"^"_PHARMN_"^"_PSDT_"^"_PSDCOMS_"^"_PSDCD_"^"_PHARMNC_"^"_PSDCOM3_"^"_PSDGS_"^"_PVAULT_"^"_PSDPATR_"^"_PSDPDU_"^"_PBACOM
106 Q
Note: See TracBrowser for help on using the repository browser.