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

BGP8PC1.m

Go to the documentation of this file.
BGP8PC1 ;IHS/CMI/LAB - CALC MEASURES;  ; 12 Apr 2018  11:08 AM
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
PROC ;EP
 S BGPBT=$H
 D JRNL^BGP8PCUT
 S BGPJ=$J,BGPH=$H
 K ^XTMP("BGP15TAX",$J),^XTMP("BGPSNOMEDSUBSET",$J)
 D UNFOLDTX^BGP8UTL2
 D XTMP^BGP8UTL("BGP8D","IPC Patient List")
 ;calculate 3 years before end of each time frame
 S BGP3YE=$$FMADD^XLFDT(BGPED,-1096)
 S BGPP3YE=$$FMADD^XLFDT(BGPPED,-1096)
 S BGPB3YE=$$FMADD^XLFDT(BGPBED,-1096)
 ;process each patient
 S DFN=0 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  D
 .Q:'$D(^AUPNPAT(DFN,0))
 .;I DUZ=2881 Q:$$HRN^AUPNPAT(DFN,DUZ(2))'=144641
 .Q:$P($G(^DPT(DFN,0)),U)["DEMO,PATIENT"
 .S X=$O(^DIBT("B","RPMS DEMO PATIENT NAMES",0)) I X Q:$D(^DIBT(X,1,DFN))
 .D PROCCY,PROCPY,PROCBY
N ;
 S BGPET=$H
 K ^XTMP("BGP15TAX",$J),^XTMP("BGPSNOMEDSUBSET",$J)
 Q
 ;
PROCCY ;EP - current time period
 K ^TMP($J)
 K BGPG
 Q:'$D(^DPT(DFN,0))
 Q:$P(^DPT(DFN,0),U,2)=""
 Q:"FM"'[$P(^DPT(DFN,0),U,2)
 S BGPEDATE=BGPED,BGPTIME=1,BGPBDATE=BGPBD,BGPGBL="^BGPGPDCR("
 S BGPAGEB=$$AGE^AUPNPAT(DFN,BGPBDATE)
 S BGPAGEE=$$AGE^AUPNPAT(DFN,BGPEDATE)
 S BGPSEX=$P(^D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 K ^TMP($J,"A")
 NEW A,B,X,G,V,R
 S R=$NA(^TMP($J,"A"))
 D ALLV^APCLAPIU(P,BDATE,EDATE,R)
 I '$D(^TMP($J,"A",1)) Q ""
 S (X,G)=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G>1)  S V=$P(^TMP($J,"A",X),U,5) D
 .Q:'$D(^AUPNVSIT(V,0))
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
 .Q:"V"[$P(^AUPNVSIT(V,0),U,3)
 .Q:$P(^AUPNVSIT(V,0),U,6)=""
 .S G=G+1
 .Q
 K ^TMP($J,"A")
 Q $S(G<2:"",1:1)
 ;
COMMBEN(P,B,T,C,PP,EDATE) ;
 NEW X
 I PP,'$D(^DIBT(PP,1,P)) Q 0 ;PATIENT PANEL AND PATIENT NOT IN THE PANEL
 I PP,$D(^DIBT(PP,1,P)) Q 1  ;PATIENT IS IN PP
 I B=1,$$BEN^AUPNPAT(P,"C")'="01" Q 0  ;must be Indian/Alaskan Native
 I B=2,$$BEN^AUPNPAT(P,"C")="01" Q 0  ;must not be I/A
 S DOD=$$DOD^AUPNPAT(P) I DOD]"",DOD<EDATE Q 0
 I T="",C="" Q 1  ;all communities
 I C,$P($G(^AUPNPAT(P,11)),U,17)'=C Q 0
 I C,$P($G(^AUPNPAT(P,11)),U,17)=C Q 1
 S X=$P($G(^AUPNPAT(P,11)),U,18) I X="" Q 0
 I '$D(^ATXAX(T,21,"B",($P(^AUPNPAT(P,11),U,18)))),'$D(^ATXAX(T,21,"AA",$P(^AUPNPAT(P,11),U,18),$P(^AUPNPAT(P,11),U,18))) Q 0
 Q 1
 ;
IPCACTUP(P,BDATE,EDATE) ;EP - is this patient in user pop?
 NEW X,DOD
 S DOD=$$DOD^AUPNPAT(P) I DOD]"",DOD<EDATE Q 0
