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

APCHS73.m

Go to the documentation of this file.
APCHS73 ; IHS/CMI/LAB - PART 7 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ;
 ;;2.0;IHS PCC SUITE;**2,5**;MAY 14, 2009
 ;
 ;
MEDSCURR ; ************** CURRENT MEDICATIONS * 9000010.14 ********
 S APCHSMTY="CURR" G CONT
MEDSALL ; **************** ALL MEDICATIONS * 9000010.14 **********
 S APCHSMTY="ALL" G CONT
MEDSCHRN ; ************* CHRONIC MEDCICATIONS ************
 S APCHSMTY="CHRONIC" G CONT
MEDSNDUP ; ************* ALL, NON DUPLICATED *************
 S APCHSMTY="NODUP" G CONT
 ;
CONT ; <SETUP>
 ;Q:'$D(^AUPNVMED("AC",APCHSPAT))
 X APCHSCKP Q:$D(APCHSQIT)  I 'APCHSNPG W ! X APCHSBRK
 ; <BUILD>
 K ^TMP($J,"APCHSMED")
 S APCHSIVD=0 F  S APCHSIVD=$O(^AUPNVMED("AA",APCHSPAT,APCHSIVD)) Q:APCHSIVD=""!(APCHSIVD>APCHSDLM)  S APCHSMX=0 F  S APCHSMX=$O(^AUPNVMED("AA",APCHSPAT,APCHSIVD,APCHSMX)) Q:APCHSMX=""  D
 .;Q:$P($G(^AUPNVMED(APCHSMX,11)),U,8)]""  ;NON VA MED WILL GET IT LATER
 .S M=+^AUPNVMED(APCHSMX,0)
 .S $P(^TMP($J,"APCHSMED",M),U)=$P($G(^TMP($J,"APCHSMED",M)),U)+1
 .S X=$P(^TMP($J,"APCHSMED",M),U)
 .I X<10 S $P(^TMP($J,"APCHSMED",M),U,(X+1))=$$FMTE^XLFDT((9999999-APCHSIVD),5)
 K ^TMP($J,"APCHSMTB"),^TMP($J,"APCHSMTP"),^TMP($J,"APCHSNO")
 S APCHSIVD=0 F APCHSQ=0:0 S APCHSIVD=$O(^AUPNVMED("AA",APCHSPAT,APCHSIVD)) Q:APCHSIVD=""!(APCHSIVD>APCHSDLM)  S APCHSMX=0 F APCHSQ=0:0 S APCHSMX=$O(^AUPNVMED("AA",APCHSPAT,APCHSIVD,APCHSMX)) Q:APCHSMX=""  D MEDBLD
 D NONVA^APCHS74
 ; <DISPLAY>
 X APCHSCKP I $D(APCHSQIT) G MEDX
 W !,"MEDICATIONS DISPENSED SINCE ",$$FMTE^XLFDT((9999999-APCHSDLM)),!
 W "(C) - Chronic Medication, (CRx) - Controlled Drug",!!
 S (APCHSIVD,APCHSCC)=0 F APCHSQ=0:0 S APCHSIVD=$O(^TMP($J,"APCHSMTP",APCHSIVD)) Q:'APCHSIVD  S:$P(^TMP($J,"APCHSMTP",APCHSIVD),U,2)="C" APCHSCC=APCHSCC+1 D MEDDSP
 ;S (APCHSIVD,APCHSCC)=0 F APCHSQ=0:0 S APCHSIVD=$O(^TMP($J,"APCHSMTP",APCHSIVD)) Q:'APCHSIVD  I $P(^TMP($J,"APCHSMTP",APCHSIVD),U,2)'="C" S APCHSCC=APCHSCC+1 W:APCHSCC=1 !,"Other Medications",!,"Last Fill Date",! D MEDDSP
 ;added last fill date per Carlene 11/14/01
 ; <CLEANUP>
 ;hold meds
 D HOLDDSP^APCHS7
 Q:$D(APCHSQIT)
 ;now display MED refusals
 S APCHST="MEDICATION",APCHSFN=50 D DISPREF^APCHS3C
 D MEDRU^APCHS7
 K APCHST,APCHSFN
