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

PSOMAUEX.m

Go to the documentation of this file.
  1. PSOMAUEX ;BIR/SAB-Auto expire of prescriptions ; 10/10/07 11:17am
  1. ;;7.0;OUTPATIENT PHARMACY;**40,73,139,148,257**;DEC 1997;Build 19
  1. ;;
  1. ;External reference to STATUS^ORQOR2 is supported by DBIA 3458
  1. ;External reference to ^PS(59.7 is supported by DBIA 694
  1. ;External reference to LOCK1^ORX2 and UNLK1^ORX2 are supported by DBIA 867
  1. ;
  1. I '$G(DT) S DT=$$DT^XLFDT
  1. W @IOF,!!?10," ******* Auto Expire of Prescriptions *******"
  1. W !!,"You need to run this job only if expired prescriptions are showing up as active"
  1. W !,"orders on the Orders tab in CPRS. This could be due to the following:"
  1. W !,"1. The Expire Prescriptions [PSO EXPIRE PRESCRIPTIONS] option was not"
  1. W !," queued as a daily task. ***** AND *****"
  1. W !,"2. Those patient's prescription(s) were never being accessed/viewed in"
  1. W !," Patient Prescription Processing [PSO LM BACKDOOR ORDERS] option.",!
  1. W !,"*******************************************************************************"
  1. W !,"* For sites that have not queued the Expire Prescriptions job on their *"
  1. W !,"* daily task schedule, you should do so by selecting the Queue Background *"
  1. W !,"* Jobs [PSO AUTOQUEUE JOBS] option from the Maintenance (Outpatient Pharmacy) *"
  1. W !,"* [PSO MAINTENANCE] option and in the Edit Option Schedule template make an *"
  1. W !,"* entry for Expire Prescriptions [PSO EXPIRE PRESCRIPTIONS] option and *"
  1. W !,"* schedule it to run daily. *"
  1. W !,"*******************************************************************************"
  1. W !!
  1. S ZZDT=$S($P($G(^PS(59.7,1,49.99)),"^",7):$P(^PS(59.7,1,49.99),"^",7),1:$P($G(^PS(59.7,1,49.99)),"^",4))
  1. I 'ZZDT D Q ; V7.0 inst. dt not found, quit this job
  1. .W !!!,"***** Outpatient installation date was not found, *****"
  1. .W !,"***** therefore this job cannot be run!!!!! *****",!!
  1. ;
  1. ; - Ask for START DATE
  1. K %DT S %DT(0)=-DT,%DT="AEP",%DT("A")="Start Date: "
  1. S %DT("B")=$$FMTE^XLFDT($$FMADD^XLFDT(ZZDT\1,-121))
  1. W ! D ^%DT I Y<0!($D(DTOUT)) Q
  1. S ZZDT=Y
  1. ;
  1. K %DT D NOW^%DTC S %DT="RAEX",%DT(0)=%,%DT("A")="Select the Date/Time to queue this job: "
  1. W ! D ^%DT K %DT I $D(DTOUT)!(Y<0) W !!!?10,"Job not queued!" Q
  1. S ZTDTH=$G(Y),ZTSAVE("ZZDT")="",ZTIO="",ZTRTN="EN^PSOMAUEX",ZTDESC="Auto expire of Rxs "
  1. D ^%ZTLOAD
  1. W:$D(ZTSK) !!,"Task Queued !",!
  1. Q
  1. EN ;
  1. N PSOSVDT
  1. S PSOSVDT=""
  1. S X1=DT,X2=-1 D C^%DTC S CDT=X ; setting the end date to to today-1
  1. F S ZZDT=$O(^PSRX("AG",ZZDT)) Q:'ZZDT!(ZZDT>CDT) D EN1 S PSOSVDT=ZZDT
  1. I PSOSVDT>($P(^PS(59.7,1,49.99),"^",8)) D
  1. .S DIE=59.7,DA=1,DR="49.95///"_PSOSVDT D ^DIE K DIE,DA,DR
  1. K PSOEXRX,PSOEXSTA,ZZDT,CDT,ORN,PIFN,PSUSD,PRFDT,PDA,PSDTEST S:$D(ZTQUEUED) ZTREQ="@"
  1. Q
  1. EN1 ;
  1. F PSOEXRX=0:0 S PSOEXRX=$O(^PSRX("AG",ZZDT,PSOEXRX)) Q:'PSOEXRX D
  1. .Q:$P($G(^PSRX(PSOEXRX,2)),"^",6)'=ZZDT
  1. .I $D(^PSRX(PSOEXRX,0)) D EN2
  1. Q
  1. EN2 ;
  1. N CPRSDC,CPRSSTA
  1. S CPRSDC=",1,7,12,13,"
  1. S ORN=$P($G(^PSRX(PSOEXRX,"OR1")),"^",2),CPRSSTA=""
  1. I ORN S CPRSSTA=+$$STATUS^ORQOR2(ORN)
  1. S DA=PSOEXRX K CMOP D ^PSOCMOPA
  1. S DA=$O(^PS(52.5,"B",PSOEXRX,0))
  1. I DA,$P($G(^PS(52.5,DA,0)),"^",2),$P($G(^(0)),"^",3) S DIK="^PS(52.5," D ^DIK K DIK
  1. I $D(^PS(52.4,PSOEXRX,0)) S DIK="^PS(52.4,",DA=PSOEXRX D ^DIK K DIK
  1. I $G(^PSRX(PSOEXRX,"H"))]"" K:$P(^PSRX(PSOEXRX,"H"),"^") ^PSRX("AH",$P(^PSRX(PSOEXRX,"H"),"^"),PSOEXRX) S ^PSRX(PSOEXRX,"H")=""
  1. S PSOEXSTA=$P($G(^PSRX(PSOEXRX,"STA")),"^")
  1. ;
  1. I PSOEXSTA=11 S ORN=$P($G(^PSRX(PSOEXRX,"OR1")),"^",2) I ORN I CPRSDC'[(","_CPRSSTA_",") D
  1. .S $P(^PSRX(PSOEXRX,0),"^",19)=1
  1. .D EN^PSOHLSN1(PSOEXRX,"SC","ZE","Prescription is expired")
  1. ;
  1. I PSOEXSTA=13 D Q
  1. .I 'ORN D EN^PSOHDR("PRES",PSOEXRX)
  1. ;
  1. I PSOEXSTA>9&(PSOEXSTA'=16) Q
  1. ;
  1. I +$P($G(^PSRX(PSOEXRX,2)),"^",6),+$P($G(^(2)),"^",6)<DT D
  1. .S $P(^PSRX(PSOEXRX,"STA"),"^")=11
  1. .S (PIFN,PSUSD,PRFDT)=0
  1. .F S PIFN=$O(^PSRX(PSOEXRX,1,PIFN)) Q:'PIFN S PSUSD=PIFN,PRFDT=+$P($G(^PSRX(PSOEXRX,1,PIFN,0)),"^")
  1. .D REVERSE^PSOBPSU1(PSOEXRX,+PSUSD,"DE",5,"RX EXPIRED")
  1. .I $G(PSUSD),'$P($G(^PSRX(PSOEXRX,1,PSUSD,0)),"^",18) D EN3
  1. .S ORN=$P($G(^PSRX(PSOEXRX,"OR1")),"^",2) I 'ORN D EN^PSOHDR("PRES",PSOEXRX) Q
  1. .;If CPRS side already DC'd or expired, just send the expiration to the HDR
  1. .I CPRSDC[(","_CPRSSTA_",") D EN^PSOHDR("PRES",PSOEXRX) Q
  1. .S $P(^PSRX(PSOEXRX,0),"^",19)=1
  1. .D EN^PSOHLSN1(PSOEXRX,"SC","ZE","Prescription past expiration date")
  1. Q
  1. EN3 ;
  1. S (PSDTEST,PDA)=0 F S PDA=$O(^PSRX(PSOEXRX,"L",PDA)) Q:'PDA S:$P($G(^PSRX(PSOEXRX,"L",PDA,0)),"^",2)=PSUSD PSDTEST=1
  1. Q:PSDTEST
  1. I $G(CMOP(CMOP("L")))="",".L.X."[("."_$G(CMOP("S"))_".") S PSDTEST=1
  1. N PSOORL
  1. S PSOORL=$$LOCK1^ORX2(ORN) S:'PSOORL PSDTEST=1 I PSOORL D UNLK1^ORX2(ORN)
  1. N PDAQ,PDA0
  1. S PDAQ=0
  1. F PDA=0:0 S PDA=$O(^PSRX(PSOEXRX,4,PDA)) Q:'PDA D
  1. .S PDA0=$G(^PSRX(PSOEXRX,4,PDA,0)) Q:PDA0=""
  1. .I $P(PDA0,"^",3)=PSUSD S PSDTEST=1
  1. ENX I 'PSDTEST K ^PSRX(PSOEXRX,1,PSUSD),^PSRX("AD",PRFDT,PSOEXRX,PSUSD),^PSRX(PSOEXRX,1,"B",PRFDT,PSUSD) D NSET
  1. Q
  1. NSET ;
  1. N PSONM,PSONMX
  1. S PSONM="" F PSONMX=0:0 S PSONMX=$O(^PSRX(PSOEXRX,1,PSONMX)) Q:'PSONMX S PSONM=PSONMX
  1. S ^PSRX(PSOEXRX,1,0)="^52.1DA^"_$G(PSONM)_"^"_$G(PSONM)
  1. Q