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

BTIULO15.m

Go to the documentation of this file.
BTIULO15 ; IHS/MSC/MGH - STILL MORE OBJECTS FOR ASTHMA ;14-Sep-2011 11:49;DU
 ;;1.0;TEXT INTEGRATION UTILITIES;**1009**;NOV 04, 2004;Build 22
AREL(DFN,TARGET) ;Active reliever meds
 K @TARGET
 W !,"Take your long-term control medication every day.",!
 K BTIUHL,BTIUREL
 D LAST1YRR(DFN)
 K BTIUHL
 M BTIUHL=BTIUREL
 D DISPMEDS
 Q "~@"_$NA(@TARGET)
ACON(DFN,TARGET) ;Active controller meds
 K @TARGET
 K BTIUHL,BTIUCONT
 D LAST1YRC(DFN)
 K BTIUHL
 M BTIUHL=BTIUCONT
 D DISPMEDS
 Q "~@"_$NA(@TARGET)
 ;
PHARM(L,I) ;
 NEW %
 S %=$O(^PS(59,"C",L,0))
 I '%,I="N" Q $P(^DIC(4,L,0),U)
 I '%,I="P" Q $$VAL^XBDIQ1(9999999.06,L,.13)
 I I="N" Q $P(^PS(59,%,0),U)
 I I="P" Q $P(^PS(59,%,0),U,4)
 Q ""
 ;
DISPMEDS ;EP
 N D,E,N,X,CNT,BIUMED,BTIUREF,BTIUQTY,BTIUD,BTIUDC,BTIUDYS,BTIUMFX,BTIUCRN,BTIUSIG
 N BTIUDTM,BTIUEXP,BTUYSSGY,BTIUORTS,BTIUMED,BTIURX,BTIUSSGY
 I '$O(BTIUHL(0)) S @TARGET@(1,0)="None documented" Q
 S CNT=0
 S D=0 F  S D=$O(BTIUHL(D)) Q:D'=+D  D
 .S E=0 F  S E=$O(BTIUHL(D,E)) Q:E'=+E  S N=^AUPNVMED(E,0) D
 ..S BTIUD=$$FMTE^XLFDT($P(^AUPNVSIT($P(N,U,3),0),U),"5D")
 ..S BTIUDC=$P(N,U,8),BTIUDYS=$P(N,U,7),BTIUMFX=$S($P(N,U,4)="":+N,1:$P(N,U,4)) S:BTIUDYS="" BTIUDYS=30 S BTIURX=$S($D(^PSRX("APCC",E)):$O(^(E,0)),1:0)
 ..S BTIUCRN=$S(+BTIURX:$D(^PS(55,DFN,"P","CP",BTIURX)),1:0)
 ..S BTIUQTY=$P(N,U,6),BTIUSIG=$P(N,U,5)
 ..S BTIUDTM=$P($P(^AUPNVSIT($P(N,U,3),0),U),"."),BTIUEXP=""
 ..S X=$$FMDIFF^XLFDT(DT,BTIUDTM)
 ..I X>BTIUDYS S Y=$$FMADD^XLFDT(BTIUDTM,BTIUDYS) S BTIUEXP="-- Ran out "_$$FMTE^XLFDT(Y,"2D")
 ..S BTIUMED=$S($P(N,U,4)="":$P(^PSDRUG(BTIUMFX,0),U),1:$P(N,U,4))
 ..I BTIUDC S Y=$$FMTE^XLFDT(BTIUDC) S BTIUEXP="-- D/C "_Y
 ..S BTIUORTS=$G(^AUPNVMED(E,11))
 ..I BTIUORTS["RETURNED TO STOCK",BTIUDC S BTIUEXP="--RTS "_Y
 ..D SIG S BTIUSIG=BTIUSSGY
 ..D REF I BTIUREF S BTIUSIG=BTIUSIG_" "_BTIUREF_$S(BTIUREF=1:" refill",1:" refills")_" left."
 ..S X=BTIUD,$E(X,13)=BTIUMED_" #"_BTIUQTY_" ("_BTIUDYS_" days) "_BTIUEXP
 ..S CNT=CNT+1
 ..S @TARGET@(CNT,0)=X
 ..S X="",$E(X,14)=$E(BTIUSIG,1,65)
 ..S CNT=CNT+1
 ..S @TARGET@(CNT,0)=X
 ..I $L(BTIUSIG)>65 D
 ...S X="",$E(X,14)=$E(BTIUSIG,66,999)
 ...S CNT=CNT+1
 ...S @TARGET@(CNT,0)=X
 ..Q
 .Q
 Q
 ;
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
 N BTIUSP
 S BTIUSSGY="" F BTIUSP=1:1:$L(BTIUSIG," ") S X=$P(BTIUSIG," ",BTIUSP) I X]"" D
 . S Y=$O(^PS(51,"B",X,0)) I Y>0 S X=$P(^PS(51,Y,0),"^",2) I $D(^(9)) S Y=$P(BTIUSIG," ",BTIUSP-1),Y=$E(Y,$L(Y)) S:Y>1 X=$P(^(9),"^",1)
 . S BTIUSSGY=BTIUSSGY_X_" "
 Q
 ;
REF ;DETERMINE THE NUMBER OF REFILLS REMAINING
 N BTIURFL
 I 'BTIURX S BTIUREF=0 Q
 S BTIURFL=$P(^PSRX(BTIURX,0),U,9) S BTIUREF=0 F  S BTIUREF=$O(^PSRX(BTIURX,1,BTIUREF)) Q:'BTIUREF  S BTIURFL=BTIURFL-1
 S BTIUREF=BTIURFL
 Q
 ;
