PSOUTL ;BHAM ISC/SAB - pso utility routine ;29-May-2012 15:16;PLS
;;7.0;OUTPATIENT PHARMACY;**1,21,126,1006,1011,174,218,259,1015**;DEC 1997;Build 62
;External reference SERV^IBARX1 supported by DBIA 2245
;External reference ^PS(55, supported by DBIA 2228
;
;*218 prevent refill from being deleted if pending processing via
; external dispense machines
;*259 reverse *218 restrictions & Add del only last refill logic.
; Modified - IHS/MSC/PLS - 02/21/08 - Line ECAN+7 commented out
; 04/30/08 - Line CAN+7 commented out
; 03/28/11 - Line CID+1,CIDH, CIDADJ (new EP)
SUSPCAN ;dcl rx from suspense used in new, renew AND verification of Rxs
S PSLAST=0 F PSI=0:0 S PSI=$O(^PSRX(PSRX,1,PSI)) Q:'PSI S PSLAST=PSI
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
S $P(^PSRX(PSRX,3),"^",7)="DISCONTINUED FROM SUSPENSE BEFORE FILLING" K PSI,SUSX,SUS1,SUS2 Q
;
ACTLOG ;
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
ACTOUT 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
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)
I $D(PSS),PSS K:$D(^PS(55,PSDFN,"P","A",PSS,PSRX)) ^(PSRX)
I PSREA="R",$D(^PSRX(PSRX,2))#2 S ^PS(55,PSDFN,"P","A",+$P(^PSRX(PSRX,2),"^",6),PSRX)=""
Q
;
QUES ;INSTRUCTIONS FOR RENEW AND REFILL
W !?5,"Enter the item #(s) or RX #(s) you wish to ",$S(PSFROM="N":"renew ",PSFROM="R":"REFILL "),"separated by commas."
W !?5,"For example: 1,2,5 or 123456,33254A,232323B."
W !?5,"Do not enter the same number twice, duplicates are not allowed."
Q
ENDVCHK S PSOPOP=0 Q:'PSODIV Q:'$P(^PSRX(PSRX,2),"^",9)!($P(^(2),"^",9)=PSOSITE)
CHK1 I '$P(PSOSYS,"^",2) W !?10,$C(7),"RX# ",$P(^PSRX(PSRX,0),"^")," is not a valid choice. (Different Division)" S PSPOP=1 Q
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
I (ANS']"")!("YNyn"'[$E(ANS)) W !?10,$C(7),"Answer 'YES' or 'NO'." G CHK1
S:$E(ANS)["Nn" PSPOP=1 Q
;PSO*7*259; SET VAR PSOSFN TO CHECK FOR SUSPENDED REFILL
K52 K PSOSFN S SFN=+$O(^PS(52.5,"B",DA(1),0)),PSOSFN=SFN Q:SFN=0
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
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
.S SDT=+$P(^PS(52.5,SFN,0),"^",2) K ^PS(52.5,"C",SDT,SFN)
.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")
.I $P($G(^PS(52.5,SFN,0)),"^",7)="" K ^PS(52.5,"AC",+$P(^PS(52.5,SFN,0),"^",3),SDT,SFN)
.K SFN,SDT
Q
S52 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
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
.I '$D(^PS(52.5,SFN,0))!($P($G(^(0)),"^",5)) Q
.S $P(^PS(52.5,SFN,0),"^",2)=RFID,^PS(52.5,"C",RFID,SFN)=""
.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")
.I $P($G(^PS(52.5,SFN,0)),"^",7)="" S ^PS(52.5,"AC",+$P(^PS(52.5,SFN,0),"^",3),RFID,SFN)=""
K SFN,RFIN,RFID,PSOSX,PSOSXDT Q
KILL N DFN
I SFN D
.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),"^")
.;I $P(^PS(52.5,SFN,0),"^",5) Q
.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)
.I $P($G(^PS(52.5,SFN,0)),"^",7)="" D
..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
..K ^PS(52.5,"AC",DFN,+$P(^PS(52.5,SFN,0),"^",2),SFN)
.I $P($G(^PS(52.5,SFN,0)),"^",7)'="" D
..;Kill CMOP xrefs
..N PSOC7 S PSOC7=$P($G(^PS(52.5,SFN,0)),"^",7)
..I PSOC7="Q"!(PSOC7="P") K ^PS(52.5,"AG",+$P(^PS(52.5,SFN,0),"^",3),SFN) D KCMPX^PSOCMOP(SFN,PSOC7)
..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)
..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)
.K ^PS(52.5,SFN,0),^PS(52.5,SFN,"P"),DFN,SFN,PAT
S CNT=0 F SUB=0:0 S SUB=$O(^PSRX(DA(1),"A",SUB)) Q:'SUB S CNT=SUB
S:DA>5 DA=DA+1 D NOW^%DTC S CNT=CNT+1
S ^PSRX(DA(1),"A",0)="^52.3DA^"_CNT_"^"_CNT,^PSRX(DA(1),"A",CNT,0)=%_"^D^"_DUZ_"^"_DA_"^"
I '$D(PSOXX) S ^PSRX(DA(1),"A",CNT,0)=^PSRX(DA(1),"A",CNT,0)_"Refill "
;if PSOXX not exist, = refill. otherwise, it is a partial.
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
Q
CID ;calculates six months limit on issue dates
;IHS/MSC/PLS - 03/28/11 - Next four lines
;S PSID=X,X="T-6M",%DT="X" D ^%DT S %DT(0)=Y,X=PSID,%DT="EX" D ^%DT K PSID
S PSID=X
S X=$$CIDADJ()
S %DT="X" D ^%DT S %DT(0)=Y,X=PSID,%DT="EX" D ^%DT K PSID
Q
CIDH ;IHS/MSC/PLS - 03/28/11 - Next 3 lines
;S X="T-6M",%DT="X" D ^%DT X ^DD("DD") D EN^DDIOL("Issue Date must be greater or equal to "_Y,"","!")
S X=$$CIDADJ()
S %DT="X" D ^%DT X ^DD("DD") D EN^DDIOL("Issue Date must be greater or equal to "_Y,"","!")
Q
; Result earliest Issue Date
CIDADJ() ;EP - p1011
N RES
S RES="T-6M"
I $G(PSODRUG("IEN")) D
.Q:$$ISSCH^APSPFNC2(PSODRUG("IEN"),"345")
.S RES="T-365"
Q RES
SPR F RF=0:0 S RF=$O(^PSRX(DA(1),1,RF)) Q:'RF S NODE=RF
I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) Q
SREF I $G(NODE) S NODE=NODE-1 G:'$D(^PSRX(DA(1),1,NODE,0)) SREF
I NODE=0 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) Q
S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),1,NODE,0),"^",1) Q
K NODE,RF
Q
KPR F RF=0:0 S RF=$O(^PSRX(DA(1),1,RF)) Q:'RF S NODE=RF
I NODE=DA&(X'="") S NODE=NODE-1 S:NODE=1 NODE=0 G:'NODE ORIG G:NODE>1 KREF
I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
KREF S NODE=NODE-1 G:'NODE EX
I NODE=1 S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
G:NODE=DA&(X'="") KREF G:'$D(^PSRX(DA(1),1,NODE,0)) KREF
ORIG I 'NODE S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),2),"^",2) G EX
S $P(^PSRX(DA(1),3),"^",4)=$P(^PSRX(DA(1),1,NODE,0),"^",1) G EX
EX K NODE,RF
Q
IBSS N PSOHLP S PSOHLP(1,"F")="!!"
S PSOHLP(1)="Entry in this field must match the SERVICE field for pharmacy action"
S PSOHLP(2,"F")="!"
S PSOHLP(2)="types in the IB ACTION TYPE file AND be a valid entry in your"
S PSOHLP(3,"F")="!"
S PSOHLP(3)="SERVICE/SECTION file to generate copay charges!"
S PSOHLP(4,"F")="!!"
D EN^DDIOL(.PSOHLP) K PSOHLP
Q
IBSSR 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
.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
Q
WARN ;
I $G(PSOUNHLD) D Q
.D EN^DDIOL("You cannot delete a refill while removing from Hold! Use the Edit Action.","","$C(7),!!"),EN^DDIOL(" ","","!!")
I $G(CMOP(DA))]""&(+$G(CMOP(DA))<3) D K CMOP Q
.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","","!!")
.D EN^DDIOL(" ","","!!")
K CMOP
;
N PSOL,PSR
S PSR=0 F S PSR=$O(^PSRX(DA(1),1,PSR)) Q:'PSR S PSOL=PSR
I DA=PSOL,$P(^PSRX(DA(1),1,DA,0),"^",18) D Q
.D EN^DDIOL("Refill Released! Use the 'Return to Stock' option!","","$C(7),!!"),EN^DDIOL(" ","","!")
;
;Only allow deletion if last refill *259
I $O(^PSRX(DA(1),1,DA)) D Q
.D EN^DDIOL("Only the last refill can be deleted. Later refills must be deleted first.","","$C(7),!!")
.D EN^DDIOL("","","!!")
;
;Warn of In Process, Only delete if answered Yes ;*259
I $$REFIP^PSOUTLA1(DA(1),DA,"R") D I 'Y Q ;reset $T
. D EN^DDIOL("** Refill has previously been sent to the External Dispense Machine","","!!,?2")
. D EN^DDIOL("** for filling and is still Pending Processing","","$C(7),!,?2")
. D EN^DDIOL("","","!")
. K DIR
. S DIR("A")="Do you want to continue? "
. S DIR("B")="Y"
. S DIR(0)="YA^^"
. S DIR("?")="Enter Y for Yes or N for No."
. D ^DIR
. K DIR
Q
;
WARN1 ;move to PSOUTLA1
D WARN1^PSOUTLA1
Q
;
CAN(PSOXRX) ;Clean up Rx when discontinued
N SUSD,IFN,RF,NODE,DA
Q:'$D(^PSRX(PSOXRX,0))
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
I $D(^PS(52.4,PSOXRX,0)) S DIK="^PS(52.4,",DA=PSOXRX D ^DIK K DIK
I $G(^PSRX(PSOXRX,"H"))]"" K:$P(^PSRX(PSOXRX,"H"),"^") ^PSRX("AH",$P(^PSRX(PSOXRX,"H"),"^"),PSOXRX) S ^PSRX(PSOXRX,"H")=""
; IHS/MSC/PLS - 04/30/08 - Suppress the setting of the Fill Date for prescriptions on HOLD
;I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
Q
ECAN(PSOXRX) ;Clean up Rx when expired
N DA
Q:'$D(^PSRX(PSOXRX,0))
S DA=$O(^PS(52.5,"B",PSOXRX,0)) I DA K DIK S DIK="^PS(52.5," D ^DIK K DIK
I $D(^PS(52.4,PSOXRX,0)) K DIK S DIK="^PS(52.4,",DA=PSOXRX D ^DIK K DIK
I $G(^PSRX(PSOXRX,"H"))]"" K:$P(^PSRX(PSOXRX,"H"),"^") ^PSRX("AH",$P(^PSRX(PSOXRX,"H"),"^"),PSOXRX) S ^PSRX(PSOXRX,"H")=""
; IHS/MSC/PLS - 02/21/08 - Suppress the setting of the Fill Date for prescriptions on HOLD
;I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
Q
CMOP ;CMOP("L")=LAST FILL... if it is orig Rx =0
;CMOP(FILL #)=CMOP status from 52[TRAN=0,DISP=1,RETRAN=2,NOT DISP=3
;If suspended CMOP("S")=CMOP suspense status Q,L,X,P,R
;All returned variables can be killed by K CMOP
;
S CRX=DA
CMOP1 N X
S (CMOP("L"),X)=0 F S X=$O(^PSRX(CRX,1,X)) Q:'X S CMOP("L")=X
I $O(^PSRX(CRX,4,0)) F X=0:0 S X=$O(^PSRX(CRX,4,X)) Q:'X D
.S CMOP($P($G(^PSRX(CRX,4,X,0)),"^",3))=$P($G(^(0)),"^",4)
S X=$O(^PS(52.5,"B",CRX,0)) I X]"" S CMOP("S")=$P($G(^PS(52.5,X,0)),"^",7)
K CRX,X
Q
PSOUTL ;BHAM ISC/SAB - pso utility routine ;29-May-2012 15:16;PLS
+1 ;;7.0;OUTPATIENT PHARMACY;**1,21,126,1006,1011,174,218,259,1015**;DEC 1997;Build 62
+2 ;External reference SERV^IBARX1 supported by DBIA 2245
+3 ;External reference ^PS(55, supported by DBIA 2228
+4 ;
+5 ;*218 prevent refill from being deleted if pending processing via
+6 ; external dispense machines
+7 ;*259 reverse *218 restrictions & Add del only last refill logic.
+8 ; Modified - IHS/MSC/PLS - 02/21/08 - Line ECAN+7 commented out
+9 ; 04/30/08 - Line CAN+7 commented out
+10 ; 03/28/11 - Line CID+1,CIDH, CIDADJ (new EP)
SUSPCAN ;dcl rx from suspense used in new, renew AND verification of Rxs
+1 SET PSLAST=0
FOR PSI=0:0
SET PSI=$ORDER(^PSRX(PSRX,1,PSI))
IF 'PSI
QUIT
SET PSLAST=PSI
+2 IF PSLAST
SET PSI=^PSRX(PSRX,1,PSLAST,0)
KILL ^PSRX(PSRX,1,PSLAST),^PSRX(PSRX,1,"B",+PSI,PSLAST)
SET ^(0)=$PIECE(^PSRX(PSRX,1,0),"^",1,3)_"^"_($PIECE(^(0),"^",4)-1)
KILL PSLAST,PSI,SUSX,SUS1,SUS2
QUIT
+3 SET $PIECE(^PSRX(PSRX,3),"^",7)="DISCONTINUED FROM SUSPENSE BEFORE FILLING"
KILL PSI,SUSX,SUS1,SUS2
QUIT
+4 ;
ACTLOG ;
+1 FOR PSI=0:0
SET PSI=$ORDER(^PSRX(PSRX,"A",PSI))
IF 'PSI!'$ORDER(^(PSI))
SET ^PSRX(PSRX,"A",+PSI+1,0)=DT_"^"_PSREA_"^"_PSOCLC_"^"_PSRXREF_"^"_PSMSG
SET ^PSRX(PSRX,"A",0)="^52.3DA^"_(+PSI+1)_"^"_(+PSI+1)
QUIT
ACTOUT IF PSREA="C"
SET PSI=$SELECT($DATA(^PSRX(PSRX,2)):+$PIECE(^(2),"^",6),1:0)
IF $DATA(^PS(55,PSDFN,"P","A",PSI,PSRX))
KILL ^(PSRX)
SET ^PS(55,PSDFN,"P","A",DT,PSRX)=""
QUIT
+1 IF PSREA="R"
FOR PSI=0:0
SET PSI=$ORDER(^PSRX(PSRX,"A",PSI))
IF 'PSI
QUIT
IF $DATA(^(PSI,0))
IF $PIECE(^(0),"^",2)="C"
SET PSS=+^(0)
+2 IF $DATA(PSS)
IF PSS
IF $DATA(^PS(55,PSDFN,"P","A",PSS,PSRX))
KILL ^(PSRX)
+3 IF PSREA="R"
IF $DATA(^PSRX(PSRX,2))#2
SET ^PS(55,PSDFN,"P","A",+$PIECE(^PSRX(PSRX,2),"^",6),PSRX)=""
+4 QUIT
+5 ;
QUES ;INSTRUCTIONS FOR RENEW AND REFILL
+1 WRITE !?5,"Enter the item #(s) or RX #(s) you wish to ",$SELECT(PSFROM="N":"renew ",PSFROM="R":"REFILL "),"separated by commas."
+2 WRITE !?5,"For example: 1,2,5 or 123456,33254A,232323B."
+3 WRITE !?5,"Do not enter the same number twice, duplicates are not allowed."
+4 QUIT
ENDVCHK SET PSOPOP=0
IF 'PSODIV
QUIT
IF '$PIECE(^PSRX(PSRX,2),"^",9)!($PIECE(^(2),"^",9)=PSOSITE)
QUIT
CHK1 IF '$PIECE(PSOSYS,"^",2)
WRITE !?10,$CHAR(7),"RX# ",$PIECE(^PSRX(PSRX,0),"^")," is not a valid choice. (Different Division)"
SET PSPOP=1
QUIT
+1 IF $PIECE(PSOSYS,"^",3)
WRITE !?10,$CHAR(7),"RX# ",$PIECE(^PSRX(PSRX,0),"^")," is from another division. Continue? (Y/N) "
READ ANS:DTIME
IF ANS="^"!(ANS="")
SET PSPOP=1
QUIT
+2 IF (ANS']"")!("YNyn"'[$EXTRACT(ANS))
WRITE !?10,$CHAR(7),"Answer 'YES' or 'NO'."
GOTO CHK1
+3 IF $EXTRACT(ANS)["Nn"
SET PSPOP=1
QUIT
+4 ;PSO*7*259; SET VAR PSOSFN TO CHECK FOR SUSPENDED REFILL
K52 KILL PSOSFN
SET SFN=+$ORDER(^PS(52.5,"B",DA(1),0))
SET PSOSFN=SFN
IF SFN=0
QUIT
+1 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",5)=$PIECE($GET(^PSRX(+^PS(52.5,SFN,0),"P",0)),"^",3)
IF $PIECE($GET(^PSRX($PIECE(^PS(52.5,SFN,0),"^"),"P",0)),"^",4)=0
NEW PSOXX
SET PSOXX=1
GOTO KILL
+2 IF X'=""&($GET(Y)=1)
GOTO KILL
IF $GET(Y)'=1
IF SFN
IF $DATA(^PS(52.5,SFN,0))
IF '$PIECE(^(0),"^",5)
IF '$PIECE($GET(^("P")),"^")
Begin DoDot:1
+3 SET SDT=+$PIECE(^PS(52.5,SFN,0),"^",2)
KILL ^PS(52.5,"C",SDT,SFN)
+4 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)="Q"
KILL ^PS(52.5,"AQ",SDT,+$PIECE(^PS(52.5,SFN,0),"^",3),SFN)
DO KCMPX^PSOCMOP(SFN,"Q")
+5 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)=""
KILL ^PS(52.5,"AC",+$PIECE(^PS(52.5,SFN,0),"^",3),SDT,SFN)
+6 KILL SFN,SDT
End DoDot:1
+7 QUIT
S52 SET (RIFN,PSOSX)=0
FOR
SET RIFN=$ORDER(^PSRX(DA(1),1,RIFN))
IF 'RIFN
QUIT
SET RFID=$PIECE(^PSRX(DA(1),1,RIFN,0),"^")
SET PSOSX=PSOSX+1
+1 SET SFN=+$ORDER(^PS(52.5,"B",DA(1),0))
IF SFN
IF '$GET(^PS(52.5,SFN,"P"))
IF $PIECE($GET(^PSRX($PIECE($GET(^PS(52.5,SFN,0)),"^"),"STA")),"^")=5
Begin DoDot:1
+2 IF '$DATA(^PS(52.5,SFN,0))!($PIECE($GET(^(0)),"^",5))
QUIT
+3 SET $PIECE(^PS(52.5,SFN,0),"^",2)=RFID
SET ^PS(52.5,"C",RFID,SFN)=""
+4 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)="Q"
SET ^PS(52.5,"AQ",RFID,+$PIECE(^PS(52.5,SFN,0),"^",3),SFN)=""
DO SCMPX^PSOCMOP(SFN,"Q")
+5 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)=""
SET ^PS(52.5,"AC",+$PIECE(^PS(52.5,SFN,0),"^",3),RFID,SFN)=""
End DoDot:1
+6 KILL SFN,RFIN,RFID,PSOSX,PSOSXDT
QUIT
KILL NEW DFN
+1 IF SFN
Begin DoDot:1
+2 SET $PIECE(^PSRX(DA(1),"STA"),"^")=0
IF '$DATA(^PS(52.5,SFN,0))
QUIT
SET DFN=+$PIECE(^PS(52.5,SFN,0),"^",3)
SET PAT=$PIECE(^DPT(DFN,0),"^")
+3 ;I $P(^PS(52.5,SFN,0),"^",5) Q
+4 KILL ^PS(52.5,"B",+$PIECE(^PS(52.5,SFN,0),"^"),SFN),^PS(52.5,"C",+$PIECE(^PS(52.5,SFN,0),"^",2),SFN),^PS(52.5,"D",PAT,SFN),^PS(52.5,"AF",DFN,SFN)
+5 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)=""
Begin DoDot:2
+6 IF $GET(^PS(52.5,SFN,"P"))
KILL ^PS(52.5,"AS",+$PIECE(^(0),"^",8),+$PIECE(^(0),"^",9),+$PIECE(^(0),"^",6),+$PIECE(^(0),"^",11),SFN),^PS(52.5,"ADL",$EXTRACT(+$PIECE(^PS(52.5,SFN,0),"^",8),1,7),SFN)
QUIT
+7 KILL ^PS(52.5,"AC",DFN,+$PIECE(^PS(52.5,SFN,0),"^",2),SFN)
End DoDot:2
+8 IF $PIECE($GET(^PS(52.5,SFN,0)),"^",7)'=""
Begin DoDot:2
+9 ;Kill CMOP xrefs
+10 NEW PSOC7
SET PSOC7=$PIECE($GET(^PS(52.5,SFN,0)),"^",7)
+11 IF PSOC7="Q"!(PSOC7="P")
KILL ^PS(52.5,"AG",+$PIECE(^PS(52.5,SFN,0),"^",3),SFN)
DO KCMPX^PSOCMOP(SFN,PSOC7)
+12 IF PSOC7="X"!(PSOC7="P")!(PSOC7="L")
KILL ^PS(52.5,$SELECT(PSOC7="X":"AX",PSOC7="P":"AP",1:"AL"),$PIECE(^PS(52.5,SFN,0),"^",2),$PIECE(^(0),"^",3),SFN)
DO KCMPX^PSOCMOP(SFN,PSOC7)
+13 KILL ^PS(52.5,"APR",+$PIECE(^PS(52.5,SFN,0),"^",8),+$PIECE(^(0),"^",9),+$PIECE(^(0),"^",6),+$PIECE(^(0),"^",11),SFN),^PS(52.5,"ADL",$EXTRACT(+$PIECE(^PS(52.5,SFN,0),"^",8),1,7),SFN)
End DoDot:2
+14 KILL ^PS(52.5,SFN,0),^PS(52.5,SFN,"P"),DFN,SFN,PAT
End DoDot:1
+15 SET CNT=0
FOR SUB=0:0
SET SUB=$ORDER(^PSRX(DA(1),"A",SUB))
IF 'SUB
QUIT
SET CNT=SUB
+16 IF DA>5
SET DA=DA+1
DO NOW^%DTC
SET CNT=CNT+1
+17 SET ^PSRX(DA(1),"A",0)="^52.3DA^"_CNT_"^"_CNT
SET ^PSRX(DA(1),"A",CNT,0)=%_"^D^"_DUZ_"^"_DA_"^"
+18 IF '$DATA(PSOXX)
SET ^PSRX(DA(1),"A",CNT,0)=^PSRX(DA(1),"A",CNT,0)_"Refill "
+19 ;if PSOXX not exist, = refill. otherwise, it is a partial.
+20 SET ^PSRX(DA(1),"A",CNT,0)=^PSRX(DA(1),"A",CNT,0)_$SELECT($GET(RESK):"returned to stock.",$GET(PSOPSDAL):"deleted during Controlled Subs release.",$GET(PSOXX)=1:"Partial deleted from suspense file.",1:"deleted during Rx edit.")
KILL CNT,SUB
+21 QUIT
CID ;calculates six months limit on issue dates
+1 ;IHS/MSC/PLS - 03/28/11 - Next four lines
+2 ;S PSID=X,X="T-6M",%DT="X" D ^%DT S %DT(0)=Y,X=PSID,%DT="EX" D ^%DT K PSID
+3 SET PSID=X
+4 SET X=$$CIDADJ()
+5 SET %DT="X"
DO ^%DT
SET %DT(0)=Y
SET X=PSID
SET %DT="EX"
DO ^%DT
KILL PSID
+6 QUIT
CIDH ;IHS/MSC/PLS - 03/28/11 - Next 3 lines
+1 ;S X="T-6M",%DT="X" D ^%DT X ^DD("DD") D EN^DDIOL("Issue Date must be greater or equal to "_Y,"","!")
+2 SET X=$$CIDADJ()
+3 SET %DT="X"
DO ^%DT
XECUTE ^DD("DD")
DO EN^DDIOL("Issue Date must be greater or equal to "_Y,"","!")
+4 QUIT
+5 ; Result earliest Issue Date
CIDADJ() ;EP - p1011
+1 NEW RES
+2 SET RES="T-6M"
+3 IF $GET(PSODRUG("IEN"))
Begin DoDot:1
+4 IF $$ISSCH^APSPFNC2(PSODRUG("IEN"),"345")
QUIT
+5 SET RES="T-365"
End DoDot:1
+6 QUIT RES
SPR FOR RF=0:0
SET RF=$ORDER(^PSRX(DA(1),1,RF))
IF 'RF
QUIT
SET NODE=RF
+1 IF NODE=1
SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),2),"^",2)
QUIT
SREF IF $GET(NODE)
SET NODE=NODE-1
IF '$DATA(^PSRX(DA(1),1,NODE,0))
GOTO SREF
+1 IF NODE=0
SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),2),"^",2)
QUIT
+2 SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),1,NODE,0),"^",1)
QUIT
+3 KILL NODE,RF
+4 QUIT
KPR FOR RF=0:0
SET RF=$ORDER(^PSRX(DA(1),1,RF))
IF 'RF
QUIT
SET NODE=RF
+1 IF NODE=DA&(X'="")
SET NODE=NODE-1
IF NODE=1
SET NODE=0
IF 'NODE
GOTO ORIG
IF NODE>1
GOTO KREF
+2 IF NODE=1
SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),2),"^",2)
GOTO EX
KREF SET NODE=NODE-1
IF 'NODE
GOTO EX
+1 IF NODE=1
SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),2),"^",2)
GOTO EX
+2 IF NODE=DA&(X'="")
GOTO KREF
IF '$DATA(^PSRX(DA(1),1,NODE,0))
GOTO KREF
ORIG IF 'NODE
SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),2),"^",2)
GOTO EX
+1 SET $PIECE(^PSRX(DA(1),3),"^",4)=$PIECE(^PSRX(DA(1),1,NODE,0),"^",1)
GOTO EX
EX KILL NODE,RF
+1 QUIT
IBSS NEW PSOHLP
SET PSOHLP(1,"F")="!!"
+1 SET PSOHLP(1)="Entry in this field must match the SERVICE field for pharmacy action"
+2 SET PSOHLP(2,"F")="!"
+3 SET PSOHLP(2)="types in the IB ACTION TYPE file AND be a valid entry in your"
+4 SET PSOHLP(3,"F")="!"
+5 SET PSOHLP(3)="SERVICE/SECTION file to generate copay charges!"
+6 SET PSOHLP(4,"F")="!!"
+7 DO EN^DDIOL(.PSOHLP)
KILL PSOHLP
+8 QUIT
IBSSR SET PSOIBFL=0
FOR PSOIBLP=0:0
SET PSOIBLP=$ORDER(^DIC(49,PSOIBLP))
IF 'PSOIBLP!(PSOIBFL)
QUIT
SET Y=PSOIBLP
SET PSOIBST=$$SERV^IBARX1(+Y)
IF $GET(PSOIBST)
SET DIE="^PS(59,"
SET DA=PSOSITE
SET DR="1003////"_PSOIBLP
DO ^DIE
KILL DIE
Begin DoDot:1
+1 WRITE $CHAR(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!"
QUIT
End DoDot:1
SET PSOIBFL=1
+2 QUIT
WARN ;
+1 IF $GET(PSOUNHLD)
Begin DoDot:1
+2 DO EN^DDIOL("You cannot delete a refill while removing from Hold! Use the Edit Action.","","$C(7),!!")
DO EN^DDIOL(" ","","!!")
End DoDot:1
QUIT
+3 IF $GET(CMOP(DA))]""&(+$GET(CMOP(DA))<3)
Begin DoDot:1
+4 DO EN^DDIOL("You cannot delete a refill that"_$SELECT(+$GET(CMOP(DA))=1:" has been released by",1:" is being transmitted to")_" the CMOP","","!!")
+5 DO EN^DDIOL(" ","","!!")
End DoDot:1
KILL CMOP
QUIT
+6 KILL CMOP
+7 ;
+8 NEW PSOL,PSR
+9 SET PSR=0
FOR
SET PSR=$ORDER(^PSRX(DA(1),1,PSR))
IF 'PSR
QUIT
SET PSOL=PSR
+10 IF DA=PSOL
IF $PIECE(^PSRX(DA(1),1,DA,0),"^",18)
Begin DoDot:1
+11 DO EN^DDIOL("Refill Released! Use the 'Return to Stock' option!","","$C(7),!!")
DO EN^DDIOL(" ","","!")
End DoDot:1
QUIT
+12 ;
+13 ;Only allow deletion if last refill *259
+14 IF $ORDER(^PSRX(DA(1),1,DA))
Begin DoDot:1
+15 DO EN^DDIOL("Only the last refill can be deleted. Later refills must be deleted first.","","$C(7),!!")
+16 DO EN^DDIOL("","","!!")
End DoDot:1
QUIT
+17 ;
+18 ;Warn of In Process, Only delete if answered Yes ;*259
+19 ;reset $T
IF $$REFIP^PSOUTLA1(DA(1),DA,"R")
Begin DoDot:1
+20 DO EN^DDIOL("** Refill has previously been sent to the External Dispense Machine","","!!,?2")
+21 DO EN^DDIOL("** for filling and is still Pending Processing","","$C(7),!,?2")
+22 DO EN^DDIOL("","","!")
+23 KILL DIR
+24 SET DIR("A")="Do you want to continue? "
+25 SET DIR("B")="Y"
+26 SET DIR(0)="YA^^"
+27 SET DIR("?")="Enter Y for Yes or N for No."
+28 DO ^DIR
+29 KILL DIR
End DoDot:1
IF 'Y
QUIT
+30 QUIT
+31 ;
WARN1 ;move to PSOUTLA1
+1 DO WARN1^PSOUTLA1
+2 QUIT
+3 ;
CAN(PSOXRX) ;Clean up Rx when discontinued
+1 NEW SUSD,IFN,RF,NODE,DA
+2 IF '$DATA(^PSRX(PSOXRX,0))
QUIT
+3 SET DA=$ORDER(^PS(52.5,"B",PSOXRX,0))
IF DA
SET DIK="^PS(52.5,"
SET SUSD=$PIECE($GET(^PS(52.5,DA,0)),"^",2)
DO ^DIK
KILL DIK
IF $ORDER(^PSRX(PSOXRX,1,0))
SET DA=PSOXRX
DO REF^PSOCAN2
+4 IF $DATA(^PS(52.4,PSOXRX,0))
SET DIK="^PS(52.4,"
SET DA=PSOXRX
DO ^DIK
KILL DIK
+5 IF $GET(^PSRX(PSOXRX,"H"))]""
IF $PIECE(^PSRX(PSOXRX,"H"),"^")
KILL ^PSRX("AH",$PIECE(^PSRX(PSOXRX,"H"),"^"),PSOXRX)
SET ^PSRX(PSOXRX,"H")=""
+6 ; IHS/MSC/PLS - 04/30/08 - Suppress the setting of the Fill Date for prescriptions on HOLD
+7 ;I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
+8 QUIT
ECAN(PSOXRX) ;Clean up Rx when expired
+1 NEW DA
+2 IF '$DATA(^PSRX(PSOXRX,0))
QUIT
+3 SET DA=$ORDER(^PS(52.5,"B",PSOXRX,0))
IF DA
KILL DIK
SET DIK="^PS(52.5,"
DO ^DIK
KILL DIK
+4 IF $DATA(^PS(52.4,PSOXRX,0))
KILL DIK
SET DIK="^PS(52.4,"
SET DA=PSOXRX
DO ^DIK
KILL DIK
+5 IF $GET(^PSRX(PSOXRX,"H"))]""
IF $PIECE(^PSRX(PSOXRX,"H"),"^")
KILL ^PSRX("AH",$PIECE(^PSRX(PSOXRX,"H"),"^"),PSOXRX)
SET ^PSRX(PSOXRX,"H")=""
+6 ; IHS/MSC/PLS - 02/21/08 - Suppress the setting of the Fill Date for prescriptions on HOLD
+7 ;I '$P($G(^PSRX(PSOXRX,2)),"^",2) K DIE S DIE="^PSRX(",DA=PSOXRX,DR="22///"_DT D ^DIE
+8 QUIT
CMOP ;CMOP("L")=LAST FILL... if it is orig Rx =0
+1 ;CMOP(FILL #)=CMOP status from 52[TRAN=0,DISP=1,RETRAN=2,NOT DISP=3
+2 ;If suspended CMOP("S")=CMOP suspense status Q,L,X,P,R
+3 ;All returned variables can be killed by K CMOP
+4 ;
+5 SET CRX=DA
CMOP1 NEW X
+1 SET (CMOP("L"),X)=0
FOR
SET X=$ORDER(^PSRX(CRX,1,X))
IF 'X
QUIT
SET CMOP("L")=X
+2 IF $ORDER(^PSRX(CRX,4,0))
FOR X=0:0
SET X=$ORDER(^PSRX(CRX,4,X))
IF 'X
QUIT
Begin DoDot:1
+3 SET CMOP($PIECE($GET(^PSRX(CRX,4,X,0)),"^",3))=$PIECE($GET(^(0)),"^",4)
End DoDot:1
+4 SET X=$ORDER(^PS(52.5,"B",CRX,0))
IF X]""
SET CMOP("S")=$PIECE($GET(^PS(52.5,X,0)),"^",7)
+5 KILL CRX,X
+6 QUIT