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

APCM11E1.m

Go to the documentation of this file.
APCM11E1 ; IHS/CMI/LAB - IHS MU 24 Feb 2011 10:32 AM ; 
 ;;1.0;IHS MU PERFORMANCE REPORTS;**1,2,5,6**;MAR 26, 2012;Build 65
 ;
BQI(BQIGREF,APCMPRV) ;PEP-Call from iCare
 ; input
 ; BQIGREF - Global reference
 ; APCMPRV - Array of providers
 ;
PROC ;EP
 S APCMBT=$H
 D JRNL^APCM1UTL
 S APCMJ=$J,APCMH=$H
 D XTMP^APCM1UTL("APCM1D","MU Patient List")
 ;process each patient
 ;first gather up provider exclusions
 I APCMRPTT=2 D  G PROC1  ;hospital report doesn't need this stuff for exclusions
 .K APCM2ON
 .K APCMOFFV
 .K APCM13ON
 .K APCMTRAE
 .K APCMIMME
 .K APCMN565
 .K APCMHO65
 .K APCMRCIS
 .K APCMNOEC
 .S X=APCMFAC  S APCMX=$$VSTH(APCMFAC,APCMBD,APCMED) D
 ..I '$P(APCMX,U,3) S APCM13ON(X,1)=""
 ..I '$P(APCMX,U,2) S APCM2ON(X,1)=""
 ..I '$P(APCMX,U,1) S APCMOFFV(X,1)=""
 ..I '$P(APCMX,U,4) S APCMTRAE(X,1)=""
 ..I '$P(APCMX,U,5) S APCMIMME(X,1)=""
 ..I '$P(APCMX,U,6) S APCMN565(X,1)=""
 ..I '$P(APCMX,U,7) S APCMHO65(X,1)=""
 ..I '$P(APCMX,U,8) S APCMRCIS(X,1)=""
 ..I '$P(APCMX,U,9) S APCMNOEC(X,1)=""
 .I $G(APCMWPP) S X=APCMFAC S APCMX=$$VSTH(APCMFAC,APCMPBD,APCMPED) D
 ..I '$P(APCMX,U,3) S APCM13ON(X,2)=""
 ..I '$P(APCMX,U,2) S APCM2ON(X,2)=""
 ..I '$P(APCMX,U,1) S APCMOFFV(X,2)=""
 ..I '$P(APCMX,U,4) S APCMTRAE(X,2)=""
 ..I '$P(APCMX,U,5) S APCMIMME(X,2)=""
 ..I '$P(APCMX,U,6) S APCMN565(X,2)=""
 ..I '$P(APCMX,U,7) S APCMHO65(X,2)=""
 ..I '$P(APCMX,U,8) S APCMRCIS(X,2)=""
 ..I '$P(APCMX,U,9) S APCMNOEC(X,2)=""
 .D ROIH^APCM11E7
 K APCM100R
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  I '$$H100(X,APCMBD,APCMED) S APCM100R(X,1)=""
 I $G(APCMWPP) S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  I '$$H100(X,APCMPBD,APCMPED) S APCM100R(X,2)=""
 K APCM2ON
 K APCMOFFV
 K APCM13ON
 K APCMTRAE
 K APCMIMME
 K APCMN565
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMX=$$VST(X,APCMBD,APCMED) D
 .I '$P(APCMX,U,3) S APCM13ON(X,1)=""
 .I '$P(APCMX,U,2) S APCM2ON(X,1)=""
 .I '$P(APCMX,U,1) S APCMOFFV(X,1)=""
 .I '$P(APCMX,U,4) S APCMTRAE(X,1)=""
 .I '$P(APCMX,U,5) S APCMIMME(X,1)=""
 I $G(APCMWPP) S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMX=$$VST(X,APCMPBD,APCMPED) D
 .I '$P(APCMX,U,3) S APCM13ON(X,2)=""
 .I '$P(APCMX,U,2) S APCM2ON(X,2)=""
 .I '$P(APCMX,U,1) S APCMOFFV(X,2)=""
 .I '$P(APCMX,U,4) S APCMTRAE(X,2)=""
 .I '$P(APCMX,U,5) S APCMIMME(X,2)=""