LVD I '$$V1(P,BDATE,EDATE) Q 0  ;did they have 1 visit to IPC clinic list
 Q 1
 ;
V1(P,BDATE,EDATE) ;
 NEW R,X,G,F,S,B,BGPV
 D ALLV^APCLAPIU(P,BDATE,EDATE,"BGPV")
 S (X,G,F,S)=0 F  S X=$O(BGPV(X)) Q:X'=+X!(G)  S V=$P(BGPV(X),U,5) D
 .Q:'$D(^AUPNVSIT(V,0))
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:'$D(^AUPNVPRV("AD",V))
 .Q:"SAHOI"'[$P(^AUPNVSIT(V,0),U,7)
 .Q:$P(^AUPNVSIT(V,0),U,6)=""
 .I $P(^AUPNVSIT(V,0),U,7)="H" S G=1 Q   ;H visit has no clinic
 .I $P(^AUPNVSIT(V,0),U,7)="I" S G=1 Q   ;I visit has no clinic
 .S B=$$CLINIC^APCLV(V,"C")
 .Q:B=""
 .I $D(^BGPCTRL($O(^BGPCTRL("B",2018,0)),1101,"B",B)) S G=1  ;must be a primary clinic S G=V
 Q $S(G:1,1:0)
DMC ;EP
 ;
 I 'BGPIPCUP S BGPSTOP=1 Q  ;must be ipc up
 I '$$FDMPRIOR(DFN,$$FMADD^XLFDT(BGPBDATE,-1)) S BGPSTOP=1 Q  ;NO DIAGNOSIS PRIOR TO REPORT PERIOD
 ;EXCLUSIONS
 S X=$$BLINDPL^BGP8D21A(DFN,BGPEDATE) I X S BGPSTOP=1 Q  ;BLIND
 S X=$$LASTDX^BGP8UTL1(DFN,"BGP BILATERAL BLINDNESS DXS",$$DOB^AUPNPAT(DFN),BGPEDATE) I X S BGPSTOP=1 Q  ;BLIND DX
 S X=$$EYEENUC^BGP8D21A(DFN,BGPEDATE) I X S BGPSTOP=1 Q  ;BLIND
 S X=$$AMP^BGP8D27(DFN,BGPEDATE) I X S BGPSTOP=1 Q  ;FOOT AMP
 ;
 S BGPVALUE=""
 S (BGPN1,BGPD1,BGPI1,BGPI2,BGPI3,BGPI4,BGPI5)=0
 S BGPD1=1  ;hit denominator
 ;
 S BGPI1=$$HGBA1C^BGP8D2(DFN,BGPBDATE,BGPEDATE)
 I BGPI1 S BGPVALUE=BGPVALUE_"A1c: "_$$DATE^BGP8UTL($P(BGPI1,U,3))_" "_$P(BGPI1,U,4)
 K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,J,K,G,I,L,T,BGPG
22 ;BPS to set numr 2
 S BGPV=""
 S BGPBP=$$LASTBP(DFN,BGPBDATE,BGPEDATE)  ;RETURN 1^EXT DATE BP VALUE
 ;I BGPBP="" S BGPBP=$$BPCPT(DFN,BGPBDATE,BGPEDATE) I BGPBP]"" S BGPI2=1 G BPS
 I BGPBP="" G BPS
 S BGPI2=1
 S BGPV=$P(BGPBP,U,2)
BPS ;
 I BGPV]"" S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_"BP: "_BGPV
 ;
23 ;
24 ;micro or pos urine & GFR
 S BGPGFR=$$GFR^BGP8D211(DFN,BGPBDATE,BGPEDATE)
 S BGPESRD=$$ESRD^BGP8D211(DFN,$P(^DPT(DFN,0),U,3),BGPEDATE)
 S BGPQUP=$$QUANTUP^BGP8D211(DFN,BGPBDATE,BGPEDATE)
 I $P(BGPESRD,U) S BGPI3=1
 I BGPGFR&(BGPQUP) S BGPI3=1
 I BGPI3 D
 .I BGPESRD S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$S(BGPESRD]"":"ESRD: "_$$DATE^BGP8UTL($P(BGPESRD,U,3))_" "_$P(BGPESRD,U,2),1:"") Q
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_"GFR: "_$$DATE^BGP8UTL($P(BGPGFR,U,2))
 .S BGPVALUE=BGPVALUE_" & UACR: "_$$DATE^BGP8UTL($P(BGPQUP,U,3))_" "_$P(BGPQUP,U,2)
 K BGPX,BGPC
