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

BGPMUH12.m

Go to the documentation of this file.
BGPMUH12 ;IHS/MSC/MGH - MI measure NQF0373-VTE-3 ;02-Mar-2011 16:21;DU
 ;;11.0;IHS CLINICAL REPORTING;**4**;JAN 06, 2011;Build 84
 ;ED meaningful use hospital measures
 ;BGPMUH10 - VTE Measure 1 - VTE started in 24hrs of arrival
 ;BGPMUH11 - VTE Measure 2 - VTE started in 24hrs of arrival to ICU
 ;BGPMUH12 - VTE Measure 3 - VTE measure 3 - VTE pts on overlap therapy
ENTRY ;PEP  Vte measure 3 - VTE pts on overlap therapy
 ; Print routine    - VTE3^BGPMUHP7
 ; Delimited output - VTE3^BGPMUHD6
 N START,END,BGPIEN,DFN,BGPVST,BGPISDX,BGPHSDX,BGPAGEE,BGPIPROB,BGPHPROB,EXC,NUM,BGPDIS,INWAR
 N BGPER,BGPADTMI,BGPDD,EVDT,PDTE,FIRST,EXCL,OPWAR,IPWAR,EXC,BGPVCODE,BGPVTEPB,BGPVTE,BGPVICD0
 S EXC=""
 ;Start by finding all admissions during the reporting period
 S START=BGPBDATE,EXCL="",OPWAR=0,IPWAR=0
 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=""
 ..;Get the admit time & discharge times
 ..S BGPADMIT=$P($G(^DGPM(BGPIEN,0)),U,1)
 ..S BGPDD=$P($G(^DGPM(BGPDIS,0)),U,1)
 ..;Look for DX of VTE
 ..S BGPVTE=$$VSTPOVA^BGPMUUT3(DFN,BGPVST,"BGPMU VTE DX")
 ..;S BGPVTEPB=$$PLTAX^BGPMUUT1(DFN,"BGPMU VTE DX")
 ..;I (+BGPVTE!(+BGPVTEPB))&(BGPVCODE!(BGPVICD0)) D    ;Must have DX of VTE
 ..I +BGPVTE D    ;Must have DX of VTE
 ...S EXC=$$EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS,BGPADMIT)
 ...;If no exclusions see if they had Warfarin ordered at discharge
 ...I EXC="" D
 ....S OPWAR=$$OPWAR(DFN,BGPDIS)
 ....I '+OPWAR S EXC=OPWAR
 ...;If pt had warfarin in discharge, check and make sure pt had warfar on inpt
 ...I EXC="" D
 ....S INWAR=$$INWAR(DFN,BGPADMIT,BGPDD)
 ....I '+INWAR S EXC=INWAR
 ...;OK, now can evaluate overlaping therapy
 ...I EXC="" S NUM=$$NUMER(DFN,BGPADMIT,BGPDD,BGPVST)
 ...;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("BGPMU0373",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0373",$J,BGPMUTF,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0373",$J,BGPMUTF,"NUM"))
 S EXCCT=+$G(^TMP("BGPMU0373",$J,BGPMUTF,"EXC"))
 S NOTCT=+$G(^TMP("BGPMU0373",$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("BGPMU0373",$J,BGPMUTF,"DEN")=DENCT
 I EXC'="" D
 .S EXCCT=EXCCT+1 S ^TMP("BGPMU0373",$J,BGPMUTF,"EXC")=EXCCT
 .I BGPMUTF="C" S ^TMP("BGPMU0373",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DATE_U_$P(EXC,U,2)
 I EXC="" D
 .I +NUM D
 ..S NUMCT=NUMCT+1 S ^TMP("BGPMU0373",$J,BGPMUTF,"NUM")=NUMCT
 ..S ^TMP("BGPMU0373",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DATE_U_$P(NUM,U,2)_U_$P(NUM,U,4)_U_$P(NUM,U,5)_U_$P(NUM,U,3)
 .I '+NUM D
 ..S ^TMP("BGPMU0373",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DATE_U_$P(NUM,U,2)
 ..S NOTCT=NOTCT+1 S ^TMP("BGPMU0373",$J,BGPMUTF,"NOT")=NOTCT
 S ^TMP("BGPMU0373",$J,BGPMUTF,"TOT")=PTCNT
 S BGPICARE("MU.VTE.0373.1",BGPMUTF,DFN)=1_U_+$G(NUM)_U_+EXC_U_DATE_";"_$P($G(NUM),U,2)_","_$P($G(NUM),U,4)_","_$P($G(NUM),U,5)_","_$P($G(NUM),U,3)_";"_$P(EXC,U,2)
 Q
EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS,BGPADMIT,OPWAR,IPWAR) ;See if there are exclusions
 N REASON,BGPLOS,BGPHOS,BGPCLIN,BGPECI,BGPALL,BGPREF,MED,PHARM,PHARMP,MECH,MECHP,FIRST,CPT
 N BGPVCODE,BGPRCODE,BGPVICD0
 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 palliative Care
 S BGPHOS=$$HOSPICE^BGPMUH08(DFN,BGPVST)
 I +BGPHOS S REASON=BGPHOS Q REASON
 ;Check for clinical trial
 S BGPCLIN=$$TRIAL^BGPMUH08(DFN,BGPVST)
 I +BGPCLIN S REASON=BGPCLIN Q REASON
 S BGPVCODE=$$VSTCPT^BGPMUUT1(DFN,BGPVST,"BGPMU VTE TEST CPT")
 S BGPRCODE=$$FIND^BGPMUUT7(DFN,"BGPMU VTE TEST CPT",BGPADMIT,BGPDD) ;RAD procedure check
 ;S BGPVICD0=$$VSTICD0^BGPMUUT3(DFN,BGPVST,"BGPMU VTE TEST ICD0")  ;not in ORT
 ;I '+BGPRCODE&('BGPVCODE)&('+BGPVICD0) S REASON="1^No VTE Proc"
 I '+BGPRCODE&('BGPVCODE) S REASON="1^No VTE Proc"
 Q REASON
NUMER(DFN,ADMIT,DISCH,TVST) ;Check to see if pt is in the numerator
 N TAX,MEDDTE,ENDDT,MEDIEN,STATUS,DRUG,DISPENSE,INR,RETURN
 N LABDATA,WARDATA,INJDATA,OVER,X,CNT
 S RETURN=0
 ;Get return list of INRs between admit and discharge
 S TAX="BGPMU LAB LOINC INR"
 D LAB^BGPMUUT5(.LABDATA,DFN,TAX,ADMIT,DISCH)
 ;Get array of inpt dates for which Warfarin was active
 S TAX="BGPMU WARFARIN NDCS"
 D MEDLIST(.WARDATA,DFN,ADMIT,DISCH,TAX)
 ;Get array of inpt dates for which concurrent anticoag therapy was active
 S TAX="BGPMU VTE ANTICOAG NDCS"
 D MEDLIST(.INJDATA,DFN,ADMIT,DISCH,TAX)
 ;Now loop through the list of warfarin dates and see if a corresponding
 ;date exists in the injectable list. If it does, increment the count of days
 ;If it doesn't, start over
 S CNT=0
 S X=0 F  S X=$O(WARDATA(X)) Q:X=""  D
 .I $D(INJDATA(X)) S CNT=CNT+1
 ;If the count >4, then check the latest INR to see if it was >2
 I CNT=0 Q 0 ;No overlap therapy
 I CNT>4 D
 .S INR=$$INRCK(.LABDATA,BGPDD)
 .I $P(INR,U,1)>1.99999 S RETURN=1_U_CNT_U_U_INR
 .;If its less then 2, must go home on concurrent therapy
 .I $P(INR,U,1)<2.0 D
 ..S OVER=$$OPINJ(DFN,BGPDIS)
 ..I OVER S RETURN=1_U_CNT_U_BGPDD_U_INR
 ;If the count <5, check for an outpt RX for overlap med
 I CNT<5 D
 .S INR=$$INRCK(.LABDATA,BGPDD)
 .S OVER=$$OPINJ(DFN,BGPDIS)
 .I OVER S RETURN=1_U_CNT_U_BGPDD_U_INR
 Q RETURN
OPWAR(DFN,BGPDIS) ;Check to see if pt was discharged on Warfarin
 N DRUG,TAX,MEDTYPE,DDATE
 S MEDTYPE="OP",TAX="BGPMU WARFARIN NDCS"
 S DDATE=$P($G(^DGPM(BGPDIS,0)),U,1)
 S DRUG=$$FIND^BGPMUUT4(DFN,TAX,DDATE,MEDTYPE)
 Q DRUG
INWAR(DFN,BGPADMIT,BGPDD) ;Check to see if Warfarin given in inpt
 N DRUG,TAX,MEDTYPE
 S MEDTYPE="UD",TAX="BGPMU WARFARIN NDCS"
 S DRUG=$$FIND^BGPMUUT4(DFN,TAX,BGPADMIT,MEDTYPE,BGPDD)
 Q DRUG
MEDLIST(ARRAY,DFN,BGPADMIT,BGPDD,TAX) ;Check each day of inpt stay to see if med active
 N DRUG,MEDTYPE,BDATE,EDATE,DDATE,I,START,END
 S MEDTYPE="UD"
 ;Only use the date portion
 S BDATE=$P(BGPADMIT,".",1),EDATE=$$FMADD^XLFDT($P(BGPDD,".",1),1)
 S START=$$FMADD^XLFDT(BDATE,-1)
 F  S START=$$FMADD^XLFDT(START,1) Q:START>EDATE  D
 .S END=$$FMADD^XLFDT(START,+1)
 .S DRUG=$$FIND^BGPMUUT6(DFN,TAX,START,MEDTYPE,END)
 .I +DRUG S ARRAY(START)=DRUG
 S MEDTYPE="IV"
 S BDATE=$P(BGPADMIT,".",1),EDATE=$$FMADD^XLFDT($P(BGPDD,".",1),1)
 S START=$$FMADD^XLFDT(BDATE,-1)
 F  S START=$$FMADD^XLFDT(START,1) Q:START>EDATE  D
 .S END=$$FMADD^XLFDT(START,+1)
 .S DRUG=$$FIND^BGPMUUT6(DFN,TAX,START,MEDTYPE,END)
 .I +DRUG S ARRAY(START)=DRUG
 Q
OPINJ(DFN,BGPDIS) ;Check to see if pt was discharged on concurrent therapy
 N DRUG,TAX,MEDTYPE,DDATE
 S MEDTYPE="OP",TAX="BGPMU VTE ANTICOAG NDCS"
 S DDATE=$P($G(^DGPM(BGPDIS,0)),U,1)
 S DRUG=$$FIND^BGPMUUT4(DFN,TAX,DDATE,MEDTYPE)
 Q DRUG
INRCK(LABS,BGPDD) ;Find the INR prior to discharge date
 N VALUE,X,CK
 S VALUE=0
 S X="" F  S X=$O(LABS(X)) Q:'+X!(+VALUE)  D
 .S CK=9999999-X
 .Q:CK>BGPDD
 .I CK<BGPDD S VALUE=$G(LABS(X))
 Q VALUE_U_$$DATE^BGPMUUTL(CK)