MEDX K APCHSIVD,APCHSMX,APCHSMFX,APCHSQTY,APCHSIG,APCHSSGY,APCHSEXP,APCHSMTS,APCHSMED,APCHSDTM,APCHSDAT,APCHSDYS,APCHSN,APCHSDC,APCHSVDF,APCHSP,APCHSNON,APCHSDLU,APCHSIEN
 K APCHSNFL,APCHSNSH,APCHSNAB,APCHSVSC,APCHSITE,APCHSRX,APCHSDRG,APCHSCRN,APCHSREF,APCHSRFL,APCHSALL,APCHSTXT,APCHSMTY
 K ^TMP($J,"APCHSMTB"),^TMP($J,"APCHSMTP"),^TMP($J,"APCHSNO"),^TMP($J,"APCHSMED")
 K X1,X2,X,Y
 Q
MEDBLD ;BUILD ARRAY OF MEDICATIONS 
 ;APCHSDC=DATE DISCONTINUED,DYS=DAYS PRESCRIBED,SIG=DIRECTIONS
 ;VDF=VISIT FILE DATE
 ;Q:$P($G(^AUPNVMED(APCHSMX,11)),U,8)]""  ;NON VA MED WILL GET IT LATERQ:'$D(^AUPNVMED(APCHSMX,0))
 Q:'$D(^AUPNVMED(APCHSMX,0))
 S APCHSN=^AUPNVMED(APCHSMX,0)
 Q:'$D(^PSDRUG($P(APCHSN,U,1)))
 S APCHSDTM=-APCHSIVD\1+9999999
 S APCHSDC=$P(APCHSN,U,8),APCHSDYS=$P(APCHSN,U,7)
 S APCHSMFX=$S($P(APCHSN,U,4)="":+APCHSN,$P(APCHSN,U,4)=$P(^PSDRUG(+APCHSN,0),U):+APCHSN,1:$P(APCHSN,U,4))
 S APCHSCHR=$$CHRONIC^APCHS72(APCHSMX),APCHSCHR=$S(APCHSCHR=1:"C",1:"C")
 D @APCHSMTY
 Q
 ;
CURR ; current meds only
 I $D(^TMP($J,"APCHSMTB",APCHSMFX)),^TMP($J,"APCHSMTB",APCHSMFX)="" Q
 S X1=DT,X2=APCHSDTM D ^%DTC Q:X>60&(X>(2*APCHSDYS))
 S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX
 Q
ALL ;all meds included
 S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX
 ;
 Q
NODUP ;
 ;I $D(^TMP($J,"APCHSMTB",APCHSMFX)) Q
 ;S X="" F  S X=$O(^TMP($J,"APCHSMTP",X)) Q:X=""  I $P(X,"-",2)=APCHSMFX K ^TMP($J,"APCHSMTP",X)
 I $D(^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)) S ^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX_"^"_APCHSCHR
 I $D(^TMP($J,"APCHSMTB",APCHSMFX)) Q
 S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX_"^"_APCHSCHR
 Q
CHRONIC ;chronic meds only
 I $D(^TMP($J,"APCHSMTB",APCHSMFX)) Q
 S X=$S($D(^PSRX("APCC",APCHSMX)):$O(^(APCHSMX,0)),1:0)
 S Y=$S(+X:$D(^PS(55,APCHSPAT,"P","CP",X)),1:0)
 Q:'Y
 S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX
 Q