N1 D ROI  ;roi exclusions
 D RCIS ;SUMMARY OF CARE EXCLUSIONS
 ;any patients 0-5 or >64?
 S APCMN565(1)=1
 S P=0 F  S P=$O(^DPT(P)) Q:P'=+P!(APCMN565(1)=0)  D
 .S X=$$DOD^AUPNPAT(P)
 .I X,X'>APCMED Q
 .Q:$$DOB^AUPNPAT(P)>APCMBD  ;born after time period begin date
 .S X=$P($G(^AUPNPAT(P,41,DUZ(2),0)),U,3)
 .I X,X'>APCMED Q
 .S A=$$AGE^AUPNPAT(P,APCMBD)
 .I A<6 S APCMN565(1)=0 Q
 .I A>64 S APCMN565(1)=0 Q
 ;
 G:'$G(APCMWPP) PROC1
 S APCMN565(2)=1
 S P=0 F  S P=$O(^DPT(P)) Q:P'=+P!(APCMN565(2)=0)  D
 .S X=$$DOD^AUPNPAT(P)
 .I X,X'>APCMPED Q
 .Q:$$DOB^AUPNPAT(P)>APCMPBD  ;born after time period begin date
 .S X=$P($G(^AUPNPAT(P,41,DUZ(2),0)),U,3)
 .I X,X'>APCMPED Q
 .S A=$$AGE^AUPNPAT(P,APCMPBD)
 .I A<6 S APCMN565(2)=0 Q
 .I A>64 S APCMN565(2)=0 Q
PROC1 ;
 S DFN=0 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  D
 .Q:'$D(^DPT(DFN,0))
 .;I APCLDEMO'="I" Q:$P($G(^DPT(DFN,0)),U)["DEMO,PATIENT"
 .Q:$$DEMO^APCLUTL(DFN,$G(APCMDEMO))
 .D PROCCY,PROCPY
N ;
 ;NOW DO ATTESTATION MEASURES
 D PROCACY,PROCAPY
 S APCMET=$H
 Q
 ;
PROCCY ;EP - current time period
 K ^TMP($J)
 Q:'$D(^DPT(DFN,0))
 Q:$P(^DPT(DFN,0),U,2)=""
 ;Q:"FM"'[$P(^DPT(DFN,0),U,2)
 S APCMEDAT=APCMED,APCMTIME=1,APCMBDAT=APCMBD,APCMGBL="^APCMMUDC(",APCMFILN=9001300.0311
 S APCMAGEB=$$AGE^AUPNPAT(DFN,APCMBDAT)
 S APCMAGEE=$$AGE^AUPNPAT(DFN,APCMEDAT)
 S APCMSEX=$P(^DPT(DFN,0),U,2)
 ;had visit to each provider?
 D CALCIND
 K ^TMP($J,"A")
 Q
PROCPY ;
 Q:'$G(APCMWPP)
 K ^TMP($J)
 Q:'$D(^DPT(DFN,0))
 Q:$P(^DPT(DFN,0),U,2)=""
 ;Q:"FM"'[$P(^DPT(DFN,0),U,2)
 S APCMEDAT=APCMPED,APCMTIME=2,APCMBDAT=APCMPBD,APCMGBL="^APCMMUDP(",APCMFILN=9001300.0411
 S APCMAGEB=$$AGE^AUPNPAT(DFN,APCMBDAT)
 S APCMAGEE=$$AGE^AUPNPAT(DFN,APCMEDAT)
 S APCMSEX=$P(^DPT(DFN,0),U,2)
 D CALCIND
 K ^TMP($J,"A")
 Q
CALCIND ;
 D CALCIND^APCM11CI
 Q
PROCACY ;EP - current time period
 S APCMEDAT=APCMED,APCMTIME=1,APCMBDAT=APCMBD,APCMGBL="^APCMMUDC(",APCMFILN=9001300.0311
 D CALCINDA^APCM11CI
 Q
