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

BHSMSUP1.m

Go to the documentation of this file.
BHSMSUP1 ;IHS/CIA/MGH - Health Summary for Supplements ;17-Mar-2006 10:36;MGH
 ;;1.0;HEALTH SUMMARY COMPONENTS;;March 17, 2006
 ;===================================================================
 ;Taken from APCHS9M2
 ; IHS/TUCSON/LAB - MEDICATION TURN AROUND SUPPLEMENT;  [ 05/10/04  2:03 PM ]
 ;;2.0;IHS RPMS/PCC Health Summary;**12**;JUN 24, 1997
 ;==================================================================
 ;
EP ;EP - called from component
 N BHSPAT
 S BHSPAT=DFN
 Q:'$G(BHSPAT)
 Q:'$D(^AUPNVMED("AC",BHSPAT))
 D CKP^GMTSUP Q:$D(GMTSQIT)
WR ;write out array
 K BHSQUIT
 S BHSPAGE=0,BHSQUIT=0
 D EP2  ;write out document
 I BHSQUIT S GMTSQIT=1
 D EOJ
 Q
 ;
EOJ ;
 K BHSCLN,BHSDATM,BHSDIEN,BHSIPRV,BHSMIEN,BHSNARC,BHSPAGE,BHSPROV,BHSQUIT,BHSRTN,BHSTXRF,BHSBEG,BHSCRN,BHSDC,BHSDLM,BHSDOO,BHSDTM,BHSDYS,BHSED,BHSEXP,BHSRXRF
 K BHSICL,BHSIG,BHSITE,BHSIVD,BHSM0,BHSNAM,BHSNRQ,BHSP,BHSQTY,BHSREF,BHSRFL,BHSRX,BHSSGY,BHSTEX,BHSTOB,BHSTOP,BHSTXT,BHSUPI,BHSTC,BHSTILN,BHSTOB,BHSTOBN,BHSTQ,BHSTYPE,BHSVIEN,BHSX,BHSXRX,BHSY
 K DIR,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,V,X,Y,Z,W,X1,X2
 Q
