source: FOIAVistA/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOATRF.m@ 1783

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

initial load of FOIAVistA 6/30/08 version

File size: 8.8 KB
Line 
1PSOATRF ;BIR/MHA - Automate Internet Refill ;07/09/07
2 ;;7.0;OUTPATIENT PHARMACY;**264**;DEC 1997;Build 19
3 ;Reference to ^PSSLOCK supported by DBIA 2789
4 ;Reference ^PSDRUG supported by DBIA 221
5 ;Reference ^PS(55 supported by DBIA 2228
6 ;
7START ;
8 S PSOITMG="",U="^",PSOITNS="PSOATRF" S:'$G(DT) DT=$$DT^XLFDT
9 I '$D(^PS(52.43,"AINST")) S PSOITMG="There are no internet refills to process." G END
10 S (SITE,DA)=$P(^XMB(1,1,"XUS"),U,17),DIC="4",DIQ(0)="IE",DR=".01;99",DIQ="PSOUTIL" D EN^DIQ1
11 S PSOINST=$G(PSOUTIL(4,SITE,99,"I"))
12 I PSOINST']"" S PSOITMG="The Institution "_SITE_" is not defined in the INSTITUTION file (#4)." G END
13 S PSXSYS=+$O(^PSX(550,"C",""))_"^"_$G(PSOINST)_"^"_$G(PSOUTIL(4,SITE,.01,"E"))
14 K SITE,DA,PSOUTIL,DIQ
15 I $G(PSXSYS) D
16 . K:($P($G(^PSX(550,+PSXSYS,0)),"^",2)'="A") PSXSYS
17 . I $$VERSION^XPDUTL("PSO")<7.0 K PSXSYS
18 S DUZ=$O(^XUSEC("PSOAUTRF","")) I 'DUZ S PSOITMG="There are no users with PSOAUTRF key, at least one should have this key." G END
19 I '$D(^PS(52.43,"AINST",PSOINST)) S PSOITMG="There are no internet refills to process for Institution "_PSOINST G END
20 L +^XTMP(PSOITNS):3 E S PSOITMG="Automate Internet Refill job is currently running - Try later." G END
21 K ^XTMP(PSOITNS,$J)
22 S PSOSYS=$G(^PS(59.7,1,40.1))
23 S (I,J,PSOITDD)=0 F S I=$O(^PS(59,I)) Q:'I I '$P($G(^PS(59,I,"I")),U)!(DT<$P($G(^("I")),U)) S J=J+1 D G:PSOITMG]"" END
24 . S PSOSITE(I)=I,PSOSNM(I)=$P(^PS(59,I,0),U),PSORFN(I)=$G(^PS(59,I,"RF")),PSOPAR(I)=$G(^PS(59,I,1)),PSOPRPAS(I)=$P($G(PSOPAR),U,7)
25 . S PSOPAR7(I)=$G(^PS(59,I,"IB")),PSOPINST(I)=$P($G(^PS(59,I,"INI")),U)
26 . I J=1 D SDIV S PSOITDD=I
27 I 'J S PSOITMG="There are no active divisions in File #(59) - At least one division should be active - None processed." G END
28 D PRORF
29END ;
30 I $D(^XTMP(PSOITNS,$J)) D SMAIL^PSOATRF1 G:'$G(PSOITC) KV
31 S PSOITMG(1)=$S($G(PSOITC):"Total internet refills processed = "_PSOITC,PSOITMG="":"There are no internet refills to process.",1:PSOITMG)
32 D GRP
33 S:'$O(XMY(0)) XMY(DUZ)=""
34 S XMDUZ=.5,XMSUB="Outpatient Pharmacy - PSO AUTO REFILL"
35 S XMTEXT="PSOITMG(" N DIFROM D ^XMD K XMDUZ,XMTEXT,XMSUB
36KV ;
37 L -^XTMP(PSOITNS) K ^XTMP(PSOITNS)
38 K DFN,PSODFN,PSODTCUT,PSOITMG,PSOITNF,PSOITNS,PSOITC,PSOITDD,PSOITF,PSOITP,PSOITR
39 K PSOINST,PSOPAR,PSOPINST,PSOPRPAS,PSOPAR7,PSOPTPST,PSOSITE,PSOSNM,PSOSYS,PSORFN
40 K DRG,DIVN,PSXSYS,RX,RX0,RXN,VA,ZZ,LC,PSOS,XMY,PSOREA,PSOSTAT,PSOD
41 Q
42 ;
43PRORF ;
44 S X1=DT,X2=-120 D C^%DTC S PSODTCUT=X
45 S PSOITR="",PSOITC=0
46 F S PSOITR=$O(^PS(52.43,"AINST",PSOINST,PSOITR)) Q:'PSOITR D D:PSOITMG]"" FILE D ULK
47 . S (PSOITF,PSOITNF)=0,PSOITMG="",PSOITRX=+PSOITR,PSOITP=$O(^PS(52.43,"AINST",PSOINST,PSOITRX,""))
48 . Q:'PSOITP
49 . I '$D(^PS(52.43,PSOITP))!($P(^(PSOITP,0),U,5)'="") K ^PS(52.43,"AINST",PSOINST,PSOITRX,PSOITP) Q
50 . I '$D(^PSRX(PSOITRX,0))!($P(^(0),U)="")!('$D(^(2)))!($P(^("STA"),U)=13) S PSOITNF=1,PSOITMG="Rx IEN "_PSOITRX_" not in file (#52)/Incomplete/Deleted" Q
51 . D PSOL^PSSLOCK(PSOITRX) I '$G(PSOMSG) K PSOMSG Q
52 . K PSOMSG
53 . S PSOITRX0=^PSRX(PSOITRX,0),PSOITRX2=^(2),PSOITRX3=^(3),PSOITRXS=^("STA")
54 . S (DFN,PSODFN)=$P(PSOITRX0,U,2),RXN=$P(PSOITRX0,U),DRG=$P(PSOITRX0,U,6)
55 . I PSODFN'=$P(^PS(52.43,PSOITP,0),U,9) D Q
56 . . S PSOITNF=1,PSOITMG="Can't refill Rx # "_RXN_", it is not for this patient. DFN in file #52="_DFN_", DFN in file #52.43="_$P(^PS(52.43,PSOITP,0),U,9)
57 . D GET^PSOPTPST
58 . I $G(PSOPTPST(2,PSODFN,.351))]"" S PSOITNF=1,PSOITMG="Patient Died on "_PSOPTPST(2,PSODFN,.351) Q
59 . D ICN^PSODPT(DFN)
60 . S PSOLOUD=1 D:$P($G(^PS(55,DFN,0)),U,6)'=2 EN^PSOHLUP(DFN) K PSOLOUD
61 . I '$P(PSOPAR,U,11),$G(^PSDRUG(DRG,"I"))]"",DT>$G(^("I")) D Q
62 . . S PSOITNF=1,PSOITMG="Drug is inactive for Rx # "_RXN_" cannot be refilled"
63 . S I=$P(^PSRX(PSOITRX,2),U,9) S:'I I=PSOITDD D SDIV
64 . I $G(PSOPTPST(2,PSODFN,.1))]"",'PSORFN S PSOITNF=1,PSOITMG="Patient is an Inpatient on Ward "_PSOPTPST(2,PSODFN,.1) Q
65 . I $G(PSOPTPST(2,PSODFN,148))="YES",'$P(PSORFN,U,2) S PSOITNF=1,PSOITMG="Patient is in a Contract Nursing Home" Q
66 . D CHKRF Q:PSOITNF
67 . I $O(^PS(52.5,"B",PSOITRX,0)),'$G(^PS(52.5,+$O(^PS(52.5,"B",PSOITRX,0)),"P")) S PSOITNF=1,PSOITMG="Rx is in suspense and cannot be refilled" Q
68 . S PSOY=1+$$LSTRFL^PSOBPSU1(PSOITRX)
69 . I PSOY>$P(PSOITRX0,U,9) S PSOITNF=1,PSOITMG="Can't refill, no refills remaining" Q
70 . S (PSOITF,PSOX("NUMBER"))=PSOY
71 . S PSOX("RX0")=PSOITRX0,PSOX("RX2")=PSOITRX2,PSOX("RX3")=PSOITRX3,PSOX("STA")=PSOITRXS
72 . S DRG=$P(PSOITRX0,U,6)
73 . N PSODEA,PSODAY
74 . S PSODEA=$P($G(^PSDRUG(DRG,0)),U,3)
75 . S PSODAY=$P(PSOITRX0,U,8)
76 . I $$DEACHK^PSOUTLA1(PSOITRX,PSODEA,PSODAY) D Q
77 . . S PSOITNF=1,PSOITMG="This drug has been changed, No refills allowed"
78 . D CHKDT Q:PSOITNF
79 . D EN^PSOR52(.PSOX) I PSOITF,$D(^PSRX(PSOITRX,1,PSOITF,0)) S PSOITC=PSOITC+1,PSOITMG=PSOITF_" Susp. until "_$$DSP($P(^(0),U))
80 Q
81 ;
82CHKRF ;
83 D ^PSOBUILD
84 I '$G(PSOSD) S PSOITNF=1,PSOITMG="This patient has no prescriptions" Q
85 S (PSOX,PSOY,PSOS)="",PSOX("STA")=PSOITRXS
86 F S PSOS=$O(PSOSD(PSOS)) Q:PSOS="" F S PSOX=$O(PSOSD(PSOS,PSOX)) Q:PSOX']"" D
87 . I PSOITRX=+PSOSD(PSOS,PSOX) S PSOY=PSOSD(PSOS,PSOX) I $P(PSOY,U,4)]"" D
88 . . S PSOITNF=1,PSOITMG="Cannot refill Rx # "_RXN
89 . . S PSOREA=$P(PSOY,U,4),PSOSTAT=PSOX("STA")
90 . . I PSOREA["Z" S:PSOSTAT=4 PSOSTAT=1 D Q
91 . . . S PSOA=";"_PSOSTAT,PSOB=$P(^DD(52,100,0),U,3),PSOA=$F(PSOB,PSOA),PSOA=$P($E(PSOB,PSOA,999),";",1)
92 . . . S PSOITMG=PSOITMG_" Rx is in "_$P(PSOA,":",2)_" status"
93 . . . K PSOA,PSOB
94 . . I PSOREA["M" S PSOITMG=PSOITMG_" Drug no longer used by Outpatient Pharmacy" Q
95 . . I PSOREA["B" S PSOITMG=PSOITMG_" Narcotic Drug" Q
96 . . I PSOREA["C" S PSOITMG=PSOITMG_" Non-Renewable Drug" Q
97 . . I PSOREA["D" S PSOITMG=PSOITMG_" Non-Renewable Patient Status" Q
98 . . I PSOREA["E" S PSOITMG=PSOITMG_" Non-Verified Rx" Q
99 . . I PSOREA["G",PSOREA'["B" S PSOITMG=PSOITMG_" No more refills left"
100 I PSOY="" S PSOITNF=1,PSOITMG="Cannot refill, Rx is DC/Exp. Later Rx may exist " D
101 . S (PSOS,PSOX)="",PSOD=$P(^PSDRUG($P(PSOITRX0,U,6),0),U)
102 . N ZRX S ZRX="" F S PSOS=$O(PSOSD(PSOS)) Q:PSOS="" F S PSOX=$O(PSOSD(PSOS,PSOX)) Q:PSOX']"" I PSOD=PSOX,+PSOSD(PSOS,PSOX) S ZRX=$P($G(^PSRX(+PSOSD(PSOS,PSOX),0)),U)
103 . S PSOITMG=PSOITMG_ZRX
104 Q
105 ;
106FILE ;
107 K DIE S DA=PSOITP
108 S DIE="^PS(52.43,",DR="5////"_DT_";6///"_$S(PSOITNF:"NOT ",1:"")_"FILLED;10////"_PSOITMG D ^DIE
109 K ^PS(52.43,"AINST",PSOINST,PSOITRX,DA) I PSOITNF S ^XTMP(PSOITNS,$J,PSOSITE,DFN,PSOITRX)=PSOITMG
110 Q
111 ;
112GRP ;
113 S MDUZ=0
114 I '$D(^XUSEC("PSOAUTRF")) D Q
115 . F S MDUZ=$O(^XUSEC("PSORPH",MDUZ)) Q:MDUZ'>0 S XMY(MDUZ)=""
116 F S MDUZ=$O(^XUSEC("PSOAUTRF",MDUZ)) Q:MDUZ'>0 S XMY(MDUZ)=""
117 K MDUZ Q
118 ;
119ULK ;
120 I '$G(PSOITRX) Q
121 D PSOUL^PSSLOCK(PSOITRX)
122 K PSOITRX,PSOSD,PSOX,PSORX,PSOITRX0,PSOITRX2,PSOITRX3,PSOITRXS
123 Q
124SETUP ;
125 I '$D(^XUSEC("PSOAUTRF",DUZ)) W !,"You must hold the PSOAUTRF key to run this option!" Q
126 N PATCH,JOBN
127 S JOBN="PSO AUTO REFILL"
128 L +^XTMP("PSOATRF"):5 I '$T D Q
129 .D BMES^XPDUTL("The Refill Automation job is currently running, try later.")
130 .D MES^XPDUTL("")
131 .S DIR(0)="E",DIR("A")=" Press ENTER to Continue" D ^DIR K DIR
132 K %DT,DIC,DTOUT S DIC(0)="XZM",DIC="^DIC(19.2,",X="PSO AUTO REFILL" D ^DIC
133 I +Y>0 D EDIT^XUTMOPT("PSO AUTO REFILL") G EX
134 D RESCH^XUTMOPT("PSO AUTO REFILL","","","24H","L"),EDIT^XUTMOPT("PSO AUTO REFILL") K DIC,Y,X
135EX ;
136 L -^XTMP("PSOATRF") K Y,C,D,D0,DI,DQ,DA,DIE,DR,DIC,X
137 Q
138 ;
139SDIV ;
140 S PSOSITE=PSOSITE(I),PSOPAR=PSOPAR(I),PSOPRPAS=PSOPRPAS(I),PSORFN=PSORFN(I)
141 S PSOPAR7=PSOPAR7(I),PSOPINST=PSOPINST(I)
142 Q
143 ;
144CHKDT ;
145 S PSOX("IRXN")=PSOITRX
146 S PSOX("MAIL/WINDOW")="M",PSOX("FLD")=2,PSOX("QS")="S"
147 S PSOX("FIELD")=0,(PSORX("FILL DATE"),PSOX("FILL DATE"))=DT,PSOX("FLD")=1,X1=DT,X2=-180
148 D C^%DTC S PSOX("ISSUE DATE")=X,PSOX("CLERK CODE")=DUZ
149 S PSOX("STOP DATE")=$P(PSOITRX2,U,6) D NEXT
150 I PSOX("FILL DATE")<$P(PSOITRX3,U,2) D SUSDATE^PSOUTIL(.PSOX)
151 I PSOX("FILL DATE")>PSOX("STOP DATE") S PSOITNF=1 D Q
152 .S PSOITMG="Can't refill, Refill Date "_$$DSP(PSOX("FILL DATE"))
153 .S PSOITMG=PSOITMG_" is past Expiration Date "_$$DSP(PSOX("STOP DATE"))
154 S PSOX("LAST REFILL DATE")=$P(PSOITRX3,U,1)
155 I PSOX("LAST REFILL DATE"),PSOX("FILL DATE")=PSOX("LAST REFILL DATE") S PSOITNF=1 D Q
156 .S PSOITMG="Can't refill, Fill Date already exists for "_$$DSP(PSOX("FILL DATE"))
157 I PSOX("LAST REFILL DATE"),PSOX("FILL DATE")<PSOX("LAST REFILL DATE") S PSOITNF=1 D Q
158 .S PSOITMG="Can't refill, later Refill Date already exists for "_$$DSP(PSOX("LAST REFILL DATE"))
159 Q
160 ;
161NEXT ;
162 S PSOX1=$P(PSOITRX2,U,2)
163 I '$O(^PSRX(PSOITRX,1,0)) D Q
164 . S $P(PSOITRX3,U)=PSOX1,X1=PSOX1
165 . S X2=$P(PSOITRX0,U,8)-10\1
166 . D C^%DTC
167 . S:'$P(PSOITRX3,U,8) $P(PSOITRX3,U,2)=X K X
168 S PSOY2=0
169 F PSOY=0:0 S PSOY=$O(^PSRX(PSOITRX,1,PSOY)) Q:'PSOY S PSOY1=PSOY,PSOY2=PSOY2+1
170 S PSOY=^PSRX(PSOITRX,1,PSOY1,0)
171 S PSOX2=$P(PSOY,U)
172 S $P(PSOITRX3,U)=PSOX2,X1=PSOX2
173 S X2=$P(PSOITRX0,U,8)-10\1
174 D C^%DTC S PSOY3=X
175 S X1=PSOX1,X2=(PSOY2+1)*$P(PSOITRX0,U,8)-10\1
176 D C^%DTC S PSOY4=X
177 S $P(PSOITRX3,U,2)=$S(PSOY3<PSOY4:PSOY4,1:PSOY3)
178 K X,PSOX1,PSOX2,PSOY,PSOY1,PSOY2,PSOY3,PSOY4
179 Q
180 ;
181DSP(X) ;
182 Q:'X ""
183 Q $E(X,4,5)_"/"_$E(X,6,7)_"/"_$E(X,2,3)
184 ;
Note: See TracBrowser for help on using the repository browser.