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

PSOBUILD.m

Go to the documentation of this file.
PSOBUILD ;IHS/DSD/JCM - BUILD ARRAY OF PATIENTS CURRENT MEDS  [ 07/15/96  5:25 PM ] ;6/21/07 8:20am
 ;;7.0;OUTPATIENT PHARMACY;**23,82,119,132,235,206,251,441**;DEC 1997;Build 208
 ;External reference ^PS(50.606 supported by DBIA 2174
 ;External reference ^PS(50.7 supported by DBIA 2223
 ;External reference ^PS(55 supported by DBIA 2228
 ;External reference ^PSDRUG( supported by DBIA 221
 ; Input variables: PSODFN,DT,PSODTCUT
 ;
 ;Add Complex Orders to NVA Meds
 ;
START N ORD K PSOSD I '$D(PSODFN)!('$D(DT)) G END
 D EOJ,INIT G:PSOQFLG END D BUILD
 S STA="ACTIVE^NON-VERIFIED^REFILL^HOLD^NON-VERIFIED^ACTIVE^^^^^^ACTIVE^DISCONTINUED^^DISCONTINUED^DISCONTINUED^HOLD"
 S DRG="" F I=0:0 S DRG=$O(PSOSD(DRG)) Q:DRG=""  I $G(PSOSD(DRG))]"" S PSOSD($P(STA,"^",$P(PSOSD(DRG),"^",2)+1),DRG)=PSOSD(DRG) D  K PSOSD(DRG)
 .S $P(PSOSD($P(STA,"^",$P(PSOSD(DRG),"^",2)+1),DRG),"^",9)=$G(^TMP("PS",$J,$P(STA,"^",$P(PSOSD(DRG),"^",2)+1),DRG))
 F PEN=0:0 S PEN=$O(^PS(52.41,"P",PSODFN,PEN)) Q:'PEN  S ORD=^PS(52.41,PEN,0),PSOOI=$P(ORD,"^",8),PSODD=+$P(ORD,"^",9) D:$P(ORD,"^",3)'="DC"&($P(ORD,"^",3)'="DE")&($P(ORD,"^",3)'="HD")
 .I 'PSODD N ZPSI,ZPSDC S (ZPSDC,ZPSI)=0 I $G(PSOOI) D
 ..F  S ZPSI=$O(^PSDRUG("ASP",PSOOI,ZPSI)) Q:'ZPSI  I $S('$D(^PSDRUG(ZPSI,"I")):1,'^("I"):1,DT'>^("I"):1,1:0),$S($P($G(^PSDRUG(ZPSI,2)),"^",3)'["O":0,1:1) S ZPSDC=ZPSDC+1,ZPSDC(ZPSDC)=ZPSI
 ..I ZPSDC=1 S PSODD=ZPSDC(1),$P(^PS(52.41,PEN,0),"^",9)=ZPSDC(1)
 .K ZPSI,ZPSDC
 .S DRG=$S(PSODD:$P($G(^PSDRUG(PSODD,0)),"^"),+PSOOI&('PSODD):$P(^PS(50.7,+PSOOI,0),"^")_" "_$P(^PS(50.606,$P(^PS(50.7,+PSOOI,0),"^",2),0),"^"),1:"") Q:DRG']""
 .I $D(PSOSD("PENDING",DRG)) S DRG=DRG_"^"_PEN
 .S PSOSD("PENDING",DRG)="*****^17^Z^Z^"_$S(PSODD:$P(^PSDRUG(PSODD,0),"^",2),1:"")_"^"_$P(^PS(52.41,PEN,0),"^",11)_"^"_$S($G(^PSDRUG(PSODD,"ND"))]"":+^("ND")_"A"_$P(^("ND"),"^",3),1:"")
 .S PSOSD("PENDING",DRG)=PSOSD("PENDING",DRG)_"^"_$P(ORD,"^",10)_"^"_$P(ORD,"^",6)_"^"_PEN_"^"_$S($G(PSODD):$G(PSODD),1:""),PSOSD=+$G(PSOSD)+1 K PSOOI,PSODD
 ;***    Complex NVA Order Modifications    ***
 N DD,DDX,DOSE,SCHD,MEDR,DURA,CONJ,COMPLEX
 F NVA=0:0 S NVA=$O(^PS(55,PSODFN,"NVA",NVA)) Q:'NVA  S NON=^PS(55,PSODFN,"NVA",NVA,0) D:'$P(^PS(55,PSODFN,"NVA",NVA,0),"^",7)   ;DO if not DC'd date
 .I $O(^PS(55,PSODFN,"NVA",NVA,3,0)) D NVANEW Q
 .D NVAOLD
END D EOJ
 Q
 ;
NVANEW ;New Complex NVA order multiple file format logic
 ;loop thru DD multiple and create separate array entries for each item (in case contain a complex order)
 F DD=0:0 S DD=$O(^PS(55,PSODFN,"NVA",NVA,3,DD)) Q:'DD  D
 .S DDX=DD_","_NVA_","_PSODFN
 .S DOSE=$$GET1^DIQ(55.516,DDX,"DOSAGE","I")
 .S SCHD=$$GET1^DIQ(55.516,DDX,"SCHEDULE","I")
 .S MEDR=$$GET1^DIQ(55.516,DDX,"MEDICATION ROUTE","I")
 .S DURA=$$GET1^DIQ(55.516,DDX,"DURATION","I")
 .S CONJ=$$GET1^DIQ(55.516,DDX,"CONJUNCTION")
 .S PSODD=$P(NON,"^",2),PSOOI=$P(NON,"^")
 .S DRG=$S(PSODD:$P($G(^PSDRUG(PSODD,0)),"^"),+PSOOI&('PSODD):$P(^PS(50.7,+PSOOI,0),"^")_" "_$P(^PS(50.606,$P(^PS(50.7,+PSOOI,0),"^",2),0),"^"),1:"")
 .I $D(PSOSD("ZNONVA",DRG)) S DRG=DRG_"^"_NVA_"^"_DD
 .S PSOSD("ZNONVA",DRG)="****^9^Z^Z^"_$S(PSODD:$P(^PSDRUG(PSODD,0),"^",2),1:"")_"^"_DOSE_"^^"_SCHD_"^"_$P(NON,"^",10)_"^"_NVA_"^"_PSODD_"^"_DURA_"^"_CONJ   ;append new pieces 12 & 13
 .I PSODD S $P(PSOSD("ZNONVA",DRG),"^",7)=$S($G(^PSDRUG(PSODD,"ND"))]"":+^("ND")_"A"_$P(^("ND"),"^",3),1:"")
 .S PSOSD=+$G(PSOSD)+1
 Q
 ;
NVAOLD ;NVA Backwards compatible for old NON-VA file DD, pre-complex order SIG multiple file setup 
 ;   (after 441. By attrition, all records will eventually have the new complex order mult. file format)
 S PSODD=$P(NON,"^",2),PSOOI=$P(NON,"^")
 S DRG=$S(PSODD:$P($G(^PSDRUG(PSODD,0)),"^"),+PSOOI&('PSODD):$P(^PS(50.7,+PSOOI,0),"^")_" "_$P(^PS(50.606,$P(^PS(50.7,+PSOOI,0),"^",2),0),"^"),1:"")
 I $D(PSOSD("ZNONVA",DRG)) S DRG=DRG_U_NVA    ;build unique nva drug name subscript when same drug
 S PSOSD("ZNONVA",DRG)="****^9^Z^Z^"_$S($P(NON,"^",2):$P(^PSDRUG($P(NON,"^",2),0),"^",2),1:"")_"^"_$P(NON,"^",3)_"^^"_$P(NON,"^",5)_"^"_$P(NON,"^",10)_"^"_NVA_"^"_$P(NON,"^",2)
 I $P(NON,"^",2) S $P(PSOSD("ZNONVA",DRG),"^",7)=$S($G(^PSDRUG(PSODD,"ND"))]"":+^("ND")_"A"_$P(^("ND"),"^",3),1:"")
 S PSOSD=+$G(PSOSD)+1
 Q
 ;
INIT ;
 K PSOSD,PSOMED S PSOQFLG=0,U="^",PSOBUILD("COUNT")=0 G:$D(PSODTCUT) INITX
 I '$D(^PS(53,"B","OUTPATIENT")) S PSOQFLG=1 G INITX
 S PSOX=$O(^PS(53,"B","OUTPATIENT","")) I 'PSOX S PSOQFLG=1 G INITX
 ;S DAYS=$S($D(DAYS360):360,1:45),X2=-$S($P($G(^PS(53,PSOX,0)),"^",3)+15>DAYS:$P($G(^(0)),"^",3)+15,1:DAYS),X1=DT D C^%DTC S PSODTCUT=X
 S X2=-120,X1=DT D C^%DTC S PSODTCUT=X
INITX K X,X1,X2,PSOX
 Q
 ;
BUILD ;build profiles
 F PSOEXPDT=(PSODTCUT-1):0 S PSOEXPDT=$O(^PS(55,PSODFN,"P","A",PSOEXPDT)) Q:'PSOEXPDT  F PSOBUILD("RX")=0:0 S PSOBUILD("RX")=$O(^PS(55,PSODFN,"P","A",PSOEXPDT,PSOBUILD("RX"))) Q:'PSOBUILD("RX")  I $D(^PSRX(PSOBUILD("RX"),0)) D GET
BUILDX I PSOBUILD("COUNT")>0 S PSOSD=PSOBUILD("COUNT")
 Q
GET ;data for profiles
 Q:'$P(^PSRX(PSOBUILD("RX"),0),"^",2)
 S (PSOSTF,PSOSTN)="",PSORX0=^PSRX(PSOBUILD("RX"),0),PSOST0=+^PSRX(PSOBUILD("RX"),"STA"),$P(PSORX0,"^",15)=PSOST0
 G:PSOST0=13 GETX S PSORX2=$G(^PSRX(PSOBUILD("RX"),2))
 S PSORX3=$G(^PSRX(PSOBUILD("RX"),3)) S:PSORX3="" PSORX3=$P(PSORX2,"^",2)
 S PSODRG=+$P(PSORX0,"^",6) G:'$D(^PSDRUG(PSODRG,0)) GETX S PSODRUG0=^PSDRUG(PSODRG,0),PSOVACL=$P(PSODRUG0,"^",2),PSODYS=$P(PSORX0,"^",8)
 ;
 I PSOST0<12!(PSOST0=16),PSOEXPDT<DT D:$P(PSORX0,"^",15)'=11
 .S PSOST0=11,$P(PSORX0,"^",15)=11 N DIE,DIC,DR,DA,PSOBEXDA S DIE=52,(DA,PSOBEXDA)=PSOBUILD("RX"),DR="100////11" D ^DIE K DIE,DIC,DR
 .D ECAN^PSOUTL(DA) K DA
 .S STAT="SC",PHARMST="ZE",COMM="Medication Expired on "_$E(PSOEXPDT,4,5)_"/"_$E(PSOEXPDT,6,7)_"/"_$E(PSOEXPDT,2,3) D EN^PSOHLSN1(PSOBEXDA,STAT,PHARMST,COMM) K COMM,STAT,PHARMST,PSOBEXDA
 I PSOST0=12,PSOEXPDT<DT S PSOST0=12
 I PSOST0=5 D  G GT1
 .I $O(^PS(52.5,"B",PSOBUILD("RX"),0)),'$D(^PS(52.5,+$O(^(0)),0)) D  Q
 ..S PSOST0=0 D FSTA
 ..K ^PS(52.5,"B",PSOBUILD("RX"),$O(^PS(52.5,"B",PSOBUILD("RX"),0)))
 .I '$O(^PS(52.5,"B",PSOBUILD("RX"),0)) S PSOST0=0 D FSTA
 I 'PSOST0 D STAT
GT1 G GETX:$D(NOEXP)&(PSOST0=11)
 I $D(^PSDRUG(PSODRG,"I")),^("I")]"",DT>^("I") S PSOSTN=PSOSTN_"A" I $P($G(PSOPAR),"^",11)']"" S PSOSTF=PSOSTF_"A"
 S PSONDF=$S($G(^PSDRUG(PSODRG,"ND"))]"":+^("ND")_"A"_$P(^("ND"),"^",3),1:0)
 I $P($G(^PSDRUG(PSODRG,2)),"^",3)'["O" S PSOSTN=PSOSTN_"M"
 S CLOZPT=$S($P($G(^PSDRUG(PSODRG,"CLOZ1")),"^")="PSOCLO1":1,1:0)
 I 'CLOZPT,($P(PSODRUG0,"^",3)["A")&($P(PSODRUG0,"^",3)'["B") S PSOSTN=PSOSTN_"B",PSOSTF=PSOSTF_"B"
 K CLOZPT I ($P(PSODRUG0,"^",3)["W")!($P(PSODRUG0,"^",3)[1)!($P(PSODRUG0,"^",3)[2) S PSOSTN=PSOSTN_"C"
 I $D(^PS(53,+$P(PSORX0,"^",3),0)),'$P(^(0),"^",5) S PSOSTN=PSOSTN_"D"
 I PSOST0=1 S PSOSTN=PSOSTN_"E"
 S PSOLC=$P(PSORX0,"^"),PSOLC=$E(PSOLC,$L(PSOLC)) I $A(PSOLC)>90 S PSOSTN=PSOSTN_"F"
 I PSOST0,PSOST0'=2,PSOST0'=6 S PSOSTF=PSOSTF_"Z"
 I $G(PSORX("BAR CODE")),PSOST0,PSOST0'=2,PSOST0'=5,PSOST0'=6,PSOST0'=11,PSOST0'=12 S PSOSTN=PSOSTN_"Z" G BARC
 I PSOST0,PSOST0'=2,PSOST0'=5,PSOST0'=6,PSOST0'=11,PSOST0'=12,PSOST0'=14 S PSOSTN=PSOSTN_"Z"
BARC S PSORFRM=$P(PSORX0,"^",9) F PSOJ=0:0 S PSOJ=$O(^PSRX(PSOBUILD("RX"),1,PSOJ)) Q:'PSOJ  S PSORFRM=PSORFRM-1
 S:PSORFRM<0 PSORFRM=0 S:PSORFRM=0 PSOSTF=PSOSTF_"G"
 S PSODRUGN=$P(PSODRUG0,"^") I $D(PSOSD(PSODRUGN)),PSOST0>10 Q:$P(PSOSD(PSODRUGN),"^",2)<11  Q:$P(PSOSD(PSODRUGN),"^",2)>10&($P(PSORX0,"^",13)<$P(^PSRX(+$P(PSOSD(PSODRUGN),"^"),0),"^",13))
 S:'$D(PSOSD(PSODRUGN)) PSOBUILD("COUNT")=PSOBUILD("COUNT")+1
 I $D(PSOSD(PSODRUGN)),$P(PSOSD(PSODRUGN),"^",2)<10,PSOST0<10 S PSOSD(PSODRUGN_"^"_PSOBUILD("RX"))=PSOBUILD("RX")_"^"_PSOST0_"^"_PSOSTN_"^"_PSOSTF_"^"_PSOVACL_"^"_PSORFRM_"^"_PSONDF_"^"_PSODYS,PSOBUILD("COUNT")=PSOBUILD("COUNT")+1
 E  S PSOSD(PSODRUGN)=PSOBUILD("RX")_"^"_PSOST0_"^"_PSOSTN_"^"_PSOSTF_"^"_PSOVACL_"^"_PSORFRM_"^"_PSONDF_"^"_PSODYS
GETX Q
STAT N X S X=+$O(^PS(52.5,"B",PSOBUILD("RX"),0))
 I X,$D(^PS(52.5,X,0)),$P($G(^PS(52.5,X,0)),"^",7)'="X",'$G(^PS(52.5,X,"P")) S PSOST0=5
 I PSOST0 D FSTA
 Q
FSTA S $P(PSORX0,"^",15)=PSOST0
 N DIE,DR,DA S DIE=52,DA=PSOBUILD("RX"),DR="100////"_PSOST0 D ^DIE K DIE,DR,DA
 Q
 ;
EOJ K ORD,PSOX,PSOEXPDT,PSODRG,PSODRUG0,PSOLC,PSONDF,PSOQFLG,PSORFRM,PSORX0,PSORX2,PSORX3,PSOST0,PSOSTF,PSOSTN,PSOJ,PSODRUGN,PSOVACL,PSOBUILD,PSODYS,PEN,DRG,NON,NVA
 Q
INPAT(PSODFN) ;entry point for inpat meds to view patient's outpat. meds
 D FULL^VALM1
 S INPAT=1,X2=-120,X1=DT D C^%DTC S PSODTCUT=X D START,^PSODSPL
 K PSOSD,DDH,PSCNT,PSOCT,PSODD,PSOOI,PSOPAR,PSOSTA,STP,STR,PSODTCUT,PSODFN,INPAT,DRG
 Q