LAST1YRR(DFN) ;EP
 NEW T,E,D,Y,M,G,C,N
 N BTIURXN,BTIUSTAT
 S BTIUREL=0
 S T(1)=$O(^ATXAX("B","BAT ASTHMA SHRT ACT RELV MEDS",0))
 S T(2)=$O(^ATXAX("B","BAT ASTHMA SHRT ACT RELV NDC",0))
 S T(3)=$O(^ATXAX("B","BAT ASTHMA SHRT ACT INHLR MEDS",0))
 S T(4)=$O(^ATXAX("B","BAT ASTHMA SHRT ACT INHLR NDC",0))
 S T(5)=$O(^ATXAX("B","BGP RA GLUCOCORTIOCOIDS MEDS",0))
 S T(6)=$O(^ATXAX("B","BGP RA GLUCOCORTIOCOIDS CLASS",0))
 S E=9999999-$$FMADD^XLFDT(DT,-183)
 S D=0 F  S D=$O(^AUPNVMED("AA",DFN,D)) Q:D'=+D!(D>E)  D
 .S M=0 F  S M=$O(^AUPNVMED("AA",DFN,D,M)) Q:M'=+M  D
 ..Q:'$D(^AUPNVMED(M,0))
 ..S Y=$P(^AUPNVMED(M,0),U)
 ..Q:'Y
 ..;is it active?
 ..I $P(^AUPNVMED(M,0),U,8)]"",$P(^AUPNVMED(M,0),U,8)'>DT Q
 ..S BTIURXN=$O(^PSRX("APCC",M,0))
 ..S G=1 I BTIURXN D
 ...S BTIUSTAT=$P($G(^PSRX(BTIURXN,"STA")),U,1)
 ...I BTIUSTAT'=0 S G=0
 ..I 'G Q
 ..I T(1),$D(^ATXAX(T(1),21,"B",Y)) D SR Q
 ..I T(3),$D(^ATXAX(T(3),21,"B",Y)) D SR Q
 ..I T(5),$D(^ATXAX(T(5),21,"B",Y)) D SR Q
 ..S N=$P($G(^PSDRUG(Y,2)),U,4)
 ..Q:N=""
 ..I N]"",T(2),$D(^ATXAX(T(2),21,"B",N)) D SR Q
 ..I N]"",T(4),$D(^ATXAX(T(4),21,"B",N)) D SR Q
 ..S C=$P(^PSDRUG(Y,0),U,2)
 ..I C,T(6),$D(^ATXAX(T(6),21,"B",C)) D SR Q
 .Q
 Q
SR ;
 S BTIUREL(D,M)="",BTIUREL=BTIUREL+1
 Q
 ;
LAST1YRC(DFN) ;EP
 NEW T,E,D,Y,M,G,C,N
 N BTIURXN,BTIUSTAT
 S BTIUCONT=0
 S T(1)=$O(^ATXAX("B","BAT ASTHMA CONTROLLER MEDS",0))
 S T(2)=$O(^ATXAX("B","BAT ASTHMA CONTROLLER NDC",0))
 S T(3)=$O(^ATXAX("B","BAT ASTHMA INHALED STEROIDS",0))
 S T(4)=$O(^ATXAX("B","BAT ASTHMA INHLD STEROIDS NDC",0))
 S T(5)=$O(^ATXAX("B","BAT ASTHMA LEUKOTRIENE MEDS",0))
 S T(6)=$O(^ATXAX("B","BAT ASTHMA LEUKOTRIENE NDC",0))
 S E=9999999-$$FMADD^XLFDT(DT,-183)
 S D=0 F  S D=$O(^AUPNVMED("AA",DFN,D)) Q:D'=+D!(D>E)  D
 .S M=0 F  S M=$O(^AUPNVMED("AA",DFN,D,M)) Q:M'=+M  D
 ..Q:'$D(^AUPNVMED(M,0))
 ..S Y=$P(^AUPNVMED(M,0),U)
 ..Q:'Y
 ..;is it active?
 ..I $P(^AUPNVMED(M,0),U,8)]"",$P(^AUPNVMED(M,0),U,8)'>DT Q
 ..S BTIURXN=$O(^PSRX("APCC",M,0))
 ..S G=1 I BTIURXN D
 ...S BTIUSTAT=$P($G(^PSRX(BTIURXN,"STA")),U,1)
 ...I BTIUSTAT'=0 S G=0
 ..I 'G Q
 ..I T(1),$D(^ATXAX(T(1),21,"B",Y)) D SC Q
 ..I T(3),$D(^ATXAX(T(3),21,"B",Y)) D SC Q
 ..I T(5),$D(^ATXAX(T(5),21,"B",Y)) D SC Q
 ..S N=$P($G(^PSDRUG(Y,2)),U,4)
 ..Q:N=""
 ..I T(2),$D(^ATXAX(T(2),21,"B",N)) D SC Q
 ..I T(4),$D(^ATXAX(T(4),21,"B",N)) D SC Q
 ..I T(6),$D(^ATXAX(T(6),21,"B",N)) D SC Q
 .Q
 Q
SC ;
 S BTIUCONT(D,M)="",BTIUCONT=BTIUCONT+1
 Q
 ;