BHSMEDSF ;IHS/CIA/MGH - Health Summary for V MED file ;01-May-2014 10:15;DU
;;1.0;HEALTH SUMMARY COMPONENTS;**1,2,6,9**;March 17, 2006;Build 16
;===================================================================
;Taken from APCHS72
; IHS/TUCSON/LAB - PART 7 OF BHS -- SUMMARY PRODUCTION COMPONENTS ; [ 01/20/04 8:47 PM ]
;;2.0;IHS RPMS/PCC Health Summary;**9,10,11**;JUN 24, 1997
;
;Routine to display meds in a short form
;Patch 1 changes prescribed at to dispensed at as in IHS patch 15
;Patch 2 changes for patch 16
;Patch 6 for non-Va and medication review
;====================================================================
MEDS ;EP - called from component - <SETUP>
N BHSPAT
S BHSPAT=DFN
I '$D(^AUPNVMED("AC",BHSPAT)) S BHST="MEDICATION",BHSFN=50 D DISPREF^BHSRAD Q
D CKP^GMTSUP Q:$D(GMTSQIT)
; <BUILD>
S Z=GMTSDLM,Y=GMTSDLM
D GETMEDS(BHSPAT,Y,Z,"S")
D DISPLAY
;Patch2 hold meds
D HOLDDSP^BHSMED
Q:$D(GMTSQIT)
;Patch 2 refusals
S BHST="MEDICATION",BHSFN=50 D DISPREF^BHSRAD
;Patch 6
D MEDRU^BHSMED ;display last date reviewed/updated/nam
K BHST,BHSFN
MEDX ;
K ^TMP($J,"BHSAOM"),^TMP($J,"BHSBCM"),^TMP("BHSMEDS",$J)
K BHSX
K X1,X2,X,Y
Q
;
DISPLAY ;
I $D(^TMP("BHSMEDS",$J,"C")) W ?4,"LAST OF EACH CHRONIC MEDICATION (no limit on days)",?57,"Last fill date",!! D
.S BHSX=0 F S BHSX=$O(^TMP("BHSMEDS",$J,"C",BHSX)) Q:BHSX'=+BHSX!($D(GMTSQIT)) D CKP^GMTSUP Q:$D(GMTSQIT) W ^TMP("BHSMEDS",$J,"C",BHSX),!
I $D(^TMP("BHSMEDS",$J,"A")) W !?4,"LAST OF EACH OTHER MEDICATION "_GMTSEGL_"",?57,"Last fill date",!! D
.S BHSX=0 F S BHSX=$O(^TMP("BHSMEDS",$J,"A",BHSX)) Q:BHSX'=+BHSX!($D(GMTSQIT)) D CKP^GMTSUP Q:$D(GMTSQIT) W ^TMP("BHSMEDS",$J,"A",BHSX),!
Q
GETMEDS(DFN,Y,Z,SIGT) ;PEP - return array of meds for patient P
;optionally Y is defined as the max # of days back the acute meds
;to be included
;optionally Z is the max # of days of chronic meds to be included
;the array will contain all chronic meds (listed first and ordered
;by NDC class
;and then all acute meds listed in NDC class order
;the array is ^TMP("BHSMEDS",$J,"C" - chronic
;and ^TMP("BHSMEDS",$J,"A" - other (non-chronic)
NEW A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,V,W,X,%
K ^TMP($J,"BHSAOM"),^TMP($J,"BHSBCM"),^TMP("BHSMEDS",$J)
I '$G(DFN) Q
I '$D(^DPT(DFN)) Q ;not a valid patient
I '$G(Y) S Y=GMTS1
I '$G(Z) S Z=GMTS2
;store dates
I Y S Y="-"_Y S Y=9999999-$$FMADD^XLFDT(DT,Y)
E S Y=9999999
I Z S Z="-"_Z S Z=9999999-$$FMADD^XLFDT(DT,Z)
E S Z=9999999
;gather up all chronic meds ever, store last of each 1
NEW I
S I=0 F S I=$O(^AUPNVMED("AA",DFN,I)) Q:I=""!(I>GMTSDLM) D
.NEW X S X=0 F S X=$O(^AUPNVMED("AA",DFN,I,X)) Q:X'=+X D
..Q:'$D(^AUPNVMED(X,0))
..I $D(^TMP($J,"BHSBCM",$P(^AUPNVMED(X,0),U))) Q
..Q:'$$CHRONIC(X) ;not marked as chronic in prescription file
..S ^TMP($J,"BHSBCM",$P(^AUPNVMED(X,0),U))=X
..Q
.Q
OTH ;gather up all others by date range in components, get last of each
NEW I S I=0 F S I=$O(^AUPNVMED("AA",DFN,I)) Q:I=""!(I>GMTSDLM) D
.S X=0 F S X=$O(^AUPNVMED("AA",DFN,I,X)) Q:X="" D
..Q:'$D(^AUPNVMED(X,0))
..I $D(^TMP($J,"BHSAOM",$P(^AUPNVMED(X,0),U))) Q
..Q:$$CHRONIC(X)
..S ^TMP($J,"BHSAOM",$P(^AUPNVMED(X,0),U))=X
..Q
.Q
;NOW MERGE IN NON VA MEDS FROM PS(55
NONVA ; S DFN=APCHSPAT,PSOACT=1 D ^PSOHCSUM
;quit if chronic
S X=0 F S X=$O(^PS(55,BHSPAT,"NVA",X)) Q:X'=+X D
.I $P($G(^PS(55,BHSPAT,"NVA",X,999999911)),U,1),$D(^AUPNVMED($P(^PS(55,BHSPAT,"NVA",X,999999911),U,1),0)) Q
.S L=$P($P($G(^PS(55,BHSPAT,"NVA",X,0)),U,10),".")
.S L=9999999-L
.Q:L>GMTSDLM
.S D=$P(^PS(55,BHSPAT,"NVA",X,0),U,2) ;DRUG
.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,BHSPAT,"NVA",X,0),U,1),0),U,1)) ;NAME
.S ^TMP($J,"BHSAOM",$S(D:D,1:N))=U_$P(^PS(55,BHSPAT,"NVA",X,0),U,6)_U_N_U_$P(^PS(55,BHSPAT,"NVA",X,0),U,4)_" "_$P(^PS(55,BHSPAT,"NVA",X,0),U,5)_U_$P(^PS(55,BHSPAT,"NVA",X,0),U,7)_U_(9999999-L)_U_$S(D:$P(^PSDRUG(D,0),U,1),1:N)
REORDER ;
;reorder by NDC or by name
NEW I,N,O,S,M S (C,I)=0 F S I=$O(^TMP($J,"BHSBCM",I)) Q:I'=+I S C=C+1,N=$$VAL^XBDIQ1(50,I,25),O="ZZZ-"_$$VAL^XBDIQ1(50,I,.01) S S=$S(N]"":N,1:O),M(S,C)=^TMP($J,"BHSBCM",I)
NEW I,N,O,S,A S (C,I)=0 F S I=$O(^TMP($J,"BHSAOM",I)) Q:I'=+I S C=C+1,N=$$VAL^XBDIQ1(50,I,25),O="ZZZ-"_$$VAL^XBDIQ1(50,I,.01) S S=$S(N]"":N,1:O),A(S,C)=^TMP($J,"BHSAOM",I)
NEW BHSX,BHSC,I,N S BHSX=0,I="C" F S BHSX=$O(M(BHSX)) Q:BHSX="" S BHSC=0 F S BHSC=$O(M(BHSX,BHSC)) Q:BHSC'=+BHSC S N=M(BHSX,BHSC) D SETARRAY
NEW BHSX,BHSC,I,N S BHSX=0,I="A" F S BHSX=$O(A(BHSX)) Q:BHSX="" S BHSC=0 F S BHSC=$O(A(BHSX,BHSC)) Q:BHSC'=+BHSC S N=A(BHSX,BHSC) D SETARRAY
K ^TMP("BHSMEDS",$J,"C",0),^TMP("BHSMEDS",$J,"A",0)
K ^TMP($J,"BHSBCM"),^TMP($J,"BHSAOM")
Q
CHRONIC(N) ;EP
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
SETARRAY ;DISPLAY MEDICATION
N DRG,RXNORM
I 'N D SETNVA Q
S %=^AUPNVMED(N,0)
S DRG=+%
;d = external value of date, t=internal value of date
S V=$P(%,U,3) I V S T=$P($P(^AUPNVSIT(V,0),U),"."),D=$$FMTE^XLFDT(T,"2D")
I 'V S (D,T)="<???>"
S E=$P(%,U,8),Q=$P(%,U,6),G=$P(%,U,5),T=$P(%,U,7)_" days"
S K=$S($P(N,U,4)="":$P(^PSDRUG(+%,0),U,1),1:$P(N,U,4))
I E S E="-- D/C "_$$FMTE^XLFDT(E,"2D")
D SIG S G=$$LOW^XLFSTR(Z)
D SITE ;I S]"" S G=G_" ["_S_"]"
S X="",$E(X,2)=K,X=X_" "_G_" "_" # "_$S(Q:Q,1:"?")_" "_T_" "_D D S(X)
;Patch 8 Add Rxnorm code here
S RXNORM=$$GET1^DIQ(50,DRG,9999999.27)
S X="",$E(X,5)="Dispensed at: "_S D S(X)
S X="",$E(X,6)="RxNorm: "_RXNORM D S(X)
Q
;
SETNVA ;
S D=$P(N,U,6)
I 'D S D="<???>"
I D S D=$$FMTE^XLFDT(D,"2D")
S E=$P(N,U,5)
S G=$P(N,U,4)
S K=$P(N,U,7)
S B="" I E S B="-- D/C"_$$FMTE^XLFDT(E,"2D")
D SIG S G=$$LOW^XLFSTR(Z)
S X="",$E(X,2)=K,X=X_" "_G_" "_D_" "_B D S(X)
S X="",$E(X,5)="Dispensed at: (EHR Outside Medication)" D S(X)
Q
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
I $G(SIGT)="S" S Z=G Q
NEW P S Z="" F P=1:1:$L(G," ") S X=$P(G," ",P) 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(G," ",P-1),Y=$E(Y,$L(Y)) S:Y>1 X=$P(^(9),"^",1)
. S Z=Z_X_" "
Q
;
SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
S S=""
I $D(^AUPNVSIT(V,21))#2 S S=$P(^(21),U) Q
Q:$P(^AUPNVSIT(V,0),U,6)=""
I $P(^AUPNVSIT(V,0),U,6)'=DUZ(2) S S=$E($P(^DIC(4,$P(^AUPNVSIT(V,0),U,6),0),U),1,30)
Q
S(Y,F,C,T) ;set up array
NEW X
I '$G(F) S F=0
I '$G(T) S T=0
;blank lines
F F=1:1:F S X="" D S1
S X=Y
I $G(C) S L=$L(Y),T=(80-L)/2 D D S1 Q
.F %=1:1:(T-1) S X=" "_X
F %=1:1:T S X=" "_Y
D S1
Q
S1 ;
I '$D(^TMP("BHSMEDS",$J,I,0)) S ^TMP("BHSMEDS",$J,I,0)=0
S %=$P(^TMP("BHSMEDS",$J,I,0),U)+1,$P(^TMP("BHSMEDS",$J,I,0),U)=%
S ^TMP("BHSMEDS",$J,I,%)=X
Q
BHSMEDSF ;IHS/CIA/MGH - Health Summary for V MED file ;01-May-2014 10:15;DU
+1 ;;1.0;HEALTH SUMMARY COMPONENTS;**1,2,6,9**;March 17, 2006;Build 16
+2 ;===================================================================
+3 ;Taken from APCHS72
+4 ; IHS/TUCSON/LAB - PART 7 OF BHS -- SUMMARY PRODUCTION COMPONENTS ; [ 01/20/04 8:47 PM ]
+5 ;;2.0;IHS RPMS/PCC Health Summary;**9,10,11**;JUN 24, 1997
+6 ;
+7 ;Routine to display meds in a short form
+8 ;Patch 1 changes prescribed at to dispensed at as in IHS patch 15
+9 ;Patch 2 changes for patch 16
+10 ;Patch 6 for non-Va and medication review
+11 ;====================================================================
MEDS ;EP - called from component - <SETUP>
+1 NEW BHSPAT
+2 SET BHSPAT=DFN
+3 IF '$DATA(^AUPNVMED("AC",BHSPAT))
SET BHST="MEDICATION"
SET BHSFN=50
DO DISPREF^BHSRAD
QUIT
+4 DO CKP^GMTSUP
IF $DATA(GMTSQIT)
QUIT
+5 ; <BUILD>
+6 SET Z=GMTSDLM
SET Y=GMTSDLM
+7 DO GETMEDS(BHSPAT,Y,Z,"S")
+8 DO DISPLAY
+9 ;Patch2 hold meds
+10 DO HOLDDSP^BHSMED
+11 IF $DATA(GMTSQIT)
QUIT
+12 ;Patch 2 refusals
+13 SET BHST="MEDICATION"
SET BHSFN=50
DO DISPREF^BHSRAD
+14 ;Patch 6
+15 ;display last date reviewed/updated/nam
DO MEDRU^BHSMED
+16 KILL BHST,BHSFN
MEDX ;
+1 KILL ^TMP($JOB,"BHSAOM"),^TMP($JOB,"BHSBCM"),^TMP("BHSMEDS",$JOB)
+2 KILL BHSX
+3 KILL X1,X2,X,Y
+4 QUIT
+5 ;
DISPLAY ;
+1 IF $DATA(^TMP("BHSMEDS",$JOB,"C"))
WRITE ?4,"LAST OF EACH CHRONIC MEDICATION (no limit on days)",?57,"Last fill date",!!
Begin DoDot:1
+2 SET BHSX=0
FOR
SET BHSX=$ORDER(^TMP("BHSMEDS",$JOB,"C",BHSX))
IF BHSX'=+BHSX!($DATA(GMTSQIT))
QUIT
DO CKP^GMTSUP
IF $DATA(GMTSQIT)
QUIT
WRITE ^TMP("BHSMEDS",$JOB,"C",BHSX),!
End DoDot:1
+3 IF $DATA(^TMP("BHSMEDS",$JOB,"A"))
WRITE !?4,"LAST OF EACH OTHER MEDICATION "_GMTSEGL_"",?57,"Last fill date",!!
Begin DoDot:1
+4 SET BHSX=0
FOR
SET BHSX=$ORDER(^TMP("BHSMEDS",$JOB,"A",BHSX))
IF BHSX'=+BHSX!($DATA(GMTSQIT))
QUIT
DO CKP^GMTSUP
IF $DATA(GMTSQIT)
QUIT
WRITE ^TMP("BHSMEDS",$JOB,"A",BHSX),!
End DoDot:1
+5 QUIT
GETMEDS(DFN,Y,Z,SIGT) ;PEP - return array of meds for patient P
+1 ;optionally Y is defined as the max # of days back the acute meds
+2 ;to be included
+3 ;optionally Z is the max # of days of chronic meds to be included
+4 ;the array will contain all chronic meds (listed first and ordered
+5 ;by NDC class
+6 ;and then all acute meds listed in NDC class order
+7 ;the array is ^TMP("BHSMEDS",$J,"C" - chronic
+8 ;and ^TMP("BHSMEDS",$J,"A" - other (non-chronic)
+9 NEW A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,V,W,X,%
+10 KILL ^TMP($JOB,"BHSAOM"),^TMP($JOB,"BHSBCM"),^TMP("BHSMEDS",$JOB)
+11 IF '$GET(DFN)
QUIT
+12 ;not a valid patient
IF '$DATA(^DPT(DFN))
QUIT
+13 IF '$GET(Y)
SET Y=GMTS1
+14 IF '$GET(Z)
SET Z=GMTS2
+15 ;store dates
+16 IF Y
SET Y="-"_Y
SET Y=9999999-$$FMADD^XLFDT(DT,Y)
+17 IF '$TEST
SET Y=9999999
+18 IF Z
SET Z="-"_Z
SET Z=9999999-$$FMADD^XLFDT(DT,Z)
+19 IF '$TEST
SET Z=9999999
+20 ;gather up all chronic meds ever, store last of each 1
+21 NEW I
+22 SET I=0
FOR
SET I=$ORDER(^AUPNVMED("AA",DFN,I))
IF I=""!(I>GMTSDLM)
QUIT
Begin DoDot:1
+23 NEW X
SET X=0
FOR
SET X=$ORDER(^AUPNVMED("AA",DFN,I,X))
IF X'=+X
QUIT
Begin DoDot:2
+24 IF '$DATA(^AUPNVMED(X,0))
QUIT
+25 IF $DATA(^TMP($JOB,"BHSBCM",$PIECE(^AUPNVMED(X,0),U)))
QUIT
+26 ;not marked as chronic in prescription file
IF '$$CHRONIC(X)
QUIT
+27 SET ^TMP($JOB,"BHSBCM",$PIECE(^AUPNVMED(X,0),U))=X
+28 QUIT
End DoDot:2
+29 QUIT
End DoDot:1
OTH ;gather up all others by date range in components, get last of each
+1 NEW I
SET I=0
FOR
SET I=$ORDER(^AUPNVMED("AA",DFN,I))
IF I=""!(I>GMTSDLM)
QUIT
Begin DoDot:1
+2 SET X=0
FOR
SET X=$ORDER(^AUPNVMED("AA",DFN,I,X))
IF X=""
QUIT
Begin DoDot:2
+3 IF '$DATA(^AUPNVMED(X,0))
QUIT
+4 IF $DATA(^TMP($JOB,"BHSAOM",$PIECE(^AUPNVMED(X,0),U)))
QUIT
+5 IF $$CHRONIC(X)
QUIT
+6 SET ^TMP($JOB,"BHSAOM",$PIECE(^AUPNVMED(X,0),U))=X
+7 QUIT
End DoDot:2
+8 QUIT
End DoDot:1
+9 ;NOW MERGE IN NON VA MEDS FROM PS(55
NONVA ; S DFN=APCHSPAT,PSOACT=1 D ^PSOHCSUM
+1 ;quit if chronic
+2 SET X=0
FOR
SET X=$ORDER(^PS(55,BHSPAT,"NVA",X))
IF X'=+X
QUIT
Begin DoDot:1
+3 IF $PIECE($GET(^PS(55,BHSPAT,"NVA",X,999999911)),U,1)
IF $DATA(^AUPNVMED($PIECE(^PS(55,BHSPAT,"NVA",X,999999911),U,1),0))
QUIT
+4 SET L=$PIECE($PIECE($GET(^PS(55,BHSPAT,"NVA",X,0)),U,10),".")
+5 SET L=9999999-L
+6 IF L>GMTSDLM
QUIT
+7 ;DRUG
SET D=$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,2)
+8 IF D=""
SET D="NO DRUG IEN"
+9 ;NAME
SET N=$SELECT(D:$PIECE(^PSDRUG(D,0),U,1),1:$PIECE(^PS(50.7,$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,1),0),U,1))
+10 SET ^TMP($JOB,"BHSAOM",$SELECT(D:D,1:N))=U_$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,6)_U_N_U_$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,4)_" "_$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,5)_U_$PIECE(^PS(55,BHSPAT,"NVA",X,0),U,7)_U_(9999999-L)_U_$SELECT(D:...
... $PIECE(^PSDRUG(D,0),U,1),1:N)
End DoDot:1
REORDER ;
+1 ;reorder by NDC or by name
+2 NEW I,N,O,S,M
SET (C,I)=0
FOR
SET I=$ORDER(^TMP($JOB,"BHSBCM",I))
IF I'=+I
QUIT
SET C=C+1
SET N=$$VAL^XBDIQ1(50,I,25)
SET O="ZZZ-"_$$VAL^XBDIQ1(50,I,.01)
SET S=$SELECT(N]"":N,1:O)
SET M(S,C)=^TMP($JOB,"BHSBCM",I)
+3 NEW I,N,O,S,A
SET (C,I)=0
FOR
SET I=$ORDER(^TMP($JOB,"BHSAOM",I))
IF I'=+I
QUIT
SET C=C+1
SET N=$$VAL^XBDIQ1(50,I,25)
SET O="ZZZ-"_$$VAL^XBDIQ1(50,I,.01)
SET S=$SELECT(N]"":N,1:O)
SET A(S,C)=^TMP($JOB,"BHSAOM",I)
+4 NEW BHSX,BHSC,I,N
SET BHSX=0
SET I="C"
FOR
SET BHSX=$ORDER(M(BHSX))
IF BHSX=""
QUIT
SET BHSC=0
FOR
SET BHSC=$ORDER(M(BHSX,BHSC))
IF BHSC'=+BHSC
QUIT
SET N=M(BHSX,BHSC)
DO SETARRAY
+5 NEW BHSX,BHSC,I,N
SET BHSX=0
SET I="A"
FOR
SET BHSX=$ORDER(A(BHSX))
IF BHSX=""
QUIT
SET BHSC=0
FOR
SET BHSC=$ORDER(A(BHSX,BHSC))
IF BHSC'=+BHSC
QUIT
SET N=A(BHSX,BHSC)
DO SETARRAY
+6 KILL ^TMP("BHSMEDS",$JOB,"C",0),^TMP("BHSMEDS",$JOB,"A",0)
+7 KILL ^TMP($JOB,"BHSBCM"),^TMP($JOB,"BHSAOM")
+8 QUIT
CHRONIC(N) ;EP
+1 IF '$GET(N)
QUIT ""
+2 IF '$DATA(^AUPNVMED(N))
QUIT ""
+3 NEW X,Y,P
+4 SET P=$PIECE(^AUPNVMED(N,0),U,2)
+5 SET X=$SELECT($DATA(^PSRX("APCC",N)):$ORDER(^(N,0)),1:0)
+6 SET Y=$SELECT(+X:$DATA(^PS(55,P,"P","CP",X)),1:0)
+7 IF 'Y
QUIT ""
+8 QUIT 1
SETARRAY ;DISPLAY MEDICATION
+1 NEW DRG,RXNORM
+2 IF 'N
DO SETNVA
QUIT
+3 SET %=^AUPNVMED(N,0)
+4 SET DRG=+%
+5 ;d = external value of date, t=internal value of date
+6 SET V=$PIECE(%,U,3)
IF V
SET T=$PIECE($PIECE(^AUPNVSIT(V,0),U),".")
SET D=$$FMTE^XLFDT(T,"2D")
+7 IF 'V
SET (D,T)="<???>"
+8 SET E=$PIECE(%,U,8)
SET Q=$PIECE(%,U,6)
SET G=$PIECE(%,U,5)
SET T=$PIECE(%,U,7)_" days"
+9 SET K=$SELECT($PIECE(N,U,4)="":$PIECE(^PSDRUG(+%,0),U,1),1:$PIECE(N,U,4))
+10 IF E
SET E="-- D/C "_$$FMTE^XLFDT(E,"2D")
+11 DO SIG
SET G=$$LOW^XLFSTR(Z)
+12 ;I S]"" S G=G_" ["_S_"]"
DO SITE
+13 SET X=""
SET $EXTRACT(X,2)=K
SET X=X_" "_G_" "_" # "_$SELECT(Q:Q,1:"?")_" "_T_" "_D
DO S(X)
+14 ;Patch 8 Add Rxnorm code here
+15 SET RXNORM=$$GET1^DIQ(50,DRG,9999999.27)
+16 SET X=""
SET $EXTRACT(X,5)="Dispensed at: "_S
DO S(X)
+17 SET X=""
SET $EXTRACT(X,6)="RxNorm: "_RXNORM
DO S(X)
+18 QUIT
+19 ;
SETNVA ;
+1 SET D=$PIECE(N,U,6)
+2 IF 'D
SET D="<???>"
+3 IF D
SET D=$$FMTE^XLFDT(D,"2D")
+4 SET E=$PIECE(N,U,5)
+5 SET G=$PIECE(N,U,4)
+6 SET K=$PIECE(N,U,7)
+7 SET B=""
IF E
SET B="-- D/C"_$$FMTE^XLFDT(E,"2D")
+8 DO SIG
SET G=$$LOW^XLFSTR(Z)
+9 SET X=""
SET $EXTRACT(X,2)=K
SET X=X_" "_G_" "_D_" "_B
DO S(X)
+10 SET X=""
SET $EXTRACT(X,5)="Dispensed at: (EHR Outside Medication)"
DO S(X)
+11 QUIT
SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
+1 IF $GET(SIGT)="S"
SET Z=G
QUIT
+2 NEW P
SET Z=""
FOR P=1:1:$LENGTH(G," ")
SET X=$PIECE(G," ",P)
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(G," ",P-1)
SET Y=$EXTRACT(Y,$LENGTH(Y))
IF Y>1
SET X=$PIECE(^(9),"^",1)
+4 SET Z=Z_X_" "
End DoDot:1
+5 QUIT
+6 ;
SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
+1 SET S=""
+2 IF $DATA(^AUPNVSIT(V,21))#2
SET S=$PIECE(^(21),U)
QUIT
+3 IF $PIECE(^AUPNVSIT(V,0),U,6)=""
QUIT
+4 IF $PIECE(^AUPNVSIT(V,0),U,6)'=DUZ(2)
SET S=$EXTRACT($PIECE(^DIC(4,$PIECE(^AUPNVSIT(V,0),U,6),0),U),1,30)
+5 QUIT
S(Y,F,C,T) ;set up array
+1 NEW X
+2 IF '$GET(F)
SET F=0
+3 IF '$GET(T)
SET T=0
+4 ;blank lines
+5 FOR F=1:1:F
SET X=""
DO S1
+6 SET X=Y
+7 IF $GET(C)
SET L=$LENGTH(Y)
SET T=(80-L)/2
Begin DoDot:1
+8 FOR %=1:1:(T-1)
SET X=" "_X
End DoDot:1
DO S1
QUIT
+9 FOR %=1:1:T
SET X=" "_Y
+10 DO S1
+11 QUIT
S1 ;
+1 IF '$DATA(^TMP("BHSMEDS",$JOB,I,0))
SET ^TMP("BHSMEDS",$JOB,I,0)=0
+2 SET %=$PIECE(^TMP("BHSMEDS",$JOB,I,0),U)+1
SET $PIECE(^TMP("BHSMEDS",$JOB,I,0),U)=%
+3 SET ^TMP("BHSMEDS",$JOB,I,%)=X
+4 QUIT