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

APCHS7.m

Go to the documentation of this file.
APCHS7 ; IHS/CMI/LAB - PART 7 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ; 09 Aug 2010  10:17 AM
 ;;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
MEDSCHR1 ; ******* CHRONIC MEDICATIONS, W/O D/C'ED *******
 S APCHSMTY="CHRONIC",APCHSDCP=1 G CONT
 ;
CONT ; <SETUP>
 ;Q:'$D(^AUPNVMED("AC",APCHSPAT))
 X APCHSCKP Q:$D(APCHSQIT)  I 'APCHSNPG W ! X APCHSBRK
 ; <BUILD>
 K ^TMP($J,"APCHSMTB"),^TMP($J,"APCHSMTP")
 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  ;get all NON-VA meds that didn't pass to PCC
 ; <DISPLAY>
 S APCHSIVD=0 F APCHSQ=0:0 S APCHSIVD=$O(^TMP($J,"APCHSMTP",APCHSIVD)) Q:'APCHSIVD  D MEDDSP
 ; <CLEANUP>
 ;now display all meds on hold
 D HOLDDSP
 ;now display MED refusals
 S APCHST="MEDICATION",APCHSFN=50 D DISPREF^APCHS3C
 D MEDRU  ;display last date reviewed/updated/nam
 K APCHST,APCHSFN
MEDX K APCHSIVD,APCHSMX,APCHSMFX,APCHSQTY,APCHSIG,APCHSSGY,APCHSEXP,APCHSMTS,APCHSMED,APCHSDTM,APCHSDAT,APCHSDYS,APCHSN,APCHSDC,APCHSVDF,APCHSP,APCHORTS,APCHSDCP
 K APCHSNFL,APCHSNSH,APCHSNAB,APCHSVSC,APCHSITE,APCHSRX,APCHSDRG,APCHSCRN,APCHSREF,APCHSRFL,APCHSALL,APCHSTXT,APCHSMTY
 K ^TMP($J,"APCHSMTB"),^TMP($J,"APCHSMTP")
 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)]""  ;WILL GET NON-VA MEDS LATER
 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),APCHSMFX=+APCHSN
 S APCHSDC=$P(APCHSN,U,8),APCHSDYS=$P(APCHSN,U,7),APCHSMFX=$S($P(APCHSN,U,4)="":+APCHSN,1:$P(APCHSN,U,4))
 S APCHSCMT=$P($G(^AUPNVMED(APCHSMX,11)),U,1)
 ;I $D(^TMP($J,"APCHSMTB",APCHSMFX)),^TMP($J,"APCHSMTB",APCHSMFX)="" Q
 S:APCHSDYS="" APCHSDYS=30
 ;SCREENS OUT MEDS NOT CURRENT; APCHSALL FORCES INCLUSION OF ALL MEDS
 ;I 'APCHSALL 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
 D @APCHSMTY
 Q
NONVA ;EP - ;NEW DFN,PSOACT S DFN=APCHSPAT,PSOACT=1 D ^PSOHCSUM
 ;quit if chronic
 Q:APCHSMTY="CHRONIC"
 S X=0 F  S X=$O(^PS(55,APCHSPAT,"NVA",X)) Q:X'=+X  D
 .I $P($G(^PS(55,APCHSPAT,"NVA",X,999999911)),U,1),$D(^AUPNVMED($P(^PS(55,APCHSPAT,"NVA",X,999999911),U,1),0)) Q
 .;S L=$P(^PS(55,APCHSPAT,"NVA",X,0),U,9)
 .;:'L
 .S L=$P($P($G(^PS(55,APCHSPAT,"NVA",X,0)),U,10),".")
 .S L=9999999-L
 .Q:L>APCHSDLM
 .;S M=$P($G(^PS(55,APCHSPAT,"NVA",X,999999911)),U,1)  ;passed to PCC so got it already
 .;I M,$D(^AUPNVMED(M)) Q  ;passed to PCC and v med exists so we already got it from V MED
 .S D=$P(^PS(55,APCHSPAT,"NVA",X,0),U,2)
 .I D="" S D="NO DRUG IEN"
 .S N=$S(D:$P(^PSDRUG(D,0),U,1),1:$P(^PS(50.7,$P(^PS(55,APCHSPAT,"NVA",X,0),U,1),0),U,1))
 .S ^TMP($J,"APCHSMTP",L_"-"_N)=U_$P(^PS(55,APCHSPAT,"NVA",X,0),U,6)_U_N_U_$P(^PS(55,APCHSPAT,"NVA",X,0),U,4)_" "_$P(^PS(55,APCHSPAT,"NVA",X,0),U,5)_U_$P(^PS(55,APCHSPAT,"NVA",X,0),U,7)
 .S ^TMP($J,"APCHSMTB",N)=$P(^PS(55,APCHSPAT,"NVA",X,0),U,6)
 Q
 ;
