APCM14E5 ;IHS/CMI/LAB - IHS MU;
;;1.0;IHS MU PERFORMANCE REPORTS;**5,6**;MAR 26, 2012;Build 65
;
PATEDUC ;EP - CALCULATE PAT ED
;if so, then check to see if they have PAT ED LITERATURE documented anytime from report period begin date to DT
NEW APCMP
S (APCMD1,APCMN1)=0
I APCMRPTT=1 D Q
.S APCMP=0 F S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP D
..Q:'$D(APCMHVTP(APCMP))
..D PATEDUC1
..Q
I APCMRPTT=2 D
.S APCMP=APCMFAC
.Q:'$D(APCMHVTP(APCMP))
.D PATEDUC1
.Q
Q
PATEDUC1 ;
;set denominator value into field
S F=$P(^APCM14OB(APCMIC,0),U,8)
D S^APCM14E1(APCMRPT,APCMIC,1,APCMP,APCMRPTT,APCMTIME,F)
;numerator?
S APCMVALU="VISIT: "_$$DATE^APCM1UTL(APCMHVTP(APCMP))
;S APCMEP=$$HASED(DFN,APCMBDAT,DT)
;S APCMEP=$$HASED(DFN,$$FMADD^XLFDT(APCMBDAT,-365),DT)
;I APCMRPTT=2 S APCMEP=$$HASEDH(DFN,APCMBDAT,APCMEDAT,APCMFAC,.APCMVSTS)
NEW B
I APCMRPTT=1 S B=$E(APCMBDAT,1,3)_"0101"
I APCMRPTT=2 S B=$S(+$E(APCMBDAT,4,5)>9:$E(APCMBDAT,1,3)_"1001",1:$E(APCMBDAT,1,3)-1_"1001")
S APCMEP=$$HASED(DFN,B,APCMEDAT)
S APCMVALU=APCMVALU_"|||"_$P(APCMEP,U,2)_"|||"_$P(APCMEP,U,1)
S F=$P(^APCM14OB(APCMIC,0),U,9)
D S^APCM14E1(APCMRPT,APCMIC,$P(APCMEP,U,1),APCMP,APCMRPTT,APCMTIME,F)
;S APCMVALU=APCMVALU_"|||"_$P(APCMEP,U,2)_"|||"_$P(APCMEP,U,1)
D SETLIST^APCM14E1
Q
HASED(P,BD,ED) ;does patient have Patient Ed -L
;
NEW A,B,C,D,E,PED,Y,EDUC,X,T
S C=0
S PED=""
S Y="EDUC("
S X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED) S E=$$START1^APCLDF(X,Y)
I '$D(EDUC(1)) Q ""
S (X,D)=0,%="",T="" F S X=$O(EDUC(X)) Q:X'=+X!(PED]"") D
.S T=$P(^AUPNVPED(+$P(EDUC(X),U,4),0),U)
.Q:'T
.Q:'$D(^AUTTEDT(T,0))
.S T=$P(^AUTTEDT(T,0),U,2)
.I $P(T,"-",2)="L" S PED=1_U_T_" on "_$$DATE^APCM1UTL($P(EDUC(X),U)) Q
Q PED
;
HASMMR(P,BDD,EDD) ;does patient have a m-mr ON this visit in v updated/reviewed
;
NEW X,Y,Z,B,W,E,D,T
;V UPDATED REVIEWED SNOMED 2 WEEKS BEFORE REPORT PERIOD UP THROUGH TODAY
S Z="",B=""
S W=0 F S W=$O(^AUPNVRUP("AC",P,W)) Q:W'=+W!(Z) D
.S Y=0 F S Y=$O(^AUPNVRUP(W,26,Y)) Q:Y'=+Y!(Z) D
..I $P($G(^AUPNVRUP(W,26,Y,0)),U,1)'=428191000124101 Q
..S E=""
..S D=$P($$GET1^DIQ(9000010.54,W,1201,"I"),".")
..I D<BDD Q
..I D>EDD Q
SNN ..S Z=1
Q Z
PR ;EP - patient reminders
;for each provider or for the facility find out if this
;if patient is <=5 or >=65 count them
;exclude deceased, and inactive charts
;if so, then check to see if they have icare notice ocumented any time before end of report period
NEW APCMP
S (APCMD1,APCMN1)=0
I APCMRPTT=1 S APCMP=0 F S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP D
.I APCMN565(APCMTIME) S F=$P(^APCM14OB(APCMIC,0),U,11) D Q
..D S^APCM14E1(APCMRPT,APCMIC,"Facility is excluded from this measure as the database does not have any patients <=5 or >=65 years old.",APCMP,APCMRPTT,APCMTIME,F,1) Q
.;set denominator value into field
.S G=0
.I APCMAGEB<5 G PR1
.I APCMAGEB<65 Q
.Q:$$DOB^AUPNPAT(DFN)>APCMBDAT
PR1 .;IS CHART ACTIVE OR DECEASED
.S X=$$DOD^AUPNPAT(DFN)
.I X,X'>APCMEDAT Q
.Q:'$O(^AUPNPAT(DFN,41,0)) ;no charts
.S X=$P($G(^AUPNPAT(DFN,41,DUZ(2),0)),U,3)
.I X,X'>APCMEDAT Q
.;did they have a visit ever to the EP?
.;K APCMPRVT
.;D ALLV^APCLAPIU(DFN,$$DOB^AUPNPAT(DFN),APCMEDAT,"APCMPRVT")
.I '$$HADV^APCM13E5(DFN,APCMP,$$DOB^AUPNPAT(DFN),APCMEDAT) Q
.S F=$P(^APCM14OB(APCMIC,0),U,8)
.D S^APCM14E1(APCMRPT,APCMIC,1,APCMP,APCMRPTT,APCMTIME,F)
.S APCMVALU=""
.;numerator?
.S APCMEP=$$HASRM(DFN,APCMBDAT,APCMEDAT,APCMP,.APCMVSTS) ;return # of visits^# w/pwh
.S APCMVALU="Patient age: "_$$AGE^AUPNPAT(DFN,APCMBDAT)_"|||"_"NOTIFICATION: "_$P(APCMEP,U,2)_"|||"_$P(APCMEP,U,1)
.S F=$P(^APCM14OB(APCMIC,0),U,9)
.D S^APCM14E1(APCMRPT,APCMIC,$P(APCMEP,U,1),APCMP,APCMRPTT,APCMTIME,F)
.D SETLIST^APCM14E1
Q
HASRM(P,BD,ED,R,VSTS) ;
;
NEW A,B,C,NOTIF,N
S NOTIF=""
S A=0 F S A=$O(^BQI(90509.4,"B",P,A)) Q:A'=+A!(NOTIF) D
.S N=$G(^BQI(90509.4,A,0))
.I N="" Q ;BAD XREF
.S B=$P($P(N,U,4),".")
.Q:B<BD ;before time period
.Q:B>ED ;after time period
.S C=$P(N,U,2) ;preferred method
.I C="" S NOTIF=1_U_$$GET1^DIQ(90509.4,A,.09)_" "_$$FMTE^XLFDT(B) Q
.I C'=$P(N,U,3) ;preferred doesn't match notificaton type so don't count it
.S NOTIF=1_U_$$GET1^DIQ(90509.4,A,.09)_" "_$$FMTE^XLFDT(B)
Q NOTIF
SC ;EP - TRANSITION OF CARE SUMMARY
;for each provider count each Visit that HAS a v referral
K ^TMP($J,"TRANS")
NEW APCMLABS,MMR
D TOCSUMC
NEW APCMP,N,F
S (APCMD1,APCMN1)=0
I APCMRPTT=1 S APCMP=0 F S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP D
.I '$P($G(MMR(APCMP)),U,1) D
..S F=$P(^APCM14OB(APCMIC,0),U,11) D S^APCM14E1(APCMRPT,APCMIC,"Provider is excluded from this measure as he/she did not have any referrals during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1) Q
.;set denominator value into field
.S F=$P(^APCM14OB(APCMIC,0),U,8) ;denom field for this measure
.S N=$P($G(MMR(APCMP)),U,1) ;returns # of transS^# with mmr
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
.;now set patient list for this provider
.S P=0 F S P=$O(^TMP($J,"TRANS",APCMP,P)) Q:P'=+P D
..I $P(^TMP($J,"TRANS",APCMP,P),U,1)=$P(^TMP($J,"TRANS",APCMP,P),U,2) S APCMVALU="# referrals: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||1" D Q
...S DFN=P D SETLIST^APCM14E1 Q
..S DFN=P,APCMVALU="# referrals: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||0" D SETLIST^APCM14E1
.;numerator?
.S F=$P(^APCM14OB(APCMIC,0),U,9)
.S N=$P($G(MMR(APCMP)),U,2)
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
I APCMRPTT=2 S APCMP=APCMFAC D
.I '$P($G(MMR(APCMP)),U,1) D Q
..S F=$P(^APCM14OB(APCMIC,0),U,11) D S^APCM14E1(APCMRPT,APCMIC,"Facility is excluded from this measure as he/she did not have any referrals during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1) Q
.;set denominator value into field
.S F=$P(^APCM14OB(APCMIC,0),U,8) ;denom field for this measure
.S N=$P($G(MMR(APCMP)),U,1) ;returns # of transS^# with mmr
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
.;now set patient list for this provider
.S P=0 F S P=$O(^TMP($J,"TRANS",APCMP,P)) Q:P'=+P D
..I $P(^TMP($J,"TRANS",APCMP,P),U,1)=$P(^TMP($J,"TRANS",APCMP,P),U,2) S APCMVALU="# referrals: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||1" D Q
...S DFN=P D SETLIST^APCM14E1 Q
..S DFN=P,APCMVALU="# referrals: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||0" D SETLIST^APCM14E1
.;numerator?
.S F=$P(^APCM14OB(APCMIC,0),U,9)
.S N=$P($G(MMR(APCMP)),U,2)
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
K ^TMP($J,"TRANS")
Q
TOCSUMC ;EP - ep toc
;SET ARRAY MMR to MMR(prov ien)=denom^numer
;DENOM=# VISITS W/REFERRAL
;NUMER=# W/TOC DOCUMENT IN 600 MULTIPLE
;IF DENOM =0 THEN PROVIDER EXCLUSION
NEW T,C,PAT,N,APCMX,R,C,G,Z,S,B,E,J,K
S C=0,N=0,PAT=""
S T=$O(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
;GO THROUGH EACH PATIENT WHO HAS VISITS
S PAT=0 F S PAT=$O(^AUPNVSIT("AA",PAT)) Q:PAT'=+PAT D TOCSUMC1
Q
TOCSUMC1 ;
NEW APCMLAB
S APCMLAB="APCMLAB"
D ALLV^APCLAPIU(PAT,APCMBDAT,APCMEDAT,APCMLAB) ;get all visits for this patient in time period
S APCMX=0 F S APCMX=$O(APCMLAB(APCMX)) Q:APCMX'=+APCMX D
.S V=$P(APCMLAB(APCMX),U,5) ;VISIT IEN
.Q:'$D(^AUPNVSIT(V,0)) ;NO VISIT??
.I APCMRPTT=2,APCMMETH="E" Q:'$$HOSER^APCM24E6(V,APCMFAC) S R=APCMFAC G TOCS2
.I APCMRPTT=2,APCMMETH="O" Q:"OH"'[$P(^AUPNVSIT(V,0),U,7) Q:$P(^AUPNVSIT(V,0),U,6)'=APCMFAC S R=APCMFAC G TOCS2
.S R=$$PRIMPROV^APCLV(V,"I") ;primary provider IEN
.Q:'R
.I '$D(APCMPRV(R)) Q ;not a provider of interest for this report
.Q:"AOSM"'[$P(^AUPNVSIT(V,0),U,7)
.S C=$$CLINIC^APCLV(V,"C")
.Q:C=30
.Q:C=77
.Q:C=76
.Q:C=63
.Q:C=39
TOCS2 .;IS THERE A V REFERAL THAT MEETS DENOM DEFINITION
.S Z=0 F S Z=$O(^AUPNVREF("AD",V,Z)) Q:Z'=+Z D
..Q:'$D(^AUPNVREF(Z,0)) ;??
..S S=$P(^AUPNVREF(Z,0),U,6) ;REFERRAL IEN
..Q:'S ;no referral??
..Q:'$D(^BMCREF(S,0)) ;bad pointer
..Q:$P(^BMCREF(S,0),U,4)="N" ;NO INHOUSE
..Q:$P($G(^BMCREF(S,11)),U,5)="" ;MUST HAVE AN EXPECTED BEGIN DOS
..S D=$P($G(^BMCREF(S,13)),U,5) ;approval date
..Q:D="" ;NO APPROVAL DATE
..Q:D>APCMEDAT ;AFTER TP
..Q:D<APCMBDAT ;BEFORE TP
SUMNUM ..;
..I '$D(MMR(R)) S MMR(R)=""
..S $P(MMR(R),U,1)=$P(MMR(R),U,1)+1 D
...S $P(^TMP($J,"TRANS",R,PAT),U,1)=$P($G(^TMP($J,"TRANS",R,PAT)),U,1)+1
...S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_" "_$$VD^APCLV(V,"S")_"-"_$P(^BMCREF(S,0),U,2)
..;now check numerator, FIELD 600
..S G=0,T=0
..S B=0 F S B=$O(^BMCREF(S,6,B)) Q:B'=+B!(G) D
...S (A,E)=""
...I $P(^BMCREF(S,6,B,0),U,4)'="CT" G SUMNUM1
...S E=$P($P(^BMCREF(S,6,B,0),U,6),".")
...I E="" G SUMNUM1 ;NO DATE TRANSMITTED
...I E<D G SUMNUM1 ;BEFORE APPROVAL DATE
...I E>APCMEDAT G SUMNUM1 ;AFTER TIME PERIOD
...S A=$P($P(^BMCREF(S,6,B,0),U,3),".") ;tx date
...I A,A'<D,A'>APCMEDAT S A=1
...S G=1,T="CT" Q ;got a transmitted go set numerator
SUMNUM1 ...;
...I $P(^BMCREF(S,6,B,0),U,4)'="CP" Q
...S E=$P($P(^BMCREF(S,6,B,0),U,1),".") ;DATE/TIME PRINTED
...I E="" Q ;NO DATE SENT/PRINTED
...I E<D Q ;BEFORE APPROVAL DATE
...I E>APCMEDAT Q ;AFTER TIME PERIOD
...S G=1,T="CP"
..I G D SN Q
..;
SUMAPCC ..;CHECK APCC DOCUMENT FILE
..S J=0 F S J=$O(^APCCDPL(V,1,J)) Q:J'=+J!(G) D
...Q:$P($G(^APCCDPL(V,1,J,0)),U,4)'=2 ;TOC ONLY
...Q:$P($P(^APCCDPL(V,1,J,0),U,1),".")'=$$VD^APCLV(V) ;DATE MUST EQUAL VISIT DATE
...S G=1
...S $P(MMR(R),U,2)=$P(MMR(R),U,2)+1 D
....S $P(^TMP($J,"TRANS",R,PAT),U,2)=$P($G(^TMP($J,"TRANS",R,PAT)),U,2)+1
....S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_";YES APCC TOCS"
..I 'G S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_";NO TOCS" Q
Q
SN ;
S $P(MMR(R),U,2)=$P(MMR(R),U,2)+1 D Q
.S $P(^TMP($J,"TRANS",R,PAT),U,2)=$P($G(^TMP($J,"TRANS",R,PAT)),U,2)+1
.S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_";YES "_T I T="CT" S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_$S(A:" TX",1:"")
.I T="CT" S $P(MMR(R),U,4)=$P(MMR(R),U,4)+1 I A S $P(MMR(R),U,5)=$P(MMR(R),U,5)+1
Q
MEDREC ;EP
;for each provider count each Visit that is a new patient visit and of those # with snomed in v updated/reviewed
K ^TMP($J,"TRANS")
NEW APCMLABS,MMR
D TOTMEDR
NEW APCMP,N,F
S (APCMD1,APCMN1)=0
I APCMRPTT=1 S APCMP=0 F S APCMP=$O(APCMPRV(APCMP)) Q:APCMP'=+APCMP D
.I '$P($G(MMR(APCMP)),U,1) D
..S F=$P(^APCM14OB(APCMIC,0),U,11) D S^APCM14E1(APCMRPT,APCMIC,"Provider is excluded from this measure as he/she did not have any transitions during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1) Q
.;set denominator value into field
.S F=$P(^APCM14OB(APCMIC,0),U,8) ;denom field for this measure
.S N=$P($G(MMR(APCMP)),U,1) ;returns # of transS^# with mmr
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
.;now set patient list for this provider
.S P=0 F S P=$O(^TMP($J,"TRANS",APCMP,P)) Q:P'=+P D
..I $P(^TMP($J,"TRANS",APCMP,P),U,1)=$P(^TMP($J,"TRANS",APCMP,P),U,2) S APCMVALU="# transitions: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/mmr: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||1" D Q
...S DFN=P D SETLIST^APCM14E1 Q
..S DFN=P,APCMVALU="# transitions: "_$P(^TMP($J,"TRANS",APCMP,P),U,1)_"|||"_" # w/mmr: "_+$P(^TMP($J,"TRANS",APCMP,P),U,2)_" "_$P(^TMP($J,"TRANS",APCMP,P),U,3)_"|||0" D SETLIST^APCM14E1
.;numerator?
.S F=$P(^APCM14OB(APCMIC,0),U,9)
.S N=$P($G(MMR(APCMP)),U,2)
.D S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
K ^TMP($J,"TRANS")
Q
TOTMEDR ;EP - ep MR
;SET ARRAY MMR to MMR(prov ien)=denom^numer
;IF DENOM =0 THEN PROVIDER EXCLUSION
NEW T,C,PAT,N,APCMX,R,C,G
S C=0,N=0,PAT=""
S T=$O(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
;GO THROUGH EACH PATIENT WHO HAS VISITS
S PAT=0 F S PAT=$O(^AUPNVSIT("AA",PAT)) Q:PAT'=+PAT D TOTMEDR1
Q
TOTMEDR1 ;
NEW APCMLAB
S APCMLAB="APCMLAB"
D ALLV^APCLAPIU(PAT,APCMBDAT,APCMEDAT,APCMLAB) ;get all visits for this patient in time period
S APCMX=0 F S APCMX=$O(APCMLAB(APCMX)) Q:APCMX'=+APCMX D
.S V=$P(APCMLAB(APCMX),U,5) ;VISIT IEN
.Q:'$D(^AUPNVSIT(V,0)) ;NO VISIT??
.S R=$$PRIMPROV^APCLV(V,"I") ;primary provider IEN
.Q:'R
.I '$D(APCMPRV(R)) Q
.Q:"AOSM"'[$P(^AUPNVSIT(V,0),U,7)
.S C=$$CLINIC^APCLV(V,"C")
.Q:C=30
.I C]"",T,$D(^APCMMUCN(T,14,"B",C)) Q ;don't count these clinics
.;IS THERE A V CPT OR IMAGE
.;S G=$$CPT(V)
.;I G G NUM
.;S G=$$IMAGE(V,R)
.;I 'G Q
NUM .;
.I '$D(MMR(R)) S MMR(R)=""
.S $P(MMR(R),U,1)=$P(MMR(R),U,1)+1 D
..S $P(^TMP($J,"TRANS",R,PAT),U,1)=$P($G(^TMP($J,"TRANS",R,PAT)),U,1)+1
..S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_" "_$$VD^APCLV(V,"S")
.;now check numerator
.S G=$$HASMMR(PAT,APCMBDAT,APCMEDAT)
.I 'G S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_";NO MMR" Q
.S $P(MMR(R),U,2)=$P(MMR(R),U,2)+1 D
..S $P(^TMP($J,"TRANS",R,PAT),U,2)=$P($G(^TMP($J,"TRANS",R,PAT)),U,2)+1
..S $P(^TMP($J,"TRANS",R,PAT),U,3)=$P(^TMP($J,"TRANS",R,PAT),U,3)_";YES MMR"
Q
;
CPT(V) ;was there a 99201-99205 or 99381-99387 on this visit
NEW X,C,A
S A=""
S X=0 F S X=$O(^AUPNVCPT("AD",V,X)) Q:X'=+X!(A) D
.S C=$$GET1^DIQ(9000010.18,X,.01)
.I C>99200,C<99206 S A=1 Q
.I C>99380,C<99388 S A=1 Q
Q A
IMAGE(V,R) ;WAS THERE AN IMAGE BEFORE VISIT DATE AND IF SO WAS THIS THE FIRST VISIT AFTER THE IMAGE DATE
NEW D,A,B,C,P,X,Y,T,G,Z,VST
S P=$P(^AUPNVSIT(V,0),U,5)
I '$D(^MAG(2005,"AC",P)) Q 0
S G=""
S D=$$VDTM^APCLV(V) ;fileman visit date/time
S B=0 F S B=$O(^MAG(2005,"AC",P,B)) Q:B'=+B!(G) D
.Q:$$UP^XLFSTR($$GET1^DIQ(2005,B,42))'="CCD-SUMMARY"
.S C=$$GET1^DIQ(2005,B,7,"I")
.Q:C>D ;image save after visit date/time
.;is this the first visit after the image date/time to the EP?
.S X=C
.S T=$O(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
.K VST
.D ALLV^APCLAPIU(P,$P(C,"."),$$FMADD^XLFDT($P(D,"."),1),"VST")
.;now reorder by visit/date time
.S X=0 F S X=$O(VST(X)) Q:X'=+X S VST("DTM",$$VDTM^APCLV($P(VST(X),U,5)),X)=$P(VST(X),U,5)
.S Y=0 F S Y=$O(VST("DTM",Y)) Q:Y'=+Y!(G) D
..S B=0 F S B=$O(VST("DTM",Y,B)) Q:B'=+B!(G) D
...S Z=VST("DTM",Y,B)
...Q:'$D(^AUPNVSIT(Z,0))
...Q:$$PRIMPROV^APCLV(Z,"I")'=R
...Q:"AOSM"'[$P(^AUPNVSIT(Z,0),U,7)
...S C=$$CLINIC^APCLV(Z,"C")
...Q:C=30
...I C]"",T,$D(^APCMMUCN(T,14,"B",C)) Q ;don't count these clinics
...Q:Z'=V
...S G=1
Q G
APCM14E5 ;IHS/CMI/LAB - IHS MU;
+1 ;;1.0;IHS MU PERFORMANCE REPORTS;**5,6**;MAR 26, 2012;Build 65
+2 ;
PATEDUC ;EP - CALCULATE PAT ED
+1 ;if so, then check to see if they have PAT ED LITERATURE documented anytime from report period begin date to DT
+2 NEW APCMP
+3 SET (APCMD1,APCMN1)=0
+4 IF APCMRPTT=1
Begin DoDot:1
+5 SET APCMP=0
FOR
SET APCMP=$ORDER(APCMPRV(APCMP))
IF APCMP'=+APCMP
QUIT
Begin DoDot:2
+6 IF '$DATA(APCMHVTP(APCMP))
QUIT
+7 DO PATEDUC1
+8 QUIT
End DoDot:2
End DoDot:1
QUIT
+9 IF APCMRPTT=2
Begin DoDot:1
+10 SET APCMP=APCMFAC
+11 IF '$DATA(APCMHVTP(APCMP))
QUIT
+12 DO PATEDUC1
+13 QUIT
End DoDot:1
+14 QUIT
PATEDUC1 ;
+1 ;set denominator value into field
+2 SET F=$PIECE(^APCM14OB(APCMIC,0),U,8)
+3 DO S^APCM14E1(APCMRPT,APCMIC,1,APCMP,APCMRPTT,APCMTIME,F)
+4 ;numerator?
+5 SET APCMVALU="VISIT: "_$$DATE^APCM1UTL(APCMHVTP(APCMP))
+6 ;S APCMEP=$$HASED(DFN,APCMBDAT,DT)
+7 ;S APCMEP=$$HASED(DFN,$$FMADD^XLFDT(APCMBDAT,-365),DT)
+8 ;I APCMRPTT=2 S APCMEP=$$HASEDH(DFN,APCMBDAT,APCMEDAT,APCMFAC,.APCMVSTS)
+9 NEW B
+10 IF APCMRPTT=1
SET B=$EXTRACT(APCMBDAT,1,3)_"0101"
+11 IF APCMRPTT=2
SET B=$SELECT(+$EXTRACT(APCMBDAT,4,5)>9:$EXTRACT(APCMBDAT,1,3)_"1001",1:$EXTRACT(APCMBDAT,1,3)-1_"1001")
+12 SET APCMEP=$$HASED(DFN,B,APCMEDAT)
+13 SET APCMVALU=APCMVALU_"|||"_$PIECE(APCMEP,U,2)_"|||"_$PIECE(APCMEP,U,1)
+14 SET F=$PIECE(^APCM14OB(APCMIC,0),U,9)
+15 DO S^APCM14E1(APCMRPT,APCMIC,$PIECE(APCMEP,U,1),APCMP,APCMRPTT,APCMTIME,F)
+16 ;S APCMVALU=APCMVALU_"|||"_$P(APCMEP,U,2)_"|||"_$P(APCMEP,U,1)
+17 DO SETLIST^APCM14E1
+18 QUIT
HASED(P,BD,ED) ;does patient have Patient Ed -L
+1 ;
+2 NEW A,B,C,D,E,PED,Y,EDUC,X,T
+3 SET C=0
+4 SET PED=""
+5 SET Y="EDUC("
+6 SET X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED)
SET E=$$START1^APCLDF(X,Y)
+7 IF '$DATA(EDUC(1))
QUIT ""
+8 SET (X,D)=0
SET %=""
SET T=""
FOR
SET X=$ORDER(EDUC(X))
IF X'=+X!(PED]"")
QUIT
Begin DoDot:1
+9 SET T=$PIECE(^AUPNVPED(+$PIECE(EDUC(X),U,4),0),U)
+10 IF 'T
QUIT
+11 IF '$DATA(^AUTTEDT(T,0))
QUIT
+12 SET T=$PIECE(^AUTTEDT(T,0),U,2)
+13 IF $PIECE(T,"-",2)="L"
SET PED=1_U_T_" on "_$$DATE^APCM1UTL($PIECE(EDUC(X),U))
QUIT
End DoDot:1
+14 QUIT PED
+15 ;
HASMMR(P,BDD,EDD) ;does patient have a m-mr ON this visit in v updated/reviewed
+1 ;
+2 NEW X,Y,Z,B,W,E,D,T
+3 ;V UPDATED REVIEWED SNOMED 2 WEEKS BEFORE REPORT PERIOD UP THROUGH TODAY
+4 SET Z=""
SET B=""
+5 SET W=0
FOR
SET W=$ORDER(^AUPNVRUP("AC",P,W))
IF W'=+W!(Z)
QUIT
Begin DoDot:1
+6 SET Y=0
FOR
SET Y=$ORDER(^AUPNVRUP(W,26,Y))
IF Y'=+Y!(Z)
QUIT
Begin DoDot:2
+7 IF $PIECE($GET(^AUPNVRUP(W,26,Y,0)),U,1)'=428191000124101
QUIT
+8 SET E=""
+9 SET D=$PIECE($$GET1^DIQ(9000010.54,W,1201,"I"),".")
+10 IF D<BDD
QUIT
+11 IF D>EDD
QUIT
SNN SET Z=1
End DoDot:2
End DoDot:1
+1 QUIT Z
PR ;EP - patient reminders
+1 ;for each provider or for the facility find out if this
+2 ;if patient is <=5 or >=65 count them
+3 ;exclude deceased, and inactive charts
+4 ;if so, then check to see if they have icare notice ocumented any time before end of report period
+5 NEW APCMP
+6 SET (APCMD1,APCMN1)=0
+7 IF APCMRPTT=1
SET APCMP=0
FOR
SET APCMP=$ORDER(APCMPRV(APCMP))
IF APCMP'=+APCMP
QUIT
Begin DoDot:1
+8 IF APCMN565(APCMTIME)
SET F=$PIECE(^APCM14OB(APCMIC,0),U,11)
Begin DoDot:2
+9 DO S^APCM14E1(APCMRPT,APCMIC,"Facility is excluded from this measure as the database does not have any patients <=5 or >=65 years old.",APCMP,APCMRPTT,APCMTIME,F,1)
QUIT
End DoDot:2
QUIT
+10 ;set denominator value into field
+11 SET G=0
+12 IF APCMAGEB<5
GOTO PR1
+13 IF APCMAGEB<65
QUIT
+14 IF $$DOB^AUPNPAT(DFN)>APCMBDAT
QUIT
PR1 ;IS CHART ACTIVE OR DECEASED
+1 SET X=$$DOD^AUPNPAT(DFN)
+2 IF X
IF X'>APCMEDAT
QUIT
+3 ;no charts
IF '$ORDER(^AUPNPAT(DFN,41,0))
QUIT
+4 SET X=$PIECE($GET(^AUPNPAT(DFN,41,DUZ(2),0)),U,3)
+5 IF X
IF X'>APCMEDAT
QUIT
+6 ;did they have a visit ever to the EP?
+7 ;K APCMPRVT
+8 ;D ALLV^APCLAPIU(DFN,$$DOB^AUPNPAT(DFN),APCMEDAT,"APCMPRVT")
+9 IF '$$HADV^APCM13E5(DFN,APCMP,$$DOB^AUPNPAT(DFN),APCMEDAT)
QUIT
+10 SET F=$PIECE(^APCM14OB(APCMIC,0),U,8)
+11 DO S^APCM14E1(APCMRPT,APCMIC,1,APCMP,APCMRPTT,APCMTIME,F)
+12 SET APCMVALU=""
+13 ;numerator?
+14 ;return # of visits^# w/pwh
SET APCMEP=$$HASRM(DFN,APCMBDAT,APCMEDAT,APCMP,.APCMVSTS)
+15 SET APCMVALU="Patient age: "_$$AGE^AUPNPAT(DFN,APCMBDAT)_"|||"_"NOTIFICATION: "_$PIECE(APCMEP,U,2)_"|||"_$PIECE(APCMEP,U,1)
+16 SET F=$PIECE(^APCM14OB(APCMIC,0),U,9)
+17 DO S^APCM14E1(APCMRPT,APCMIC,$PIECE(APCMEP,U,1),APCMP,APCMRPTT,APCMTIME,F)
+18 DO SETLIST^APCM14E1
End DoDot:1
+19 QUIT
HASRM(P,BD,ED,R,VSTS) ;
+1 ;
+2 NEW A,B,C,NOTIF,N
+3 SET NOTIF=""
+4 SET A=0
FOR
SET A=$ORDER(^BQI(90509.4,"B",P,A))
IF A'=+A!(NOTIF)
QUIT
Begin DoDot:1
+5 SET N=$GET(^BQI(90509.4,A,0))
+6 ;BAD XREF
IF N=""
QUIT
+7 SET B=$PIECE($PIECE(N,U,4),".")
+8 ;before time period
IF B<BD
QUIT
+9 ;after time period
IF B>ED
QUIT
+10 ;preferred method
SET C=$PIECE(N,U,2)
+11 IF C=""
SET NOTIF=1_U_$$GET1^DIQ(90509.4,A,.09)_" "_$$FMTE^XLFDT(B)
QUIT
+12 ;preferred doesn't match notificaton type so don't count it
IF C'=$PIECE(N,U,3)
+13 SET NOTIF=1_U_$$GET1^DIQ(90509.4,A,.09)_" "_$$FMTE^XLFDT(B)
End DoDot:1
+14 QUIT NOTIF
SC ;EP - TRANSITION OF CARE SUMMARY
+1 ;for each provider count each Visit that HAS a v referral
+2 KILL ^TMP($JOB,"TRANS")
+3 NEW APCMLABS,MMR
+4 DO TOCSUMC
+5 NEW APCMP,N,F
+6 SET (APCMD1,APCMN1)=0
+7 IF APCMRPTT=1
SET APCMP=0
FOR
SET APCMP=$ORDER(APCMPRV(APCMP))
IF APCMP'=+APCMP
QUIT
Begin DoDot:1
+8 IF '$PIECE($GET(MMR(APCMP)),U,1)
Begin DoDot:2
+9 SET F=$PIECE(^APCM14OB(APCMIC,0),U,11)
DO S^APCM14E1(APCMRPT,APCMIC,"Provider is excluded from this measure as he/she did not have any referrals during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1)
QUIT
End DoDot:2
+10 ;set denominator value into field
+11 ;denom field for this measure
SET F=$PIECE(^APCM14OB(APCMIC,0),U,8)
+12 ;returns # of transS^# with mmr
SET N=$PIECE($GET(MMR(APCMP)),U,1)
+13 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
+14 ;now set patient list for this provider
+15 SET P=0
FOR
SET P=$ORDER(^TMP($JOB,"TRANS",APCMP,P))
IF P'=+P
QUIT
Begin DoDot:2
+16 IF $PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)=$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)
SET APCMVALU="# referrals: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||1"
Begin DoDot:3
+17 SET DFN=P
DO SETLIST^APCM14E1
QUIT
End DoDot:3
QUIT
+18 SET DFN=P
SET APCMVALU="# referrals: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||0"
DO SETLIST^APCM14E1
End DoDot:2
+19 ;numerator?
+20 SET F=$PIECE(^APCM14OB(APCMIC,0),U,9)
+21 SET N=$PIECE($GET(MMR(APCMP)),U,2)
+22 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
End DoDot:1
+23 IF APCMRPTT=2
SET APCMP=APCMFAC
Begin DoDot:1
+24 IF '$PIECE($GET(MMR(APCMP)),U,1)
Begin DoDot:2
+25 SET F=$PIECE(^APCM14OB(APCMIC,0),U,11)
DO S^APCM14E1(APCMRPT,APCMIC,"Facility is excluded from this measure as he/she did not have any referrals during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1)
QUIT
End DoDot:2
QUIT
+26 ;set denominator value into field
+27 ;denom field for this measure
SET F=$PIECE(^APCM14OB(APCMIC,0),U,8)
+28 ;returns # of transS^# with mmr
SET N=$PIECE($GET(MMR(APCMP)),U,1)
+29 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
+30 ;now set patient list for this provider
+31 SET P=0
FOR
SET P=$ORDER(^TMP($JOB,"TRANS",APCMP,P))
IF P'=+P
QUIT
Begin DoDot:2
+32 IF $PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)=$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)
SET APCMVALU="# referrals: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||1"
Begin DoDot:3
+33 SET DFN=P
DO SETLIST^APCM14E1
QUIT
End DoDot:3
QUIT
+34 SET DFN=P
SET APCMVALU="# referrals: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/TOCS: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||0"
DO SETLIST^APCM14E1
End DoDot:2
+35 ;numerator?
+36 SET F=$PIECE(^APCM14OB(APCMIC,0),U,9)
+37 SET N=$PIECE($GET(MMR(APCMP)),U,2)
+38 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
End DoDot:1
+39 KILL ^TMP($JOB,"TRANS")
+40 QUIT
TOCSUMC ;EP - ep toc
+1 ;SET ARRAY MMR to MMR(prov ien)=denom^numer
+2 ;DENOM=# VISITS W/REFERRAL
+3 ;NUMER=# W/TOC DOCUMENT IN 600 MULTIPLE
+4 ;IF DENOM =0 THEN PROVIDER EXCLUSION
+5 NEW T,C,PAT,N,APCMX,R,C,G,Z,S,B,E,J,K
+6 SET C=0
SET N=0
SET PAT=""
+7 SET T=$ORDER(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
+8 ;GO THROUGH EACH PATIENT WHO HAS VISITS
+9 SET PAT=0
FOR
SET PAT=$ORDER(^AUPNVSIT("AA",PAT))
IF PAT'=+PAT
QUIT
DO TOCSUMC1
+10 QUIT
TOCSUMC1 ;
+1 NEW APCMLAB
+2 SET APCMLAB="APCMLAB"
+3 ;get all visits for this patient in time period
DO ALLV^APCLAPIU(PAT,APCMBDAT,APCMEDAT,APCMLAB)
+4 SET APCMX=0
FOR
SET APCMX=$ORDER(APCMLAB(APCMX))
IF APCMX'=+APCMX
QUIT
Begin DoDot:1
+5 ;VISIT IEN
SET V=$PIECE(APCMLAB(APCMX),U,5)
+6 ;NO VISIT??
IF '$DATA(^AUPNVSIT(V,0))
QUIT
+7 IF APCMRPTT=2
IF APCMMETH="E"
IF '$$HOSER^APCM24E6(V,APCMFAC)
QUIT
SET R=APCMFAC
GOTO TOCS2
+8 IF APCMRPTT=2
IF APCMMETH="O"
IF "OH"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
IF $PIECE(^AUPNVSIT(V,0),U,6)'=APCMFAC
QUIT
SET R=APCMFAC
GOTO TOCS2
+9 ;primary provider IEN
SET R=$$PRIMPROV^APCLV(V,"I")
+10 IF 'R
QUIT
+11 ;not a provider of interest for this report
IF '$DATA(APCMPRV(R))
QUIT
+12 IF "AOSM"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+13 SET C=$$CLINIC^APCLV(V,"C")
+14 IF C=30
QUIT
+15 IF C=77
QUIT
+16 IF C=76
QUIT
+17 IF C=63
QUIT
+18 IF C=39
QUIT
TOCS2 ;IS THERE A V REFERAL THAT MEETS DENOM DEFINITION
+1 SET Z=0
FOR
SET Z=$ORDER(^AUPNVREF("AD",V,Z))
IF Z'=+Z
QUIT
Begin DoDot:2
+2 ;??
IF '$DATA(^AUPNVREF(Z,0))
QUIT
+3 ;REFERRAL IEN
SET S=$PIECE(^AUPNVREF(Z,0),U,6)
+4 ;no referral??
IF 'S
QUIT
+5 ;bad pointer
IF '$DATA(^BMCREF(S,0))
QUIT
+6 ;NO INHOUSE
IF $PIECE(^BMCREF(S,0),U,4)="N"
QUIT
+7 ;MUST HAVE AN EXPECTED BEGIN DOS
IF $PIECE($GET(^BMCREF(S,11)),U,5)=""
QUIT
+8 ;approval date
SET D=$PIECE($GET(^BMCREF(S,13)),U,5)
+9 ;NO APPROVAL DATE
IF D=""
QUIT
+10 ;AFTER TP
IF D>APCMEDAT
QUIT
+11 ;BEFORE TP
IF D<APCMBDAT
QUIT
SUMNUM ;
+1 IF '$DATA(MMR(R))
SET MMR(R)=""
+2 SET $PIECE(MMR(R),U,1)=$PIECE(MMR(R),U,1)+1
Begin DoDot:3
+3 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,1)=$PIECE($GET(^TMP($JOB,"TRANS",R,PAT)),U,1)+1
+4 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_" "_$$VD^APCLV(V,"S")_"-"_$PIECE(^BMCREF(S,0),U,2)
End DoDot:3
+5 ;now check numerator, FIELD 600
+6 SET G=0
SET T=0
+7 SET B=0
FOR
SET B=$ORDER(^BMCREF(S,6,B))
IF B'=+B!(G)
QUIT
Begin DoDot:3
+8 SET (A,E)=""
+9 IF $PIECE(^BMCREF(S,6,B,0),U,4)'="CT"
GOTO SUMNUM1
+10 SET E=$PIECE($PIECE(^BMCREF(S,6,B,0),U,6),".")
+11 ;NO DATE TRANSMITTED
IF E=""
GOTO SUMNUM1
+12 ;BEFORE APPROVAL DATE
IF E<D
GOTO SUMNUM1
+13 ;AFTER TIME PERIOD
IF E>APCMEDAT
GOTO SUMNUM1
+14 ;tx date
SET A=$PIECE($PIECE(^BMCREF(S,6,B,0),U,3),".")
+15 IF A
IF A'<D
IF A'>APCMEDAT
SET A=1
+16 ;got a transmitted go set numerator
SET G=1
SET T="CT"
QUIT
SUMNUM1 ;
+1 IF $PIECE(^BMCREF(S,6,B,0),U,4)'="CP"
QUIT
+2 ;DATE/TIME PRINTED
SET E=$PIECE($PIECE(^BMCREF(S,6,B,0),U,1),".")
+3 ;NO DATE SENT/PRINTED
IF E=""
QUIT
+4 ;BEFORE APPROVAL DATE
IF E<D
QUIT
+5 ;AFTER TIME PERIOD
IF E>APCMEDAT
QUIT
+6 SET G=1
SET T="CP"
End DoDot:3
+7 IF G
DO SN
QUIT
+8 ;
SUMAPCC ;CHECK APCC DOCUMENT FILE
+1 SET J=0
FOR
SET J=$ORDER(^APCCDPL(V,1,J))
IF J'=+J!(G)
QUIT
Begin DoDot:3
+2 ;TOC ONLY
IF $PIECE($GET(^APCCDPL(V,1,J,0)),U,4)'=2
QUIT
+3 ;DATE MUST EQUAL VISIT DATE
IF $PIECE($PIECE(^APCCDPL(V,1,J,0),U,1),".")'=$$VD^APCLV(V)
QUIT
+4 SET G=1
+5 SET $PIECE(MMR(R),U,2)=$PIECE(MMR(R),U,2)+1
Begin DoDot:4
+6 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,2)=$PIECE($GET(^TMP($JOB,"TRANS",R,PAT)),U,2)+1
+7 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_";YES APCC TOCS"
End DoDot:4
End DoDot:3
+8 IF 'G
SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_";NO TOCS"
QUIT
End DoDot:2
End DoDot:1
+9 QUIT
SN ;
+1 SET $PIECE(MMR(R),U,2)=$PIECE(MMR(R),U,2)+1
Begin DoDot:1
+2 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,2)=$PIECE($GET(^TMP($JOB,"TRANS",R,PAT)),U,2)+1
+3 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_";YES "_T
IF T="CT"
SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_$SELECT(A:" TX",1:"")
+4 IF T="CT"
SET $PIECE(MMR(R),U,4)=$PIECE(MMR(R),U,4)+1
IF A
SET $PIECE(MMR(R),U,5)=$PIECE(MMR(R),U,5)+1
End DoDot:1
QUIT
+5 QUIT
MEDREC ;EP
+1 ;for each provider count each Visit that is a new patient visit and of those # with snomed in v updated/reviewed
+2 KILL ^TMP($JOB,"TRANS")
+3 NEW APCMLABS,MMR
+4 DO TOTMEDR
+5 NEW APCMP,N,F
+6 SET (APCMD1,APCMN1)=0
+7 IF APCMRPTT=1
SET APCMP=0
FOR
SET APCMP=$ORDER(APCMPRV(APCMP))
IF APCMP'=+APCMP
QUIT
Begin DoDot:1
+8 IF '$PIECE($GET(MMR(APCMP)),U,1)
Begin DoDot:2
+9 SET F=$PIECE(^APCM14OB(APCMIC,0),U,11)
DO S^APCM14E1(APCMRPT,APCMIC,"Provider is excluded from this measure as he/she did not have any transitions during the EHR reporting period.",APCMP,APCMRPTT,APCMTIME,F,1)
QUIT
End DoDot:2
+10 ;set denominator value into field
+11 ;denom field for this measure
SET F=$PIECE(^APCM14OB(APCMIC,0),U,8)
+12 ;returns # of transS^# with mmr
SET N=$PIECE($GET(MMR(APCMP)),U,1)
+13 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
+14 ;now set patient list for this provider
+15 SET P=0
FOR
SET P=$ORDER(^TMP($JOB,"TRANS",APCMP,P))
IF P'=+P
QUIT
Begin DoDot:2
+16 IF $PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)=$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)
SET APCMVALU="# transitions: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/mmr: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||1"
Begin DoDot:3
+17 SET DFN=P
DO SETLIST^APCM14E1
QUIT
End DoDot:3
QUIT
+18 SET DFN=P
SET APCMVALU="# transitions: "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,1)_"|||"_" # w/mmr: "_+$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,2)_" "_$PIECE(^TMP($JOB,"TRANS",APCMP,P),U,3)_"|||0"
DO SETLIST^APCM14E1
End DoDot:2
+19 ;numerator?
+20 SET F=$PIECE(^APCM14OB(APCMIC,0),U,9)
+21 SET N=$PIECE($GET(MMR(APCMP)),U,2)
+22 DO S^APCM14E1(APCMRPT,APCMIC,N,APCMP,APCMRPTT,APCMTIME,F)
End DoDot:1
+23 KILL ^TMP($JOB,"TRANS")
+24 QUIT
TOTMEDR ;EP - ep MR
+1 ;SET ARRAY MMR to MMR(prov ien)=denom^numer
+2 ;IF DENOM =0 THEN PROVIDER EXCLUSION
+3 NEW T,C,PAT,N,APCMX,R,C,G
+4 SET C=0
SET N=0
SET PAT=""
+5 SET T=$ORDER(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
+6 ;GO THROUGH EACH PATIENT WHO HAS VISITS
+7 SET PAT=0
FOR
SET PAT=$ORDER(^AUPNVSIT("AA",PAT))
IF PAT'=+PAT
QUIT
DO TOTMEDR1
+8 QUIT
TOTMEDR1 ;
+1 NEW APCMLAB
+2 SET APCMLAB="APCMLAB"
+3 ;get all visits for this patient in time period
DO ALLV^APCLAPIU(PAT,APCMBDAT,APCMEDAT,APCMLAB)
+4 SET APCMX=0
FOR
SET APCMX=$ORDER(APCMLAB(APCMX))
IF APCMX'=+APCMX
QUIT
Begin DoDot:1
+5 ;VISIT IEN
SET V=$PIECE(APCMLAB(APCMX),U,5)
+6 ;NO VISIT??
IF '$DATA(^AUPNVSIT(V,0))
QUIT
+7 ;primary provider IEN
SET R=$$PRIMPROV^APCLV(V,"I")
+8 IF 'R
QUIT
+9 IF '$DATA(APCMPRV(R))
QUIT
+10 IF "AOSM"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+11 SET C=$$CLINIC^APCLV(V,"C")
+12 IF C=30
QUIT
+13 ;don't count these clinics
IF C]""
IF T
IF $DATA(^APCMMUCN(T,14,"B",C))
QUIT
+14 ;IS THERE A V CPT OR IMAGE
+15 ;S G=$$CPT(V)
+16 ;I G G NUM
+17 ;S G=$$IMAGE(V,R)
+18 ;I 'G Q
NUM ;
+1 IF '$DATA(MMR(R))
SET MMR(R)=""
+2 SET $PIECE(MMR(R),U,1)=$PIECE(MMR(R),U,1)+1
Begin DoDot:2
+3 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,1)=$PIECE($GET(^TMP($JOB,"TRANS",R,PAT)),U,1)+1
+4 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_" "_$$VD^APCLV(V,"S")
End DoDot:2
+5 ;now check numerator
+6 SET G=$$HASMMR(PAT,APCMBDAT,APCMEDAT)
+7 IF 'G
SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_";NO MMR"
QUIT
+8 SET $PIECE(MMR(R),U,2)=$PIECE(MMR(R),U,2)+1
Begin DoDot:2
+9 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,2)=$PIECE($GET(^TMP($JOB,"TRANS",R,PAT)),U,2)+1
+10 SET $PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)=$PIECE(^TMP($JOB,"TRANS",R,PAT),U,3)_";YES MMR"
End DoDot:2
End DoDot:1
+11 QUIT
+12 ;
CPT(V) ;was there a 99201-99205 or 99381-99387 on this visit
+1 NEW X,C,A
+2 SET A=""
+3 SET X=0
FOR
SET X=$ORDER(^AUPNVCPT("AD",V,X))
IF X'=+X!(A)
QUIT
Begin DoDot:1
+4 SET C=$$GET1^DIQ(9000010.18,X,.01)
+5 IF C>99200
IF C<99206
SET A=1
QUIT
+6 IF C>99380
IF C<99388
SET A=1
QUIT
End DoDot:1
+7 QUIT A
IMAGE(V,R) ;WAS THERE AN IMAGE BEFORE VISIT DATE AND IF SO WAS THIS THE FIRST VISIT AFTER THE IMAGE DATE
+1 NEW D,A,B,C,P,X,Y,T,G,Z,VST
+2 SET P=$PIECE(^AUPNVSIT(V,0),U,5)
+3 IF '$DATA(^MAG(2005,"AC",P))
QUIT 0
+4 SET G=""
+5 ;fileman visit date/time
SET D=$$VDTM^APCLV(V)
+6 SET B=0
FOR
SET B=$ORDER(^MAG(2005,"AC",P,B))
IF B'=+B!(G)
QUIT
Begin DoDot:1
+7 IF $$UP^XLFSTR($$GET1^DIQ(2005,B,42))'="CCD-SUMMARY"
QUIT
+8 SET C=$$GET1^DIQ(2005,B,7,"I")
+9 ;image save after visit date/time
IF C>D
QUIT
+10 ;is this the first visit after the image date/time to the EP?
+11 SET X=C
+12 SET T=$ORDER(^APCMMUCN("B","INTERIM STAGE 1 2014",0))
+13 KILL VST
+14 DO ALLV^APCLAPIU(P,$PIECE(C,"."),$$FMADD^XLFDT($PIECE(D,"."),1),"VST")
+15 ;now reorder by visit/date time
+16 SET X=0
FOR
SET X=$ORDER(VST(X))
IF X'=+X
QUIT
SET VST("DTM",$$VDTM^APCLV($PIECE(VST(X),U,5)),X)=$PIECE(VST(X),U,5)
+17 SET Y=0
FOR
SET Y=$ORDER(VST("DTM",Y))
IF Y'=+Y!(G)
QUIT
Begin DoDot:2
+18 SET B=0
FOR
SET B=$ORDER(VST("DTM",Y,B))
IF B'=+B!(G)
QUIT
Begin DoDot:3
+19 SET Z=VST("DTM",Y,B)
+20 IF '$DATA(^AUPNVSIT(Z,0))
QUIT
+21 IF $$PRIMPROV^APCLV(Z,"I")'=R
QUIT
+22 IF "AOSM"'[$PIECE(^AUPNVSIT(Z,0),U,7)
QUIT
+23 SET C=$$CLINIC^APCLV(Z,"C")
+24 IF C=30
QUIT
+25 ;don't count these clinics
IF C]""
IF T
IF $DATA(^APCMMUCN(T,14,"B",C))
QUIT
+26 IF Z'=V
QUIT
+27 SET G=1
End DoDot:3
End DoDot:2
End DoDot:1
+28 QUIT G