BGPMUD05 ; IHS/MSC/SAT - MU measure NQF0014 ;14-JUN-2011 15:43;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;code to collect meaningful use report Prenatal Anti-D Immune Globulin
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: P14ENT^BGPMUDP3
; Delimited Routine: D14ENT^BGPMUDD3
N BGP3,BGPDEN,BGPDSTR,BGPDT,BGPEXC,BGPNSTR,BGPNUM,BGPP,BGPRHO,BGPSEX,BGPUNSEN
N END,EXC,FIRST,IEN,START,VIEN,ESTDOC
S (BGPDEN,BGPEXC,BGPNUM)=0
S (BGPNSTR,BGPDSTR,BGP3)=""
;only check female
S BGPSEX=$$SEX^AUPNPAT(DFN)
Q:BGPSEX'="F"
;
;look for a delivery live birth procedure during the reporting period
S BGPP=$$DLBCPT^BGPMUD04(DFN,BGPBDATE,BGPEDATE,"BGPMU DELIVERY LIVE BIRTH CPT")
Q:'BGPP
S ESTDOC=$$FMADD^XLFDT($P(BGPP,U,3),-300)
;
;look for prenatal visit with EP within 300 days of birth
S START=9999999-ESTDOC,END=9999999-$P(BGPP,U,3)
S FIRST=END-0.1 F S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START) D
.S VIEN=0 F S VIEN=$O(^AUPNVSIT("AA",DFN,FIRST,VIEN)) Q:'+VIEN D
..S BGPDT=$P($P($G(^AUPNVSIT(VIEN,0)),U,1),".",1)
..;Check provider, determine if there are visits with ICD codes for prenatal visit
..I $$PRV^BGPMUUT1(VIEN,BGPPROV) D
...S X=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU PRENATAL VISIT DX")
...I +X S BGP3=BGP3_$S(BGP3'="":";",1:"")_$G(BGPDT)
;quit if no diagnosis for prenatal visit
Q:BGP3=""
;
S BGPUNSEN=$$UNSEN(DFN)
Q:'BGPUNSEN
;getting here means patient is in the denominator
S BGPDEN=1
S BGPDSTR="DEL:"_$$DATE^BGPMUUTL($P(BGPP,U,3))_";EN:"_$$DATE^BGPMUUTL($P(BGP3,";"))
;
;determine if patient was given anti-d immune globulin between 118-90 days before the delivery date
S BGPNUM=$$FIND^BGPMUUT8(DFN,"BGPMU ANTI-D IMMUNE GLOBUL NDC",$$FMADD^XLFDT($P(BGPP,U,3),-118),"",$$FMADD^XLFDT($P(BGPP,U,3),-90))
;
;check for exclusions
I +BGPNUM D
.S BGPNSTR="M:MED "_$$DATE^BGPMUUTL($P(BGPNUM,U,3))
E D
.S EXC=$$MEDREF^BGPMUUT2(DFN,ESTDOC,$P(BGPP,U,3),"BGPMU ANTI-D IMMUNE GLOBUL NDC")
.S:EXC BGPEXC=1,BGPNSTR="Excluded" ;patient is excluded
.S:'EXC BGPNSTR="NM:"
;
D TOTAL(DFN)
;
K BGP3,BGPDEN,BGPDSTR,BGPDT,BGPEXC,BGPNSTR,BGPNUM,BGPP,BGPRHO,BGPSEX,BGPUNSEN
K END,EXC,FIRST,IEN,START,VIEN,ESTDOC
Q
UNSEN(DFN) ;Determine if patient is Rh negative and unsensitized
N BGPRHT,RHTVAL,BGPABO,ABOVAL,BGPABO1,LIEN,VAL,DATA
S (RHTVAL,ABOVAL)=""
;check for Rh type in blood bank
S BGPRHT=$$RHTYPE^BGPMUUT5(DFN)
S:+BGPRHT RHTVAL=$P(BGPRHT,U,2)
;check for Rh type in V LAB
I '+BGPRHT D
.S BGPRHT=$$LOINC^BGPMUUT2(DFN,"",$P(BGPP,U,3),"BGPMU RH TYPE LOINC")
.I +BGPRHT D
..S LIEN=$P(BGPRHT,U,2)
..S RHTVAL=$P($G(^AUPNVLAB(LIEN,0)),U,4)
Q:('BGPRHT)!((RHTVAL'="N")&(RHTVAL'="NEG")&(RHTVAL'="NEGATIVE")) 0
;check for result of antibody screen (indirect COOMBS)
S BGPABO=$$ANTI^BGPMUUT5(DFN)
S:+BGPABO ABOVAL=$P(BGPABO,U,2)
I '+BGPABO D
.S BGPABO=$$LOINC^BGPMUUT2(DFN,ESTDOC,$P(BGPP,U,3),"BGPMU INDIRECT COOMBS LOINC")
.I +BGPABO D
..S ABOVAL=$P($G(^AUPNVLAB($P(BGPABO,U,2),0)),U,4)
.E D
..;check for HDL via CPT codes in LAB
..D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU INDIRECT COOMBS CPT",ESTDOC,$P(BGPP,U,3))
..S VAL="" S VAL=$O(DATA(VAL))
..I +VAL D
...S ABOVAL=$G(DATA(VAL))
...S BGPABO=1_(9999999-VAL)
Q:('BGPABO)!((ABOVAL'="N")&(ABOVAL'="NEG")&(ABOVAL'="NEGATIVE")) 0
Q 1
;
;
;CODE BELOW IS NO LONGER USED - NO MENTION OF RHOGAM OR ICD'S IN THE DENOMINATOR CRITERIA
;FROM Dr. Advani: Per Terry's recommendation earlier, we do not include system reasons until we implement full hl7 3.0 RIM codes for this.
;if no anti-body screening, look for ICD on problem list
S BGPRHO=0
I $P(BGPABO,U,2)=0 D
.S BGPABO1=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU CTRL HIGH BP HYP DX")
.S:BGPABO1="" BGPABO1=$$PLTAX^BGPMUUT1(DFN,"BGPMU CTRL HIGH BP HYP DX")
Q:'BGPABO1 0
;if unsensitized
S:$P(BGPABO,U,2)="N" BGPRHO=$$FIND^BGPMUUT7(DFN,"BGPMU PRENATAL RHOGAM CPT",BGPBDATE,BGPEDATE)
Q:'BGPRHO 0
;if sensitized check for sensitization ICD codes in problems list
S:$P(BGPABO,U,2)="P" BGPRHO=$$PLTAX^BGPMUUT1(DFN,"BGPMU PRENATAL SENSITIZED ICD")
Q:'BGPRHO 0
Q 1
;
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("BGPMU0014",$J,BGPMUTF,"TOT"))
S NUMCT=+$G(^TMP("BGPMU0014",$J,BGPMUTF,"NUM"))
S NOTCT=+$G(^TMP("BGPMU0014",$J,BGPMUTF,"NOT"))
S DENCT=+$G(^TMP("BGPMU0014",$J,BGPMUTF,"DEN"))
S EXCCT=+$G(^TMP("BGPMU0014",$J,BGPMUTF,"EXC"))
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("BGPMU0014",$J,BGPMUTF,"DEN")=DENCT
.S ^TMP("BGPMU0014",$J,BGPMUTF,"DEN","PAT",DENCT)=DFN
.I BGPEXC D
..S EXCCT=EXCCT+1
..S ^TMP("BGPMU0014",$J,BGPMUTF,"EXC")=EXCCT
..S ^TMP("BGPMU0014",$J,"PAT",BGPMUTF,"EXC",PT1)=DFN_U_BGPDSTR_U_"Excluded"
.I 'BGPEXC D
..I BGPNUM D
...S NUMCT=NUMCT+1
...S ^TMP("BGPMU0014",$J,BGPMUTF,"NUM")=NUMCT
...S ^TMP("BGPMU0014",$J,"PAT",BGPMUTF,"NUM",PT1)=DFN_U_BGPDSTR_U_BGPNSTR
..I 'BGPNUM D
...S NOTCT=NOTCT+1
...S ^TMP("BGPMU0014",$J,BGPMUTF,"NOT")=NOTCT
...S ^TMP("BGPMU0014",$J,"PAT",BGPMUTF,"NOT",PT1)=DFN_U_BGPDSTR_U_BGPNSTR
S ^TMP("BGPMU0014",$J,BGPMUTF,"TOT")=PTCNT_U_PT1
;Setup iCare array for patient
S BGPICARE("MU.EP.0014.1",BGPMUTF)=+BGPDEN_U_+BGPNUM_U_+BGPEXC_U_$G(BGPDSTR)_";"_$G(BGPNSTR)
Q
;
TEST ; debug target
;S U="^"
;S DT=$$DT^XLFDT()
;S DFN=184 ; DFN = patient code from VA PATIENT file
;S BGPBDATE=3100401 ; BGPBDATE = begin date of report
;S BGPEDATE=3110401 ; 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
Q
BGPMUD05 ; IHS/MSC/SAT - MU measure NQF0014 ;14-JUN-2011 15:43;DU
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;code to collect meaningful use report Prenatal Anti-D Immune Globulin
ENTRY ;EP
+1 ; expects:
+2 ; DFN = patient code from VA PATIENT file
+3 ; BGPBDATE = begin date of report
+4 ; BGPEDATE = end date of report
+5 ; BGPPROV = provider code from NEW PERSON file
+6 ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
+7 ; Print Routine: P14ENT^BGPMUDP3
+8 ; Delimited Routine: D14ENT^BGPMUDD3
+9 NEW BGP3,BGPDEN,BGPDSTR,BGPDT,BGPEXC,BGPNSTR,BGPNUM,BGPP,BGPRHO,BGPSEX,BGPUNSEN
+10 NEW END,EXC,FIRST,IEN,START,VIEN,ESTDOC
+11 SET (BGPDEN,BGPEXC,BGPNUM)=0
+12 SET (BGPNSTR,BGPDSTR,BGP3)=""
+13 ;only check female
+14 SET BGPSEX=$$SEX^AUPNPAT(DFN)
+15 IF BGPSEX'="F"
QUIT
+16 ;
+17 ;look for a delivery live birth procedure during the reporting period
+18 SET BGPP=$$DLBCPT^BGPMUD04(DFN,BGPBDATE,BGPEDATE,"BGPMU DELIVERY LIVE BIRTH CPT")
+19 IF 'BGPP
QUIT
+20 SET ESTDOC=$$FMADD^XLFDT($PIECE(BGPP,U,3),-300)
+21 ;
+22 ;look for prenatal visit with EP within 300 days of birth
+23 SET START=9999999-ESTDOC
SET END=9999999-$PIECE(BGPP,U,3)
+24 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+25 SET VIEN=0
FOR
SET VIEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,VIEN))
IF '+VIEN
QUIT
Begin DoDot:2
+26 SET BGPDT=$PIECE($PIECE($GET(^AUPNVSIT(VIEN,0)),U,1),".",1)
+27 ;Check provider, determine if there are visits with ICD codes for prenatal visit
+28 IF $$PRV^BGPMUUT1(VIEN,BGPPROV)
Begin DoDot:3
+29 SET X=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU PRENATAL VISIT DX")
+30 IF +X
SET BGP3=BGP3_$SELECT(BGP3'="":";",1:"")_$GET(BGPDT)
End DoDot:3
End DoDot:2
End DoDot:1
+31 ;quit if no diagnosis for prenatal visit
+32 IF BGP3=""
QUIT
+33 ;
+34 SET BGPUNSEN=$$UNSEN(DFN)
+35 IF 'BGPUNSEN
QUIT
+36 ;getting here means patient is in the denominator
+37 SET BGPDEN=1
+38 SET BGPDSTR="DEL:"_$$DATE^BGPMUUTL($PIECE(BGPP,U,3))_";EN:"_$$DATE^BGPMUUTL($PIECE(BGP3,";"))
+39 ;
+40 ;determine if patient was given anti-d immune globulin between 118-90 days before the delivery date
+41 SET BGPNUM=$$FIND^BGPMUUT8(DFN,"BGPMU ANTI-D IMMUNE GLOBUL NDC",$$FMADD^XLFDT($PIECE(BGPP,U,3),-118),"",$$FMADD^XLFDT($PIECE(BGPP,U,3),-90))
+42 ;
+43 ;check for exclusions
+44 IF +BGPNUM
Begin DoDot:1
+45 SET BGPNSTR="M:MED "_$$DATE^BGPMUUTL($PIECE(BGPNUM,U,3))
End DoDot:1
+46 IF '$TEST
Begin DoDot:1
+47 SET EXC=$$MEDREF^BGPMUUT2(DFN,ESTDOC,$PIECE(BGPP,U,3),"BGPMU ANTI-D IMMUNE GLOBUL NDC")
+48 ;patient is excluded
IF EXC
SET BGPEXC=1
SET BGPNSTR="Excluded"
+49 IF 'EXC
SET BGPNSTR="NM:"
End DoDot:1
+50 ;
+51 DO TOTAL(DFN)
+52 ;
+53 KILL BGP3,BGPDEN,BGPDSTR,BGPDT,BGPEXC,BGPNSTR,BGPNUM,BGPP,BGPRHO,BGPSEX,BGPUNSEN
+54 KILL END,EXC,FIRST,IEN,START,VIEN,ESTDOC
+55 QUIT
UNSEN(DFN) ;Determine if patient is Rh negative and unsensitized
+1 NEW BGPRHT,RHTVAL,BGPABO,ABOVAL,BGPABO1,LIEN,VAL,DATA
+2 SET (RHTVAL,ABOVAL)=""
+3 ;check for Rh type in blood bank
+4 SET BGPRHT=$$RHTYPE^BGPMUUT5(DFN)
+5 IF +BGPRHT
SET RHTVAL=$PIECE(BGPRHT,U,2)
+6 ;check for Rh type in V LAB
+7 IF '+BGPRHT
Begin DoDot:1
+8 SET BGPRHT=$$LOINC^BGPMUUT2(DFN,"",$PIECE(BGPP,U,3),"BGPMU RH TYPE LOINC")
+9 IF +BGPRHT
Begin DoDot:2
+10 SET LIEN=$PIECE(BGPRHT,U,2)
+11 SET RHTVAL=$PIECE($GET(^AUPNVLAB(LIEN,0)),U,4)
End DoDot:2
End DoDot:1
+12 IF ('BGPRHT)!((RHTVAL'="N")&(RHTVAL'="NEG")&(RHTVAL'="NEGATIVE"))
QUIT 0
+13 ;check for result of antibody screen (indirect COOMBS)
+14 SET BGPABO=$$ANTI^BGPMUUT5(DFN)
+15 IF +BGPABO
SET ABOVAL=$PIECE(BGPABO,U,2)
+16 IF '+BGPABO
Begin DoDot:1
+17 SET BGPABO=$$LOINC^BGPMUUT2(DFN,ESTDOC,$PIECE(BGPP,U,3),"BGPMU INDIRECT COOMBS LOINC")
+18 IF +BGPABO
Begin DoDot:2
+19 SET ABOVAL=$PIECE($GET(^AUPNVLAB($PIECE(BGPABO,U,2),0)),U,4)
End DoDot:2
+20 IF '$TEST
Begin DoDot:2
+21 ;check for HDL via CPT codes in LAB
+22 DO LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU INDIRECT COOMBS CPT",ESTDOC,$PIECE(BGPP,U,3))
+23 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+24 IF +VAL
Begin DoDot:3
+25 SET ABOVAL=$GET(DATA(VAL))
+26 SET BGPABO=1_(9999999-VAL)
End DoDot:3
End DoDot:2
End DoDot:1
+27 IF ('BGPABO)!((ABOVAL'="N")&(ABOVAL'="NEG")&(ABOVAL'="NEGATIVE"))
QUIT 0
+28 QUIT 1
+29 ;
+30 ;
+31 ;CODE BELOW IS NO LONGER USED - NO MENTION OF RHOGAM OR ICD'S IN THE DENOMINATOR CRITERIA
+32 ;FROM Dr. Advani: Per Terry's recommendation earlier, we do not include system reasons until we implement full hl7 3.0 RIM codes for this.
+33 ;if no anti-body screening, look for ICD on problem list
+34 SET BGPRHO=0
+35 IF $PIECE(BGPABO,U,2)=0
Begin DoDot:1
+36 SET BGPABO1=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU CTRL HIGH BP HYP DX")
+37 IF BGPABO1=""
SET BGPABO1=$$PLTAX^BGPMUUT1(DFN,"BGPMU CTRL HIGH BP HYP DX")
End DoDot:1
+38 IF 'BGPABO1
QUIT 0
+39 ;if unsensitized
+40 IF $PIECE(BGPABO,U,2)="N"
SET BGPRHO=$$FIND^BGPMUUT7(DFN,"BGPMU PRENATAL RHOGAM CPT",BGPBDATE,BGPEDATE)
+41 IF 'BGPRHO
QUIT 0
+42 ;if sensitized check for sensitization ICD codes in problems list
+43 IF $PIECE(BGPABO,U,2)="P"
SET BGPRHO=$$PLTAX^BGPMUUT1(DFN,"BGPMU PRENATAL SENSITIZED ICD")
+44 IF 'BGPRHO
QUIT 0
+45 QUIT 1
+46 ;
TOTAL(DFN) ;See where this patient ends up
+1 ; BGPDSTR = Denominator string: encounter dates in FM format pieced by ";"
+2 ; BGPNSTR = Numerator string: <health factor text> ";" <health factor edit date in FM format>
+3 ;if we got here, this patient is in the denominator
+4 NEW BGPDT,PTCNT,DENCT,NUMCT,NOTCT,TOTALS,PT1
+5 SET TOTALS=$GET(^TMP("BGPMU0014",$JOB,BGPMUTF,"TOT"))
+6 SET NUMCT=+$GET(^TMP("BGPMU0014",$JOB,BGPMUTF,"NUM"))
+7 SET NOTCT=+$GET(^TMP("BGPMU0014",$JOB,BGPMUTF,"NOT"))
+8 SET DENCT=+$GET(^TMP("BGPMU0014",$JOB,BGPMUTF,"DEN"))
+9 SET EXCCT=+$GET(^TMP("BGPMU0014",$JOB,BGPMUTF,"EXC"))
+10 SET PTCNT=$PIECE(TOTALS,U,1)
SET PT1=$PIECE(TOTALS,U,2)
+11 SET PTCNT=PTCNT+1
+12 SET PT1=PT1+1
+13 IF BGPDEN
Begin DoDot:1
+14 SET DENCT=DENCT+1
SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"DEN")=DENCT
+15 SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"DEN","PAT",DENCT)=DFN
+16 IF BGPEXC
Begin DoDot:2
+17 SET EXCCT=EXCCT+1
+18 SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"EXC")=EXCCT
+19 SET ^TMP("BGPMU0014",$JOB,"PAT",BGPMUTF,"EXC",PT1)=DFN_U_BGPDSTR_U_"Excluded"
End DoDot:2
+20 IF 'BGPEXC
Begin DoDot:2
+21 IF BGPNUM
Begin DoDot:3
+22 SET NUMCT=NUMCT+1
+23 SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"NUM")=NUMCT
+24 SET ^TMP("BGPMU0014",$JOB,"PAT",BGPMUTF,"NUM",PT1)=DFN_U_BGPDSTR_U_BGPNSTR
End DoDot:3
+25 IF 'BGPNUM
Begin DoDot:3
+26 SET NOTCT=NOTCT+1
+27 SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"NOT")=NOTCT
+28 SET ^TMP("BGPMU0014",$JOB,"PAT",BGPMUTF,"NOT",PT1)=DFN_U_BGPDSTR_U_BGPNSTR
End DoDot:3
End DoDot:2
End DoDot:1
+29 SET ^TMP("BGPMU0014",$JOB,BGPMUTF,"TOT")=PTCNT_U_PT1
+30 ;Setup iCare array for patient
+31 SET BGPICARE("MU.EP.0014.1",BGPMUTF)=+BGPDEN_U_+BGPNUM_U_+BGPEXC_U_$GET(BGPDSTR)_";"_$GET(BGPNSTR)
+32 QUIT
+33 ;
TEST ; debug target
+1 ;S U="^"
+2 ;S DT=$$DT^XLFDT()
+3 ;S DFN=184 ; DFN = patient code from VA PATIENT file
+4 ;S BGPBDATE=3100401 ; BGPBDATE = begin date of report
+5 ;S BGPEDATE=3110401 ; BGPEDATE = end date of report
+6 ;S BGPPROV=2 ; BGPPROV = provider code from NEW PERSON file
+7 ;S BGPMUTF="C" ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
+8 ;D ENTRY
+9 QUIT