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

BUDDRP6U.m

Go to the documentation of this file.
BUDDRP6U ; IHS/CMI/LAB - UDS REPORT PROCESSOR ;
 ;;11.0;IHS/RPMS UNIFORM DATA SYSTEM;;JAN 18, 2017;Build 66
 ;
 ;
H ;EP ; ASTHMA
 S BUDDOB=$P(^DPT(DFN,0),U,3)
 S BUD64RB=($E(BUDBD,1,3)-64)_"0101"
 S BUD5RB=($E(BUDED,1,3)-5)_"1231"
 Q:BUDDOB>BUD5RB
 Q:BUDDOB<BUD64RB
 S Z=($E(BUDDOB,1,3)+5)_$E(BUDDOB,4,7)
 Q:$$VD^APCLV(BUDLASTV)<Z
 S Z=($E(BUDDOB,1,3)+65)_$E(BUDDOB,4,7)
 Q:$$VD^APCLV(BUDLASTV)'<Z
 Q:BUDMEDV<1
 ;
 S BUDAST=$$ASTHMA(DFN,BUDBD,BUDED)  ;no diagnosis of asthma during time period
 I BUDAST="" Q  ;no dx of peristent asthma and no pl entry
 Q:$$EXCL(DFN,$$DOB^AUPNPAT(P),BUDED)  ; had exclusion dx
 Q:$$AST1039(DFN,$P(BUDAST,U,2),BUDED)]""  ;had a 1039f after the asthma dx/1038f
 Q:$$SABA(DFN,BUDBD,BUDED)  ;if only SABA, quit
 ;numerator
 S BUDASTT=$$ASTHTHER(DFN,BUDBD,BUDED)
 I BUDASTT]"" S BUDSECTH("APT")=$G(BUDSECTH("APT"))+1
 ;put the rest in demoninator
 S BUDSECTH("PTS")=$G(BUDSECTH("PTS"))+1 D
 .I $G(BUDAPT2L) D
 ..I BUDASTT="" S ^XTMP("BUDDRP6B",BUDJ,BUDH,"APT2",BUDAGE,$P(^DPT(DFN,0),U),BUDCCOM,DFN)=$P(BUDAST,U)_U_$P(BUDASTT,U,2)
 .I $G(BUDAPT1L) D
 ..I BUDASTT]"" S ^XTMP("BUDDRP6B",BUDJ,BUDH,"APT1",BUDAGE,$P(^DPT(DFN,0),U),BUDCCOM,DFN)=$P(BUDAST,U)_U_$P(BUDASTT,U,2)
 Q
