APCHS77 ; 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 ********
D MEDX S APCHSMTY="CURR" 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,"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
; <DISPLAY>
S APCHSNAM="" F APCHSQ=0:0 S APCHSNAM=$O(^TMP($J,"APCHSMTP",APCHSNAM)) Q:APCHSNAM=""!($D(APCHSQIT)) S APCHSMX=0 F S APCHSMX=$O(^TMP($J,"APCHSMTP",APCHSNAM,APCHSMX)) Q:APCHSMX=""!($D(APCHSQIT)) D MEDDSP
; <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,APCHORTS,APCHSDCP,APCHSNAM,APCHSMED
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
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",N,"NONVA")=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)_U_L
.S ^TMP($J,"APCHSMTB","NONVA")=$P(^PS(55,APCHSPAT,"NVA",X,0),U,6)
Q
;
MEDBLD ;BUILD ARRAY OF MEDICATIONS
;APCHSDC=DATE DISCONTINUED,DYS=DAYS PRESCRIBED,SIG=DIRECTIONS
;VDF=VISIT FILE DATE
Q:'$D(^AUPNVMED(APCHSMX,0))
;Q:$P($G(^AUPNVMED(APCHSMX,11)),U,8)]""
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=$S($P(APCHSN,U,4)="":+APCHSN,1:$P(APCHSN,U,4))
S:APCHSDYS="" APCHSDYS=30
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 APCHSN=^AUPNVMED(APCHSMX,0)
S APCHSMED=$S($P(APCHSN,U,4)="":$P(^PSDRUG(APCHSMFX,0),U,1),1:$P(APCHSN,U,4))
S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSMED,APCHSMX)=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]"" Q ;IHS/CMI/LAB - new component patch 9
S APCHSN=^AUPNVMED(APCHSMX,0)
S APCHSMED=$S($P(APCHSN,U,4)="":$P(^PSDRUG(APCHSMFX,0),U,1),1:$P(APCHSN,U,4))
S ^TMP($J,"APCHSMTB",APCHSMFX)=APCHSDC,^TMP($J,"APCHSMTP",APCHSMED,APCHSMX)=APCHSMX
Q
MEDDSP ;DISPLAY MEDICATION
;APCHSRX=RX# in FILE 52,CHRN=CHRONIC FLAG,REF=#REFILLS
I $P(^TMP($J,"APCHSMTP",APCHSNAM,APCHSMX),U,1)="" D NVADSP Q
S APCHSN=^AUPNVMED(APCHSMX,0)
S APCHZ=$P(^AUPNVMED(APCHSMX,0),U,3)
S APCHSIVD=$P($P(^AUPNVSIT(APCHZ,0),U),".")
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 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."
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_"]"
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
;
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(^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)=9999999-$P(^TMP($J,"APCHSMTP",APCHSNAM,"NONVA"),U,6) X APCHSCVD S APCHSDAT=Y
S APCHSDC=$P(^TMP($J,"APCHSMTP",APCHSNAM,"NONVA"),U,5)
S APCHSMED=$P(^TMP($J,"APCHSMTP",APCHSNAM,"NONVA"),U,3)
I APCHSDC S Y=APCHSDC X APCHSCVD S APCHSEXP="-- D/C "_Y
S APCHSIG=$P(^TMP($J,"APCHSMTP",APCHSNAM,"NONVA"),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
;
APCHS77 ; IHS/CMI/LAB - PART 7 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ;
+1 ;;2.0;IHS PCC SUITE;**2,5**;MAY 14, 2009
+2 ;
+3 ;
MEDSCURR ; ************** CURRENT MEDICATIONS * 9000010.14 ********
+1 DO MEDX
SET APCHSMTY="CURR"
GOTO CONT
MEDSCHRN ; ************* CHRONIC MEDCICATIONS ************
+1 SET APCHSMTY="CHRONIC"
GOTO CONT
MEDSNDUP ; ************* ALL, NON DUPLICATED *************
+1 SET APCHSMTY="NODUP"
GOTO CONT
CONT ; <SETUP>
+1 ;Q:'$D(^AUPNVMED("AC",APCHSPAT))
+2 XECUTE APCHSCKP
IF $DATA(APCHSQIT)
QUIT
IF 'APCHSNPG
WRITE !
XECUTE APCHSBRK
+3 ; <BUILD>
+4 KILL ^TMP($JOB,"APCHSMTB"),^TMP($JOB,"APCHSMTP")
+5 SET APCHSIVD=0
FOR APCHSQ=0:0
SET APCHSIVD=$ORDER(^AUPNVMED("AA",APCHSPAT,APCHSIVD))
IF APCHSIVD=""!(APCHSIVD>APCHSDLM)
QUIT
SET APCHSMX=0
FOR APCHSQ=0:0
SET APCHSMX=$ORDER(^AUPNVMED("AA",APCHSPAT,APCHSIVD,APCHSMX))
IF APCHSMX=""
QUIT
DO MEDBLD
+6 DO NONVA
+7 ; <DISPLAY>
+8 SET APCHSNAM=""
FOR APCHSQ=0:0
SET APCHSNAM=$ORDER(^TMP($JOB,"APCHSMTP",APCHSNAM))
IF APCHSNAM=""!($DATA(APCHSQIT))
QUIT
SET APCHSMX=0
FOR
SET APCHSMX=$ORDER(^TMP($JOB,"APCHSMTP",APCHSNAM,APCHSMX))
IF APCHSMX=""!($DATA(APCHSQIT))
QUIT
DO MEDDSP
+9 ; <CLEANUP>
+10 ;hold meds
+11 DO HOLDDSP^APCHS7
+12 IF $DATA(APCHSQIT)
QUIT
+13 ;now display MED refusals
+14 SET APCHST="MEDICATION"
SET APCHSFN=50
DO DISPREF^APCHS3C
+15 DO MEDRU^APCHS7
+16 KILL APCHST,APCHSFN
MEDX KILL APCHSIVD,APCHSMX,APCHSMFX,APCHSQTY,APCHSIG,APCHSSGY,APCHSEXP,APCHSMTS,APCHSMED,APCHSDTM,APCHSDAT,APCHSDYS,APCHSN,APCHSDC,APCHSVDF,APCHSP,APCHORTS,APCHSDCP,APCHSNAM,APCHSMED
+1 KILL APCHSNFL,APCHSNSH,APCHSNAB,APCHSVSC,APCHSITE,APCHSRX,APCHSDRG,APCHSCRN,APCHSREF,APCHSRFL,APCHSALL,APCHSTXT,APCHSMTY
+2 KILL ^TMP($JOB,"APCHSMTB"),^TMP($JOB,"APCHSMTP")
+3 KILL X1,X2,X,Y
+4 QUIT
NONVA ;EP - ;NEW DFN,PSOACT S DFN=APCHSPAT,PSOACT=1 D ^PSOHCSUM
+1 ;quit if chronic
+2 IF APCHSMTY="CHRONIC"
QUIT
+3 SET X=0
FOR
SET X=$ORDER(^PS(55,APCHSPAT,"NVA",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 IF $PIECE($GET(^PS(55,APCHSPAT,"NVA",X,999999911)),U,1)
IF $DATA(^AUPNVMED($PIECE(^PS(55,APCHSPAT,"NVA",X,999999911),U,1),0))
QUIT
+5 ;S L=$P(^PS(55,APCHSPAT,"NVA",X,0),U,9)
+6 ;:'L
+7 SET L=$PIECE($PIECE($GET(^PS(55,APCHSPAT,"NVA",X,0)),U,10),".")
+8 SET L=9999999-L
+9 IF L>APCHSDLM
QUIT
+10 ;S M=$P($G(^PS(55,APCHSPAT,"NVA",X,999999911)),U,1) ;passed to PCC so got it already
+11 ;I M,$D(^AUPNVMED(M)) Q ;passed to PCC and v med exists so we already got it from V MED
+12 SET D=$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,2)
+13 IF D=""
SET D="NO DRUG IEN"
+14 SET N=$SELECT(D:$PIECE(^PSDRUG(D,0),U,1),1:$PIECE(^PS(50.7,$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,1),0),U,1))
+15 SET ^TMP($JOB,"APCHSMTP",N,"NONVA")=U_$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,6)_U_N_U_$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,4)_" "_$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,5)_U_$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,7)_U_L
+16 SET ^TMP($JOB,"APCHSMTB","NONVA")=$PIECE(^PS(55,APCHSPAT,"NVA",X,0),U,6)
End DoDot:1
+17 QUIT
+18 ;
MEDBLD ;BUILD ARRAY OF MEDICATIONS
+1 ;APCHSDC=DATE DISCONTINUED,DYS=DAYS PRESCRIBED,SIG=DIRECTIONS
+2 ;VDF=VISIT FILE DATE
+3 IF '$DATA(^AUPNVMED(APCHSMX,0))
QUIT
+4 ;Q:$P($G(^AUPNVMED(APCHSMX,11)),U,8)]""
+5 SET APCHSN=^AUPNVMED(APCHSMX,0)
+6 IF '$DATA(^PSDRUG($PIECE(APCHSN,U,1)))
QUIT
+7 SET APCHSDTM=-APCHSIVD\1+9999999
+8 SET APCHSDC=$PIECE(APCHSN,U,8)
SET APCHSDYS=$PIECE(APCHSN,U,7)
SET APCHSMFX=$SELECT($PIECE(APCHSN,U,4)="":+APCHSN,1:$PIECE(APCHSN,U,4))
+9 IF APCHSDYS=""
SET APCHSDYS=30
+10 DO @APCHSMTY
+11 QUIT
+12 ;
CURR ; current meds only
+1 IF $DATA(^TMP($JOB,"APCHSMTB",APCHSMFX))
IF ^TMP($JOB,"APCHSMTB",APCHSMFX)=""
QUIT
+2 SET X1=DT
SET X2=APCHSDTM
DO ^%DTC
IF X>60&(X>(2*APCHSDYS))
QUIT
+3 SET APCHSN=^AUPNVMED(APCHSMX,0)
+4 SET APCHSMED=$SELECT($PIECE(APCHSN,U,4)="":$PIECE(^PSDRUG(APCHSMFX,0),U,1),1:$PIECE(APCHSN,U,4))
+5 SET ^TMP($JOB,"APCHSMTB",APCHSMFX)=APCHSDC
SET ^TMP($JOB,"APCHSMTP",APCHSMED,APCHSMX)=APCHSMX
+6 QUIT
CHRONIC ;chronic meds only
+1 IF $DATA(^TMP($JOB,"APCHSMTB",APCHSMFX))
QUIT
+2 SET X=$SELECT($DATA(^PSRX("APCC",APCHSMX)):$ORDER(^(APCHSMX,0)),1:0)
+3 SET Y=$SELECT(+X:$DATA(^PS(55,APCHSPAT,"P","CP",X)),1:0)
+4 IF 'Y
QUIT
+5 ;IHS/CMI/LAB - new component patch 9
IF $GET(APCHSDCP)
IF APCHSDC]""
QUIT
+6 SET APCHSN=^AUPNVMED(APCHSMX,0)
+7 SET APCHSMED=$SELECT($PIECE(APCHSN,U,4)="":$PIECE(^PSDRUG(APCHSMFX,0),U,1),1:$PIECE(APCHSN,U,4))
+8 SET ^TMP($JOB,"APCHSMTB",APCHSMFX)=APCHSDC
SET ^TMP($JOB,"APCHSMTP",APCHSMED,APCHSMX)=APCHSMX
+9 QUIT
MEDDSP ;DISPLAY MEDICATION
+1 ;APCHSRX=RX# in FILE 52,CHRN=CHRONIC FLAG,REF=#REFILLS
+2 IF $PIECE(^TMP($JOB,"APCHSMTP",APCHSNAM,APCHSMX),U,1)=""
DO NVADSP
QUIT
+3 SET APCHSN=^AUPNVMED(APCHSMX,0)
+4 SET APCHZ=$PIECE(^AUPNVMED(APCHSMX,0),U,3)
+5 SET APCHSIVD=$PIECE($PIECE(^AUPNVSIT(APCHZ,0),U),".")
+6 SET APCHSRX=$SELECT($DATA(^PSRX("APCC",APCHSMX)):$ORDER(^(APCHSMX,0)),1:0)
+7 SET APCHSCRN=$SELECT(+APCHSRX:$DATA(^PS(55,APCHSPAT,"P","CP",APCHSRX)),1:0)
+8 SET (Y,APCHSDTM)=APCHSIVD
XECUTE APCHSCVD
SET APCHSDAT=Y
+9 SET APCHSDC=$PIECE(APCHSN,U,8)
SET APCHSDYS=$PIECE(APCHSN,U,7)
SET APCHSQTY=$PIECE(APCHSN,U,6)
SET APCHSIG=$PIECE(APCHSN,U,5)
SET APCHSVDF=$PIECE(APCHSN,U,3)
SET APCHSMFX=+APCHSN
+10 IF APCHSDYS=""
SET APCHSDYS=30
+11 ;Q:X>60&(X>(2*APCHSDYS))
SET X1=DT
SET X2=APCHSDTM
DO ^%DTC
+12 SET APCHSEXP=""
+13 IF X>APCHSDYS
SET X1=APCHSDTM
SET X2=APCHSDYS
DO C^%DTC
SET Y=X
XECUTE APCHSCVD
SET APCHSEXP="-- Ran out "_Y
+14 SET APCHSMED=$SELECT($PIECE(APCHSN,U,4)="":$PIECE(^PSDRUG(APCHSMFX,0),U,1),1:$PIECE(APCHSN,U,4))
+15 IF APCHSDC
SET Y=APCHSDC
XECUTE APCHSCVD
SET APCHSEXP="-- D/C "_Y
+16 ;CHANGE IT AROUND A BIT LOOK FOR RETURNED TO STOCK IHS/OKCAO/POC 2/14/2000
+17 SET APCHORTS=$GET(^AUPNVMED(APCHSMX,11))
+18 IF APCHORTS["RETURNED TO STOCK"
IF APCHSDC
SET APCHSEXP="--RTS "_Y
+19 ;END OF LOCAL CHANGES IHS/OKCAO/POC 2/14/2000
+20 DO SIG
SET APCHSIG=APCHSSGY
+21 DO REF
IF APCHSREF
SET APCHSIG=APCHSIG_" "_APCHSREF_$SELECT(APCHSREF=1:" refill",1:" refills")_" left."
+22 SET V=$PIECE(^AUPNVMED(APCHSMX,0),U,3)
IF $PIECE($GET(^AUPNVSIT(+V,0)),U,7)="E"
SET APCHSIG=APCHSIG_" (OUTSIDE MEDICATION)"
+23 ;I APCHSITE]"" S APCHSIG=APCHSIG_" ["_APCHSITE_"]"
DO SITE
+24 XECUTE APCHSCKP
IF $DATA(APCHSQIT)
QUIT
+25 WRITE APCHSDAT,?10,$SELECT(APCHSCRN:"(C)",1:""),?14,APCHSMED," #",APCHSQTY," (",APCHSDYS," days) ",APCHSEXP,!
+26 IF APCHSITE]""
WRITE ?14,"Dispensed at: ",APCHSITE,!
+27 XECUTE APCHSCKP
IF $DATA(APCHSQIT)
QUIT
+28 SET APCHSICL=14
SET APCHSNRQ=""
SET APCHSTXT=APCHSIG
DO PRTTXT^APCHSUTL
KILL APCHSICL,APCHSNRQ,APCHSP
+29 QUIT
+30 ;
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
+1 IF $$VALI^XBDIQ1(9001015,APCHSTYP,3.5)="S"
SET APCHSSGY=APCHSIG
QUIT
+2 SET APCHSSGY=""
FOR APCHSP=1:1:$LENGTH(APCHSIG," ")
SET X=$PIECE(APCHSIG," ",APCHSP)
IF X]""
Begin DoDot:1
+3 SET Y=$ORDER(^PS(51,"B",X,0))
IF Y>0
SET X=$PIECE(^PS(51,Y,0),"^",2)
IF $DATA(^(9))
SET Y=$PIECE(APCHSIG," ",APCHSP-1)
SET Y=$EXTRACT(Y,$LENGTH(Y))
IF Y>1
SET X=$PIECE(^(9),"^",1)
+4 SET APCHSSGY=APCHSSGY_X_" "
End DoDot:1
+5 QUIT
+6 ;
REF ;DETERMINE THE NUMBER OF REFILLS REMAINING
+1 IF 'APCHSRX
SET APCHSREF=0
QUIT
+2 SET APCHSRFL=$PIECE($GET(^PSRX(APCHSRX,0)),U,9)
SET APCHSREF=0
FOR
SET APCHSREF=$ORDER(^PSRX(APCHSRX,1,APCHSREF))
IF 'APCHSREF
QUIT
SET APCHSRFL=APCHSRFL-1
+3 SET APCHSREF=APCHSRFL
+4 QUIT
+5 ;
SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
+1 SET APCHSITE=""
+2 IF $DATA(^AUPNVSIT(APCHSVDF,21))#2
SET APCHSITE=$PIECE(^(21),U)
QUIT
+3 IF $PIECE(^AUPNVSIT(APCHSVDF,0),U,6)=""
QUIT
+4 IF $PIECE(^AUPNVSIT(APCHSVDF,0),U,6)'=DUZ(2)
SET APCHSITE=$EXTRACT($PIECE(^DIC(4,$PIECE(^AUPNVSIT(APCHSVDF,0),U,6),0),U),1,30)
+5 QUIT
NVADSP ;
+1 SET APCHSEXP=""
+2 SET (Y,APCHSDTM)=9999999-$PIECE(^TMP($JOB,"APCHSMTP",APCHSNAM,"NONVA"),U,6)
XECUTE APCHSCVD
SET APCHSDAT=Y
+3 SET APCHSDC=$PIECE(^TMP($JOB,"APCHSMTP",APCHSNAM,"NONVA"),U,5)
+4 SET APCHSMED=$PIECE(^TMP($JOB,"APCHSMTP",APCHSNAM,"NONVA"),U,3)
+5 IF APCHSDC
SET Y=APCHSDC
XECUTE APCHSCVD
SET APCHSEXP="-- D/C "_Y
+6 SET APCHSIG=$PIECE(^TMP($JOB,"APCHSMTP",APCHSNAM,"NONVA"),U,4)
+7 XECUTE APCHSCKP
IF $DATA(APCHSQIT)
QUIT
+8 WRITE APCHSDAT,?14,APCHSMED," ",APCHSEXP,!
+9 XECUTE APCHSCKP
IF $DATA(APCHSQIT)
QUIT
+10 SET APCHSICL=14
SET APCHSNRQ=""
SET APCHSTXT=APCHSIG_" (EHR OUTSIDE MEDICATION)"
DO PRTTXT^APCHSUTL
KILL APCHSICL,APCHSNRQ,APCHSP
+11 QUIT
+12 ;