MEDDSP ;DISPLAY MEDICATION
 ;APCHSRX=RX# in FILE 52,CHRN=CHRONIC FLAG,REF=#REFILLS
 S APCHSMX=$P(^TMP($J,"APCHSMTP",APCHSIVD),U)
 I $P(APCHSMX,U,1)="" D NVADSP Q
 S APCHSN=^AUPNVMED(APCHSMX,0)
 S APCHSIEN=+APCHSN
 S APCHSRX=$S($D(^PSRX("APCC",APCHSMX)):$O(^(APCHSMX,0)),1:0)
 S APCHSCRN=$S(+APCHSRX:$D(^PS(55,APCHSPAT,"P","CP",APCHSRX)),1:0)
 S (Y,APCHSDTM)=-APCHSIVD\1+9999999 X APCHSCVD S APCHSDAT=Y
 S APCHSDC=$P(APCHSN,U,8),APCHSDYS=$P(APCHSN,U,7),APCHSQTY=$P(APCHSN,U,6),APCHSIG=$P(APCHSN,U,5),APCHSVDF=$P(APCHSN,U,3),APCHSMFX=+APCHSN
 S X1=DT,X2=APCHSDTM D ^%DTC ;Q:X>60&(X>(2*APCHSDYS))
 S APCHSEXP=""
 S APCHSMED=$S($P(APCHSN,U,4)="":$P(^PSDRUG(APCHSMFX,0),U,1),1:$P(APCHSN,U,4))
 I APCHSDC S Y=APCHSDC X APCHSCVD S APCHSEXP="-- D/C "_Y
 S APCHORTS=$P($G(^AUPNVMED(APCHSMX,11)),U)
 I APCHORTS["RETURNED TO STOCK",APCHSDC S APCHSEXP="--RTS "_Y
 D SIG S APCHSIG=APCHSSGY
 D REF I APCHSREF S APCHSIG=APCHSIG_" "_APCHSREF_$S(APCHSREF=1:" refill",1:" refills")_" left."
 S V=$P(^AUPNVMED(APCHSMX,0),U,3) I $P($G(^AUPNVSIT(+V,0)),U,7)="E" S APCHSIG=APCHSIG_"  (OUTSIDE MEDICATION)"
 D SITE ;I APCHSITE]"" S APCHSIG=APCHSIG_"  ["_APCHSITE_"]"
 S APCHCRX=""
 I $P(^PSDRUG(APCHSMFX,0),U,3)[2 S APCHCRX=1
 I $P(^PSDRUG(APCHSMFX,0),U,3)[3 S APCHCRX=1
 I $P(^PSDRUG(APCHSMFX,0),U,3)[4 S APCHCRX=1
 I $P(^PSDRUG(APCHSMFX,0),U,3)[5 S APCHCRX=1
 X APCHSCKP Q:$D(APCHSQIT)
 W APCHSDAT,?9,$S(APCHSCRN:"(C) ",1:""),$S(APCHCRX:"(CRx)",1:""),?19,APCHSMED W:APCHSQTY " #",APCHSQTY
 W:APCHSDYS " (",APCHSDYS," days) " W APCHSEXP,!
 I APCHSITE]"" W ?19,"Dispensed at: ",APCHSITE,!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSICL=19,APCHSNRQ="",APCHSTXT="  "_APCHSIG D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 X APCHSCKP Q:$D(APCHQUIT)
 I APCHSRX,$D(^PSRX(APCHSRX,0)) W ?21,"Most recent issue date:  ",$$FMTE^XLFDT($P(^PSRX(APCHSRX,0),U,13),5),!
 S Y=$P(^TMP($J,"APCHSMED",APCHSIEN),U)
 Q:Y<2
 X APCHSCKP Q:$D(APCHSQIT)
 W ?21,"# times prev filled: ",Y-1 W "  " F I=3:1:5 W " ",$P(^TMP($J,"APCHSMED",APCHSIEN),U,I)
 W !
 Q
 ;
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
 S APCHSSGY="" F APCHSP=1:1:$L(APCHSIG," ") S X=$P(APCHSIG," ",APCHSP) 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(APCHSIG," ",APCHSP-1),Y=$E(Y,$L(Y)) S:Y>1 X=$P(^(9),"^",1)
 . S APCHSSGY=APCHSSGY_X_" "
 Q
 ;
REF ;DETERMINE THE NUMBER OF REFILLS REMAINING
 I 'APCHSRX S APCHSREF=0 Q
 S APCHSRFL=$P(^PSRX(APCHSRX,0),U,9) S APCHSREF=0 F  S APCHSREF=$O(^PSRX(APCHSRX,1,APCHSREF)) Q:'APCHSREF  S APCHSRFL=APCHSRFL-1
 S APCHSREF=APCHSRFL
 Q
 ;
 ;
SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
 S APCHSITE=""
 I $D(^AUPNVSIT(APCHSVDF,21))#2 S APCHSITE=$P(^(21),U) Q
 Q:$P(^AUPNVSIT(APCHSVDF,0),U,6)=""
 I $P(^AUPNVSIT(APCHSVDF,0),U,6)'=DUZ(2) S APCHSITE=$E($P(^DIC(4,$P(^AUPNVSIT(APCHSVDF,0),U,6),0),U),1,30)
 Q
NVADSP ;
 S APCHSEXP=""
 S (Y,APCHSDTM)=-APCHSIVD\1+9999999 X APCHSCVD S APCHSDAT=Y
 S APCHSDC=$P(^TMP($J,"APCHSMTP",APCHSIVD),U,5)
 S APCHSMED=$P(^TMP($J,"APCHSMTP",APCHSIVD),U,3)
 I APCHSDC S Y=APCHSDC X APCHSCVD S APCHSEXP="-- D/C "_Y
 S APCHSIG=$P(^TMP($J,"APCHSMTP",APCHSIVD),U,4)
 X APCHSCKP Q:$D(APCHSQIT)
 W APCHSDAT,?19,APCHSMED,"  ",APCHSEXP,!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSICL=19,APCHSNRQ="",APCHSTXT=APCHSIG_"  (EHR OUTSIDE MEDICATION)" D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 Q