PROCAPY ;
 Q:'$G(APCMWPP)
 S APCMEDAT=APCMPED,APCMTIME=2,APCMBDAT=APCMPBD,APCMGBL="^APCMMUDP(",APCMFILN=9001300.0411
 D CALCINDA^APCM11CI
 Q
S(RPT,IND,VALUE,PROV,RT,T,F,NT) ;EP - set counter
 NEW N,P,Y,J
 I VALUE="" Q  ;no value to add
 I RT=1 S I=PROV_";VA(200,"
 I RT=2 S I=PROV_";AUTTLOC("
 I T=1 D  Q
 .I $G(BQIGREF)'="" D  Q
 ..NEW ID
 ..S ID=$P(^APCMMUM(IND,0),U,1)
 ..I $P(^APCMMUM(IND,0),U,8)=F S $P(@BQIGREF@(PROV,ID,"CURR"),U,1)=$P($G(@BQIGREF@(PROV,ID,"CURR")),U,1)+VALUE
 ..I $P(^APCMMUM(IND,0),U,9)=F S $P(@BQIGREF@(PROV,ID,"CURR"),U,2)=$P($G(@BQIGREF@(PROV,ID,"CURR")),U,2)+VALUE
 ..I $P(^APCMMUM(IND,0),U,11)=F S $P(@BQIGREF@(PROV,ID,"CURR"),U,3)=VALUE
 ..S $P(@BQIGREF@(PROV,ID,"CURR"),U,4)=$G(APCMVALU)
 .S Y=$P(^DD(9001300.0311,F,0),U,4)
 .S N=$P(Y,";")
 .S P=$P(Y,";",2)
 .S J=$O(^APCMMUDC(RPT,11,"B",I,0))
 .I 'J W APCMBOMB Q
 .I VALUE?.N S $P(^APCMMUDC(RPT,11,J,N),U,P)=$P($G(^APCMMUDC(RPT,11,J,N)),U,P)+VALUE
 .I VALUE'?.N S $P(^APCMMUDC(RPT,11,J,N),U,P)=VALUE
 .Q  ;now set total multiple (1200) - NOW NO TOTAL PER TIFFANY
 .Q:$G(NT)=1
 .S Y=$P(^DD(9001300.0312,F,0),U,4)
 .S N=$P(Y,";")
 .S P=$P(Y,";",2)
 .S J=$O(^APCMMUDC(RPT,12,"B","TOTAL",0))
 .I 'J S ^APCMMUDC(RPT,12,0)="^9001300.0312A^1^1",^APCMMUDC(RPT,12,1,0)="TOTAL",^APCMMUDC(RPT,12,"B","TOTAL",1)="",J=1
 .I VALUE?.N S $P(^APCMMUDC(RPT,12,J,N),U,P)=$P($G(^APCMMUDC(RPT,12,J,N)),U,P)+VALUE Q
 .S $P(^APCMMUDC(RPT,12,J,N),U,P)=VALUE
 I T=2 D
 .I $G(BQIGREF)'="" D  Q
 ..NEW ID
 ..S ID=$P(^APCMMUM(IND,0),U,1)
 ..I $P(^APCMMUM(IND,0),U,8)=F S $P(@BQIGREF@(PROV,ID,"PREV"),U,1)=$P($G(@BQIGREF@(PROV,ID,"PREV")),U,1)+VALUE
 ..I $P(^APCMMUM(IND,0),U,9)=F S $P(@BQIGREF@(PROV,ID,"PREV"),U,2)=$P($G(@BQIGREF@(PROV,ID,"PREV")),U,2)+VALUE
 ..I $P(^APCMMUM(IND,0),U,11)=F S $P(@BQIGREF@(PROV,ID,"PREV"),U,3)=VALUE
 ..S $P(@BQIGREF@(PROV,ID,"PREV"),U,4)=$G(APCMVALU)
 .S Y=$P(^DD(9001300.0411,F,0),U,4)
 .S N=$P(Y,";")
 .S P=$P(Y,";",2)
 .S J=$O(^APCMMUDP(RPT,11,"B",I,0))
 .I 'J W APCMBOMB Q
 .I VALUE?.N S $P(^APCMMUDP(RPT,11,J,N),U,P)=$P($G(^APCMMUDP(RPT,11,J,N)),U,P)+VALUE
 .I VALUE'?.N S $P(^APCMMUDP(RPT,11,J,N),U,P)=VALUE
 .Q  ;  NOT TOTALS PER TIFFANY
 .Q:$G(NT)=1  ;no totals
 .S Y=$P(^DD(9001300.0412,F,0),U,4)
 .S N=$P(Y,";")
 .S P=$P(Y,";",2)
 .S J=$O(^APCMMUDP(RPT,12,"B","TOTAL",0))
 .I 'J S ^APCMMUDP(RPT,12,0)="^9001300.0412A^1^1",^APCMMUDP(RPT,12,1,0)="TOTAL",^APCMMUDP(RPT,12,"B","TOTAL",1)="",J=1
 .I VALUE?.N S $P(^APCMMUDP(RPT,12,J,N),U,P)=$P($G(^APCMMUDP(RPT,12,J,N)),U,P)+VALUE Q
 .I VALUE'?.N S $P(^APCMMUDP(RPT,12,J,N),U,P)=VALUE
 Q
