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

BGP8D24.m

Go to the documentation of this file.
BGP8D24 ;IHS/CMI/LAB - sti measure; 
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
STI ;EP
 ;D EN^BKMSTIDS(DFN,BGPBDATE,BGPEDATE,"KEY",.BGPYAR,.BGPZAR)
 ;Q
ISTI ;EP
 NEW BGPCIN
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPN15,BGPN16,BGPN17,BGPN18,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5)=0
 S BGPVALUE="",BGPDENV=""
 I 'BGPACTCL S BGPSTOP=1 Q  ;only active clinical pts
 S BGPZAR=$$KEYSTI^BGP8D24A(DFN,BGPBDATE,BGPEDATE)
 I '$P(BGPZAR,U,1) S BGPSTOP=1 Q  ;no incidences or diagnoses
 I $P($G(BGPZAR),U)=0 S BGPSTOP=1 Q  ;no incidences or diagnoses
 S (BGPN1,BGPN2)=$P(BGPZAR,U,1)  ;TOTAL # OF INCIDENCES
 S BGPD1=$P(BGPZAR,U,2) ;TOTAL # SCREENINGS NEEDED
 S BGPN3=$P(BGPZAR,U,3) ;TOTAL # OF SCREENINGS DONE
 S BGPN4=$P(BGPZAR,U,4) ;TOTAL # OF REFUSALS
 S BGPVALUE="UP"_$S(BGPACTCL:";AC",1:"")_" "_$P(BGPZAR,U,5)_"|||"_$P(BGPZAR,U,6)
 ;S BGPCIN=0 S X=0 F  S X=$O(BGPNUMV(X)) Q:X'=+X  S BGPCIN=BGPCIN+1 S BGPVALUE=BGPVALUE_$S(BGPCIN>1:"; ",1:"")_BGPCIN_") "_$S(BGPNUMV(X)="":"N/A",1:BGPNUMV(X))
 Q
 ;
SBI ;EP
 F X=1:1:10 S Y="BGPD"_X S @Y=""  ;10 denominators
 F X=1:1:7 S Y="BGPN"_X S @Y="" ;7 numerators
 S BGPVALUE=""
 I 'BGPACTUP S BGPSTOP=1 Q
 I BGPAGEB<9 S BGPSTOP=1 Q
 I BGPAGEB>75 S BGPSTOP=1 Q
 I BGPACTCB D
 .S BGPD1=1
 .I BGPAGEB>8,BGPAGEB<13 S BGPD2=1
 .I BGPAGEB>12,BGPAGEB<19 S BGPD3=1
 .I BGPAGEB>18,BGPAGEB<25 S BGPD4=1
 .I BGPAGEB>24,BGPAGEB<35 S BGPD5=1
 .I BGPAGEB>34,BGPAGEB<45 S BGPD6=1
 .I BGPAGEB>44,BGPAGEB<55 S BGPD7=1
 .I BGPAGEB>54,BGPAGEB<65 S BGPD8=1
 .I BGPAGEB>64 S BGPD9=1
 I BGPACTUP S BGPD10=1  ;UP 9-75
 K BGPALL
 D ALSCRN^BGP8D55(DFN,BGPBDATE,BGPEDATE,.BGPALL,1)
 I $D(BGPALL) S BGPN1=1
 ;if screened, is any screen positive
 I BGPD10,'BGPD1,'BGPN1 S BGPSTOP=1 Q  ;UP 9-75, NOT AC+BH, NOT SCREENED
 S BGPSCRC="",BGPSCRD=""
 S D=0 F  S D=$O(BGPALL(D)) Q:D'=+D!(BGPSCRC]"")  S Y=0 F  S Y=$O(BGPALL(D,Y)) Q:Y'=+Y!(BGPSCRC]"")  I $P(BGPALL(D,Y),U,5) S BGPSCRC=BGPALL(D,Y),BGPSCRD=$P(BGPALL(D,Y),U,4)
 I BGPSCRC]"" S BGPN2=1
 ;I BGPD10,'BGPD1,'BGPN2 S BGPSTOP=1 Q  ;UP 9-75
 ;if no positive then take latest one
 I BGPSCRC="" S D=$O(BGPALL(0)) I D S Y=$O(BGPALL(D,0)) S BGPSCRC=BGPALL(D,Y),BGPSCRD=$P(BGPALL(D,Y),U,4)
 I BGPSCRD="" G SETL  ;NO SCREENING SO DON'T BOTHER WITH NUMERATOR BNI
 ;GET BNI DATE/ITEM/
 K BGPABNI
 S BGPBNID=""
 D BNI(DFN,BGPSCRD,$$FMADD^XLFDT(BGPSCRD,7),.BGPABNI)
 I '$D(BGPABNI) G TRT  ;NO BNIS
 ;GET 1ST ONE
 S D=$O(BGPABNI(0)) I D S Y=$O(BGPABNI(D,0)) S BGPBNID=BGPABNI(D,Y)
 S BGPN3=1
 S X=$P(BGPBNID,U,5)
 I X=0 S BGPN4=1
 I X>0,X<4 S BGPN5=1
 I X>3 S BGPN6=1
TRT S BGPTRT=""
 I BGPN2 D
 .S BGPTRT=$$TXPTED(DFN,BGPSCRD,$$FMADD^XLFDT(BGPSCRD,7))
 .I BGPTRT S BGPN7=1
