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

BGPMUD07.m

Go to the documentation of this file.
BGPMUD07 ; IHS/MSC/SAT - MU measure NQF0027 ;12-JUL-2011 15:43;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;code to collect meaningful use report SMOKING CESSATION MEDICAL ASSIST
ENTRY ;EP
 ; expects:
 ;  DFN      = patient code from VA PATIENT file
 ;  BGPBDATE = begin date of report
 ;  BGPEDATE = end date of report
 ;  BGPPROV   = provider code from NEW PERSON file
 ;  BGPMUTF  = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
 ; Print Routine:     P27ENT^BGPMUDP?
 ; Delimited Routine: D27ENT^BGPMUDD?
 N BGPDEN,BGPNUM1,BGPNUM2,BGPNOT1,BGPNOT2,BGPDT,BGPAGEE,VIEN
 N BGPHFI
 N END,HF,N2CPT,START,TOPC,TOPCL,TOPIEN,VPEDD,VPEDIEN
 S HF=0
 S (BGPDEN,BGPNUM1,BGPNUM2,BGPNOT1,BGPNOT2)=0
 S BGPAGEE=$$AGE^AUPNPAT(DFN,BGPEDATE)
 ;quit if not 18 by the end of the reporting period
 Q:BGPAGEE<18
 ;look for 1 outpatient encounter with the EP back to 730 days prior to the end of the reporting period
 S START=9999999-$$FMADD^XLFDT(BGPEDATE,-730),END=9999999-BGPEDATE
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)  D  Q:+BGPDEN
 .S VIEN=0 F  S VIEN=$O(^AUPNVSIT("AA",DFN,FIRST,VIEN)) Q:'+VIEN  D  Q:+BGPDEN
 ..S BGPDT=$P($P($G(^AUPNVSIT(VIEN,0)),U,1),".",1)
 ..;Check provider, determine if there are visits with E&M codes
 ..I $$PRV^BGPMUUT1(VIEN,BGPPROV) D
 ...S X=$$VSTCPT^BGPMUUT1(DFN,VIEN,"BGPMU CTRL HIGH BP EM")
 ...I +X S BGPDEN=1_U_"EN:"_$$DATE^BGPMUUTL(BGPDT)
 ...I '+BGPDEN D
 ....S X=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU ENC OUTPATIENT ICD")
 ....I +X S BGPDEN=1_U_"EN:"_$$DATE^BGPMUUTL(BGPDT)
 ;quit if visits with E&M code(s) not found for given DFN
 Q:'+BGPDEN
 ;
 ;check numerator 1
 S HF=$$HF(DFN,"BGPMU TOB SMOKER HF")
 S BGPDENT=""
 I +HF D
 .S BGPNUM1="M:"_$P(HF,U,2)_" "_$$DATE^BGPMUUTL($P(HF,U,4))  ;patient is in numerator 1
 .S BGPNUM1=1_U_$$FL(BGPNUM1,17,";")
 .S BGPDENT="HF:"_$$DATE^BGPMUUTL($P(HF,U,4))
 I 'BGPNUM1 D
 .S HF=$$HF(DFN,"BGPMU TOB NON-USER HF")
 .S BGPNOT1="NM:"_$S(+HF:$P(HF,U,2)_" "_$$DATE^BGPMUUTL($P(HF,U,4)),1:"")
 .S BGPNOT1=1_U_$$FL(BGPNOT1,17,";")
 ;
 ;check numerator 2
 I +BGPNUM1 D
 .S N2CPT=$$CPT^BGPMUUT1(DFN,$$FMADD^XLFDT(BGPEDATE,-365),BGPEDATE,"BGPMU TOBACCO USE CESS COUNSEL")
 .I +N2CPT S BGPNUM2=1_U_"M:"_$P(N2CPT,U,2)_" "_$$DATE^BGPMUUTL($P(N2CPT,U,3))
 .I '+BGPNUM2 D
 ..S START=9999999-$$FMADD^XLFDT(BGPEDATE,-365)
 ..S END=9999999-BGPEDATE
 ..S VPEDD=END-1 F  S VPEDD=$O(^AUPNVPED("AA",DFN,VPEDD)) Q:VPEDD=""  D
 ...S VPEDIEN=0 F  S VPEDIEN=$O(^AUPNVPED("AA",DFN,VPEDD,VPEDIEN)) Q:VPEDIEN=""  D
 ....S TOPIEN=$P(^AUPNVPED(VPEDIEN,0),U,1)
 ....Q:TOPIEN=""
 ....S TOPC=$P(^AUTTEDT(TOPIEN,0),U,2)
 ....S TOPCL=$L(TOPC)
 ....I ("TO"=$E(TOPC,1,2))!("TO"=$E(TOPC,TOPCL-1,TOPCL))!("SHS"=$E(TOPC,TOPCL-2,TOPCL)) S BGPNUM2="M:"_TOPC_" "_$$DATE^BGPMUUTL((9999999-VPEDD)),BGPNUM2=1_U_$$FL(BGPNUM2,17,";")
 S:'+BGPNUM2 BGPNOT2=1_U_"NM:"
 ;
 D TOTAL(DFN)
 ; check these
 K BGPL,BGPLWTS,BGPLHTS,%,X,BGPLWTS1,BGPLHTS1,Y,TERMINAL,NORMAL,FOLLOW,EXCEPT
 Q
 ;
