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

AMHRSB2.m

Go to the documentation of this file.
AMHRSB2 ; IHS/CMI/LAB - list sbirt 24 Aug 2009 6:21 PM ;
 ;;4.0;IHS BEHAVIORAL HEALTH;**8**;JUN 02, 2010;Build 7
 ;
 ;
BNI(P,BDATE,EDATE,AMHABNI) ;EP - GET FIRST BNI AVAILABLE ON A VISITS
 NEW AMHG,%,E,AMHSC,V,AMHC,T,F,D,R,AMHCT,AMHX,AMHV,AMHVD,AMHIVD,X
 K AMHABNI
 S AMHSC=0
PCC ;check PCC first
 S AMHCT=$O(^ATXAX("B","BGP BNI CPTS",0))
 K AMHG
 D ALLV^APCLAPIU(P,BDATE,EDATE,"AMHG")
 S AMHX=0 F  S AMHX=$O(AMHG(AMHX)) Q:AMHX'=+AMHX  S AMHV=$P(AMHG(AMHX),U,5) D
 .Q:$P(^AUPNVSIT(AMHV,0),U,7)'="A"  ;IF SBI ONLY AMBULATORY
 .S AMHVD=$$VD^APCLV(AMHV)
PCCCPT .;
 .S E=0 F  S E=$O(^AUPNVCPT("AD",AMHV,E)) Q:E'=+E  D
 ..S I=$P($G(^AUPNVCPT(E,0)),U,1)
 ..Q:'I
 ..Q:'$$ICD^ATXAPI(I,AMHCT,1)
 ..S J=$P(^ICPT(I,0),U,1)
 ..S AMHSC=AMHSC+1
 ..S AMHABNI(AMHVD,AMHSC)=1_"^CPT "_J_"^"_$$FMTE^XLFDT(AMHVD)_U_AMHVD_U_$$FMDIFF^XLFDT(AMHVD,BDATE)
PCCPTED .;
 .S E=0 F  S E=$O(^AUPNVPED("AD",AMHV,E)) Q:E'=+E  D
 ..S I=$P($G(^AUPNVPED(E,0)),U,1)
 ..Q:'I
 ..S T=$P($G(^AUTTEDT(I,0)),U,2)
 ..I T="AOD-BNI" G PCS
 ..Q:$L($P(T,"-",1))'=5
 ..S I=+$$CODEN^ICPTCOD($P(T,"-",1))
 ..Q:'$$ICD^ATXAPI(I,AMHCT,1)
PCS ..S AMHSC=AMHSC+1
 ..S AMHABNI(AMHVD,AMHSC)=1_"^PT ED "_T_"^"_$$FMTE^XLFDT(AMHVD)_U_AMHVD_U_$$FMDIFF^XLFDT(AMHVD,BDATE)
BH ;CHECK BH VISITS
 S AMHC="",T="",F=""
 S E=9999999-BDATE,D=9999999-EDATE-1_".99"
 F  S D=$O(^AMHREC("AE",P,D)) Q:D'=+D!($P(D,".")>E)  S V=0 F  S V=$O(^AMHREC("AE",P,D,V)) Q:V'=+V  D
BHEX .;
 .S T=$$VAL^XBDIQ1(9002011,V,.07)
 .I T'="AFTERCARE",T'="OUTPATIENT",T'="INTENSIVE OUTPATIENT",T'="EMERGENCY ROOM",T'="TELE-BEHAVIORAL HEALTH" Q
 .S AMHVD=9999999-$P(D,".")
BHCPT .;now add in CPT codes
 .S X=0 F  S X=$O(^AMHRPROC("AD",V,X)) Q:X'=+X  D
 ..S I=$P($G(^AMHRPROC(X,0)),U,1)
 ..Q:'I
 ..Q:'$$ICD^ATXAPI(I,AMHCT,1)
 ..S J=$P(^ICPT(I,0),U,1)
 ..S AMHSC=AMHSC+1
 ..S AMHABNI(AMHVD,AMHSC)=1_"^CPT "_J_"^"_$$FMTE^XLFDT(AMHVD)_U_AMHVD_U_$$FMDIFF^XLFDT(AMHVD,BDATE)
 ..Q