SETL ;
 S BGPVALUE=$S(BGPD10:"UP",1:"") S:BGPD1 BGPVALUE=BGPVALUE_$S(BGPVALUE]"":",AC+BH",1:"AC+BH") S BGPVALUE=BGPVALUE_"|||"
 I BGPN1 D
 .S BGPVALUE=BGPVALUE_"SCREEN: "_$P(BGPSCRC,U,3)_" "_$P(BGPSCRC,U,2)_$S(BGPN2:" result=Pos",1:"")
 .S BGPVALUE=BGPVALUE_"; BNI: "_$S(BGPN3:$P(BGPBNID,U,3)_" Yes ["_$P(BGPBNID,U,5)_"]",1:"No")
 .S BGPVALUE=BGPVALUE_"; "_$P(BGPTRT,U,2) ;$S(BGPN7:$P(BGPTRT,U,2),1:"No")
X K BGPSCRD,BGPALL,BGPABNI,BGPBNID,BGPSCRC
 Q
 ;
TXPTED(P,BDATE,EDATE) ;
 ;LORI!!!! ADD BH
 NEW BGPG
 K BGPG
 S Y="BGPG("
 S X=P_"^FIRST EDUC AOD-TX;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG) Q 0_U_"REFERRAL: No"
 Q 1_U_"REFERRAL: "_$$DATE^BGP8UTL($P(BGPG(1),U))_" Yes"
 ;
BNI(P,BDATE,EDATE,BGPABNI) ;EP - GET FIRST BNI AVAILABLE ON A VISITS
 NEW BGPG,%,E,BGPSC,V,BGPC,T,F,D,R,BGPCT,BGPX,BGPV,BGPVD,BGPIVD
 K BGPABNI
 S BGPSC=0
PCC ;check PCC first
 S BGPCT=$O(^ATXAX("B","BGP BNI CPTS",0))
 K BGPG
 D ALLV^APCLAPIU(P,BDATE,EDATE,"BGPG")
 S BGPX=0 F  S BGPX=$O(BGPG(BGPX)) Q:BGPX'=+BGPX  S BGPV=$P(BGPG(BGPX),U,5) D
 .Q:$P(^AUPNVSIT(BGPV,0),U,7)'="A"  ;IF SBI ONLY AMBULATORY
 .S BGPVD=$$VD^APCLV(BGPV)
PCCCPT .;
 .S E=0 F  S E=$O(^AUPNVCPT("AD",BGPV,E)) Q:E'=+E  D
 ..S I=$P($G(^AUPNVCPT(E,0)),U,1)
 ..Q:'I
 ..Q:'$$ICD^BGP8UTL2(I,BGPCT,1)
 ..S J=$P(^ICPT(I,0),U,1)
 ..S BGPSC=BGPSC+1
 ..S BGPABNI(BGPVD,BGPSC)=1_"^CPT "_J_"^"_$$DATE^BGP8UTL(BGPVD)_U_BGPVD_U_$$FMDIFF^XLFDT(BGPVD,BDATE)
PCCPTED .;
 .S E=0 F  S E=$O(^AUPNVPED("AD",BGPV,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^BGP8UTL2(I,BGPCT,1)
PCS ..S BGPSC=BGPSC+1
 ..S BGPABNI(BGPVD,BGPSC)=1_"^PT ED "_T_"^"_$$DATE^BGP8UTL(BGPVD)_U_BGPVD_U_$$FMDIFF^XLFDT(BGPVD,BDATE)
BH ;CHECK BH VISITS
 S BGPC="",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 .;
 .Q:$$VAL^XBDIQ1(9002011,V,.07)'="OUTPATIENT"
 .S BGPVD=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^BGP8UTL2(I,BGPCT,1)
 ..S J=$P(^ICPT(I,0),U,1)
 ..S BGPSC=BGPSC+1
 ..S BGPABNI(BGPVD,BGPSC)=1_"^CPT "_J_"^"_$$DATE^BGP8UTL(BGPVD)_U_BGPVD_U_$$FMDIFF^XLFDT(BGPVD,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^BGP8UTL2($P(T,U,1),BGPCT,1)
BHS ..S BGPSC=BGPSC+1
 ..S BGPABNI(BGPVD,BGPSC)=1_"^PT ED "_T_"^"_$$DATE^BGP8UTL(BGPVD)_U_BGPVD_U_$$FMDIFF^XLFDT(BGPVD,BDATE)
 .Q
 Q
IPC ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
 S BGPVALUE=""
 I 'BGPACTCL Q  ;not active clinical
 S BGPVAL=$$PCV(DFN,BGPBDATE,BGPEDATE)  ;return #visits^list string
 S BGPN1=$P(BGPVAL,U)
 I BGPAGEB<18 S BGPN2=BGPN1
 I BGPAGEB>17,BGPAGEB<55 S BGPN3=BGPN1
 I BGPAGEB>54 S BGPN4=BGPN1
 ;I BGPCANCE,BGPN1>1 S BGPN5=1
 S BGPVALUE="AC"_"|||"_BGPN1_$S(BGPN1'=1:" visits: ",1:" visit: ")_$P(BGPVAL,U,2)
 K BGPVAL
 Q
 ;
PCV(P,BDATE,EDATE) ;EP
 ;all dxs BGP PALLIATIVE CARE  DXS and get unique visits count
 NEW BGPG,X,Y,E
 K BGPG
 S Y="BGPG("
 S X=P_"^ALL DX [BGP PALLIATIVE CARE DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG(1)) Q 0  ;no visits
 NEW X,C,R
 S R="",C=0
 S X=0 F  S X=$O(BGPG(X)) Q:X'=+X  I '$D(X($P(BGPG(X),U,5))) D
 .S X($P(BGPG(X),U,5))=""
 .S C=C+1
 .S R=R_$S(R="":"",1:", ")_$$DATE^BGP8UTL($P($P(^AUPNVSIT($P(BGPG(X),U,5),0),U),"."))
 Q C_U_R