TOTAL(DFN) ;See where this patient ends up
 ;  BGPDSTR = Denominator string: encounter dates in FM format pieced by ";"
 ;  BGPNSTR = Numerator string: <health factor text> ";" <health factor edit date in FM format>
 ;if we got here, this patient is in the denominator
 N BGPDT,PTCNT,DENCT,NUMCT,NOTCT,TOTALS,PT1
 S TOTALS=$G(^TMP("BGPMU0027",$J,BGPMUTF,"TOT"))
 S NUMCT1=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"NUM",1))
 S NUMCT2=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"NUM",2))
 S NOTCT1=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"NOT",1))
 S NOTCT2=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"NOT",2))
 S DENCT=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"DEN",1))
 S EXCCT=+$G(^TMP("BGPMU0027",$J,BGPMUTF,"EXC",1))
 S PTCNT=$P(TOTALS,U,1),PT1=$P(TOTALS,U,2)
 S PTCNT=PTCNT+1
 S PT1=PT1+1
 I BGPDEN D
 .S DENCT=DENCT+1 S ^TMP("BGPMU0027",$J,BGPMUTF,"DEN",1)=DENCT
 .S ^TMP("BGPMU0027",$J,"PAT",BGPMUTF,"DEN",1,DENCT)=DFN
 .I +BGPNUM1 D
 ..S NUMCT1=NUMCT1+1
 ..S ^TMP("BGPMU0027",$J,BGPMUTF,"NUM",1)=NUMCT1
 ..S ^TMP("BGPMU0027",$J,"PAT",BGPMUTF,"NUM",1,PT1)=DFN_U_$P(BGPDEN,U,2)_U_$P(BGPNUM1,U,2)
 .I '+BGPNUM1 D
 ..S NOTCT1=NOTCT1+1
 ..S ^TMP("BGPMU0027",$J,BGPMUTF,"NOT",1)=NOTCT1
 ..S ^TMP("BGPMU0027",$J,"PAT",BGPMUTF,"NOT",1,PT1)=DFN_U_$P(BGPDEN,U,2)_U_$P(BGPNOT1,U,2)
 .I +BGPNUM2 D
 ..S NUMCT2=NUMCT2+1
 ..S ^TMP("BGPMU0027",$J,BGPMUTF,"NUM",2)=NUMCT2
 ..S ^TMP("BGPMU0027",$J,"PAT",BGPMUTF,"NUM",2,PT1)=DFN_U_$P(BGPDEN,U,2)_U_$P(BGPNUM2,U,2)
 .I '+BGPNUM2 D
 ..S NOTCT2=NOTCT2+1
 ..S ^TMP("BGPMU0027",$J,BGPMUTF,"NOT",2)=NOTCT2
 ..S ^TMP("BGPMU0027",$J,"PAT",BGPMUTF,"NOT",2,PT1)=DFN_U_$P(BGPDEN,U,2)_";"_BGPDENT_U_$P(BGPNOT2,U,2)
 ;
 S ^TMP("BGPMU0027",$J,BGPMUTF,"TOT")=PTCNT_U_PT1
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0027.1",BGPMUTF)=1_U_+BGPNUM1_U_""_U_$P(BGPDEN,U,2)_";"_$P($G(BGPNUM1),U,2)
 S BGPICARE("MU.EP.0027.2",BGPMUTF)=1_U_+BGPNUM2_U_""_U_$P(BGPDEN,U,2)_";"_$P($G(BGPNUM2),U,2)
 Q
 ;