SABA(P,BD,ED) ;
 NEW BUDMEDS1,G,A,C,M,V,V1D,BGPHSABA
 S G="",BGPHSABA=""
 D GETMEDS^BUDDUTL2(P,BD,ED,"BGP PQA SABA MEDS","BGP PQA SABA NDC",,,.BUDMEDS1)
 I '$D(BUDMEDS1) Q G  ; no SABA meds
 S BUDISD=""
 S A=0,C="" F  S A=$O(BUDMEDS1(A)) Q:A'=+A!(C)  D
 .S M=$P(BUDMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BUDMEDS1(A) Q
 .I $$STATDC(M) K BUDMEDS1(A) Q  ;d/c'ed BY PROVIDER OR EDIT
 .S V=$P(BUDMEDS1(A),U,5)
 .S V1D=$$VD^APCLV(V)
 .S C=1_U_$$VAL^XBDIQ1(9000010.14,M,.01)_" on "_$$FMTE^XLFDT(V1D)
 I C S BGPHSABA=1
 I 'BGPHSABA Q ""
 S G=""
 D GETMEDS^BUDDUTL2(P,BD,ED,"BGP PQA CONTROLLER MEDS","BGP PQA CONTROLLER NDC",,,.BUDMEDS1)
 I '$D(BUDMEDS1) Q 1  ; no CONTROLLER meds BUT HAS SABA
 S BUDISD=""
 S A=0,C="" F  S A=$O(BUDMEDS1(A)) Q:A'=+A!(C)  D
 .S M=$P(BUDMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BUDMEDS1(A) Q
 .I $$STATDC(M) K BUDMEDS1(A) Q  ;d/c'ed BY PROVIDER OR EDIT
 .S V=$P(BUDMEDS1(A),U,5)
 .S V1D=$$VD^APCLV(V)
 .S C=1_U_$$VAL^XBDIQ1(9000010.14,M,.01)_" on "_$$FMTE^XLFDT(V1D)
 I C Q 0
 Q 1
ASTALG(P,ED) ;
 ;allergy tracking
 NEW BUDD,X,N,G,Y,T,T1,S,A,B,C
 S T=$O(^ATXAX("B","BGP PQA CONTROLLER MEDS",0))
 S T1=$O(^ATXAX("B","BGP PQA CONTROLLER NDC",0))
 S BUDD=0
 S X=0 F  S X=$O(^GMR(120.8,"B",P,X)) Q:X'=+X!(BUDD)  D
 .Q:$P($P($G(^GMR(120.8,X,0)),U,4),".")>ED  ;entered after end date
 .S N=$P($G(^GMR(120.8,X,0)),U,3)
 .;IF PSDRUG CHECK AGAINST MEDS TAXONOMY
 .I N["PSDRUG"!(N["PSNDF") D
 ..S Y=+N
 ..I T,$D(^ATXAX(T,21,"AA",Y)) S BUDD=1
 ..S D=$P($G(^PSDRUG(Y,2)),U,4)
 ..I D,$D(^ATXAX(T1,21,"AA",D)) S BUDD=1
 .;check name for the heck of it
 .S S=$P(^GMR(120.8,X,0),U,2)   ;NAME OF THING THEY ARE ALLERGIC TO
 .S A=0 F  S A=$O(^ATXAX(T,21,A)) Q:A'=+A  D
 ..S B=$P($G(^ATXAX(T,21,A,0)),U,1)
 ..I $P($G(^PSDRUG(B,0)),U,1)=S S BUDD=1 Q
 Q BUDD
 ;
PROBAS1(P,BDATE,EDATE) ;EP
 NEW S,A,B,T,X,G,V,Y,Z
 S G=""
 S T=$O(^ATXAX("B","BGP ASTHMA DXS",0))
 S X=0,G="" F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X  D
 .S Z=$P(^AUPNPROB(X,0),U,13)
 .I Z="" S Z=$P(^AUPNPROB(X,0),U,8)
 .Q:Z>EDATE
 .S Y=$P(^AUPNPROB(X,0),U)
 .Q:$P(^AUPNPROB(X,0),U,12)="D"
 .Q:'$$ICD^ATXCHK(Y,T,9)
 .Q:$P(^AUPNPROB(X,0),U,15)=""
 .S G(9999999-$P(^AUPNPROB(X,0),U,3))=$P(^AUPNPROB(X,0),U,15)
 .Q
 S X=$O(G(0)) I X Q G(X)
 S EDATE1=9999999-EDATE-1
 S D=$O(^AUPNVAST("AS",P,EDATE1))
 I 'D Q ""
 S LAST="",E=0 F  S E=$O(^AUPNVAST("AS",P,D,E)) Q:E'=+E  S LAST=E
 I 'LAST Q ""
 S S=^AUPNVAST("AS",P,D,LAST)
 Q S
 ;
ASTHMA(P,BDATE,EDATE) ;EP
 NEW BUDVS,TIEN,CTR,VIEN,VDATE,X,Y,Z,BUDAST
 K BUDAST
 D ALLV^APCLAPIU(P,BDATE,EDATE,"BUDVS")
 S TIEN=$O(^BUDDTSSC("B","T6B ASTHMA PERSISTENT CODES",0))
 S CTR=0 F  S CTR=$O(BUDVS(CTR)) Q:CTR'=+CTR  D
 .S VIEN=$P(BUDVS(CTR),U,5)
 .S VDATE=$P(BUDVS(CTR),U,1)
 .;CPT
 .S X=0 F  S X=$O(^AUPNVCPT("AD",VIEN,X)) Q:X'=+X  D
 ..Q:'$D(^AUPNVCPT(X,0))
 ..S Y=$$VAL^XBDIQ1(9000010.18,X,.01)
 ..Q:Y=""
 ..I $D(^BUDDTSSC("AC",Y,TIEN)) S BUDAST(9999999-VDATE)=Y_U_$$DATE^BUDDUTL1(VDATE)_U_VDATE Q
 .;V TRANS
 .S X=0 F  S X=$O(^AUPNVTC("AD",VIEN,X)) Q:X'=+X  D
 ..Q:'$D(^AUPNVTC(X,0))
 ..S Y=$$VAL^XBDIQ1(9000010.33,X,.07)
 ..Q:Y=""
 ..I $D(^BUDDTSSC("AC",Y,TIEN)) S BUDAST(9999999-VDATE)=Y_U_$$DATE^BUDDUTL1(VDATE)_U_VDATE Q
 .;POV/SNOMED
 .S X=0 F  S X=$O(^AUPNVPOV("AD",VIEN,X)) Q:X'=+X  D
 ..Q:'$D(^AUPNVPOV(X,0))
 ..S Y=$$VALI^XBDIQ1(9000010.07,X,.01) I $D(^BUDDTSSC("AD",Y,TIEN)) S BUDAST(9999999-VDATE)=$$VAL^XBDIQ1(9000010.07,X,.01)_U_$$DATE^BUDDUTL1(VDATE)_U_VDATE Q
 ..S Y=$$VAL^XBDIQ1(9000010.07,X,1101)
 ..Q:Y=""
 ..I $D(^BUDDTSSC("AS",Y,TIEN)) S BUDAST(9999999-VDATE)=Y_U_$$DATE^BUDDUTL1(VDATE)_U_VDATE Q
 I $O(BUDAST(0)) S X=$O(BUDAST(0)),X=BUDAST(X) Q $P(X,U,1)_" on "_$P(X,U,2)_U_$P(X,U,3)
 S Y=$$PLCL^BUDDDU(P,"T6B ASTHMA PERSISTENT CODES",EDATE,1)
 I Y Q "PL "_$P(Y,U,2)_" on "_$$DATE^BUDDUTL1($P(Y,U,3))_U_$P(X,U,3)
 Q ""
EXCL(P,BDATE,EDATE) ;EP - EMPHYSEMA, COPD, CYSTIC FIBROSIS, ARF
 NEW BUDVS,TIEN,CTR,VIEN,VDATE,X,Y,Z,BUDEX
 S BUDEX=0
 D ALLV^APCLAPIU(P,BDATE,EDATE,"BUDVS")
 S TIEN=$O(^BUDDTSSC("B","T6B ASTHMA EXCLUSION CODES",0))
 S CTR=0 F  S CTR=$O(BUDVS(CTR)) Q:CTR'=+CTR!(BUDEX)  D
 .S VIEN=$P(BUDVS(CTR),U,5)
 .S VDATE=$P(BUDVS(CTR),U,1)
 .;POV/SNOMED
 .S X=0 F  S X=$O(^AUPNVPOV("AD",VIEN,X)) Q:X'=+X!(BUDEX)  D
 ..Q:'$D(^AUPNVPOV(X,0))
 ..S Y=$$VALI^XBDIQ1(9000010.07,X,.01) I $D(^BUDDTSSC("AD",Y,TIEN)) S BUDEX=1 Q
 ..S Y=$$VAL^XBDIQ1(9000010.07,X,1101)
 ..Q:Y=""
 ..I $D(^BUDDTSSC("AS",Y,TIEN)) S BUDEX=1 Q
 I BUDEX Q 1
 S Y=$$PLCL^BUDDDU(P,"T6B ASTHMA EXCLUSION CODES",EDATE,1)
 I Y Q 1
 Q ""
 ;
AST1039(P,BDATE,EDATE) ;EP
 I '$D(^AUPNVSIT("AC",P)) Q ""
 NEW A,B,E,T,G,X,V,Y
 K G
 S A="^TMP($J,""A"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"A",1)) Q ""
 S Y=""
 S Y=$$CPTI^BUDDDU(P,BDATE,EDATE,$P($$CPT^ICPTCOD("1039F"),U,1))
 I Y S G($P(Y,U,2))="CPT: 1039F"
 S Y=$O(G(""),-1) I Y="" Q ""
 S X=G(Y)
 Q X_" on "_$$FMTE^XLFDT(Y)_U_Y
ASTHTHER(P,BD,ED) ;
 NEW BUDMEDS1,G,A,C,M,V,V1D
 S G=""
 D GETMEDS^BUDDUTL2(P,BD,ED,"BGP PQA CONTROLLER MEDS","BGP PQA CONTROLLER NDC",,,.BUDMEDS1)
 I '$D(BUDMEDS1) Q G  ; no CONTROLLER meds
 S BUDISD=""
 S A=0,C="" F  S A=$O(BUDMEDS1(A)) Q:A'=+A!(C)  D
 .S M=$P(BUDMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BUDMEDS1(A) Q
 .I $$STATDC(M) K BUDMEDS1(A) Q  ;d/c'ed BY PROVIDER OR EDIT
 .S V=$P(BUDMEDS1(A),U,5)
 .S V1D=$$VD^APCLV(V)
 .S C=1_U_$$VAL^XBDIQ1(9000010.14,M,.01)_" on "_$$FMTE^XLFDT(V1D)
 I C Q C
 Q ""
 ;
STATDC(V) ;EP - is the prescription associated with this V MED discontinued?
 I '$G(V) Q ""
 I '$D(^AUPNVMED(V,0)) Q 0
 NEW P,S,X
 S P=$S($D(^PSRX("APCC",V)):$O(^(V,0)),1:0)
 I 'P Q 0
 S X=$P($G(^PSRX(P,0)),U,15)
 I X=12 Q 1
 I X=13 Q 1
 I X=14 Q 1
 I X=15 Q 1
 S X=$P($G(^PSRX(P,"STA")),U,1)
 I X=12 Q 1
 I X=13 Q 1
 I X=14 Q 1
 I X=15 Q 1
 Q 0
GETV(P,BD,ED,SITE) ;EP - get all visits for this patient and COUNT MEDICAL VISITS
 NEW TV,T35V,T6V,MEDV,MEDVI,LASTV,A,X,VLOC,CLINC,TIEN,VSIT,VDATE,PP,S,LINE,D
 S TV=0,T35V=0,T6V=0,MEDV=0,MEDVI="",LASTV=""
 S A="A(""VISITS"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED),E=$$START1^APCLDF(B,A)
 S X=0 F  S X=$O(A("VISITS",X)) Q:X'=+X!(MEDV>1)  S VSIT=$P(A("VISITS",X),U,5) D
 .Q:'$D(^AUPNVSIT(VSIT,0))
 .Q:'$P(^AUPNVSIT(VSIT,0),U,9)
 .Q:$P(^AUPNVSIT(VSIT,0),U,11)
 .S VLOC=$P(^AUPNVSIT(VSIT,0),U,6)
 .Q:VLOC=""
 .Q:'$D(^BUDDSITE(SITE,11,VLOC))  ;not valid location
 .Q:"AHSORMI"'[$P(^AUPNVSIT(VSIT,0),U,7)
 .S CLINC=$$CLINIC^APCLV(VSIT,"C")
 .S TIEN=$O(^BUDDCNTL("B","UDS PT/TABLE 5 CLINIC EXCL",0))
 .I CLINC]"",$D(^BUDDCNTL(TIEN,11,"B",CLINC)) Q
 .;now eliminate subsequent visits to same provider on same day  = item 4 in SRD visit definition
 .S VDATE=$$VD^APCLV(VSIT)
 .S PP=$$PRIMPROV^APCLV(VSIT,"I")
 .I PP="" Q  ;no primary provider
 .I $P(^AUPNVSIT(VSIT,0),U,7)="I" Q  ;don't count I visits
 .I '$D(^AUPNVPOV("AD",VSIT)) Q
 .S S=0
 .I PP]"" D
 ..S D=$P($G(A("SAMEPROV",P,VDATE,PP)),U,1)
 ..I D]"",D'>$P(^AUPNVSIT(VSIT,0),U) S S=1 Q  ;already had a visit to this provider on this date
 ..S A("SAMEPROV",P,VDATE,PP)=$P(^AUPNVSIT(VSIT,0),U)_U_VSIT
 .Q:S  ;quit if already had a visit to this provider
 .S PP=$$PRIMPROV^APCLV(VSIT,"D")
 .I PP="" Q
