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

PSOSIGCX.m

Go to the documentation of this file.
PSOSIGCX ;BIR/RTR-Utility to calculate quantity ;3/23/11 8:24am [3/7/18 11:44am]
 ;;7.0;OUTPATIENT PHARMACY;**46,282,446,441**;DEC 1997;Build 208
 ;External reference to PS(51 supported by DBIA 2224
 ;External reference to PS(51.1 supported by DBIA 2225
 ;
EN(PSOSIGX) ;
 N VARIABLE
 Q
SCH ;*282 Centralized
 D SCH^PSOSIG
 Q
QTY(PSOQX) ;
 N QDOSE
QTYCP ;CPRS qty call comes through here
 N PSQQUIT,QTSH,PSQ,PSQMIN,PSQMINZ,PSOQRND,PSOLOWER,PSOLOWX,PSOLOWXL,PSOLOWST
 K PSOFRQ S PSQQUIT=0
 I '$G(PSOCPRQT) S QDOSE=0 F PSQ=0:0 S PSQ=$O(PSOQX("DOSE",PSQ)) Q:'PSQ  S QDOSE=PSQ S:'$G(PSOQX("DOSE ORDERED",PSQ)) PSQQUIT=1
 ;Q:PSQQUIT!('QDOSE)
 I '$G(PSOCPRQT) Q:PSQQUIT
 Q:'$G(PSOQX("DAYS SUPPLY"))
 Q:'$G(QDOSE)
 G:QDOSE>1 COMP
 Q:'$G(PSOQX("DOSE ORDERED",1))
 Q:'$G(PSOQX("DAYS SUPPLY"))&('$G(PSOQX("DURATION",1)))
 S PSOLOWER=0
 I $G(PSOQX("DURATION",1)) D
 .S PSOLOWX=$L(PSOQX("DURATION",1))
 .S PSOLOWXL=$S($E(PSOQX("DURATION",1),PSOLOWX)="M":1,$E(PSOQX("DURATION",1),PSOLOWX)="H":60,$E(PSOQX("DURATION",1),PSOLOWX)="S":.01666,$E(PSOQX("DURATION",1),PSOLOWX)="W":10080,$E(PSOQX("DURATION",1),PSOLOWX)="L":43200,1:1440)
 .S PSOLOWER=PSOLOWXL*(+$G(PSOQX("DURATION",1)))
 S PSOLOWX=0 I +$G(PSOQX("DAYS SUPPLY")) S PSOLOWX=1440*+$G(PSOQX("DAYS SUPPLY"))
 Q:'$G(PSOLOWER)&('$G(PSOLOWX))
 S QTSH=$G(PSOQX("SCHEDULE",1)) D QTS Q:PSQQUIT!('$G(PSOFRQ))
 S PSOLOWST=$S('$G(PSOLOWER):$G(PSOLOWX),'$G(PSOLOWX):$G(PSOLOWER),$G(PSOLOWER)>$G(PSOLOWX):$G(PSOLOWX),$G(PSOLOWX)>$G(PSOLOWER):$G(PSOLOWER),$G(PSOLOWX)=$G(PSOLOWER):$G(PSOLOWER),1:0)
 Q:'$G(PSOLOWST)
 S PSQMIN=+$G(PSOLOWST)
 S PSQMINZ=PSQMIN/PSOFRQ
 S PSOQRND=PSQMINZ*+$G(PSOQX("DOSE ORDERED",1)) Q:'PSOQRND
 D ROUND G QEND
 Q
COMP ;COMPLEX DOSE HERE - ALL ANDS
 ;N PSOQAND,PSQL,PSQMNL,PSQMNLX,PSODUTOT,PSODUDIF,PSODUMIS,PSODUREP,PSQ1,PSODUX,PSODUXX,PSODSMIN
 ;PSODUTOT = TOTAL OF ALL DURATIONS
 ;PSODUDIF = DIFF. OF DURATION VS DAYS SUPPLY
 ;PSODUMIS = # OF SEQUENCES MISSING A DURATION IF >1 CAN'T DEFAULT
 ;PSODUREP = SEQUENCE # THAT IS MISSING DURATION
 ;PSODSMIN = MINUTES OF DAYS SUPPLY
 ;PSODSAME = FLAG THAT TELL IF DURATIONS ARE THE SAME
 ;PSODURT = DURATION MINUTES FOR COMPARE
 I $G(PSOQTHEN) G COMP^PSOSIGTX
 N PSODUMSS,PSODSAME,PSODURT,PSOTMPDR S (PSODUMSS,PSODSAME,PSODURT,PSOTMPDR)=0
 F PSQ1=1:1:QDOSE D
 .S PSOTMPDR=$G(PSOQX("DURATION",PSQ1))
 .I 'PSOTMPDR S PSODUMIS=PSODUMIS+1,PSODUREP=PSQ1 Q
 .S PSODUX=$L(PSOTMPDR)
 .S PSODUMSS=1
 .S PSODUXX=$S($E(PSOTMPDR,PSODUX)="M":1,$E(PSOTMPDR,PSODUX)="H":60,$E(PSOTMPDR,PSODUX)="S":.01666,$E(PSOTMPDR,PSODUX)="W":10080,$E(PSOTMPDR,PSODUX)="L":43200,1:1440)
 .;S PSODUTOT=PSODUTOT+(PSODUXX*(+$G(PSOQX("DURATION",PSQ1))))
 .;441 MWA all "Ands" should pick largest duration...not add durations
 .S PSODUTOT=$S(PSOTMPDR>PSODUTOT:PSOTMPDR,1:$G(PSODUTOT))
 .I '$G(PSODSAME),$G(PSODURT),PSODURT'=(PSODUXX*(+$G(PSOQX("DURATION",PSQ1)))) S PSODSAME=1
 .S PSODURT=(PSODUXX*(+$G(PSOQX("DURATION",PSQ1))))
 I '$G(PSOQX("DAYS SUPPLY")) G QEND ; missing Days Supply
 S PSODSMIN=1440*+$G(PSOQX("DAYS SUPPLY"))
 I PSODUMIS,PSODSAME G QEND ; Missing Durations, other are different
 I 'PSODUMIS,PSODSAME,$G(PSODUTOT)>PSODSMIN G QEND ; Every sequence has a duration, some are different, and the total is greater than Days Supply
 I 'PSODSAME,PSODURT>PSODSMIN G QEND ; All have a duration, and it's the same, but it's greater than Days Supply, or Missing Durations with other duration the same but greater than Days Supply
 F PSQ=1:1:QDOSE D  Q:$G(PSQQUIT)
 .I '$G(PSOQX("DOSE ORDERED",PSQ))!($G(PSOQX("SCHEDULE",PSQ))="") S PSQQUIT=1 Q
 .S QTSH=$G(PSOQX("SCHEDULE",PSQ)) D QTS S:'$G(PSOFRQ) PSQQUIT=1 Q:$G(PSQQUIT)
 .I $G(PSOQX("DURATION",PSQ)) S PSQMNL=$L(PSOQX("DURATION",PSQ)) D
 ..S PSQMNLX=$S($E(PSOQX("DURATION",PSQ),PSQMNL)="M":1,$E(PSOQX("DURATION",PSQ),PSQMNL)="H":60,$E(PSOQX("DURATION",PSQ),PSQMNL)="S":.01666,$E(PSOQX("DURATION",PSQ),PSQMNL)="W":10080,$E(PSOQX("DURATION",PSQ),PSQMNL)="L":43200,1:1440)
 ..S PSQMIN=PSQMNLX*(+$G(PSOQX("DURATION",PSQ)))
 .I '$G(PSOQX("DURATION",PSQ)) S PSQMIN=$S($G(PSODURT)&('$G(PSODSAME)):$G(PSODURT),1:$G(PSODSMIN))
 .S PSQMINZ=PSQMIN/PSOFRQ
 .S PSOQRND=$S('$G(PSOQRND):PSQMINZ*+$G(PSOQX("DOSE ORDERED",PSQ)),1:$G(PSOQRND)+(PSQMINZ*+$G(PSOQX("DOSE ORDERED",PSQ))))
 I $G(PSQQUIT) G QEND
 ;
 ;If DAYS SUPPLY was edited by Pharmacy, don't re-calculate QTY automatically for Digitally Signed Pending Orders
 I $G(PSODSEDT),$G(QTYHLD),$G(PSOFDR),$P($G(OR0),"^",24) D  Q
 . W !!,"The Quantity (",QTYHLD,") has not been changed."
 . W !,"Please review and update it if necessary.",!,$C(7)
 . N DIR S DIR(0)="E",DIR("A")="Press Return to Continue" D ^DIR W !
 I $G(PSOQRND) D ROUND
 G QEND
QTS ;*282 Centralized call
 D QTS^PSOSIG
 Q
QEND ;
 K PSOFRQ
 Q
ROUND ;
 Q:'$G(PSOQRND)
 I PSOQRND'["." S PSOQX("QTY")=PSOQRND Q
 S PSOQX("QTY")=$P(PSOQRND,".")+1
 Q
DAY(DATE) ;First 5 digits of FileMan date
 N X
 I DATE'?5N Q -1
 S X=$E(DATE,4,5) I X<1!(X>12) Q -1
 S X=DATE+1+(X=12*88)_"01"
 Q $E($$FMADD^XLFDT(X,-1),6,7)
 ;
QTYX(PSOQX) ;
 N PSOQLP,PSOQLN,PSOQAR,PSOCPRQT,QDOSE,QDOSEX S PSOCPRQT=1 F PSOQLP=0:0 S PSOQLP=$O(PSOQX("DURATION",PSOQLP)) Q:'PSOQLP  D
 .S PSOQAR("DURATION",PSOQLP)=$G(PSOQX("DURATION",PSOQLP))
 .I $E(PSOQX("DURATION",PSOQLP))?1A S PSOQLN=$L(PSOQX("DURATION",PSOQLP)) S PSOQX("DURATION",PSOQLP)=$E(PSOQX("DURATION",PSOQLP),2,PSOQLN)_$E(PSOQX("DURATION",PSOQLP))
 S QDOSE=0 F QDOSEX=0:0 S QDOSEX=$O(PSOQX("DOSE ORDERED",QDOSEX)) Q:'QDOSEX  S QDOSE=QDOSE+1
 I '$G(PSOQX("QTY")) D QTYCP G QPASS
 D QTYCP^PSOSIGDS
QPASS F PSOQLP=0:0 S PSOQLP=$O(PSOQAR("DURATION",PSOQLP)) Q:'PSOQLP  D
 .S PSOQX("DURATION",PSOQLP)=$G(PSOQAR("DURATION",PSOQLP))
 K PSOCPRQT
 Q
DAYS(PSOQX) ;Entry point for Days Supply calc for PSO
 ;Kill days supply here
 Q:'$G(PSOQX("QTY"))
 D QTYOPS^PSOSIGDS
 Q