SETLIST ;EP
 NEW P,APCMX,APCMO
 Q:APCMTIME'=1
 Q:'$D(APCMINDL(APCMIC))  ;not a selected topic
 S APCMX=0 F  S APCMX=$O(APCMINDL(APCMIC,APCMX)) Q:APCMX'=+APCMX  D
 .X ^APCMMUPL(APCMX,12) Q:'$T
 .S APCMINDL(APCMIC,APCMX,APCMP)=$G(APCMINDL(APCMIC,APCMX,APCMP))+1
 .S APCMO=$S(APCMRPTT=2:$P(^APCMMUPL(APCMX,0),U,6),1:$P(^APCMMUPL(APCMX,0),U,5))
 .S P=$S(APCMRPTT=2:$P(^DIC(4,APCMP,0),U),1:$P(^VA(200,APCMP,0),U))
 .S ^XTMP("APCM1D",APCMJ,APCMH,"LIST",$P(^APCMMUM(APCMIC,0),U,4),APCMIC,APCMO,APCMX,P,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),$$AGE^AUPNPAT(DFN,APCMBDAT),DFN)=$G(APCMVALU)
 Q
H100(R,BD,ED) ;
 NEW ID,C,Y,X
 S C=0
 S ID=$$FMADD^XLFDT(BD,-1)
 F  S ID=$O(^PSRX("AC",ID)) Q:ID'=+ID!(C>100)  D
 .S X=0 F  S X=$O(^PSRX("AC",ID,X)) Q:X'=+X!(C>100)  D
 ..Q:$P($G(^PSRX(X,0)),U,4)'=R
 ..Q:$P($G(^PSRX(X,"STA")),"^")=13
 ..;SKIP ER CLINIC OR H VISIT, GET VISIT FROM V MED
 ..S VMED=$P($G(^PSRX(X,999999911)),U,1)
 ..Q:'VMED
 ..S V=$P($G(^AUPNVMED(VMED,0)),U,3)
 ..Q:'V
 ..Q:'$D(^AUPNVSIT(V,0))
 ..Q:$P(^AUPNVSIT(V,0),U,7)="H"
 ..Q:$$CLINIC^APCLV(V,"C")=30
 ..S C=C+1
 Q $S(C>100:1,1:"")