MEDC .;NOW CHECK FOR MEDICAL CARE, CAN ONLY HAVE 1 PER LOCATION OF ENCOUNTER
 .S S=0
 .S TIEN=$O(^BUDDCNTL("B","MEDICAL CARE LINE NUMBERS",0))
 .;S PP=$$PRIMPROV^APCLV(VSIT,"D")
 .I $E($$VAL^XBDIQ1(9000010,VSIT,.06),1,3)="CHS",PP=15 S LINE=2 G MEDC1
 .S Y=$O(^BUDDTFIV("C",PP,0)) I Y="" S LINE=35 G MEDC1
 .S LINE=$O(^BUDDTFIV("AA",PP,""))
MEDC1 .S S=0
 .I $D(^BUDDCNTL(TIEN,11,"B",LINE)) D
 ..S D=$P($G(A("MEDCARE",P,VDATE,VLOC,TIEN)),U,1)
 ..I D]"",D'>$P(^AUPNVSIT(VSIT,0),U) S S=1 Q  ;already have a medical care visit on this date
 ..S A("MEDCARE",P,VDATE,VLOC,TIEN)=$P(^AUPNVSIT(VSIT,0),U)_U_VSIT
 ..S MEDV=MEDV+1,MEDVI=VSIT
 ..Q
 Q MEDV
