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

BGPMUH05.m

Go to the documentation of this file.
BGPMUH05 ;IHS/MSC/MGH - MI measure NQF0437-STK-4 ;02-Mar-2011 16:05;MGH
 ;;11.0;IHS CLINICAL REPORTING;**4**;JAN 06, 2011;Build 84
 ;ED meaningful use hospital measured
ENTRY ;PEP  Stroke Measure 4 - tPA therapy within 3hrs
 N START,END,BGPIEN,DFN,BGPVST,BGPISDX,BGPHSDX,BGPAGEE,BGPIPROB,BGPHPROB,STROKE,EXC,NUM,BGPDIS
 N BGPER,BGPADTMI,BDPDD,LKW
 ;Start by finding all admissions during the reporting period
 S START=BGPBDATE
 S END=BGPEDATE_".2359"
 F  S START=$O(^DGPM("B",START)) Q:START=""!(START>END)  D
 .S BGPIEN="" F  S BGPIEN=$O(^DGPM("B",START,BGPIEN)) Q:BGPIEN=""  D
 ..Q:$P($G(^DGPM(BGPIEN,0)),U,2)'=1    ;Only include admissions
 ..S DFN=$P($G(^DGPM(BGPIEN,0)),U,3)
 ..S BGPAGEE=$$AGE^AUPNPAT(DFN,BGPEDATE)
 ..Q:DFN=""
 ..S BGPACTUP=$$ACTUPAP^BGPMUEHD(DFN,BGPBDATE,BGPEDATE,BGPBEN)
 ..I 'BGPACTUP,'$G(BGPXPXPX),'$G(BGPIISO) Q
 ..S BGPVST=$P($G(^DGPM(BGPIEN,0)),U,27)  ;Get the visit
 ..Q:BGPVST=""
 ..S BGPDIS=$P($G(^DGPM(BGPIEN,0)),U,17)  ;Don't use if pt is still an inpt
 ..Q:BGPDIS=""
 ..;Check for a diagnosis of stroke
 ..S STROKE=0,EXC=0,NUM=0
 ..S BGPISDX=$$VSTPOVA^BGPMUUT3(DFN,BGPVST,"BGPMU ISCHEMIC STROKE DX")
 ..;S BGPIPROB=$$PLTAX^BGPMUUT1(DFN,"BGPMU ISCHEMIC STROKE DX","A")
 ..;Pt must have both a POV of stoke and it must be an active problem
 ..;I +BGPISDX&(+BGPIPROB) S STROKE=1
 ..I +BGPISDX S STROKE=1
 ..I +STROKE D
 ...;Get the admit time & discharge times
 ...S BGPADMIT=$P($G(^DGPM(BGPIEN,0)),U,1)
 ...S BGPDD=$P($G(^DGPM(BGPDIS,0)),U,1)
 ...;See if there is an ER visit prior to admission
 ...S BGPER=$$ER(DFN,BGPADMIT)
 ...S EXC=$$EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS)
 ...;Find the date/time of last known well
 ...S LKW=$$WELL(DFN,BGPER,BGPADMIT,BGPDD)
 ...I LKW=0 S EXC="1^LKW"
 ...;If no exclusions see if they had tPA given in correct time frame
 ...I EXC="" S NUM=$$NUMER(DFN,LKW)
 ...;Now add it all up
 ...D TOTAL(BGPIEN)
 Q