VST(R,BD,ED) ;did this provider see anyone over 2
 NEW SD,A,B,C,G,V,T
 S T=$O(^APCMMUCN("B","INTERIM STAGE 1 2011",0))
 S SD=$$FMADD^XLFDT(BD,-1)
 S SD=SD_".9999"
 S G=""
 F  S SD=$O(^AUPNVSIT("B",SD)) Q:SD'=+SD!($P(SD,".")>ED)!($$GOTALL(G))  D
 .S V=0 F  S V=$O(^AUPNVSIT("B",SD,V)) Q:V'=+V!($$GOTALL(G))  D
 ..S B=0,C=0 F  S B=$O(^AUPNVPRV("AD",V,B)) Q:B'=+B  D
 ...Q:'$D(^AUPNVPRV(B,0))
 ...Q:$P(^AUPNVPRV(B,0),U,1)'=R
 ...Q:$P(^AUPNVPRV(B,0),U,4)'="P"
 ...S C=1
 ..Q:'C
 ..S $P(G,U,1)=1
 ..I $$AGE^AUPNPAT($P(^AUPNVSIT(V,0),U,5),$P(BD,"."))>2 S $P(G,U,2)=1
 ..I $$AGE^AUPNPAT($P(^AUPNVSIT(V,0),U,5),$P(BD,"."))>12 S $P(G,U,3)=1
 ..S C=$$CLINIC^APCLV(V,"C")
 ..I T,C]"",'$D(^APCMMUCN(T,14,"B",C)) S $P(G,U,4)=1  ;not an exclusion
 ..I $D(^AUPNVIMM("AD",V)) S $P(G,U,5)=1  ;not an exclusion for imm reg
 ..I $$DOB^AUPNPAT($P(^AUPNVSIT(V,0),U,5))>BD S A=$$AGE^AUPNPAT($P(^AUPNVSIT(V,0),U,5),BD) I A<6!(A>64) S $P(G,U,6)=1
 Q G
 ;
GOTALL(%) ;EP
 NEW Y
 S Y=$P(%,U,1)+$P(%,U,2)+$P(%,U,3)+$P(%,U,4)+$P(%,U,5)+$P(%,U,6)
 I Y=6 Q 1
 Q 0
VSTH(R,BD,ED) ;did this HOSPITAL HAVE THESE VISITS
 NEW SD,A,B,C,G,V,T,O,P,Q,E,J,S
 S T=$O(^APCMMUCN("B","INTERIM STAGE 1 2011",0))
 S SD=$$FMADD^XLFDT(BD,-1)
 S SD=SD_".9999"
 S G=""
 F  S SD=$O(^AUPNVSIT("B",SD)) Q:SD'=+SD!($P(SD,".")>ED)!($$GOTALLH(G))  D
 .S V=0 F  S V=$O(^AUPNVSIT("B",SD,V)) Q:V'=+V!($$GOTALLH(G))  D
 ..Q:$P(^AUPNVSIT(V,0),U,6)'=R
 ..Q:'$$HOSER^APCM11E6(V,R)
 ..S $P(G,U,1)=1
 ..S A=$$AGE^AUPNPAT($P(^AUPNVSIT(V,0),U,5),$P(BD,".")) I A>2 S $P(G,U,2)=1
 ..I A>12 S $P(G,U,3)=1
 ..;S C=$$CLINIC^APCLV(V,"C")
 ..;I T,C]"",'$D(^APCMMUCN(T,14,"B",C)) S $P(G,U,4)=1  ;not an exclusion
 ..S $P(G,U,4)=1
 ..I $D(^AUPNVIMM("AD",V)) S $P(G,U,5)=1  ;not an exclusion for imm reg
 ..;check age
 ..I A<6!(A>64) S $P(G,U,6)=1
 ..I $P(^AUPNVSIT(V,0),U,7)="H" S A=$$AGE^AUPNPAT($P(^AUPNVSIT(V,0),U,5),$$VD^APCLV(V)) I A>64 S $P(G,U,7)=1
 ..;was there any requests for electronic discharge instructions?  check TIU notes
 ..I $$TIUDCEL(V) S $P(G,U,9)=1
 ..;is there a referral for this visit?
 ..S P=$P(^AUPNVSIT(V,0),U,5),J=""
 ..S O=$$FMADD^XLFDT($$VD^APCLV(V),-1),E=$$FMADD^XLFDT($$DSCHDATE^APCM11E6(V),1),J=""
 ..F  S O=$O(^BMCREF("AA",P,O)) Q:O'=+O!(J)!(O>E)  D
 ...S Q=0 F  S Q=$O(^BMCREF("AA",P,O,Q)) Q:Q'=+Q!(J)  D
 ....S S=$P(^BMCREF(Q,0),U,15)
 ....I S'="A",S'="C1" Q  ;not a A or C1
 ....Q:$P(^BMCREF(Q,0),U,4)="N"
 ....Q:$P(^BMCREF(Q,0),U,5)'=R
 ....S J=1
 ..I J=1 S $P(G,U,8)=1
 Q G