EP2 ;PEP - PASS DFN get back array of patient care summary
 ;at this point you are stuck with ^TMP("BHS",$J,"DCS"
 K ^TMP($J,"BHSMEDS")
 K ^TMP($J,"BHSCOUNT")
 K ^TMP($J,"BHSMEDSA")
 K ^TMP($J,"BHSMEDSG")
 D SETARRAY
 Q
SETARRAY ;set up array containing dm care summary
 D GETMEDS
 Q
GETMEDS ;
 ;gather up in ^TMP all meds in past year that are current or Chronic
 S BHSDLM=$$FMADD^XLFDT(DT,-1030)
 S BHSDLM=9999999-BHSDLM
 Q:'$D(^AUPNVMED("AC",BHSPAT))  ;patient has no meds
 S BHSIVD=0 F  S BHSIVD=$O(^AUPNVMED("AA",BHSPAT,BHSIVD)) Q:BHSIVD=""!(BHSIVD>BHSDLM)  D
 .S BHSMIEN=0 F  S BHSMIEN=$O(^AUPNVMED("AA",BHSPAT,BHSIVD,BHSMIEN)) Q:BHSMIEN'=+BHSMIEN  D
 ..S BHSM0=^AUPNVMED(BHSMIEN,0)
 ..Q:$P(BHSM0,U)=""
 ..Q:'$D(^PSDRUG($P(BHSM0,U),0))
 ..S BHSDATM=9999999-$P(BHSIVD,".")  ;visit date
 ..S BHSDC=$P(BHSM0,U,8)
 ..S BHSDYS=$P(BHSM0,U,7) S:BHSDYS=0 BHSDYS=30  ;days supply
 ..S BHSNAM=$S($P(BHSM0,U,4)]"":$P(BHSM0,U,4),1:$P(^PSDRUG($P(BHSM0,U),0),U))  ;free text name if exists
 ..S BHSDIEN=$P(BHSM0,U,1)  ;drug ien
 ..S $P(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN),U)=$P($G(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN)),U)+1  ;store last of each different drug and keep counter
 ..S X=$P(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN),U)
 ..I X<10 S $P(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN),U,(X+1))=$$DATE((9999999-BHSIVD))
 ..I $$CHRONIC(BHSMIEN) D  Q
 ...Q:$D(^TMP($J,"BHSMEDSG","CHRONIC",BHSNAM,BHSDIEN))  ;already have this one
 ...S ^TMP($J,"BHSMEDS","CHRONIC",BHSIVD,BHSNAM,BHSDIEN,BHSMIEN)="",^TMP($J,"BHSMEDSG","CHRONIC",BHSNAM,BHSDIEN)=""
 ..S X=$$FMDIFF^XLFDT(DT,BHSDATM) Q:X>60&(X>(2*BHSDYS))
 ..Q:$D(^TMP($J,"BHSMEDSG","CURRENT",BHSNAM,BHSDIEN))  ;already have this one
 ..S ^TMP($J,"BHSMEDS","CURRENT",BHSIVD,BHSNAM,BHSDIEN,BHSMIEN)="",^TMP($J,"BHSMEDSG","CURRENT",BHSNAM,BHSDIEN)=""
 .Q
 I '$D(^TMP($J,"BHSMEDS","CURRENT")),'$D(^TMP($J,"BHSMEDS","CHRONIC")) Q  ;no meds to display
 ;NOW GET RID OF ALL DISCONTINUED MEDS BY .08 OF VMED OR BY STATUS IN FILE 52
 S I=0 F  S I=$O(^TMP($J,"BHSMEDS","CURRENT",I)) Q:I'=+I  S N="" F  S N=$O(^TMP($J,"BHSMEDS","CURRENT",I,N)) Q:N=""  S D=0 F  S D=$O(^TMP($J,"BHSMEDS","CURRENT",I,N,D)) Q:D'=+D  D
 .S M=0 F  S M=$O(^TMP($J,"BHSMEDS","CURRENT",I,N,D,M)) Q:M'=+M  I $$DC(M) K ^TMP($J,"BHSMEDS","CURRENT",I,N,D,M)
 S I=0 F  S I=$O(^TMP($J,"BHSMEDS","CHRONIC",I)) Q:I'=+I  S N="" F  S N=$O(^TMP($J,"BHSMEDS","CHRONIC",I,N)) Q:N=""  S D=0 F  S D=$O(^TMP($J,"BHSMEDS","CHRONIC",I,N,D)) Q:D'=+D  D
 .S M=0 F  S M=$O(^TMP($J,"BHSMEDS","CHRONIC",I,N,D,M)) Q:M'=+M  I $$DC(M) K ^TMP($J,"BHSMEDS","CHRONIC",I,N,D,M)
 S C=1,X=$O(^TMP($J,"BHSMEDS","CHRONIC",0)) D
 .I X="" S C=0 Q
 .S X=9999999-X I X<$$FMADD^XLFDT(DT,-366) S C=0
 S R=1,X=$O(^TMP($J,"BHSMEDS","CURRENT",0)) D
 .I X="" S R=0 Q
 .S X=9999999-X I X<$$FMADD^XLFDT(DT,-366) S R=0
 I 'C,'R Q  ;no meds in past year
 ;REORDER BY NAME AND USE THAT ARRAY
 K ^TMP($J,"BHSMEDSA")
 S BHSTOP=$$FMADD^XLFDT(DT,-366),BHSTOP=9999999-BHSTOP
 S X="" F  S X=$O(^TMP($J,"BHSMEDS",X)) Q:X=""  D
 .S D=0 F  S D=$O(^TMP($J,"BHSMEDS",X,D)) Q:D'=+D!(D>BHSTOP)  D
 ..S N="" F  S N=$O(^TMP($J,"BHSMEDS",X,D,N)) Q:N=""  D
 ...S Y=0 F  S Y=$O(^TMP($J,"BHSMEDS",X,D,N,Y)) Q:Y=""  D
 ....S M=0 F  S M=$O(^TMP($J,"BHSMEDS",X,D,N,Y,M)) Q:M'=+M  S ^TMP($J,"BHSMEDSA",X,N,Y,D,M)=^TMP($J,"BHSMEDS",X,D,N,Y,M)
 D CKP^GMTSUP Q:$D(GMTSQIT)
 K BHSCRN S BHSTYPE="CURRENT" D MEDDSP
 S BHSCRN=1 S BHSTYPE="CHRONIC" D MEDDSP
 I 'BHSQUIT W !!!,"DISPENSE UNTIL NEXT SCHEDULED EVALUATION: ________",!!,"SIGNATURE: _______________________________  DATE: ________________",!
 K ^TMP($J,"BHSMEDS")
 K ^TMP($J,"BHSCOUNT")
 K ^TMP($J,"BHSMEDSA")
 K ^TMP($J,"BHSMEDSG")
 Q