TOTAL(BGPIEN) ;add up the totals
 N PTCNT,EXCCT,DENCT,NUMCT,TOTALS,DATE,NOTCT
 S TOTALS=$G(^TMP("BGPMU0437",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0437",$J,BGPMUTF,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0437",$J,BGPMUTF,"NUM"))
 S EXCCT=+$G(^TMP("BGPMU0437",$J,BGPMUTF,"EXC"))
 S NOTCT=+$G(^TMP("BGPMU0437",$J,BGPMUTF,"NOT"))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S DATE=$$DATE^BGPMUUTL($P($G(^DGPM(BGPIEN,0)),U,1))
 S DENCT=DENCT+1 S ^TMP("BGPMU0437",$J,BGPMUTF,"DEN")=DENCT
 I EXC'="" D
 .S EXCCT=EXCCT+1 S ^TMP("BGPMU0437",$J,BGPMUTF,"EXC")=EXCCT
 .I BGPMUTF="C" S ^TMP("BGPMU0437",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DATE_U_$P(EXC,U,2)
 I EXC="" D
 .I +NUM=1 D
 ..S NUMCT=NUMCT+1 S ^TMP("BGPMU0437",$J,BGPMUTF,"NUM")=NUMCT
 ..S ^TMP("BGPMU0437",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DATE_U_$P(NUM,U,3)_U_$P(NUM,U,2)
 .I +NUM=0 D
 ..S ^TMP("BGPMU0437",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DATE_U_$P(NUM,U,3)_U_$P(NUM,U,2)
 ..S NOTCT=NOTCT+1 S ^TMP("BGPMU0437",$J,BGPMUTF,"NOT")=NOTCT
 S ^TMP("BGPMU0437",$J,BGPMUTF,"TOT")=PTCNT
 S BGPICARE("MU.STK.0437.1",BGPMUTF,DFN)=1_U_+$G(NUM)_U_+EXC_U_DATE_";"_$P($G(NUM),U,3)_";"_$P(EXC,U,2)
 Q
EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS) ;See if there are exclusions
 N REASON,BGPLOS,BGPHOS,BGPCLIN,BGPECI,DTYPE1,DTYPE2,BGPALL,BGPREF,NOXTHROM,NODTHROM,NOPTHROM
 S REASON=""
 I BGPAGEE<18 S REASON="1^AGE" Q REASON
 ;Check for LOS
 S BGPLOS=$$LOS^BGPMUH08(BGPIEN,BGPDIS)
 I BGPLOS>120 S REASON="1^LOS" Q REASON
 ;Check for clinical trial
 S BGPCLIN=$$TRIAL^BGPMUH08(DFN,BGPVST)
 I +BGPCLIN S REASON=BGPCLIN Q REASON
 ;Check for elective carotid intervention procedure
 S BGPECI=$$ELECTIVE^BGPMUH08(DFN,BGPVST,BGPIEN)
 I +BGPECI S REASON=BGPECI Q REASON
 ;Check for refusals
 S BGPREF=$$REF(DFN,BGPVST,BGPDIS)
 I +BGPREF S REASON=BGPREF Q REASON
 ;Check for reasons not initiated
 ;  Check for CPT procedure within the past 180 days
 S BGPDISDT=$P($P($G(^DGPM(BGPDIS,0)),U,1),".",1)
 S BGPDD180=$$FMADD^XLFDT(BGPDISDT,-180)
 S NOXTHROM=$$CPT^BGPMUUT1(DFN,BGPDD180,BGPDISDT,"BGPMU WARFARIN THERAPY CPT")
 I +NOXTHROM S REASON=NOXTHROM Q REASON
 ;  Check for POV within the past 180 days
 S NODTHROM=$$LASTDX^BGPMUUT2(DFN,BGPDD180,BGPDISDT,"BGPMU WARFARIN THERAPY ICD")
 I +NODTHROM S REASON=NODTHROM Q REASON
 ;  Check for Problem doc'd within the past 180 days
 S NOPTHROM=$$PLTAX^BGPMUUT1(DFN,"BGPMU WARFARIN THERAPY ICD","C")
 I +NOPTHROM D
 .S PDATE=$P(NOPTHROM,U,3)
 .I PDATE>BGPDD180 S REASON=1_U_$P(NOPTHROM,U,2)_" "_$$DATE^BGPMUUTL($P(NOPTHROM,U,3))
 Q REASON
REF(DFN,BGPVST,BGPDIS) ;Find refuals for this medication
 N ENDDT,X1,X2,X,MED,BGPEVT,DISDT
 S MED=0
 S BGPEVT=$P($G(^AUPNVSIT(BGPVST,0)),U,1)
 S DISDT=$P($G(^DGPM(BGPDIS,0)),U,1)
 S ENDDT=$$FMADD^XLFDT(DISDT,+1)
 S TAX="BGPMU TPA NDC CODES"
 S MED=$$MEDREF^BGPMUUT2(DFN,BGPEVT,ENDDT,TAX)
 Q MED
NUMER(DFN,LKW) ;Check to see if pt is in the numerator
 N TAX,MEDDTE,ENDDT,TPA,MEDIEN,STATUS,DRUG,DISPENSE
 S TPA=0
 S MEDDTE=$P(LKW,U,2)                     ;Start time is last known well
 S ENDDT=$$FMADD^XLFDT(MEDDTE,+1)    ;Don't search more than 24hrs
 F  S MEDDTE=$O(^PSB(53.79,"AADT",DFN,MEDDTE)) Q:'+MEDDTE!(MEDDTE>ENDDT)!(+TPA)  D
 .S MEDIEN="" F  S MEDIEN=$O(^PSB(53.79,"AADT",DFN,MEDDTE,MEDIEN)) Q:'+MEDIEN!(+TPA)  D
 ..S STATUS=$P($G(^PSB(53.79,MEDIEN,0)),U,9)
 ..I STATUS="G"!(STATUS="I")!(STATUS="C") D         ;Drug given
 ...S TIME=$$FMDIFF^XLFDT(MEDDTE,$P(LKW,U,2),1)     ;Lapsed time in seconds
 ...I (TIME\60)<180 D
 ....S DISPENSE=0 F  S DISPENSE=$O(^PSB(53.79,MEDIEN,.5,DISPENSE)) Q:'+DISPENSE!(+TPA)  D
 .....S DRUG=$G(^PSB(53.79,MEDIEN,.5,DISPENSE,0))
 .....S DRUG=$P(DRUG,U,1)
 .....S TAX="BGPMU TPA NDC CODES"
 .....S TPA=$$NDC^BGPMUUT4(DRUG,TAX)
 .....S:+TPA $P(TPA,U,3)=BGPDD
 Q TPA
ER(DFN,BGPADMIT,BGPVST) ;Find ER admit time since TPA is often given in the ER
 N VST,IEN,FOUND,ERDTE,NEW
 S FOUND=0,VST=0
 S IEN="" F  S IEN=$O(^AMERVSIT("AC",DFN,IEN),-1) Q:IEN=""!(+FOUND)  D
 .S ERDTE=$P($G(^AMERVSIT(IEN,0)),U,1)
 .S NEW=$$FMADD^XLFDT(BGPADMIT,-1)
 .I ERDTE>NEW&(ERDTE<BGPADMIT) S FOUND=1,VST=ERDTE
 Q VST
WELL(DFN,BGPER,BGPADMIT,BGPDD) ;Find is pt has a last known well
 N IEN,MSR,MTYP,LKW,CNT,TIME,X1,INVD
 S LKW="",CNT=0
 S MTYP="" S MTYP=$O(^AUTTMSR("B","LKW",MTYP))
 Q:MTYP="" 0
 S INVD="" F  S INVD=$O(^AUPNVMSR("AE",DFN,MTYP,INVD)) Q:INVD=""!(+CNT)  D
 .S MSR="" F  S MSR=$O(^AUPNVMSR("AE",DFN,MTYP,INVD,MSR)) Q:MSR=""!(+CNT)  D
 ..I $P($G(^AUPNVMSR(MSR,0)),U,1)=MTYP D
 ...S TIME=$P($G(^AUPNVMSR(MSR,12)),U,1)
 ...Q:TIME>BGPDD
 ...S X1=$$FMDIFF^XLFDT(BGPER,TIME,2) I (X1\60)<120 S CNT=1_U_TIME_"^ER" Q
 ...S X1=$$FMDIFF^XLFDT(BGPADMIT,TIME,2) I (X1\60)<120 S CNT=1_U_TIME_"^AD" Q
 ...I TIME>BGPADMIT S CNT=1_U_TIME_"^IN"
 Q CNT