source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOUTL.m@ 770

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

initial load of WorldVistAEHR

File size: 9.6 KB
Line 
1PSOUTL ;BHAM ISC/SAB - pso utility routine ;10/20/06 3:44pm
2 ;;7.0;OUTPATIENT PHARMACY;**1,21,126,174,218,259**;DEC 1997;Build 5
3 ;External reference SERV^IBARX1 supported by DBIA 2245
4 ;External reference ^PS(55, supported by DBIA 2228
5 ;
6 ;*218 prevent refill from being deleted if pending processing via
7 ; external dispense machines
8 ;*259 reverse *218 restrictions & Add del only last refill logic.
9 ;
10SUSPCAN ;dcl rx from suspense used in new, renew AND verification of Rxs
11 S PSLAST=0 F PSI=0:0 S PSI=$O(^PSRX(PSRX,1,PSI)) Q:'PSI S PSLAST=PSI
12 I PSLAST S PSI=^PSRX(PSRX,1,PSLAST,0) K ^PSRX(PSRX,1,PSLAST),^PSRX(PSRX,1,"B",+PSI,PSLAST) S ^(0)=$P(^PSRX(PSRX,1,0),"^",1,3)_"^"_($P(^(0),"^",4)-1) K PSLAST,PSI,SUSX,SUS1,SUS2 Q
13 S $P(^PSRX(PSRX,3),"^",7)="DISCONTINUED FROM SUSPENSE BEFORE FILLING" K PSI,SUSX,SUS1,SUS2 Q
14 ;
15ACTLOG ;
16 F PSI=0:0 S PSI=$O(^PSRX(PSRX,"A",PSI)) I 'PSI!'$O(^(PSI)) S ^PSRX(PSRX,"A",+PSI+1,0)=DT_"^"_PSREA_"^"_PSOCLC_"^"_PSRXREF_"^"_PSMSG,^PSRX(PSRX,"A",0)="^52.3DA^"_(+PSI+1)_"^"_(+PSI+1) Q
17ACTOUT I PSREA="C" S PSI=$S($D(^PSRX(PSRX,2)):+$P(^(2),"^",6),1:0) K:$D(^PS(55,PSDFN,"P","A",PSI,PSRX)) ^(PSRX) S ^PS(55,PSDFN,"P","A",DT,PSRX)="" Q
18 I PSREA="R" F PSI=0:0 S PSI=$O(^PSRX(PSRX,"A",PSI)) Q:'PSI I $D(^(PSI,0)),$P(^(0),"^",2)="C" S PSS=+^(0)
19 I $D(PSS),PSS K:$D(^PS(55,PSDFN,"P","A",PSS,PSRX)) ^(PSRX)
20 I PSREA="R",$D(^PSRX(PSRX,2))#2 S ^PS(55,PSDFN,"P","A",+$P(^PSRX(PSRX,2),"^",6),PSRX)=""
21 Q
22 ;
23QUES ;INSTRUCTIONS FOR RENEW AND REFILL
24 W !?5,"Enter the item #(s) or RX #(s) you wish to ",$S(PSFROM="N":"renew ",PSFROM="R":"REFILL "),"separated by commas."
25 W !?5,"For example: 1,2,5 or 123456,33254A,232323B."
26 W !?5,"Do not enter the same number twice, duplicates are not allowed."
27 Q
28ENDVCHK S PSOPOP=0 Q:'PSODIV Q:'$P(^PSRX(PSRX,2),"^",9)!($P(^(2),"^",9)=PSOSITE)
29CHK1 I '$P(PSOSYS,"^",2) W !?10,$C(7),"RX# ",$P(^PSRX(PSRX,0),"^")," is not a valid choice. (Different Division)" S PSPOP=1 Q
30 I $P(PSOSYS,"^",3) W !?10,$C(7),"RX# ",$P(^PSRX(PSRX,0),"^")," is from another division. Continue? (Y/N) " R ANS:DTIME I ANS="^"!(ANS="") S PSPOP=1 Q
31 I (ANS']"")!("YNyn"'[$E(ANS)) W !?10,$C(7),"Answer 'YES' or 'NO'." G CHK1
32 S:$E(ANS)["Nn" PSPOP=1 Q
33 ;PSO*7*259; SET VAR PSOSFN TO CHECK FOR SUSPENDED REFILL
34K52 K PSOSFN S SFN=+$O(^PS(52.5,"B",DA(1),0)),PSOSFN=SFN Q:SFN=0
35 I $P($G(^PS(52.5,SFN,0)),"^",5)=$P($G(^PSRX(+^PS(52.5,SFN,0),"P",0)),"^",3),$P($G(^PSRX($P(^PS(52.5,SFN,0),"^"),"P",0)),"^",4)=0 N PSOXX S PSOXX=1 G KILL
36 G:X'=""&($G(Y)=1) KILL I $G(Y)'=1,SFN I $D(^PS(52.5,SFN,0)),'$P(^(0),"^",5),'$P($G(^("P")),"^") D
37 .S SDT=+$P(^PS(52.5,SFN,0),"^",2) K ^PS(52.5,"C",SDT,SFN)
38 .I $P($G(^PS(52.5,SFN,0)),"^",7)="Q" K ^PS(52.5,"AQ",SDT,+$P(^PS(52.5,SFN,0),"^",3),SFN) D KCMPX^PSOCMOP(SFN,"Q")
39 .I $P($G(^PS(52.5,SFN,0)),"^",7)="" K ^PS(52.5,"AC",+$P(^PS(52.5,SFN,0),"^",3),SDT,SFN)
40 .K SFN,SDT
41 Q
42S52 S (RIFN,PSOSX)=0 F S RIFN=$O(^PSRX(DA(1),1,RIFN)) Q:'RIFN S RFID=$P(^PSRX(DA(1),1,RIFN,0),"^"),PSOSX=PSOSX+1
43 S SFN=+$O(^PS(52.5,"B",DA(1),0)) I SFN,'$G(^PS(52.5,SFN,"P")),$P($G(^PSRX($P($G(^PS(52.5,SFN,0)),"^"),"STA")),"^")=5 D
44 .I '$D(^PS(52.5,SFN,0))!($P($G(^(0)),"^",5)) Q
45 .S $P(^PS(52.5,SFN,0),"^",2)=RFID,^PS(52.5,"C",RFID,SFN)=""
46 .I $P($G(^PS(52.5,SFN,0)),"^",7)="Q" S ^PS(52.5,"AQ",RFID,+$P(^PS(52.5,SFN,0),"^",3),SFN)="" D SCMPX^PSOCMOP(SFN,"Q")
47 .I $P($G(^PS(52.5,SFN,0)),"^",7)="" S ^PS(52.5,"AC",+$P(^PS(52.5,SFN,0),"^",3),RFID,SFN)=""
48 K SFN,RFIN,RFID,PSOSX,PSOSXDT Q
49KILL N DFN
50 I SFN D
51 .S $P(^PSRX(DA(1),"STA"),"^")=0 Q:'$D(^PS(52.5,SFN,0)) S DFN=+$P(^PS(52.5,SFN,0),"^",3),PAT=$P(^DPT(DFN,0),"^")
52 .;I $P(^PS(52.5,SFN,0),"^",5) Q
53 .K ^PS(52.5,"B",+$P(^PS(52.5,SFN,0),"^"),SFN),^PS(52.5,"C",+$P(^PS(52.5,SFN,0),"^",2),SFN),^PS(52.5,"D",PAT,SFN),^PS(52.5,"AF",DFN,SFN)
54 .I $P($G(^PS(52.5,SFN,0)),"^",7)="" D
55 ..I $G(^PS(52.5,SFN,"P")) K ^PS(52.5,"AS",+$P(^(0),"^",8),+$P(^(0),"^",9),+$P(^(0),"^",6),+$P(^(0),"^",11),SFN),^PS(52.5,"ADL",$E(+$P(^PS(52.5,SFN,0),"^",8),1,7),SFN) Q
56 ..K ^PS(52.5,"AC",DFN,+$P(^PS(52.5,SFN,0),"^",2),SFN)
57 .I $P($G(^PS(52.5,SFN,0)),"^",7)'="" D
58 ..;Kill CMOP xrefs
59 ..N PSOC7 S PSOC7=$P($G(^PS(52.5,SFN,0)),"^",7)
60 ..I PSOC7="Q"!(PSOC7="P") K ^PS(52.5,"AG",+$P(^PS(52.5,SFN,0),"^",3),SFN) D KCMPX^PSOCMOP(SFN,PSOC7)
61 ..I PSOC7="X"!(PSOC7="P")!(PSOC7="L") K ^PS(52.5,$S(PSOC7="X":"AX",PSOC7="P":"AP",1:"AL"),$P(^PS(52.5,SFN,0),"^",2),$P(^(0),"^",3),SFN) D KCMPX^PSOCMOP(SFN,PSOC7)
62 ..K ^PS(52.5,"APR",+$P(^PS(52.5,SFN,0),"^",8),+$P(^(0),"^",9),+$P(^(0),"^",6),+$P(^(0),"^",11),SFN),^PS(52.5,"ADL",$E(+$P(^PS(52.5,SFN,0),"^",8),1,7),SFN)
63 .K ^PS(52.5,SFN,0),^PS(52.5,SFN,"P"),DFN,SFN,PAT
64 S CNT=0 F SUB=0:0 S SUB=$O(^PSRX(DA(1),"A",SUB)) Q:'SUB S CNT=SUB
65 S:DA>5 DA=DA+1 D NOW^%DTC S CNT=CNT+1
66 S ^PSRX(DA(1),"A",0)="^52.3DA^"_CNT_"^"_CNT,^PSRX(DA(1),"A",CNT,0)=%_"^D^"_DUZ_"^"_DA_"^"
67 I '$D(PSOXX) S ^PSRX(DA(1),"A",CNT,0)=^PSRX(DA(1),"A",CNT,0)_"Refill "
68 ;if PSOXX not exist, = refill. otherwise, it is a partial.
69 S ^PSRX(DA(1),"A",CNT,0)=^PSRX(DA(1),"A",CNT,0)_$S($G(RESK):"returned to stock.",$G(PSOPSDAL):"deleted during Controlled Subs release.",$G(PSOXX)=1:"Partial deleted from suspense file.",1:"deleted during Rx edit.") K CNT,SUB
70 Q
71CID ;calculates six months limit on issue dates
72 S PSID=X,X="T-6M",%DT="X" D ^%DT S %DT(0)=Y,X=PSID,%DT="EX" D ^%DT K PSID
73 Q
74CIDH S X="T-6M",%DT="X" D ^%DT X ^DD("DD") D EN^DDIOL("Issue Date must be greater or equal to "_Y,"","!")
75 Q
76SPR F RF=0:0 S RF=$O(^PSRX(DA(1),1,RF)) Q:'RF S NODE=RF
77 I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) Q
78SREF I $G(NODE) S NODE=NODE-1 G:'$D(^PSRX(DA(1),1,NODE,0)) SREF
79 I NODE=0 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) Q
80 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),1,NODE,0),"^",1) Q
81 K NODE,RF
82 Q
83KPR F RF=0:0 S RF=$O(^PSRX(DA(1),1,RF)) Q:'RF S NODE=RF
84 I NODE=DA&(X'="") S NODE=NODE-1 S:NODE=1 NODE=0 G:'NODE ORIG G:NODE>1 KREF
85 I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
86KREF S NODE=NODE-1 G:'NODE EX
87 I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
88 G:NODE=DA&(X'="") KREF G:'$D(^PSRX(DA(1),1,NODE,0)) KREF
89ORIG I 'NODE S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
90 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),1,NODE,0),"^",1) G EX
91EX K NODE,RF
92 Q
93IBSS N PSOHLP S PSOHLP(1,"F")="!!"
94 S PSOHLP(1)="Entry in this field must match the SERVICE field for pharmacy action"
95 S PSOHLP(2,"F")="!"
96 S PSOHLP(2)="types in the IB ACTION TYPE file AND be a valid entry in your"
97 S PSOHLP(3,"F")="!"
98 S PSOHLP(3)="SERVICE/SECTION file to generate copay charges!"
99 S PSOHLP(4,"F")="!!"
100 D EN^DDIOL(.PSOHLP) K PSOHLP
101 Q
102IBSSR S PSOIBFL=0 F PSOIBLP=0:0 S PSOIBLP=$O(^DIC(49,PSOIBLP)) Q:'PSOIBLP!(PSOIBFL) S Y=PSOIBLP,PSOIBST=$$SERV^IBARX1(+Y) I $G(PSOIBST) S DIE="^PS(59,",DA=PSOSITE,DR="1003////"_PSOIBLP D ^DIE K DIE D S PSOIBFL=1
103 .W $C(7),!!,"There was an invalid entry in your IB SERVICE/SECTION field in your Outpatient",!,"Site Parameter file, but we have fixed the problem for you, and you",!,"may continue!" Q
104 Q
105WARN ;
106 I $G(PSOUNHLD) D Q
107 .D EN^DDIOL("You cannot delete a refill while removing from Hold! Use the Edit Action.","","$C(7),!!"),EN^DDIOL(" ","","!!")
108 I $G(CMOP(DA))]""&(+$G(CMOP(DA))<3) D K CMOP Q
109 .D EN^DDIOL("You cannot delete a refill that"_$S(+$G(CMOP(DA))=1:" has been released by",1:" is being transmitted to")_" the CMOP","","!!")
110 .D EN^DDIOL(" ","","!!")
111 K CMOP
112 ;
113 N PSOL,PSR
114 S PSR=0 F S PSR=$O(^PSRX(DA(1),1,PSR)) Q:'PSR S PSOL=PSR
115 I DA=PSOL,$P(^PSRX(DA(1),1,DA,0),"^",18) D Q
116 .D EN^DDIOL("Refill Released! Use the 'Return to Stock' option!","","$C(7),!!"),EN^DDIOL(" ","","!")
117 ;
118 ;Only allow deletion if last refill *259
119 I $O(^PSRX(DA(1),1,DA)) D Q
120 .D EN^DDIOL("Only the last refill can be deleted. Later refills must be deleted first.","","$C(7),!!")
121 .D EN^DDIOL("","","!!")
122 ;
123 ;Warn of In Process, Only delete if answered Yes ;*259
124 I $$REFIP^PSOUTLA1(DA(1),DA,"R") D I 'Y Q ;reset $T
125 . D EN^DDIOL("** Refill has previously been sent to the External Dispense Machine","","!!,?2")
126 . D EN^DDIOL("** for filling and is still Pending Processing","","$C(7),!,?2")
127 . D EN^DDIOL("","","!")
128 . K DIR
129 . S DIR("A")="Do you want to continue? "
130 . S DIR("B")="Y"
131 . S DIR(0)="YA^^"
132 . S DIR("?")="Enter Y for Yes or N for No."
133 . D ^DIR
134 . K DIR
135 Q
136 ;
137WARN1 ;move to PSOUTLA1
138 D WARN1^PSOUTLA1
139 Q
140 ;
141CAN(PSOXRX) ;Clean up Rx when discontinued
142 N SUSD,IFN,RF,NODE,DA
143 Q:'$D(^PSRX(PSOXRX,0))
144 S DA=$O(^PS(52.5,"B",PSOXRX,0)) I DA S DIK="^PS(52.5,",SUSD=$P($G(^PS(52.5,DA,0)),"^",2) D ^DIK K DIK I $O(^PSRX(PSOXRX,1,0)) S DA=PSOXRX D REF^PSOCAN2
145 I $D(^PS(52.4,PSOXRX,0)) S DIK="^PS(52.4,",DA=PSOXRX D ^DIK K DIK
146 I $G(^PSRX(PSOXRX,"H"))]"" K:$P(^PSRX(PSOXRX,"H"),"^") ^PSRX("AH",$P(^PSRX(PSOXRX,"H"),"^"),PSOXRX) S ^PSRX(PSOXRX,"H")=""
147 I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
148 Q
149ECAN(PSOXRX) ;Clean up Rx when expired
150 N DA
151 Q:'$D(^PSRX(PSOXRX,0))
152 S DA=$O(^PS(52.5,"B",PSOXRX,0)) I DA K DIK S DIK="^PS(52.5," D ^DIK K DIK
153 I $D(^PS(52.4,PSOXRX,0)) K DIK S DIK="^PS(52.4,",DA=PSOXRX D ^DIK K DIK
154 I $G(^PSRX(PSOXRX,"H"))]"" K:$P(^PSRX(PSOXRX,"H"),"^") ^PSRX("AH",$P(^PSRX(PSOXRX,"H"),"^"),PSOXRX) S ^PSRX(PSOXRX,"H")=""
155 I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
156 Q
157CMOP ;CMOP("L")=LAST FILL... if it is orig Rx =0
158 ;CMOP(FILL #)=CMOP status from 52[TRAN=0,DISP=1,RETRAN=2,NOT DISP=3
159 ;If suspended CMOP("S")=CMOP suspense status Q,L,X,P,R
160 ;All returned variables can be killed by K CMOP
161 ;
162 S CRX=DA
163CMOP1 N X
164 S (CMOP("L"),X)=0 F S X=$O(^PSRX(CRX,1,X)) Q:'X S CMOP("L")=X
165 I $O(^PSRX(CRX,4,0)) F X=0:0 S X=$O(^PSRX(CRX,4,X)) Q:'X D
166 .S CMOP($P($G(^PSRX(CRX,4,X,0)),"^",3))=$P($G(^(0)),"^",4)
167 S X=$O(^PS(52.5,"B",CRX,0)) I X]"" S CMOP("S")=$P($G(^PS(52.5,X,0)),"^",7)
168 K CRX,X
169 Q
Note: See TracBrowser for help on using the repository browser.