MEDDSP ;
 S X=""
 Q:'$D(^TMP($J,"BHSMEDSA",BHSTYPE))  ;NO MEDS TO DISPLAY
 I BHSTYPE="CURRENT" S X="CURRENT MEDICATIONS - (TWICE DURATION OF RX - MINIMUM 60 DAYS)" D W(X,1)
 I BHSTYPE="CHRONIC" S X="LATEST OF EACH CHRONIC MEDICATION DISPENSED IN THE PAST YEAR" D W(X,1)
 S BHSTOP=$$FMADD^XLFDT(DT,-366),BHSTOP=9999999-BHSTOP
 S BHSNAM=0 F  S BHSNAM=$O(^TMP($J,"BHSMEDSA",BHSTYPE,BHSNAM)) Q:BHSNAM=""!(BHSQUIT)  D
 .S BHSDIEN=0 F  S BHSDIEN=$O(^TMP($J,"BHSMEDSA",BHSTYPE,BHSNAM,BHSDIEN)) Q:BHSDIEN'=+BHSDIEN!(BHSQUIT)  D
 ..S BHSIVD=0 S BHSIVD=$O(^TMP($J,"BHSMEDSA",BHSTYPE,BHSNAM,BHSDIEN,BHSIVD)) Q:BHSIVD=""!(BHSQUIT)  D
 ...S BHSMIEN=0 S BHSMIEN=$O(^TMP($J,"BHSMEDSA",BHSTYPE,BHSNAM,BHSDIEN,BHSIVD,BHSMIEN)) D MEDDSP1
 ...Q
 ..Q
 .Q
 Q
MEDDSP1 ;
 S BHSM0=^AUPNVMED(BHSMIEN,0)
 S BHSRX=$O(^PSRX("APCC",BHSMIEN,0)) I 'BHSRX S BHSXRX=0
 S BHSRXRF=""
 I BHSRX S BHSRXRF=$O(^PSRX("APCC",BHSMIEN,BHSRX,"")) S:BHSRXRF="" BHSRXRF=0
 S (Y,BHSDTM)=9999999-$P(BHSIVD,".")
 ;S BHSDTM=$$DATE(BHSDTM)
 S BHSDC=$P(BHSM0,U,8)
 S BHSDYS=$P(BHSM0,U,7) S:BHSDYS=0 BHSDYS=30
 S BHSNAM=$S($P(BHSM0,U,4)]"":$P(BHSM0,U,4),1:$P(^PSDRUG($P(BHSM0,U),0),U))
 S BHSQTY=$P(BHSM0,U,6)
 S BHSIG=$P(BHSM0,U,5)
 S BHSVIEN=$P(BHSM0,U,3)
 S BHSDIEN=+BHSM0
 S X1=DT,X2=BHSDTM D ^%DTC
 S BHSEXP=""
 I X>BHSDYS S X1=BHSDTM,X2=BHSDYS D C^%DTC S BHSEXP="-- Ran out "_$$DATE(X)
 S BHSNARC=+$P(^PSDRUG(BHSDIEN,0),U,3)
 ;ADDED RETURNED TO STOCK FLAG FOR NEXT 4 LINES IHS/OKCAO/POC 12/19/97
 IF $P($G(^AUPNVMED(BHSMIEN,11)),U)="RETURNED TO STOCK" S BHSRTN="R"
 I BHSDC,$G(BHSRTN)="R" S X=BHSDC D REGDT4^GMTSU S BHSEXP="--Returned to Stock "_X
 I BHSDC,$G(BHSRTN)="" S X=BHSDC D REGDT4^GMTSU S BHSEXP="-- D/C "_X
 K BHSRTN
 D SIG S BHSIG=BHSSGY
 D REF
 I BHSREF S BHSREF=BHSREF_$S(BHSREF=1:" refill",1:" refills")_" left."
 S BHSITE=$P(^AUPNVSIT(BHSVIEN,0),U,6)
 D PROV
 D CLN
 D SITE
 D WRITE
 Q
