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

AMHLEMD.m

Go to the documentation of this file.
  1. AMHLEMD ; IHS/CMI/LAB - PART 7 OF AMHS -- SUMMARY PRODUCTION COMPONENTS ;
  1. ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
  1. ;
  1. ;
  1. GETMEDS(DFN,Y,Z,SIGT) ;EP - return array of meds for patient P
  1. NEW A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,V,W,X,%
  1. K ^TMP($J,"AMHSAOM"),^TMP("AMHSMEDS",$J)
  1. I '$G(DFN) Q
  1. I '$D(^DPT(DFN)) Q ;not a valid patient
  1. I '$G(Y) S Y=""
  1. I '$G(Z) S Z=""
  1. ;store dates
  1. I Y S Y=9999999-Y
  1. E S Y=9999999
  1. I Z S Z=9999999-Z
  1. E S Z=9999999
  1. OTH ;gather up all others by date range in components, get last of each
  1. NEW I S I=0 F S I=$O(^AUPNVMED("AA",DFN,I)) Q:I=""!(I>Y) D
  1. .S X=0 F S X=$O(^AUPNVMED("AA",DFN,I,X)) Q:X="" D
  1. ..I $D(^TMP($J,"AMHSAOM",$P(^AUPNVMED(X,0),U))) Q
  1. ..S ^TMP($J,"AMHSAOM",$P(^AUPNVMED(X,0),U))=X
  1. ..S ^TMP($J,"AMHSAOM","DATE ORDER",I,$P(^AUPNVMED(X,0),U))=X
  1. ..Q
  1. .Q
  1. REORDER ;
  1. ;reorder by NDC or by name
  1. ;NEW I,N,O,S,A S (C,I)=0 F S I=$O(^TMP($J,"AMHSAOM",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,"AMHSAOM",I)
  1. ;NEW AMHSX,AMHSC,I,N S AMHSX=0,I="A" F S AMHSX=$O(A(AMHSX)) Q:AMHSX="" S AMHSC=0 F S AMHSC=$O(A(AMHSX,AMHSC)) Q:AMHSC'=+AMHSC S N=A(AMHSX,AMHSC) D SETARRAY
  1. NEW AMHSC,AMHSX,I,N S I="A" S AMHSX=0 F S AMHSX=$O(^TMP($J,"AMHSAOM","DATE ORDER",AMHSX)) Q:AMHSX="" D
  1. .S AMHSC=0 F S AMHSC=$O(^TMP($J,"AMHSAOM","DATE ORDER",AMHSX,AMHSC)) Q:AMHSC="" S N=^TMP($J,"AMHSAOM","DATE ORDER",AMHSX,AMHSC) D SETARRAY
  1. K ^TMP("AMHSMEDS",$J,"A",0)
  1. K ^TMP($J,"AMHSAOM")
  1. Q
  1. SETARRAY ;DISPLAY MEDICATION
  1. S %=^AUPNVMED(N,0)
  1. I +%,'$D(^PSDRUG(+%,0)) Q ;drug deleted
  1. ;d = external value of date, t=internal value of date
  1. S V=$P(%,U,3) I V S T=$P($P(^AUPNVSIT(V,0),U),"."),D=$$FMTE^XLFDT(T,"2D")
  1. I 'V S (D,T)="<???>"
  1. S E=$P(%,U,8),Q=$P(%,U,6),G=$P(%,U,5)
  1. S K=$S($P(N,U,4)="":$P(^PSDRUG(+%,0),U,1),1:$P(N,U,4))
  1. I E S E="-- D/C "_$$FMTE^XLFDT(E,"2D")
  1. D SIG S G=Z
  1. D SITE I S]"" S G=G_" ["_S_"]"
  1. S X="",$E(X,5)=K,$E(X,40)="# "_$S(Q:Q,1:"?"),$E(X,58)=D D S(X)
  1. S X=" Sig: "_G D S(X)
  1. Q
  1. ;
  1. SIG ;CONSTRUCT THE FULL TEXT FROM THE ENCODED SIG
  1. I $G(SIGT)="S" S Z=G Q
  1. NEW P S Z="" F P=1:1:$L(G," ") S X=$P(G," ",P) I X]"" D
  1. . 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)
  1. . S Z=Z_X_" "
  1. Q
  1. ;
  1. SITE ;DETERMINE IF OUTSIDE LOCATION INFO PRESENT
  1. S S=""
  1. I $D(^AUPNVSIT($P(%,U,3),21))#2 S S=$P(^(21),U)
  1. Q
  1. S(Y,F,C,T) ;set up array
  1. NEW X
  1. I '$G(F) S F=0
  1. I '$G(T) S T=0
  1. ;blank lines
  1. F F=1:1:F S X="" D S1
  1. S X=Y
  1. I $G(C) S L=$L(Y),T=(80-L)/2 D D S1 Q
  1. .F %=1:1:(T-1) S X=" "_X
  1. F %=1:1:T S X=" "_Y
  1. D S1
  1. Q
  1. S1 ;
  1. I '$D(^TMP("AMHSMEDS",$J,I,0)) S ^TMP("AMHSMEDS",$J,I,0)=0
  1. S %=$P(^TMP("AMHSMEDS",$J,I,0),U)+1,$P(^TMP("AMHSMEDS",$J,I,0),U)=%
  1. S ^TMP("AMHSMEDS",$J,I,%)=X
  1. Q