TIUDCEL(%) ;any electronic dc instruction TIU Notes
 NEW A,B,C
 S A=0,B=0 F  S A=$O(^AUPNVNOT("AD",%,A)) Q:A'=+A!(B)  D
 .S C=$$VAL^XBDIQ1(9000010.28,A,.01)
 .I $$UP^XLFSTR(C)="E-COPY DISCHARGE INSTR RECEIVED" S B=1 Q
 .I $$UP^XLFSTR(C)="E-COPY DISCHARGE INSTR NOT RECEIVED" S B=1 Q
 Q B
GOTALLH(%) ;EP
 NEW Y
 S Y=$P(%,U,1)+$P(%,U,2)+$P(%,U,3)+$P(%,U,4)+$P(%,U,5)+$P(%,U,6)+$P(%,U,7)+$P(%,U,8)+$P(%,U,9)
 I Y=9 Q 1
 Q 0
ROI ;
 NEW X
 S X=$O(^APCMMUM("B","S1.011.EP",0))
 I '$D(APCMIND(X)) Q  ;don't bother as this measure isn't in the report
 NEW APCMD,APCMX,APCMPAT,X,APCMP
 K APCMECHI
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMECHI(X,1)=""
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMECHI(X,2)=""
 ;LOOP THROUGH ROI AND IF I FIND 1 FOR THE PROVIDER THEN KILL OFF APCMECHI - exclusion
 S APCMD=$$FMADD^XLFDT(APCMBD,-1)
 S APCM4D=$$FMADD^XLFDT(APCMED,-4)
 F  S APCMD=$O(^BRNREC("B",APCMD)) Q:APCMD'=+APCMD!(APCMD>APCM4D)  D
 .S APCMX=0 F  S APCMX=$O(^BRNREC("B",APCMD,APCMX)) Q:APCMX'=+APCMX  D
 ..Q:$P($G(^BRNREC(APCMX,11)),U,1)'="E"  ;not an electronic request
 ..S APCMPAT=$P($G(^BRNREC(APCMX,0)),U,3)
 ..K APCMVSTS,APCMHVTP
 ..D ALLV^APCLAPIU(APCMPAT,$$FMADD^XLFDT(APCMED,-365),APCMED,"APCMVSTS")
 ..S APCMP=0 F  S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP  D
 ...S APCMHV=$$HADV^APCM11CI(APCMPAT,APCMP,$$FMADD^XLFDT(APCMED,-365),APCMED,.APCMVSTS)
 ...Q:'APCMHV
 ...K APCMECHI(APCMP,1)  ;had a visit with this patient and thus had a request, so no exclusion
 Q:'$G(APCMWPP)
 S APCMD=$$FMADD^XLFDT(APCMPBD,-1)
 S APCM4D=$$FMADD^XLFDT(APCMPED,-4)
 F  S APCMD=$O(^BRNREC("B",APCMD)) Q:APCMD'=+APCMD!(APCMD>APCM4D)  D
 .S APCMX=0 F  S APCMX=$O(^BRNREC("B",APCMD,APCMX)) Q:APCMX'=+APCMX  D
 ..Q:$P($G(^BRNREC(APCMX,11)),U,1)'="E"  ;not an electronic request
 ..S APCMPAT=$P($G(^BRNREC(APCMX,0)),U,3)
 ..K APCMVSTS,APCMHVTP
 ..D ALLV^APCLAPIU(APCMPAT,$$FMADD^XLFDT(APCMPED,-365),APCMPED,"APCMVSTS")
 ..S APCMP=0 F  S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP  D
 ...S APCMHV=$$HADV^APCM11CI(APCMPAT,APCMP,$$FMADD^XLFDT(APCMPED,-365),APCMPED,.APCMVSTS)
 ...Q:'APCMHV
 ...K APCMECHI(APCMP,2)  ;had a visit with this patient and thus had a request, so no exclusion
 Q
