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

PSO283PI.m

Go to the documentation of this file.
  1. PSO283PI ;BIR/MFR-EXPIRATION DATE PROBLEM TALLY ;05/03/07
  1. ;;7.0;OUTPATIENT PHARMACY;**283**;DEC 1997;Build 28
  1. ;External references ^DPT supported by DBIA 10035
  1. ;External reference to STATUS^ORQOR2 is supported by DBIA 3458
  1. ;External reference to ^PS(59.7 is supported by DBIA 694
  1. N NMSP,JOBSTS,DIR,DIRUT,DIROUT,DTOUT,DUOUT,Y,ACTION,EXPJOBDT,PSODUZ
  1. S NMSP="PSO283PI"
  1. ;
  1. S JOBSTS=$$JOBSTS^PSO283P1()
  1. ;
  1. W !?5,"Expiration Date problem tally patch for Outpatient Pharmacy prescriptions"
  1. W !?5,"========================================================================="
  1. W !?5,"Current status: "
  1. W:JOBSTS="N" "NEVER RUN"
  1. W:JOBSTS="S" "STOPPED ON "_$$FMTE^XLFDT($G(^XTMP(NMSP,"STOPPED")))
  1. W:JOBSTS="R" "RUNNING"
  1. W:JOBSTS="C" "COMPLETED ON "_$$FMTE^XLFDT($G(^XTMP(NMSP,"COMPLETED")))
  1. W:$G(^XTMP(NMSP,"LASTRX")) " (Last Rx IEN: "_$G(^XTMP(NMSP,"LASTRX"))_")"
  1. ;
  1. S DIR(0)="SO^",DIR("A")=""
  1. I JOBSTS="N" D
  1. .S DIR(0)=DIR(0)_"ST:START TALLY JOB;",DIR("A")=DIR("A")_"(ST)Start,",DIR("B")="START"
  1. I JOBSTS="S" D
  1. . S DIR(0)=DIR(0)_"RE:RESUME TALLY JOB;",DIR("A")=DIR("A")_"(RE)Resume,"
  1. I JOBSTS="R" D
  1. . S DIR(0)=DIR(0)_"SP:STOP TALLY JOB;",DIR("A")=DIR("A")_"(SP)Stop,"
  1. I JOBSTS="C" D
  1. . S DIR(0)=DIR(0)_"RR:RE-RUN TALLY JOB;",DIR("A")=DIR("A")_"(RR)Re-run,"
  1. S DIR(0)=DIR(0)_"VW:VIEW "_$S(JOBSTS'="C":"PARTIAL ",1:"")_"TALLY JOB RESULTS;"
  1. S DIR("A")=DIR("A")_"(VW)View,",DIR("B")="VIEW"
  1. S DIR(0)=DIR(0)_"QT:QUIT",DIR("A")=DIR("A")_"(QT)Quit"
  1. D ^DIR I $D(DIRUT)!$D(DIROUT)!$D(DTOUT)!$D(DUOUT) G QUIT
  1. S ACTION=Y
  1. ;
  1. I ACTION="SP" W !!,"Stopping..." D G QUIT
  1. . N TIME,UNABLE
  1. . S ^XTMP(NMSP,"STOP")=1,(TIME,UNABLE)=0
  1. . F Q:$D(^XTMP(NMSP,"STOPPED")) D Q:UNABLE
  1. . . H 1 S TIME=TIME+1 I $D(^XTMP(NMSP,"COMPLETED"))!($$JOBSTS^PSO283P1()'="R")!(TIME>30) S UNABLE=1
  1. . W $S(UNABLE:"NOT OK (may no longer be running)",1:"OK")
  1. . K ^XTMP(NMSP,"STOP")
  1. ;
  1. I ACTION="QT" G QUIT
  1. I ACTION="VW" D DISPLAY^PSO283P1 G QUIT
  1. I ACTION="RR" K ^XTMP(NMSP)
  1. ;
  1. D JOB^PSO283P1()
  1. Q
  1. ;
  1. PI ; Post-Install entry point
  1. N EXPJOBDT,NMSP
  1. S NMSP="PSO283PI" K ^XTMP(NMSP)
  1. D LOG^PSO283P1("PATCH INSTALLATION")
  1. D JOB^PSO283P1($$NOW^XLFDT())
  1. Q
  1. ;
  1. EN ;
  1. N NMSP,PSOINST,CUTOFF,PSOACT,RXP,STOP,PSOINACT,PATIENT,COUNTER,RXP,PATICN,DRUG,STATUS
  1. N ISSUEDT,EXPIRDT,BADRXCNT,DAYSSUP,NUMREFS
  1. ;
  1. S NMSP="PSO283PI" I '$G(PSODUZ) S PSODUZ=+$G(DUZ)
  1. ;
  1. ; - If can't get Lock, then already running.
  1. L +^XTMP(NMSP):5 I '$T D LOG^PSO283P1("UNSUCCESSFUL (LOCKED)") G QUIT
  1. ;
  1. D SETXTMP
  1. ;
  1. I '$G(DT) S DT=$$DT^XLFDT
  1. ;
  1. S PSOINST=$P($$SITE^VASITE(),"^",2)_" ("_+$$SITE^VASITE()_")"
  1. S CUTOFF=$$FMADD^XLFDT(DT,-2)
  1. S PSOINACT=",11,12,13,14,15,"
  1. S RXP=+$G(^XTMP(NMSP,0,"LASTRX")),STOP=0
  1. F COUNTER=1:1 S RXP=$O(^PSRX(RXP)) Q:'RXP D Q:STOP
  1. . S:'(COUNTER#100000) DT=$$DT^XLFDT()
  1. . S PATIENT=$P($G(^PSRX(RXP,0)),"^",2)
  1. . S PATICN=$P($$GETICN^MPIF001(PATIENT),"^")
  1. . S DRUG=$P($G(^PSRX(RXP,0)),"^",6)
  1. . S STATUS=$P($G(^PSRX(RXP,"STA")),"^")
  1. . S ISSUEDT=$P($G(^PSRX(RXP,0)),"^",13)
  1. . S DAYSSUP=$P($G(^PSRX(RXP,0)),"^",8)
  1. . S NUMREFS=$P($G(^PSRX(RXP,0)),"^",9)
  1. . S EXPIRDT=$P($G(^PSRX(RXP,2)),"^",6)
  1. . S BADRXCNT(14)=$G(BADRXCNT(14))+1
  1. . S BADRXCNT("LASTRX")=RXP
  1. . ;--- eliminate bad Rx's
  1. . I ('PATIENT!'DRUG) S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
  1. . I '$D(^DPT(PATIENT))!('$D(^PSDRUG(DRUG))) S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
  1. . I 'ISSUEDT S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
  1. . ;---
  1. . D SET
  1. . ;---
  1. . I '(COUNTER#10000) D
  1. . . M ^XTMP(NMSP)=BADRXCNT
  1. . . I $G(^XTMP(NMSP,"STOP")) S STOP=1
  1. ;
  1. I STOP D STOP G QUIT
  1. ;
  1. M ^XTMP(NMSP)=BADRXCNT
  1. S ^XTMP(NMSP,"COMPLETED")=$$NOW^XLFDT()
  1. K ^XTMP(NMSP,"LASTRX")
  1. D LOG^PSO283P1("COMPLETED")
  1. D MAIL^PSO283P1
  1. ;
  1. QUIT ;
  1. L -^XTMP(NMSP)
  1. Q
  1. ;
  1. STOP ;
  1. K ^XTMP(NMSP,"STOP")
  1. S ^XTMP(NMSP,"STOPPED")=$$NOW^XLFDT()
  1. D LOG^PSO283P1("STOPPED")
  1. D MAIL^PSO283P1
  1. Q
  1. ;
  1. SET ;
  1. N CPRSDC,CPRSTA,NEWEXPDT,DA,DIE,ORN,DR
  1. S CPRSDC=",1,7,12,13,"
  1. ;
  1. ; --- No expiration date on PRESCRIPTION file (#52)
  1. I EXPIRDT="" D Q
  1. . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
  1. . D CALCEXP^PSO283P1 I '$G(EXPIRDT) Q
  1. . I EXPIRDT>CUTOFF D Q ; Expiration Date past Cutoff (will be exp. by auto exp. job), Quit
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . S BADRXCNT(102)=$G(BADRXCNT(102))+1
  1. . . . S ^XTMP(NMSP,102,RXP,"HDR")=""
  1. . . S BADRXCNT(2)=$G(BADRXCNT(2))+1,^XTMP(NMSP,2,RXP)=""
  1. . I ORN D Q ; Rx is expired in CPRS (Update HDR with Exp. Date), Quit
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . I CPRSDC'[(","_CPRSTA_",") D
  1. . . . . S ^XTMP(NMSP,103,RXP,"HDR")="",BADRXCNT(103)=$G(BADRXCNT(103))+1
  1. . . . I CPRSDC[(","_CPRSTA_",") D
  1. . . . . S ^XTMP(NMSP,104,RXP,"HDR")="",BADRXCNT(104)=$G(BADRXCNT(104))+1
  1. . . I CPRSDC'[(","_CPRSTA_",") D Q
  1. . . . S BADRXCNT(3)=$G(BADRXCNT(3))+1,^XTMP(NMSP,3,RXP)=""
  1. . . S BADRXCNT(4)=$G(BADRXCNT(4))+1,^XTMP(NMSP,4,RXP)=""
  1. . I 'ORN D ; No CPRS Order # (Update HDR with Exp. Date)
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . S BADRXCNT(105)=$G(BADRXCNT(105))+1
  1. . . . S ^XTMP(NMSP,105,RXP,"HDR")=""
  1. . . S BADRXCNT(5)=$G(BADRXCNT(5))+1,^XTMP(NMSP,5,RXP)=""
  1. ;
  1. ; --- Rx is expired. Update CPRS and HDR if necessary
  1. I STATUS=11 D Q
  1. . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
  1. . S NEWEXPDT=0
  1. . I $$FMDIFF^XLFDT(EXPIRDT,ISSUEDT,1)>366 D ; Expiration Date is > 366, Recalculate new Date
  1. . . S NEWEXPDT=1 D CALCEXP^PSO283P1
  1. . I ORN,CPRSDC'[(","_CPRSTA_",") D ; Rx is not expired in CPRS (Update CPRS/HDR with Exp. Date), Quit
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to CPRS
  1. . . . I 'NEWEXPDT S BADRXCNT(106)=$G(BADRXCNT(106))+1,^XTMP(NMSP,106,RXP,"HDR")=""
  1. . . . I NEWEXPDT S BADRXCNT(107)=$G(BADRXCNT(107))+1,^XTMP(NMSP,107,RXP,"HDR")=""
  1. . . I 'NEWEXPDT S BADRXCNT(6)=$G(BADRXCNT(6))+1,^XTMP(NMSP,6,RXP)=""
  1. . . I NEWEXPDT S BADRXCNT(7)=$G(BADRXCNT(7))+1,^XTMP(NMSP,7,RXP)=""
  1. . I 'NEWEXPDT Q ; Expiration Date was not recalculated, don't send to HDR
  1. . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . S BADRXCNT(108)=$G(BADRXCNT(108))+1
  1. . . S ^XTMP(NMSP,108,RXP,"HDR")=""
  1. . S BADRXCNT(8)=$G(BADRXCNT(8))+1,^XTMP(NMSP,8,RXP)=""
  1. ;
  1. I EXPIRDT<CUTOFF,(PSOINACT'[(","_STATUS_",")) D ; Rx is past exp. date but is still on a non-Expired/DC'd status
  1. . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
  1. . I ORN,CPRSDC'[(","_CPRSTA_",") D Q ; Update CPRS if necessary, this will also call HDR
  1. . . I PATICN=-1 D Q ; NO ICN# - Send it to CPRS but not to HDR
  1. . . . S BADRXCNT(109)=$G(BADRXCNT(109))+1
  1. . . . S ^XTMP(NMSP,109,RXP,"HDR")=""
  1. . . S BADRXCNT(9)=$G(BADRXCNT(9))+1,^XTMP(NMSP,9,RXP)=""
  1. . I ORN D Q ; If CPRS was not updated, call HDR if there is an Order #
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . S BADRXCNT(110)=$G(BADRXCNT(110))+1
  1. . . . S ^XTMP(NMSP,110,RXP,"HDR")=""
  1. . . S BADRXCNT(10)=$G(BADRXCNT(10))+1,^XTMP(NMSP,10,RXP)=""
  1. . I 'ORN D ; If no CPRS Order #, just report (no updates to CPRS/HDR)
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . S BADRXCNT(111)=$G(BADRXCNT(111))+1
  1. . . . S ^XTMP(NMSP,111,RXP,"HDR")=""
  1. . . S BADRXCNT(11)=$G(BADRXCNT(11))+1
  1. . . S ^XTMP(NMSP,11,RXP)=""
  1. ;
  1. I STATUS=13 D Q
  1. . S ORN=+$$CPRSNUM(RXP)
  1. . I 'ORN D
  1. . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
  1. . . . S BADRXCNT(112)=$G(BADRXCNT(112))+1
  1. . . . S ^XTMP(NMSP,112,RXP,"HDR")=""
  1. . . S BADRXCNT(12)=$G(BADRXCNT(12))+1,^XTMP(NMSP,12,RXP)=""
  1. Q
  1. ;
  1. CPRSNUM(RXP) ;
  1. N ORN,STA
  1. S ORN=$P($G(^PSRX(RXP,"OR1")),"^",2),STA=""
  1. I ORN S STA=+$$STATUS^ORQOR2(ORN) I STA=0 S ORN=""
  1. Q (ORN_"^"_STA)
  1. ;
  1. SETXTMP ; - Initialize the XTMP global
  1. I $D(^XTMP(NMSP,"STARTED")) D
  1. . S ^XTMP(NMSP,"RE-STARTED")=$$NOW^XLFDT() D LOG^PSO283P1("RE-STARTED")
  1. I '$D(^XTMP(NMSP,"STARTED")) D
  1. . S ^XTMP(NMSP,"STARTED")=$$NOW^XLFDT() D LOG^PSO283P1("STARTED")
  1. K ^XTMP(NMSP,"STOP"),^XTMP(NMSP,"STOPPED")
  1. S ^XTMP(NMSP,0)=$$FMADD^XLFDT($$NOW^XLFDT(),730)_"^"_$$NOW^XLFDT()_"^PSO*7*283 - RX EXPIRATION DATE PROBLEM TALLY"
  1. Q