WRITE ;
 I $Y>(IOSL-10) D  Q:BHSQUIT
 .W !!!,"DISPENSE UNTIL NEXT SCHEDULED EVALUATION: ________"
 .W !!!,"SIGNATURE: ________________________________  DATE: ________________",!
 .D CKP^GMTSUP Q:$D(GMTSQIT)
 Q:BHSQUIT
 S X=$$DATE(BHSDTM),$E(X,10)=BHSNAM_"  "_BHSEXP D W(X,1)
 S X="",$E(X,10)="QTY: "_BHSQTY_"   ("_BHSDYS_" days)   "_BHSPROV_$S(BHSCLN]"":" - "_BHSCLN,1:"") D W(X)
 S BHSICL=10,BHSNRQ="",BHSTXT=BHSIG D PRTTXT K BHSICL,BHSNRQ,BHSP
 ;ISSUE HISTORY
 ;I BHSRX,$D(^PSRX(BHSRX,0)) S X="",$E(X,10)="Most recent issue date:  "_$$FMTE^XLFDT($P(^PSRX(BHSRX,0),U,13),5) D W(X)
 I BHSITE]"" S X="",$E(X,10)="Prescribed at: "_BHSITE D W(X)
 S X=""
 S Y=$P(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN),U)
 I Y>1 S X="" D
 .S X="",$E(X,10)="Previously filled: " F I=3:1:5 S X=X_" "_$P(^TMP($J,"BHSCOUNT",BHSNAM,BHSDIEN),U,I)
 I X]"" D W(X)
 I BHSREF S X="",$E(X,10)=BHSREF D W(X)
 S X=""
 I $G(BHSNARC)=2 S $E(X,10)="------- MUST REWRITE SCHEDULE 2 DRUGS -------" D W(X,1) Q
 I $G(BHSNARC)>2,$G(BHSNARC)<6 S $E(X,10)="RENEW __________ QTY __________ DC __________" D W(X,1) Q
 S $E(X,10)="RENEW __________  DC __________  " D W(X,1)
 Q
 ;
SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
 S BHSITE=""
 I $D(^AUPNVSIT(BHSVIEN,21))#2 S BHSITE=$P(^(21),U) Q
 Q:$P(^AUPNVSIT(BHSVIEN,0),U,6)=""
 I $P(^AUPNVSIT(BHSVIEN,0),U,6)'=DUZ(2) S BHSITE=$E($P(^DIC(4,$P(^AUPNVSIT(BHSVIEN,0),U,6),0),U),1,30)
 Q
 ;
DC(V) ;is this d/c'ed
 I '$D(^AUPNVMED(V,0)) Q 0
 I $P(^AUPNVMED(V,0),U,8)]"" Q 1
 NEW P,S
 S P=$S($D(^PSRX("APCC",N)):$O(^(N,0)),1:0)
 I 'P Q 0
 S X=$P($G(^PSRX(P,0)),U,15)
 I X=12 Q 1
 I X=13 Q 1
 I X=14 Q 1
 I X=15 Q 1
 Q 0