25 ;
 S BGPEYE=$$EYE^BGP8D21(DFN,BGPBDATE,BGPEDATE)
 S A=0 I $P(BGPEYE,U)=1 S A=1
 S B=0 I $P(BGPEYE,U)=2 S B=1
 S C=0 I $P(BGPEYE,U)=3 S C=1
 S BGPI4=0 I A!(B)!(C) S BGPI4=1
 I BGPI4 S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_"EYE: "_$$DATE^BGP8UTL($P(BGPEYE,U,2))_" "_$P(BGPEYE,U,3)
 K BGPG
 K ^TMP($J,"A")
26 ;FOOT EXAM
 S BGPFOOT=$$FOOT^BGP8D213(DFN,BGPBDATE,BGPEDATE,1)
 S BGPI5=$P(BGPFOOT,U)
 I BGPI5 S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_"FOOT EXAM: "_$$DATE^BGP8UTL($P(BGPFOOT,U,2))_" "_$P(BGPFOOT,U,3)
ALL I BGPI1,BGPI2,BGPI3,BGPI4,BGPI5 S BGPN1=1
 S BGPVALUE="IPCUP&DM DX|||"_BGPVALUE I BGPN1 S BGPVALUE=$P(BGPVALUE,"|||")_"|||*** "_$P(BGPVALUE,"|||",2)
CU1 K BGPBP,BGPLDL,BGPEYE,BGPUP,BGPLHGB,BGPG,BGPX,BGPC,BGPGFR,BGPFOOT,BGPBLIND,BGPI1,BGPI2,BGPI3,BGPI4,BGPI5
 K ^TMP($J,"A")
 Q
LASTBP(P,BDATE,EDATE) ;EP
 NEW S,D,C,E,BGPG,X,Y,G,T,M,A,Z,L
 S BGPG=$$LASTITEM^BGP8DU(P,BDATE,EDATE,"MEASUREMENT","BP")
 I BGPG Q 1_U_$$DATE^BGP8UTL($P(BGPG,U,2))_" "_$P(BGPG,U,4)
 K BGPG
 S T=$O(^ATXAX("B","BGP BP MEASURED CPT",0))
 I T D  I X]"" Q 1_U_$$DATE^BGP8UTL($P(X,U,1))_" "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 S BGPG=$$LASTDX^BGP8UTL1(P,"BGP HYPERTENSION SCREEN DXS",BDATE,EDATE) I BGPG Q 1_U_$$DATE^BGP8UTL($P(BGPG,U,3))_" "_$P(BGPG,U,2)
 S S=$$CPT^BGP8DU(P,BDATE,EDATE,$O(^ATXAX("B","BGP SYSTOLIC BP CPTS",0)),5)
 S D=$$CPT^BGP8DU(P,BDATE,EDATE,$O(^ATXAX("B","BGP DIASTOLIC BP CPTS",0)),5)
 I S,D Q 1_U_$$DATE^BGP8UTL($P(S,U,1))_"&"_$$DATE^BGP8UTL($P(D,U,1))_" "_$P(S,U,2)_"/"_$P(D,U,2)
 Q ""
FDMPRIOR(P,EDATE) ;EP
 I $G(P)="" Q ""
 NEW X,BGPG,E,Y
 K BGPG
 S Y="BGPG("
 S X=P_"^FIRST DX [SURVEILLANCE DIABETES;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG(1)) Q ""
 Q 1
STUFF ;
 S X="BGP IPC",DA=976
 F  S X=$O(^ATXAX("B",X)) Q:X=""!(X]"BGP IPCZZZZZZ")  D
 .Q:$D(^BGPTAXR("B",X))  ;already in there
 .S DA=DA+1
 .S ^BGPTAXR(DA,0)=X_"^D^^0"
 .S ^BGPTAXR("B",X,DA)=""
 .S ^BGPTAXR(DA,12,0)="^90560.0812S^1^1"
 .S ^BGPTAXR(DA,12,1,0)=8
 .S ^BGPTAXR(DA,12,"B",8,1)=""
 .W !,X
 Q
TESTBP ;
 S DFN=0
 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  S BGPBP=$$LASTBP(DFN,3120101,DT) I BGPBP W !,DFN," ",BGPBP
 Q