RCIS ;did provider have any referrals for patients he/she saw
 NEW X
 S X=$O(^APCMMUM("B","S1.023.EP",0))
 I '$D(APCMIND(X)) Q  ;don't bother as this measure isn't in the report
 NEW APCMD,APCMX,APCMPAT,X,APCMP
 K APCMRCIS
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMRCIS(X,1)=""
 S X=0 F  S X=$O(APCMPRV(X)) Q:X'=+X  S APCMRCIS(X,2)=""
 ;LOOP THROUGH ROI AND IF I FIND 1 FOR THE PROVIDER THEN KILL OFF APCMRCIS - exclusion
 S APCMD=$$FMADD^XLFDT(APCMBD,-1)
 F  S APCMD=$O(^BMCREF("B",APCMD)) Q:APCMD'=+APCMD!(APCMD>APCMED)  D
 .S APCMX=0 F  S APCMX=$O(^BMCREF("B",APCMD,APCMX)) Q:APCMX'=+APCMX  D
 ..S APCMPAT=$P($G(^BMCREF(APCMX,0)),U,3)
 ..S R=$P(^BMCREF(APCMX,0),U,6)
 ..Q:R=""
 ..Q:'$D(APCMPRV(R))  ;NOT A PROVIDER WE WANT
 ..S S=$P(^BMCREF(APCMX,0),U,15)
 ..I S'="A",S'="C1" Q  ;not a A or C1
 ..Q:$P(^BMCREF(APCMX,0),U,4)="N"
 ..;K APCMVSTS,APCMHVTP
 ..;D ALLV^APCLAPIU(APCMPAT,APCMBD,APCMED,"APCMVSTS")
 ..;S APCMP=0 F  S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP  D
 ..;.S APCMHV=$$HADV^APCM11CI(APCMPAT,APCMP,APCMBD,APCMED,.APCMVSTS)
 ..;.Q:'APCMHV
 ..K APCMRCIS(R,1)  ;had a visit with this patient and had a referral for this patient so no exclusion
 Q:'$G(APCMWPP)
 S APCMD=$$FMADD^XLFDT(APCMPBD,-1)
 F  S APCMD=$O(^BMCREF("B",APCMD)) Q:APCMD'=+APCMD!(APCMD>APCMPED)  D
 .S APCMX=0 F  S APCMX=$O(^BMCREF("B",APCMD,APCMX)) Q:APCMX'=+APCMX  D
 ..S APCMPAT=$P($G(^BMCREF(APCMX,0)),U,3)
 ..S R=$P(^BMCREF(APCMX,0),U,6)
 ..Q:R=""
 ..Q:'$D(APCMPRV(R))  ;NOT A PROVIDER WE WANT
 ..S S=$P(^BMCREF(APCMX,0),U,15)
 ..I S'="A",S'="C1" Q  ;not a A or C1
 ..Q:$P(^BMCREF(APCMX,0),U,4)="N"
 ..;K APCMVSTS,APCMHVTP
 ..;D ALLV^APCLAPIU(APCMPAT,APCMPBD,APCMPED,"APCMVSTS")
 ..;S APCMP=0 F  S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP  D
 ..;.S APCMHV=$$HADV^APCM11CI(APCMPAT,APCMP,APCMPBD,APCMPED,.APCMVSTS)
 ..;.Q:'APCMHV
 ..K APCMRCIS(R,2)  ;had a visit with this patient and thus had a request, so no exclusion
 Q