BHPTED .;
 .S X=0 F  S X=$O(^AMHREDU("AD",V,X)) Q:X'=+X  D
 ..S I=$P($G(^AMHREDU(X,0)),U,1)
 ..Q:'I
 ..S T=$P($G(^AUTTEDT(I,0)),U,2)
 ..I T="AOD-BNI" G BHS
 ..Q:$L($P(T,U,1))'=5
 ..Q:'$$ICD^ATXAPI($P(T,U,1),AMHCT,1)
BHS ..S AMHSC=AMHSC+1
 ..S AMHABNI(AMHVD,AMHSC)=1_"^PT ED "_T_"^"_$$FMTE^XLFDT(AMHVD)_U_AMHVD_U_$$FMDIFF^XLFDT(AMHVD,BDATE)
 .Q
 Q
LISTS ;EP
 D @AMHRSORT
 I AMHRSORV="" S AMHRSORV="--"
 I $D(AMHRLIST(1)) D
 .;this list is for all with any positive screen
 .Q:'GPP  ;patient had no positives
 .S X=0 F  S X=$O(AMHASCR(X)) Q:X'=+X  D
 ..S ^XTMP("AMHRSB1",AMHRJ,AMHRH,"LIST1",AMHRSORV,DFN,X)=$$FMTE^XLFDT(X)_U_$P(AMHASCR(X),U)_U_$P(AMHASCR(X),U,2)_U_"POSITIVE"_U_$P(AMHASCR(X),U,4)_U_$$FMTE^XLFDT($P(AMHASCR(X),U,7))_U_$P(AMHASCR(X),U,5)_U_$P(AMHASCR(X),U,8)
 I $D(AMHRLIST(2)) D
 .;this list is for all with any positive screen
 .Q:'GPP
 .I 'GP0,'GP1,'GP4,'GPT Q  ;had none within appropriate time window ;patient had no positives
 .S X=0 F  S X=$O(AMHASCR(X)) Q:X'=+X  D
 ..S ^XTMP("AMHRSB1",AMHRJ,AMHRH,"LIST2",AMHRSORV,DFN,X)=$$FMTE^XLFDT(X)_U_$P(AMHASCR(X),U)_U_$P(AMHASCR(X),U,2)_U_"POSITIVE"_U_$P(AMHASCR(X),U,4)_U_$$FMTE^XLFDT($P(AMHASCR(X),U,7))_U_$P(AMHASCR(X),U,5)_U_$P(AMHASCR(X),U,8)
 ..Q
 I $D(AMHRLIST(3)) D
 .;this list is for all with any positive screen
 .Q:'GPP
 .I 'GP0,'GP1,'GP4,'GPT D  ;had none within appropriate time window ;patient had no positives
 ..S X=0 F  S X=$O(AMHASCR(X)) Q:X'=+X  D
 ...S ^XTMP("AMHRSB1",AMHRJ,AMHRH,"LIST3",AMHRSORV,DFN,X)=$$FMTE^XLFDT(X)_U_$P(AMHASCR(X),U)_U_$P(AMHASCR(X),U,2)_U_"POSITIVE"_U_$P(AMHASCR(X),U,4)_U_$$FMTE^XLFDT($P(AMHASCR(X),U,7))_U_$P(AMHASCR(X),U,5)_U_$P(AMHASCR(X),U,8)
 ;
 Q
H ;
 S AMHRSORV=$$HRN^AUPNPAT(DFN,DUZ(2))
 Q
N ;
 S AMHRSORV=$P(^DPT(DFN,0),U)
 Q
A S AMHRSORV=$$AGE^AUPNPAT(DFN,AMHRBD)
 Q
G ;
 S AMHRSORV=$$VAL^XBDIQ1(2,DFN,.02)
 Q
T ;
 S %=$$HRN^AUPNPAT(DFN,DUZ(2))
 S %=%+10000000,%=$E(%,7,8)_"-"_+$E(%,2,8)
 S AMHRSORV=%
 Q