SIG ;
 ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
 ;I $$VALI^XBDIQ1(9001015,BHSTYP,3.5)="S" S BHSSGY=BHSIG Q
 S BHSSGY="" F BHSP=1:1:$L(BHSIG," ") S X=$P(BHSIG," ",BHSP) 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(BHSIG," ",BHSP-1),Y=$E(Y,$L(Y)) S:Y>1 X=$P(^(9),"^",1)
 . S BHSSGY=BHSSGY_X_" "
 Q
 ;
REF ;
 ;DETERMINE THE NUMBER OF REFILLS REMAINING
 I 'BHSRX S BHSREF="unknown # refills" Q
 S BHSRFL=$P(^PSRX(BHSRX,0),U,9) S BHSREF=0 F  S BHSREF=$O(^PSRX(BHSRX,1,BHSREF)) Q:'BHSREF  S BHSRFL=BHSRFL-1
 S BHSREF=BHSRFL
 Q
 ;
PROV ;GET THE PROVIDER FOR ORIGINAL RX OR REFILL
 S BHSPROV=""
 I 'BHSRX S BHSPROV=$$VAL^XBDIQ1(9000010.14,1202,BHSMIEN) Q
 S BHSIPRV=$S(BHSRXRF=0:$P($G(^PSRX(BHSRX,0)),"^",4),1:$P($G(^PSRX(BHSRX,1,BHSRXRF,0)),"^",17))
 S BHSPROV=$S('BHSIPRV:"UNKNOWN PROVIDER",1:$P(^VA(200,BHSIPRV,0),"^"))
 Q
 ;
CLN ;GET CLINIC FOR V MEDICATION
 S BHSCLN=$E($$VAL^XBDIQ1(9000010,BHSVIEN,.08),1,10)
 Q
DATE(D) ;EP
 I D="" Q ""
 Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_$E(D,2,3)
 ;
CHRONIC(N) ;
 I '$G(N) Q ""
 I '$D(^AUPNVMED(N)) Q ""
 NEW X,Y,P
 S P=$P(^AUPNVMED(N,0),U,2)
 S X=$S($D(^PSRX("APCC",N)):$O(^(N,0)),1:0)
 S Y=$S(+X:$D(^PS(55,P,"P","CP",X)),1:0)
 I 'Y Q ""
 Q 1
W(Y,F,C,T) ;set up array
 I '$G(F) S F=0
 I '$G(T) S T=0
 NEW %,X
 ;blank lines
 F F=1:1:F S X="" W !,X
 S X=Y
 I $G(C) S L=$L(Y),T=(80-L)/2 D  W !,X Q
 .F %=1:1:(T-1) S X=" "_X
 F %=1:1:T S X=" "_Y
 W !,X
 Q
PRTTXT ; GENERALIZED TEXT PRINTER
 S BHSTDLT=1,BHSTILN=80-BHSICL-1
 F BHSTQ=0:0 S:BHSNRQ]""&(($L(BHSNRQ)+$L(BHSTXT)+2)<255) BHSTXT=$S(BHSTXT]"":BHSTXT_"; ",1:"")_BHSNRQ,BHSNRQ="" Q:BHSTXT=""  D PRTTXT2
 K BHSTILN,BHSTDLT,BHSTF,BHSTC,BHSTXT,BHSDOO
 Q
PRTTXT2 D GETFRAG S X="",$E(X,BHSICL)=BHSTF D W(X) S BHSICL=BHSICL+BHSTDLT,BHSTILN=BHSTILN-BHSTDLT,BHSTDLT=0
 Q
GETFRAG I $L(BHSTXT)<BHSTILN S BHSTF=BHSTXT,BHSTXT="" Q
 F BHSTC=BHSTILN:-1:1 Q:$E(BHSTXT,BHSTC)=" "
 S BHSTF=$E(BHSTXT,1,BHSTC-1),BHSTXT=$E(BHSTXT,BHSTC+1,255)
 Q
 ;