HF(DFN,TAX)  ;look in health factors for values in given taxonomy
 N BGPDT,BGPH,BGPHFN,BGPTOBN,BGPTOBU
 S TIEN="" S TIEN=$O(^ATXAX("B",TAX,TIEN)) Q:'TIEN 0
 S BGPHF=0  ;health factor found flag
 S END=9999999-BGPEDATE,START=9999999-$$FMADD^XLFDT(BGPEDATE,-365)
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)  D  Q:BGPHF
 .S VIEN=0 F  S VIEN=$O(^AUPNVSIT("AA",DFN,FIRST,VIEN)) Q:'+VIEN  D  Q:BGPHF
 ..S BGPIEN="" F  S BGPIEN=$O(^AUPNVHF("AD",VIEN,BGPIEN)) Q:'+BGPIEN  D
 ...S BGPDT=$P($P($G(^AUPNVSIT(VIEN,0)),U,1),".",1)
 ...S BGPHNOD=$G(^AUPNVHF(BGPIEN,0))
 ...S BGPHFI=$P(BGPHNOD,U,1)
 ...S BGPHFC=$P(^AUTTHF(BGPHFI,0),U,2)
 ...S BGPHFN=$P(^AUTTHF(BGPHFI,0),U,1)
 ...I $D(^ATXAX(TIEN,21,"B",BGPHFN)) S BGPHF=1_"^"_BGPHFN_"^"_BGPHFC_"^"_BGPDT
 Q BGPHF
 ;
FL(STRING,WIDTH,DELIM) ;
 N FLI,TSTRING
 S:$G(DELIM)="" DELIM="^"
 S RETURN=""
 Q:$L(STRING)<=WIDTH STRING
 S TSTRING=STRING
 S TSTRINGL=$L(TSTRING)
 F  Q:TSTRING=""  D
 .S TSA=0
 .I WIDTH>=$L(TSTRING) S RETURN=RETURN_DELIM_TSTRING,TSTRING=""
 .Q:TSTRING=""
 .I $E(TSTRING,1,WIDTH)'[" " D
 ..S RETURN=$S(RETURN'="":RETURN_DELIM,1:"")_$E(TSTRING,1,WIDTH)
 ..S TSTRING=$E(TSTRING,WIDTH+1,TSTRINGL)
 ..S TSTRINGL=$L(TSTRING)
 ..S TSA=1
 .Q:TSA
 .S FLI=WIDTH
 .F  Q:FLI<1  D
 ..I $E(TSTRING,FLI)=" " D
 ...S RETURN=$S(RETURN'="":RETURN_DELIM,1:"")_$E(TSTRING,1,FLI-1)
 ...S TSTRING=$E(TSTRING,FLI+1,TSTRINGL)
 ...S TSTRINGL=$L(TSTRING)
 ...S FLI=1
 ..S FLI=FLI-1
 Q RETURN
 ;
TEST ; debug target
 ;S U="^"
 ;S DT=$$DT^XLFDT()
 ;S DFN=184            ;  DFN      = patient code from VA PATIENT file
 ;S BGPBDATE=3100930   ;  BGPBDATE = begin date of report
 ;S BGPEDATE=3110801   ;  BGPEDATE = end date of report
 ;S BGPPROV=2          ;  BGPPROV   = provider code from NEW PERSON file
 ;S BGPMUTF="C"        ;  BGPMUTF  = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
 ;D ENTRY
 ;S ZSAT=$$HF(175,"BGPMU TOB SMOKER HF")
 ;W ZSAT
 Q