CURR ; current meds only
 I $D(^TMP($J,"APCHSMTB",APCHSMFX)),^TMP($J,"APCHSMTB",APCHSMFX)="" Q  ;ALREADY GOT THIS MED
 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
 ;now get NVA meds
 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
 I $D(^TMP($J,"APCHSMTB",APCHSMFX)) Q
 S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSIVD_"-"_APCHSMFX)=APCHSMX
 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
 I $G(APCHSDCP),APCHSDC]"",APCHSCMT'="RETURNED TO STOCK" Q  ;IHS/CMI/LAB - new component patch 9
 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=^TMP($J,"APCHSMTP",APCHSIVD)
 I $P(APCHSMX,U,1)="" D NVADSP Q
 S APCHSN=^AUPNVMED(APCHSMX,0)
 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:APCHSDYS="" APCHSDYS=30
 S X1=DT,X2=APCHSDTM D ^%DTC ;Q:X>60&(X>(2*APCHSDYS))
 S APCHSEXP=""
 I X>APCHSDYS S X1=APCHSDTM,X2=APCHSDYS D C^%DTC S Y=X X APCHSCVD S APCHSEXP="-- Ran out "_Y
 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
 ;CHANGE IT AROUND A BIT LOOK FOR RETURNED TO STOCK IHS/OKCAO/POC 2/14/2000
 S APCHORTS=$G(^AUPNVMED(APCHSMX,11))
 I APCHORTS["RETURNED TO STOCK",APCHSDC S APCHSEXP="--RTS "_Y
 ;END OF LOCAL CHANGES IHS/OKCAO/POC 2/14/2000
 D SIG S APCHSIG=APCHSSGY
 D REF I APCHSREF S APCHSIG=APCHSIG_" "_APCHSREF_$S(APCHSREF=1:" refill",1:" refills")_" left."
 I '$P($G(^AUPNVMED(APCHSMX,11)),U,8) S V=$P(^AUPNVMED(APCHSMX,0),U,3) I $P($G(^AUPNVSIT(+V,0)),U,7)="E" S APCHSIG=APCHSIG_"  (OUTSIDE MEDICATION)"
 I $P($G(^AUPNVMED(APCHSMX,11)),U,8) S APCHSIG=APCHSIG_"  (EHR OUTSIDE MEDICATION)"
 D SITE ;I APCHSITE]"" S APCHSIG=APCHSIG_"  ["_APCHSITE_"]"
 X APCHSCKP Q:$D(APCHSQIT)
 W APCHSDAT,?10,$S(APCHSCRN:"(C)",1:""),?14,APCHSMED," #",APCHSQTY," (",APCHSDYS," days) ",APCHSEXP,!
 I APCHSITE]"" W ?14,"Dispensed at: ",APCHSITE,!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSICL=14,APCHSNRQ="",APCHSTXT=APCHSIG D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 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,?14,APCHSMED,"  ",APCHSEXP,!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSICL=14,APCHSNRQ="",APCHSTXT=APCHSIG_"  (EHR OUTSIDE MEDICATION)" D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 Q
 ;
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
 I $$VALI^XBDIQ1(9001015,APCHSTYP,3.5)="S" S APCHSSGY=APCHSIG Q
 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($G(^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($G(^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
 ;
HOLDMEDS(P,R) ;EP - get meds on hold for display
 ;return array of med iens of all meds for this patient that are on hold
 I '$G(P) Q
 NEW D,C,N
 S D=DT
 F  S D=$O(^PS(55,P,"P","A",D)) Q:D'=+D  D
 .S N=0 F  S N=$O(^PS(55,P,"P","A",D,N)) Q:'N  D
 ..Q:'$$HOLD(N)
 ..S R(N)=""
 ..Q
 Q
 ;
HOLD(S) ;EP - is this prescription on hold?
 NEW X
 S X=$P($G(^PSRX(S,"STA")),U,1)
 I X=3 Q 1
 I X=5 Q 1
 I X=16 Q 1
 ;version 6
 S X=$P($G(^PSRX(S,0)),U,15)
 I X=3 Q 1
 I X=5 Q 1
 I X=16 Q 1
 Q 0
 ;
HOLDDSP ;EP - display all meds on hold
 K APCHHMED
 D HOLDMEDS(APCHSPAT,.APCHHMED)
 Q:'$D(APCHHMED)
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"The following medications have been processed in the Pharmacy "
 W !,"system, and are currently active but not dispensed:",!,!
 S APCHSRX=0 F  S APCHSRX=$O(APCHHMED(APCHSRX)) Q:APCHSRX'=+APCHSRX!($D(APCHSQIT))  D
 .D HOLDDSP1
 .Q
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"Medications may be active but not dispensed for several reasons including: "
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"Too early for refill, patient has sufficient amount on hand, pharmacy"
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"resolving issue with prescriber, etc. Contact Pharmacy staff for "
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"details or view prescription details in Pharmacy system.",!
 K APCHHMED
 Q
HOLDDSP1 ;write out med
 S APCHSCRN=$S(+APCHSRX:$D(^PS(55,APCHSPAT,"P","CP",APCHSRX)),1:0)
 S (Y,APCHSDTM)=$P(^PSRX(APCHSRX,0),U,13) X APCHSCVD S APCHSDAT=Y  ;issue or fill??
 S APCHSDYS=$P(^PSRX(APCHSRX,0),U,8)
 S APCHSQTY=$P(^PSRX(APCHSRX,0),U,7)
 S APCHSIG=$P(^PSRX(APCHSRX,0),U,10)
 D SIG S APCHSIG=APCHSSGY
 D REF I APCHSREF S APCHSIG=APCHSIG_" "_APCHSREF_$S(APCHSREF=1:" refill",1:" refills")_" left."
 ;D SITE ;I APCHSITE]"" S APCHSIG=APCHSIG_"  ["_APCHSITE_"]"
 X APCHSCKP Q:$D(APCHSQIT)
 W APCHSDAT,?10,$S(APCHSCRN:"(C)",1:""),?14,$$VAL^XBDIQ1(52,APCHSRX,6)," #",APCHSQTY," (",APCHSDYS," days) ",!
 ;I APCHSITE]"" W ?14,"Dispensed at: ",APCHSITE,!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSICL=14,APCHSNRQ="",APCHSTXT=APCHSIG D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 W ?14,"Ordering Provider: ",$$VAL^XBDIQ1(52,APCHSRX,4),!
 X APCHSCKP Q:$D(APCHSQIT)
 S APCHSTXT=$$VAL^XBDIQ1(52,APCHSRX,100)_" Reason: "_$$VAL^XBDIQ1(52,APCHSRX,99)_" - "_$$VAL^XBDIQ1(52,APCHSRX,99.1)_" ("_$$VAL^XBDIQ1(52,APCHSRX,99.2)_")",APCHSICL=14,APCHSNRQ=""
 D PRTTXT^APCHSUTL K APCHSICL,APCHSNRQ,APCHSP
 Q
MEDRU ;EP
 ;get date last reviewed and display
 S APCHSX=$$LASTMLR^APCLAPI6(APCHSPAT,,DT,"A")
 X APCHSCKP Q:$D(APCHSQIT)
 W !,"Medication List Reviewed On: ",?36,$$FMTE^XLFDT($P(APCHSX,U,1)) W ?51,"By: ",?56,$E($S($P(APCHSX,U,3):$P($G(^VA(200,$P(APCHSX,U,3),0)),U),1:""),1,22),!
 S APCHSX=$$LASTMLU^APCLAPI6(APCHSPAT,,DT,"A")
 X APCHSCKP Q:$D(APCHSQIT)
 W "Medication List Updated On: ",?36,$$FMTE^XLFDT($P(APCHSX,U,1)) W ?51,"By: ",?56,$E($S($P(APCHSX,U,3):$P($G(^VA(200,$P(APCHSX,U,3),0)),U),1:""),1,22),!
 S APCHSX=$$LASTNAM^APCLAPI6(APCHSPAT,,DT,"A")
 X APCHSCKP Q:$D(APCHSQIT)
 ;I '$$ANYACTP^APCDAPRB(APCHSPAT) W !,"No Active Problems: ",?24,$$FMTE^XLFDT($P(APCHSX,U,1)) I $P(APCHSX,U,3) W ?39,"Documented By: ",?54,$E($P($G(^VA(200,$P(APCHSX,U,3),0)),U),1,25),!
 W "No Active Medications Documented On: ",?36,$$FMTE^XLFDT($P(APCHSX,U,1)) W ?51,"By: ",?56,$E($S($P(APCHSX,U,3):$P($G(^VA(200,$P(APCHSX,U,3),0)),U),1:""),1,22),!
 Q