Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSOPRK

PSOPRK.m

Go to the documentation of this file.
PSOPRK ;BIR/EJW - park/unpark functionality ; May 17, 2023@18:30:42
 ;;7.0;OUTPATIENT PHARMACY;**441,712**;DEC 1997;Build 20
 ;
 ; Reference to ^DD(52 in ICR #999
 ; Reference to ^PSDRUG( in ICR #221
 ; Reference to $$L^PSSLOCK,PSOL^PSSLOCK,PSOUL^PSSLOCK,UL^PSSLOCK in ICR #2789
 ;
UNPARK ;
 N RXIEN,PSOOLDFILLDT
 I '$D(PSOPAR) D ^PSOLSET G:'$D(PSOPAR) EX
 I $G(PSOBEDT),$G(PSOREJCT) W $C(7),$C(7) S VALMSG="Invalid Action at this time !",VALMBCK="" Q
 I $G(PSONACT) W $C(7),$C(7) S VALMSG="No Pharmacy Orderable Item !",VALMBCK="" Q
 S PSOPLCK=$$L^PSSLOCK(PSODFN,0) I '$G(PSOPLCK) D LOCK^PSOORCPY S VALMSG=$S($P($G(PSOPLCK),"^",2)'="":$P($G(PSOPLCK),"^",2)_" is working on this patient.",1:"Another person is entering orders for this patient.") K PSOPLCK S VALMBCK="" Q
 K PSOPLCK D PSOL^PSSLOCK(DA) I '$G(PSOMSG) S VALMSG=$S($P($G(PSOMSG),"^",2)'="":$P($G(PSOMSG),"^",2),1:"Another person is editing this order."),VALMBCK="" K PSOMSG D ULP Q
 S Y(0)=^PSRX(DA,0),STA=+$G(^("STA"))
 I STA!('$G(^PSRX(DA,"PARK"))) S VALMSG="Cannot unpark. Prescription is not parked.",VALMBCK="" Q
 I STA'=0!(('$D(^XUSEC("PSORPH",DUZ)))&('$D(^XUSEC("PSO TECH ADV",DUZ)))) S VALMSG="Invalid Action Selection!",VALMBCK="" K Y,STA D PSOUL^PSSLOCK(DA) D ULP Q
 D FULL^VALM1 K DIR,DTOUT,DUOUT,DIRUT
 I DT>$P(^PSRX(DA,2),"^",6) D  D ULP G EX
 .S (VALMSG,COMM)="Medication Expired on "_$E($P(^PSRX(DA,2),"^",6),4,5)_"-"_$E($P(^(2),"^",6),6,7)_"-"_$E($P(^(2),"^",6),2,3) I $P(^PSRX(DA,"STA"),"^")<11 S $P(^PSRX(DA,"STA"),"^")=11
 .D KILLPARK(DA) D EN^PSOHLSN1(DA,"SC","ZE",COMM,"") K COMM
EN S RXF=0 F I=0:0 S I=$O(^PSRX(DA,1,I)) Q:'I  S RXF=I,RSDT=$P(^(I,0),"^")
 S PSOOLDFILLDT=$S(RXF:$P(^PSRX(DA,1,RXF,0),U,1),1:$P(^PSRX(DA,2),U,2))
 S RXIEN=DA
 K Y I RXF D  I $D(Y) D ULP G EX
 .N DA,DIE S DA(1)=RXIEN,DA=RXF,DIE="^PSRX("_DA(1)_",1,",PSOUNPRK=1
 .S RLDT=$P(^PSRX(DA(1),1,DA,0),"^",18)
 .I 'RLDT D
 ..I RSDT<DT D  ;Do not display a past date for refill date
 ...N Y,TD S Y=DT X ^DD("DD") S TD=Y
 ...S DR=".01R///^S X=TD"
 ...D ^DIE
 ..I $D(Y) D  ;User quit the UNPARK process
 ...I RSDT<DT D  ;reset refill date
 ....N Y,TD S Y=RSDT X ^DD("DD") S TD=Y
 ....S DR=".01R///^S X=TD"
 ....D ^DIE
 .S ZD(RXIEN)=$P(^PSRX(DA(1),1,DA,0),"^")
 .K PSOUNPRK Q:$D(Y)  S PSORX("FILL DATE")=ZD(RXIEN),DA=PSDA K DA(1)
 ;
 ;PSO*7*298 Require an entry into fill date
 S ACT=1,DIE="^PSRX(",FDT=$S($P(^PSRX(RXIEN,2),"^",2):$P(^PSRX(RXIEN,2),"^",2),$P(^PSRX(RXIEN,3),"^",2):$P(^PSRX(RXIEN,3),"^",2),1:DT)
 I FDT<DT S FDT=DT
 S RLDT=$P(^PSRX(DA,2),"^",13),DR="",RLDTP1=$P(RLDT,".",1)
 I 'RXF&'RLDT S DR="22R//^S X=FDT;Q;"
 ; DON'T INCLUDE PROMPT FOR PARK IF UNPARKING
 I RLDT&($P(^PSRX(DA,2),"^",2)="") S DR="22R//^S X=RLDTP1;Q;"
 S DR=DR_"100///0;101///^S X=$S(RXF:$G(ZD(RXIEN)),1:$P(^PSRX(RXIEN,2),""^"",2))"
 ;
 D ^DIE K FDT I $D(Y) S VALMBCK="R" D ULP G EX
 I $G(PSOFRPK) D KILLPARK(DA) G UMSG
 N PRKMW D MW I PRKMW="" S VALMBCK="R" D ULP G EX
 D KILLPARK(DA)
 I 'RXF S $P(^PSRX(DA,0),"^",11)=PRKMW
 I RXF,$D(^PSRX(DA,1,RXF,0)) S $P(^PSRX(DA,1,RXF,0),"^",2)=PRKMW
UMSG S VALMSG="RX# "_$P(^PSRX(DA,0),"^")_" unparked"
 D RXACT(DA,"UPK")
 N PSONOOR,COMM S PSONOOR="I" ; Default to POLICY
 S COMM="Medication Removed from Park by Pharmacy" D EN^PSOHLSN1(RXIEN,"SC","",COMM,PSONOOR) K COMM
 S PSORX("FILL DATE")=$S('RXF:$P(^PSRX(DA,2),"^",2),1:ZD(RXIEN)) D KILLPARK(DA)
 S (NEW1,NEW11)="^^"
 S (RXF,RXFL(DA))=0 F JJ=0:0 S JJ=$O(^PSRX(DA,1,JJ)) Q:'JJ  S (RXFL(RXIEN),RXF)=JJ
 I $G(PSXSYS) D UNPARK^PSOCMOPA I $G(XFLAG) D ULP G EX
 I $G(RXIEN) N REFCK S REFCK=0 D REFCK I $G(REFCK) D  D ULP G EX
 . I $$TITRX^PSOUTL(RXIEN)="t" S VALMSG=VALMSG_" - Cannot Refill Titration Rx" Q
 . I $O(^PS(52.41,"ARF",RXIEN,0)) S VALMSG=VALMSG_" - Refill request exists" Q
 . N X,Y,DIC,JJ
 . S X=$G(PSORX("PATIENT STATUS")) S:'X X=$P(RX0,"^",3)
 . S DIC=53,DIC(0)="QXZ" D ^DIC
 . S JJ=$$MAXNUMRF^PSOUTIL(+$G(PSODRUG("IEN")),$P(RX0,"^",8),+Y,.CLOZPAT) I 'JJ S VALMSG=VALMSG_" - Not Refillable" Q
 . K X,Y,DIC,JJ
 . N PSOREF S PSOREF("MAIL/WINDOW")=$G(PRKMW),PSOREF("IRXN")=RXIEN D ^PSOREF0  ; create a refill
 ; IF FUTURE DATE, PUT ON SUSPENSE WHEN UNPARKED
 I PSORX("FILL DATE")>DT,$P(PSOPAR,"^",6) D S^PSORXL,EX,ULP Q
 S PCOMH(RXIEN)="Medication Removed from Park by Pharmacy"
 I $G(RXIEN) S RXRH(RXIEN)=RXIEN
 ; MARK PRESCRIPTION AND LABEL AS BEING REPRINTED WHEN UNPARKING A RETURNED TO STOCK PRESCRIPTION
 I $P($G(^PSRX(RXIEN,2)),"^",15)'="" S $P(^PSRX(RXIEN,2),"^",14)=1,RXRP(RXIEN)=1,$P(RXRP(RXIEN),"^",2)=$P($G(^PSRX(RXIEN,0)),"^",18)
 ;
 ; - Submitting Rx to ECME
 N ACTION
 I $$SUBMIT^PSOBPSUT(RXIEN,+$G(RXFL(RXIEN))) D  I ACTION="Q"!(ACTION="^") D ULP G EX
 . N RX,RFL S RX=RXIEN,RFL=+$G(RXFL(RXIEN))
 . N DA S ACTION=""
 . D ECMESND^PSOBPSU1(RX,RFL,,$S(RFL:"RF",1:"OF"))
 . ; Quit if there is an unresolved TRICARE/CHAMPVA non-billable reject code, PSO*7*358
 . I $$PSOET^PSOREJP3(RX,RFL) S ACTION="Q" Q
 . I $$FIND^PSOREJUT(RX,RFL) D
 .. S ACTION=$$HDLG^PSOREJU1(RX,RFL,"79,88","ED","IOQ","Q")
 ;
 I $G(PSORX("PSOL",1))']"" S PSORX("PSOL",1)=RXIEN_"," D ULP G EX
 F PSOX1=0:0 S PSOX1=$O(PSORX("PSOL",PSOX1)) Q:'PSOX1  S PSOX2=PSOX1
 I $L(PSORX("PSOL",PSOX2))+$L(DA)<220 S PSORX("PSOL",PSOX2)=PSORX("PSOL",PSOX2)_RXIEN_","
 E  S PSORX("PSOL",PSOX2+1)=RXIEN_","
 ;
 D ULP
EX ;
 ; If called from edit (changed to or from Park), don't unlock/kill
 I $G(PSOTOPK) K DR Q
 I $G(PSOFRPK) K DR Q
 D PSOUL^PSSLOCK($P(PSOLST(ORN),"^",2)) D ^PSOBUILD
 K PSOHRL,PSOMSG,PSOPLCK,ST,PSL,PSNP,IR,NOW,DR,NEW1,NEW11,RTN,DA,PPL,RXN,RX0,RXS,DIK,RXP,FLD,ACT,DIE,DIC,DIR,DIE,X,Y,DIRUT,DUOUT,SUSPT,C,D0,LFD,I,PSDA,RFDATE,DI,DQ,%,RFN,XFLAG
 K HRX,PSPRK,PSOLIST,PSORX("FILL DATE"),STA,QTY,RFDT,PSORX0,PSRXN,RXF,JJ Q
 ;
PARK(DA)  ;
 N PSODRUG
 S PSODRUG("DEA")=$P(^PSDRUG($P(^PSRX(DA,0),"^",6),0),"^",3)
 N RESULTS,PSOPARKX
 S RESULTS="PSOPARKX" D GETPARK^PSORPC01()
 I $G(PSOPARKX(0))'="YES" S VALMSG="Park a Prescription is turned off, Invalid Action !",VALMBCK="" Q
 I $G(PSOBEDT) W $C(7),$C(7) S VALMSG="Invalid Action at this time !",VALMBCK="" Q
 I $G(PSONACT) W $C(7),$C(7) S VALMSG="No Pharmacy Orderable Item !",VALMBCK="" Q
 I $G(PSODRUG("DEA"))["D" W $C(7),$C(7) S VALMSG="This drug is not allowed to be parked!",VALMBCK="" Q
 I $P(^PSDRUG($P(^PSRX(DA,0),"^",6),0),"^")["CLOZAPINE" W $C(7),$C(7) S VALMSG="This drug is not allowed to be parked!",VALMBCK="" Q
 I '$D(^XUSEC("PSORPH",DUZ))&'$D(^XUSEC("PSO TECH ADV",DUZ)) S VALMSG="Invalid Action Selection!",VALMBCK="" Q
 I $G(^PSRX(DA,"PARK")),+$G(^PSRX(DA,"STA"))=0 S VALMSG="Already parked!",VALMBCK="" Q
 S PSOPLCK=$$L^PSSLOCK(PSODFN,0) I '$G(PSOPLCK) D LOCK^PSOORCPY S VALMSG=$S($P($G(PSOPLCK),"^",2)'="":$P($G(PSOPLCK),"^",2)_" is working on this patient.",1:"Another person is entering orders for this patient."),VALMBCK="" K PSOPLCK Q
 K PSOPLCK D PSOL^PSSLOCK(DA) I '$G(PSOMSG) S VALMSG=$S($P($G(PSOMSG),"^",2)'="":$P($G(PSOMSG),"^",2),1:"Another person is editing this order."),VALMBCK="" K PSOMSG D ULP Q
 S Y(0)=^PSRX(DA,0),STA=+$G(^("STA")) I DT>$P(^PSRX(DA,2),"^",6) D  D ULP G D1
 .S VALMSG="Medication Expired on "_$E($P(^PSRX(DA,2),"^",6),4,5)_"-"_$E($P(^(2),"^",6),6,7)_"-"_$E($P(^(2),"^",6),2,3),VALMBCK="R"
 .I $P(^PSRX(DA,"STA"),"^")<11 S $P(^PSRX(DA,"STA"),"^")=11 D
 ..S COMM="Medication Expired on "_$E($P(^PSRX(DA,2),"^",6),4,5)_"-"_$E($P(^(2),"^",6),6,7)_"-"_$E($P(^(2),"^",6),2,3) D EN^PSOHLSN1(DA,"SC","ZE",COMM) K COMM
 S ST=$P("ERROR^ACTIVE^NON-VERIFIED^REFILL^HOLD^NON-VERIFIED^SUSPENDED^^^^^DONE^EXPIRED^DISCONTINUED^DELETED^DISCONTINUED^DISCONTINUED (EDIT)^PROVIDER HOLD^","^",STA+2)
 I STA,STA'>4!(STA>11) D  D ULP G D1
 .S VALMSG="Rx: "_$P(Y(0),"^")_" is currently in a status of "_ST,VALMBCK="R" K ST,Y Q
 D FULL^VALM1
 S PSOFROM="PARK" D EN^PSOCMOPA K PSOFROM I $G(XFLAG) K XFLAG D ULP G D1
AR ;
 D:$D(PSORX("PSOL")) RMP^PSOPRKA(DA)
 F PI=1:1 Q:$P(PPL,",",PI)=""  S DA=$P(PPL,",",PI) D PRK(DA) S DA=PSDA K PSDA D:$D(PSORX("PSOL")) RMP^PSOPRKA(DA)
 K PI D ^PSOBUILD
 D ULP
D1 D PSOUL^PSSLOCK($P(PSOLST(ORN),"^",2)) K PSOMSG,PSOPLCK,RFN,DIR,RSDT,FLD,DA,ACT,X,Y,DIRUT,DUOUT,DTOUT,DIROUT
 Q
 ;
PRK(DA) ; - Rx Park update
 ; Recheck DEA code in case called from somewhere else
 N PSODRUG
 S PSODRUG("DEA")=$P(^PSDRUG($P(^PSRX(DA,0),"^",6),0),"^",3)
 I PSODRUG("DEA")["D" Q  ; DRUG MARKED AS NOT PARKABLE
 D PARK^PSOPRKA(DA)
 Q
 ;
ULP ;
 D UL^PSSLOCK(+$G(PSODFN))
 Q
 ;
KILLPARK(RX) ; KILL PARK level and APARK xref
 K ^PSRX(RX,"PARK"),^PSRX("APARK",1,RX)
 Q
 ;
RXACT(RX,ACTION,REASON,OTHCOM,SUS) ; Adds PARK/UNPARK info to the Rx Activity Log
 N RFL,X,DIC,DA,DD,DO,DR,DINUM,Y,DLAYGO,COMM,PSOFILLDT,PSOFLDNM
 S RFL=$$LSTRFL^PSOBPSU1(RX)
 I ACTION="PK" S COMM="Rx placed in Parked status"_$S(+$G(SUS):" and removed from SUSPENSE",1:"")_" ("_$E(DT,4,5)_"-"_$E(DT,6,7)_"-"_$E(DT,2,3)_")"_"("_$G(BPMW)_")"
 I ACTION="UPK" S COMM="Rx removed from Parked status ("_$E(DT,4,5)_"-"_$E(DT,6,7)_"-"_$E(DT,2,3)_")"
 S DA(1)=RX,DIC="^PSRX("_RX_",""A"",",DLAYGO=52.3,DIC(0)="L" S:$G(OTHCOM)'="" OTHCOM=$TR(OTHCOM,";",","),COMM=COMM_" -"
 S DIC("DR")=".02////E;.03////"_DUZ_";.04///"_$S((RFL>5):RFL+1,1:RFL)_";.05///"_COMM_$S($G(OTHCOM)'="":";4///"_OTHCOM,1:"")
 S X=$$NOW^XLFDT() D FILE^DICN
 ;
 I $G(PSOFRPK)!($G(PSOTOPK)) Q   ;if park/unpark called from EDIT, that process should update Activity log
 S COMM=$P($G(^DD(52,11,0)),"^")_" ("_$S(ACTION="UPK":"P",1:$G(BPMW))_"),"
 S PSOFILLDT=$S(RFL:$P($G(^PSRX(RX,1,RFL,0)),U,1),1:$P($G(^PSRX(RX,2)),U,2))
 I $D(PSOOLDFILLDT),PSOFILLDT'=PSOOLDFILLDT D
 . N ZZ S ZZ=PSOOLDFILLDT S:ZZ ZZ=$E(ZZ,4,5)_"-"_$E(ZZ,6,7)_"-"_$E(ZZ,2,3)
 . S PSOFLDNM=$P($G(^DD(52,22,0)),U,1)
 . I RFL S PSOFLDNM=$P($G(^DD(52.1,.01,0)),U,1)
 . S COMM=COMM_PSOFLDNM_" ("_ZZ_")"
 S DIC("DR")=".02////E;.03////"_DUZ_";.04///"_$S((RFL>5):RFL+1,1:RFL)_";.05///"_COMM
 D FILE^DICN
 ;
 Q
 ;
MW ; WHEN UNPARKING, DON'T PROMPT FOR PARK
 I $G(PSOFRPK) Q  ; If unpark called from EDIT, already prompted for this field
 K DIR
 S PRKMW=""
 S DIR(0)="S^M:MAIL;W:WINDOW",DIR("A")="MAIL/WINDOW"
 S DIR("B")="MAIL"
 D ^DIR
 I X[U!($G(DIRUT)) K Y Q
 S PRKMW=Y
MWX K DIR,X,Y
 Q
 ;
MWP(PSODA,PREVMWP,REFILL) ; UNHOLD;EDIT ROUTE - CHECK TO SEE IF SHOULD ALSO PROMPT FOR PARK
 N PSODRUG,PARK,PREVMWP1
 K PSOTOPK,PSOFRPK
 I $G(PREVMWP)="" S PREVMWP="M" ; SAVE "BEFORE" PICKUP ROUTE
 S PREVMWP1=$S(PREVMWP="W":"WINDOW",PREVMWP="P":"PARK",1:"MAIL")
 S PARK=0 ; SEE WHETHER TO PROMPT FOR PARK
 ;I $P($G(PSOPAR),"^",34) S PARK=1
 N RESULTS,PSOPARKX
 S RESULTS="PSOPARKX" D GETPARK^PSORPC01()
 I $G(PSOPARKX(0))="YES" S PARK=1
 I $P(^PSDRUG($P(^PSRX(PSODA,0),"^",6),0),"^")["CLOZAPINE" S PARK=0  ;*712
 S PSODRUG("DEA")=$P(^PSDRUG($P(^PSRX(PSODA,0),"^",6),0),"^",3) I PSODRUG("DEA")["D" S PARK=0
 K DIR,DIC
 S PRKMW=""
 S DIR(0)="S^M:MAIL;W:WINDOW;P:PARK",DIR("A")="MAIL/WINDOW/PARK"
 I 'PARK S DIR(0)="S^M:MAIL;W:WINDOW",DIR("A")="MAIL/WINDOW"
 S DIR("B")=PREVMWP1
 D ^DIR
 I X[U!($G(DIRUT)) K Y Q
 S PRKMW=Y
 I PRKMW="P",PREVMWP'="P" S PSOTOPK=1 ; SET VARIABLE FOR CALLING ROUTINE TO FILE PARK LEVEL,"APARK" XREF, AND REMOVE FROM SUSPENSE AND UPDT ACT. LOG RELATED TO PARKING
 I PREVMWP="P",PRKMW'="P" S PSOFRPK=1 ; CHANGED "FROM" PARK
 K X,Y
 Q
 ;
REFCK ;
 N RSDT,LBLP
 S (RSDT,LBLP)=0
 D GETRELDT^PSOPRKA(DA)
 I 'RSDT D CHKLBL^PSOPRKA(DA,RXF)
 I 'RSDT,'LBLP D ^PSOCMOPA
 I RSDT!(LBLP)!($D(PSOCMOP)) S REFCK=1
 Q
 ;