PREVV(P,BDATE,EDATE) ;EP
 ;GO THROUGH UDS PATIENT VISITS AND CHECK CPT CODES
 NEW X,Y,V,Z,G,T,C
 S T=$O(^BUDDTSSC("B","T6B TOBACCO PREVENTATIVE CODES",0))
 S G="",C=0
 S X=0 F  S X=$O(^TMP($J,"VISITSUDSPT",X)) Q:X'=+X!(G)  D
 .S Z=0 F  S Z=$O(^AUPNVCPT("AD",X,Z)) Q:Z'=+Z!(G)  D
 ..S Y=$$VAL^XBDIQ1(9000010.18,Z,.01)
 ..I $D(^BUDDTSSC("AC",Y,T)) S G=1 Q
 .S Z=0 F  S Z=$O(^AUPNVPOV("AD",X,Z)) Q:Z'=+Z!(G)  D
 ..S Y=$$VALI^XBDIQ1(9000010.07,Z,.01)
 ..I $D(^BUDDTSSC("AD",Y,T)) S G=1 Q
 ..S Y=$$VAL^XBDIQ1(9000010.07,Z,1101)
 ..Q:Y=""
 ..I $D(^BUDDTSSC("AS",Y,T)) S G=1 Q
 .I G S C=C+1
 Q C