BUD2RP6O ; IHS/CMI/LAB - UDS REPORT PROCESSOR 01 Dec 2012 5:11 PM ;
;;10.0;IHS/RPMS UNIFORM DATA SYSTEM;;FEB 04, 2016;Build 50
;
;
I ;EP ;CAD
S BUDDOB=$P(^DPT(DFN,0),U,3)
S BUD18RB=($E(BUDBD,1,3)-18)_"1231"
Q:BUDDOB>BUD18RB
Q:BUDMEDV<1
S BUD18TH=$E(BUDDOB,1,3)+18_$E(BUDDOB,4,7)
Q:BUDMEDV<1
S X=$$GETV(DFN,BUDDOB,BUDED,BUDSITE)
Q:X<2 ;MUST HAVE 2 MEDICAL VISITS EVER
I BUD18TH'=BUDED,'$$VBBD^BUD2RP6V(DFN,$$FMADD^XLFDT(BUD18TH,1),BUDED) Q ;quit if no visiT AFTER 18TH BIRTHDAY
I BUD18TH=BUDED,'$$VBBD^BUD2RP6V(DFN,BUD18TH,BUDED) Q ;quit if no visiT AFTER 18TH BIRTHDAY
S BUDCADVU=$$CAD(DFN,BUDBD,BUDED) ;return date of problem list or visit date during report period
Q:BUDCADVU="" ;no CAD diagnosis
S BUDLDL=$$LDL(DFN,BUDBD,BUDED)
I BUDLDL]"",$P(BUDLDL,U,1)<130 Q ;
I BUDLDL="" S BUDLDL=$$LDL(DFN,$$FMADD^XLFDT($$VD^APCLV(BUDLASTV),-365),$$VD^APCLV(BUDLASTV)) Q ;no LDL per Duane and Chris
I BUDLDL="" Q
I $P(BUDLDL,U,1)<130 Q
S X=$$LIPIDALG(DFN,BUDED) I X S ^XTMP("BUD2RP6B",BUDJ,BUDH,"ALG","CAD2",BUDAGE,$P(^DPT(DFN,0),U),BUDCOM,DFN)=$P(BUDCADVU,U)_U_$P(X,U,2)_U_BUDLDL Q ;eliminate those with an allergy to a LIPID LOWERING DRUG
;I BUDCADVU="" S X="",X=$$LIPITHER(DFN,BUDBD,BUDED) I X]"" S ^XTMP("BUD2RP6B",BUDJ,BUDH,"ALG","CAD2",BUDAGE,$P(^DPT(DFN,0),U),BUDCOM,DFN)=$P(BUDCADVU,U)_U_$P(X,U,2) Q
S BUDCADT=$$LIPITHER(DFN,BUDBD,BUDED)
I BUDCADT]"" S BUDSECTI("CAD")=$G(BUDSECTI("CAD"))+1
;put the rest in demoninator
S BUDSECTI("PTS")=$G(BUDSECTI("PTS"))+1 D
.I $G(BUDCAD2L) D
..I BUDCADT="" S ^XTMP("BUD2RP6B",BUDJ,BUDH,"CAD2",BUDAGE,$P(^DPT(DFN,0),U),BUDCOM,DFN)=$P(BUDCADVU,U)_U_$P(BUDCADT,U,2)_U_BUDLDL
.I $G(BUDCAD1L) D
..I BUDCADT]"" S ^XTMP("BUD2RP6B",BUDJ,BUDH,"CAD1",BUDAGE,$P(^DPT(DFN,0),U),BUDCOM,DFN)=$P(BUDCADVU,U)_U_$P(BUDCADT,U,2)_U_BUDLDL
Q
LIPIDALG(P,ED) ;
;allergy tracking
NEW BUDC,X,N,G,Y,T,T1,S,A,B,C
S T=$O(^ATXAX("B","BUD LIPID LOWERING MEDS",0))
S T1=$O(^ATXAX("B","BGPMU LIPID LOWERING NDCS",0))
S BUDC=0
S X=0 F S X=$O(^GMR(120.8,"B",P,X)) Q:X'=+X!(BUDC) 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" D Q
..S Y=+N
..I T,$D(^ATXAX(T,21,"AA",Y)) S BUDC=1_U_"ALG: "_$P(^PSDRUG(Y,0),U,1) Q
..S D=$P($G(^PSDRUG(Y,2)),U,4),D=$$STRIP^XLFSTR(D,"-")
..I D,$D(^ATXAX(T1,21,"AA",D)) S BUDC=1_U_"ALG: "_$P(^PSDRUG(Y,0),U,1)
.I N["PSNDF" D
..S Y=$P(^GMR(120.8,X,0),U,2) ;drug name
..S Y=$O(^PSDRUG("B",Y,0)) ;drug ien
..Q:'Y
..I T,$D(^ATXAX(T,21,"AA",Y)) S BUDC=1_U_"ALG: "_$P(^PSDRUG(Y,0),U,1) Q
..S D=$P($G(^PSDRUG(Y,2)),U,4),D=$$STRIP^XLFSTR(D,"-")
..I D,$D(^ATXAX(T1,21,"AA",D)) S BUDC=1_U_"ALG: "_$P(^PSDRUG(Y,0),U,1)
..;CHECK NAME OF DRUG IN DRUG FILE/TAXONOMY
Q BUDC
;
PROBCAD(P,BDATE,EDATE) ;EP
NEW S,A,B,T,X,G,V,Y,Z
S G=""
S T=$O(^ATXAX("B","BUD CAD 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 ;DATE OF ONSET AFTER END DATE
.S Y=$P(^AUPNPROB(X,0),U)
.Q:$P(^AUPNPROB(X,0),U,12)'="A" ;MUST BE ACTIVE
.Q:'$$ICD^ATXCHK(Y,T,9)
.S G=X
.Q
I G="" Q G
Q $$FMTE^XLFDT($P(^AUPNPROB(G,0),U,3))_" Prob: "_$$VAL^XBDIQ1(9000011,G,.01)_U_G
;
CAD(P,BDATE,EDATE) ;EP
NEW A,B,E,T,G,X,V,Y,BUDVS,T1
K G
S A="BUDVS(",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
S T=$O(^ATXAX("B","BUD CAD DXS",0))
S T1=$O(^ATXAX("B","BUD CARDIAC SURGERY DXS",0))
I 'T Q ""
S X=0,G="" F S X=$O(BUDVS(X)) Q:X'=+X S V=$P(BUDVS(X),U,5) D
.Q:'$D(^AUPNVSIT(V,0))
.Q:'$P(^AUPNVSIT(V,0),U,9)
.Q:$P(^AUPNVSIT(V,0),U,11)
.Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
.S (D,Y)=0 F S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y D
..S D=0
..I $D(^AUPNVPOV(Y,0)) S %=$P(^AUPNVPOV(Y,0),U)
..I $$ICD^ATXCHK(%,T,9) S D=1
..I $$ICD^ATXCHK(%,T1,9) S D=1
..Q:'D
..S G($$VD^APCLV(V))=$$VAL^XBDIQ1(9000010.07,Y,.01)
..Q
S Y=$O(G(""),-1)
;W !,P," ",Y," " ZW G
I Y S X=G(Y) Q $$FMTE^XLFDT(Y)_" "_X_U_Y
S Y=$$CPT^BUD2DU(P,$$DOB^AUPNPAT(P),EDATE,$O(^ATXAX("B","BUD CAD CPTS",0)),5)
I Y Q $$FMTE^XLFDT($P(Y,U,1))_" CPT: "_$P(Y,U,2)
S Y=$$LASTPRC^BUD2UTL1(P,"BUD CABG PTCA PROCS",$$DOB^AUPNPAT(P),EDATE)
I Y]"" Q $$FMTE^XLFDT($P(Y,U,3))_" PROC: "_$P(Y,U,2)
S Y=$$PROBCAD(P,BDATE,EDATE)
I Y]"" Q Y
Q ""
LIPITHER(P,BD,ED) ;
NEW BUDMEDS1,G,A,C,M,V,V1D
S G=""
D GETMEDS^BUD2UTL2(P,BD,ED,"BUD LIPID LOWERING MEDS","BGPMU LIPID LOWERING NDCS",,,.BUDMEDS1)
I '$D(BUDMEDS1) Q G ; no 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(^BUDRSITE(SITE,11,VLOC)) ;not valid location
.Q:"AHSORMEI"'[$P(^AUPNVSIT(VSIT,0),U,7)
.S CLINC=$$CLINIC^APCLV(VSIT,"C")
.S TIEN=$O(^BUDRCNTL("B","FIRST LEVEL CLINIC EXCLUSIONS",0))
.I CLINC]"",$D(^BUDRCNTL(TIEN,11,"B",CLINC)) Q ;not a clinic code we want in any table
.;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 $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(^BUDRCNTL("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(^BUDRTFIV("C",PP,0)) I Y="" S LINE=35 G MEDC1
.S LINE=$O(^BUDRTFIV("AA",PP,""))
MEDC1 .S S=0
.I $D(^BUDRCNTL(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
LDL(P,BDATE,EDATE,NORES) ;EP
NEW BUDG,BUDT,BUDC,BUDLT,T,B,E,D,L,X,R,G,C,%
K BUDG,BUDT,BUDC
S BUDC=0
S NORES=$G(NORES)
;now get all loinc/taxonomy tests
S T=$O(^ATXAX("B","BGP LDL LOINC CODES",0))
S BUDLT=$O(^ATXLAB("B","DM AUDIT LDL CHOLESTEROL TAX",0))
S B=9999999-BDATE,E=9999999-EDATE S D=E-1 F S D=$O(^AUPNVLAB("AE",P,D)) Q:D'=+D!(D>B) D
.S L=0 F S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L D
..S X=0 F S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X D
...Q:'$D(^AUPNVLAB(X,0))
...Q:$P(^AUPNVLAB(X,0),U,4)=""
...S R=$P(^AUPNVLAB(X,0),U,4) I R'=+R Q ;must be a number
...I BUDLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BUDLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BUDC=BUDC+1,BUDT(D,BUDC)=$P(^AUPNVLAB(X,0),U,4) Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S R=$P(^AUPNVLAB(X,0),U,4)
...I 'R S R=""
...S BUDC=BUDC+1,BUDT(D,BUDC)=R
...Q
; now got though and set return value of done 1 or 0^VALUE^date
S D=0,G="" F S D=$O(BUDT(D)) Q:D'=+D!(G]"") D
.S C=0 F S C=$O(BUDT(D,C)) Q:C'=+C!(G]"") D
..S X=BUDT(D,C)
..I X="" Q
..S G=X_U_(9999999-D)
..Q
Q G
;
LOINC(A,B) ;EP
NEW %
S %=$P($G(^LAB(95.3,A,9999999)),U,2)
I %]"",$D(^ATXAX(B,21,"B",%)) Q 1
S %=$P($G(^LAB(95.3,A,0)),U)_"-"_$P($G(^LAB(95.3,A,0)),U,15)
I $D(^ATXAX(B,21,"B",%)) Q 1
Q ""
BUD2RP6O ; IHS/CMI/LAB - UDS REPORT PROCESSOR 01 Dec 2012 5:11 PM ;
+1 ;;10.0;IHS/RPMS UNIFORM DATA SYSTEM;;FEB 04, 2016;Build 50
+2 ;
+3 ;
I ;EP ;CAD
+1 SET BUDDOB=$PIECE(^DPT(DFN,0),U,3)
+2 SET BUD18RB=($EXTRACT(BUDBD,1,3)-18)_"1231"
+3 IF BUDDOB>BUD18RB
QUIT
+4 IF BUDMEDV<1
QUIT
+5 SET BUD18TH=$EXTRACT(BUDDOB,1,3)+18_$EXTRACT(BUDDOB,4,7)
+6 IF BUDMEDV<1
QUIT
+7 SET X=$$GETV(DFN,BUDDOB,BUDED,BUDSITE)
+8 ;MUST HAVE 2 MEDICAL VISITS EVER
IF X<2
QUIT
+9 ;quit if no visiT AFTER 18TH BIRTHDAY
IF BUD18TH'=BUDED
IF '$$VBBD^BUD2RP6V(DFN,$$FMADD^XLFDT(BUD18TH,1),BUDED)
QUIT
+10 ;quit if no visiT AFTER 18TH BIRTHDAY
IF BUD18TH=BUDED
IF '$$VBBD^BUD2RP6V(DFN,BUD18TH,BUDED)
QUIT
+11 ;return date of problem list or visit date during report period
SET BUDCADVU=$$CAD(DFN,BUDBD,BUDED)
+12 ;no CAD diagnosis
IF BUDCADVU=""
QUIT
+13 SET BUDLDL=$$LDL(DFN,BUDBD,BUDED)
+14 ;
IF BUDLDL]""
IF $PIECE(BUDLDL,U,1)<130
QUIT
+15 ;no LDL per Duane and Chris
IF BUDLDL=""
SET BUDLDL=$$LDL(DFN,$$FMADD^XLFDT($$VD^APCLV(BUDLASTV),-365),$$VD^APCLV(BUDLASTV))
QUIT
+16 IF BUDLDL=""
QUIT
+17 IF $PIECE(BUDLDL,U,1)<130
QUIT
+18 ;eliminate those with an allergy to a LIPID LOWERING DRUG
SET X=$$LIPIDALG(DFN,BUDED)
IF X
SET ^XTMP("BUD2RP6B",BUDJ,BUDH,"ALG","CAD2",BUDAGE,$PIECE(^DPT(DFN,0),U),BUDCOM,DFN)=$PIECE(BUDCADVU,U)_U_$PIECE(X,U,2)_U_BUDLDL
QUIT
+19 ;I BUDCADVU="" S X="",X=$$LIPITHER(DFN,BUDBD,BUDED) I X]"" S ^XTMP("BUD2RP6B",BUDJ,BUDH,"ALG","CAD2",BUDAGE,$P(^DPT(DFN,0),U),BUDCOM,DFN)=$P(BUDCADVU,U)_U_$P(X,U,2) Q
+20 SET BUDCADT=$$LIPITHER(DFN,BUDBD,BUDED)
+21 IF BUDCADT]""
SET BUDSECTI("CAD")=$GET(BUDSECTI("CAD"))+1
+22 ;put the rest in demoninator
+23 SET BUDSECTI("PTS")=$GET(BUDSECTI("PTS"))+1
Begin DoDot:1
+24 IF $GET(BUDCAD2L)
Begin DoDot:2
+25 IF BUDCADT=""
SET ^XTMP("BUD2RP6B",BUDJ,BUDH,"CAD2",BUDAGE,$PIECE(^DPT(DFN,0),U),BUDCOM,DFN)=$PIECE(BUDCADVU,U)_U_$PIECE(BUDCADT,U,2)_U_BUDLDL
End DoDot:2
+26 IF $GET(BUDCAD1L)
Begin DoDot:2
+27 IF BUDCADT]""
SET ^XTMP("BUD2RP6B",BUDJ,BUDH,"CAD1",BUDAGE,$PIECE(^DPT(DFN,0),U),BUDCOM,DFN)=$PIECE(BUDCADVU,U)_U_$PIECE(BUDCADT,U,2)_U_BUDLDL
End DoDot:2
End DoDot:1
+28 QUIT
LIPIDALG(P,ED) ;
+1 ;allergy tracking
+2 NEW BUDC,X,N,G,Y,T,T1,S,A,B,C
+3 SET T=$ORDER(^ATXAX("B","BUD LIPID LOWERING MEDS",0))
+4 SET T1=$ORDER(^ATXAX("B","BGPMU LIPID LOWERING NDCS",0))
+5 SET BUDC=0
+6 SET X=0
FOR
SET X=$ORDER(^GMR(120.8,"B",P,X))
IF X'=+X!(BUDC)
QUIT
Begin DoDot:1
+7 ;Q:$P($P($G(^GMR(120.8,X,0)),U,4),".")>ED ;entered after end date
+8 SET N=$PIECE($GET(^GMR(120.8,X,0)),U,3)
+9 ;IF PSDRUG CHECK AGAINST MEDS TAXONOMY
+10 IF N["PSDRUG"
Begin DoDot:2
+11 SET Y=+N
+12 IF T
IF $DATA(^ATXAX(T,21,"AA",Y))
SET BUDC=1_U_"ALG: "_$PIECE(^PSDRUG(Y,0),U,1)
QUIT
+13 SET D=$PIECE($GET(^PSDRUG(Y,2)),U,4)
SET D=$$STRIP^XLFSTR(D,"-")
+14 IF D
IF $DATA(^ATXAX(T1,21,"AA",D))
SET BUDC=1_U_"ALG: "_$PIECE(^PSDRUG(Y,0),U,1)
End DoDot:2
QUIT
+15 IF N["PSNDF"
Begin DoDot:2
+16 ;drug name
SET Y=$PIECE(^GMR(120.8,X,0),U,2)
+17 ;drug ien
SET Y=$ORDER(^PSDRUG("B",Y,0))
+18 IF 'Y
QUIT
+19 IF T
IF $DATA(^ATXAX(T,21,"AA",Y))
SET BUDC=1_U_"ALG: "_$PIECE(^PSDRUG(Y,0),U,1)
QUIT
+20 SET D=$PIECE($GET(^PSDRUG(Y,2)),U,4)
SET D=$$STRIP^XLFSTR(D,"-")
+21 IF D
IF $DATA(^ATXAX(T1,21,"AA",D))
SET BUDC=1_U_"ALG: "_$PIECE(^PSDRUG(Y,0),U,1)
+22 ;CHECK NAME OF DRUG IN DRUG FILE/TAXONOMY
End DoDot:2
End DoDot:1
+23 QUIT BUDC
+24 ;
PROBCAD(P,BDATE,EDATE) ;EP
+1 NEW S,A,B,T,X,G,V,Y,Z
+2 SET G=""
+3 SET T=$ORDER(^ATXAX("B","BUD CAD DXS",0))
+4 SET X=0
SET G=""
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+5 SET Z=$PIECE(^AUPNPROB(X,0),U,13)
+6 IF Z=""
SET Z=$PIECE(^AUPNPROB(X,0),U,8)
+7 ;DATE OF ONSET AFTER END DATE
IF Z>EDATE
QUIT
+8 SET Y=$PIECE(^AUPNPROB(X,0),U)
+9 ;MUST BE ACTIVE
IF $PIECE(^AUPNPROB(X,0),U,12)'="A"
QUIT
+10 IF '$$ICD^ATXCHK(Y,T,9)
QUIT
+11 SET G=X
+12 QUIT
End DoDot:1
+13 IF G=""
QUIT G
+14 QUIT $$FMTE^XLFDT($PIECE(^AUPNPROB(G,0),U,3))_" Prob: "_$$VAL^XBDIQ1(9000011,G,.01)_U_G
+15 ;
CAD(P,BDATE,EDATE) ;EP
+1 NEW A,B,E,T,G,X,V,Y,BUDVS,T1
+2 KILL G
+3 SET A="BUDVS("
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(B,A)
+4 SET T=$ORDER(^ATXAX("B","BUD CAD DXS",0))
+5 SET T1=$ORDER(^ATXAX("B","BUD CARDIAC SURGERY DXS",0))
+6 IF 'T
QUIT ""
+7 SET X=0
SET G=""
FOR
SET X=$ORDER(BUDVS(X))
IF X'=+X
QUIT
SET V=$PIECE(BUDVS(X),U,5)
Begin DoDot:1
+8 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+9 IF '$PIECE(^AUPNVSIT(V,0),U,9)
QUIT
+10 IF $PIECE(^AUPNVSIT(V,0),U,11)
QUIT
+11 IF "SAHO"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+12 SET (D,Y)=0
FOR
SET Y=$ORDER(^AUPNVPOV("AD",V,Y))
IF Y'=+Y
QUIT
Begin DoDot:2
+13 SET D=0
+14 IF $DATA(^AUPNVPOV(Y,0))
SET %=$PIECE(^AUPNVPOV(Y,0),U)
+15 IF $$ICD^ATXCHK(%,T,9)
SET D=1
+16 IF $$ICD^ATXCHK(%,T1,9)
SET D=1
+17 IF 'D
QUIT
+18 SET G($$VD^APCLV(V))=$$VAL^XBDIQ1(9000010.07,Y,.01)
+19 QUIT
End DoDot:2
End DoDot:1
+20 SET Y=$ORDER(G(""),-1)
+21 ;W !,P," ",Y," " ZW G
+22 IF Y
SET X=G(Y)
QUIT $$FMTE^XLFDT(Y)_" "_X_U_Y
+23 SET Y=$$CPT^BUD2DU(P,$$DOB^AUPNPAT(P),EDATE,$ORDER(^ATXAX("B","BUD CAD CPTS",0)),5)
+24 IF Y
QUIT $$FMTE^XLFDT($PIECE(Y,U,1))_" CPT: "_$PIECE(Y,U,2)
+25 SET Y=$$LASTPRC^BUD2UTL1(P,"BUD CABG PTCA PROCS",$$DOB^AUPNPAT(P),EDATE)
+26 IF Y]""
QUIT $$FMTE^XLFDT($PIECE(Y,U,3))_" PROC: "_$PIECE(Y,U,2)
+27 SET Y=$$PROBCAD(P,BDATE,EDATE)
+28 IF Y]""
QUIT Y
+29 QUIT ""
LIPITHER(P,BD,ED) ;
+1 NEW BUDMEDS1,G,A,C,M,V,V1D
+2 SET G=""
+3 DO GETMEDS^BUD2UTL2(P,BD,ED,"BUD LIPID LOWERING MEDS","BGPMU LIPID LOWERING NDCS",,,.BUDMEDS1)
+4 ; no meds
IF '$DATA(BUDMEDS1)
QUIT G
+5 SET BUDISD=""
+6 SET A=0
SET C=""
FOR
SET A=$ORDER(BUDMEDS1(A))
IF A'=+A!(C)
QUIT
Begin DoDot:1
+7 ;IEN OF V MED
SET M=$PIECE(BUDMEDS1(A),U,4)
+8 IF '$DATA(^AUPNVMED(M,0))
QUIT
+9 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(M,11)),U))["RETURNED TO STOCK"
KILL BUDMEDS1(A)
QUIT
+10 ;d/c'ed BY PROVIDER OR EDIT
IF $$STATDC(M)
KILL BUDMEDS1(A)
QUIT
+11 SET V=$PIECE(BUDMEDS1(A),U,5)
+12 SET V1D=$$VD^APCLV(V)
+13 SET C=1_U_$$VAL^XBDIQ1(9000010.14,M,.01)_" on "_$$FMTE^XLFDT(V1D)
End DoDot:1
+14 IF C
QUIT C
+15 QUIT ""
+16 ;
STATDC(V) ;EP - is the prescription associated with this V MED discontinued?
+1 IF '$GET(V)
QUIT ""
+2 IF '$DATA(^AUPNVMED(V,0))
QUIT 0
+3 NEW P,S,X
+4 SET P=$SELECT($DATA(^PSRX("APCC",V)):$ORDER(^(V,0)),1:0)
+5 IF 'P
QUIT 0
+6 SET X=$PIECE($GET(^PSRX(P,0)),U,15)
+7 IF X=12
QUIT 1
+8 IF X=13
QUIT 1
+9 IF X=14
QUIT 1
+10 IF X=15
QUIT 1
+11 SET X=$PIECE($GET(^PSRX(P,"STA")),U,1)
+12 IF X=12
QUIT 1
+13 IF X=13
QUIT 1
+14 IF X=14
QUIT 1
+15 IF X=15
QUIT 1
+16 QUIT 0
GETV(P,BD,ED,SITE) ;EP - get all visits for this patient and COUNT MEDICAL VISITS
+1 NEW TV,T35V,T6V,MEDV,MEDVI,LASTV,A,X,VLOC,CLINC,TIEN,VSIT,VDATE,PP,S,LINE,D
+2 SET TV=0
SET T35V=0
SET T6V=0
SET MEDV=0
SET MEDVI=""
SET LASTV=""
+3 SET A="A(""VISITS"","
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED)
SET E=$$START1^APCLDF(B,A)
+4 SET X=0
FOR
SET X=$ORDER(A("VISITS",X))
IF X'=+X!(MEDV>1)
QUIT
SET VSIT=$PIECE(A("VISITS",X),U,5)
Begin DoDot:1
+5 IF '$DATA(^AUPNVSIT(VSIT,0))
QUIT
+6 IF '$PIECE(^AUPNVSIT(VSIT,0),U,9)
QUIT
+7 IF $PIECE(^AUPNVSIT(VSIT,0),U,11)
QUIT
+8 SET VLOC=$PIECE(^AUPNVSIT(VSIT,0),U,6)
+9 IF VLOC=""
QUIT
+10 ;not valid location
IF '$DATA(^BUDRSITE(SITE,11,VLOC))
QUIT
+11 IF "AHSORMEI"'[$PIECE(^AUPNVSIT(VSIT,0),U,7)
QUIT
+12 SET CLINC=$$CLINIC^APCLV(VSIT,"C")
+13 SET TIEN=$ORDER(^BUDRCNTL("B","FIRST LEVEL CLINIC EXCLUSIONS",0))
+14 ;not a clinic code we want in any table
IF CLINC]""
IF $DATA(^BUDRCNTL(TIEN,11,"B",CLINC))
QUIT
+15 ;now eliminate subsequent visits to same provider on same day = item 4 in SRD visit definition
+16 SET VDATE=$$VD^APCLV(VSIT)
+17 SET PP=$$PRIMPROV^APCLV(VSIT,"I")
+18 ;don't count I visits
IF $PIECE(^AUPNVSIT(VSIT,0),U,7)="I"
QUIT
+19 IF '$DATA(^AUPNVPOV("AD",VSIT))
QUIT
+20 SET S=0
+21 IF PP]""
Begin DoDot:2
+22 SET D=$PIECE($GET(A("SAMEPROV",P,VDATE,PP)),U,1)
+23 ;already had a visit to this provider on this date
IF D]""
IF D'>$PIECE(^AUPNVSIT(VSIT,0),U)
SET S=1
QUIT
+24 SET A("SAMEPROV",P,VDATE,PP)=$PIECE(^AUPNVSIT(VSIT,0),U)_U_VSIT
End DoDot:2
+25 ;quit if already had a visit to this provider
IF S
QUIT
+26 SET PP=$$PRIMPROV^APCLV(VSIT,"D")
+27 IF PP=""
QUIT
MEDC ;NOW CHECK FOR MEDICAL CARE, CAN ONLY HAVE 1 PER LOCATION OF ENCOUNTER
+1 SET S=0
+2 SET TIEN=$ORDER(^BUDRCNTL("B","MEDICAL CARE LINE NUMBERS",0))
+3 ;S PP=$$PRIMPROV^APCLV(VSIT,"D")
+4 IF $EXTRACT($$VAL^XBDIQ1(9000010,VSIT,.06),1,3)="CHS"
IF PP=15
SET LINE=2
GOTO MEDC1
+5 SET Y=$ORDER(^BUDRTFIV("C",PP,0))
IF Y=""
SET LINE=35
GOTO MEDC1
+6 SET LINE=$ORDER(^BUDRTFIV("AA",PP,""))
MEDC1 SET S=0
+1 IF $DATA(^BUDRCNTL(TIEN,11,"B",LINE))
Begin DoDot:2
+2 SET D=$PIECE($GET(A("MEDCARE",P,VDATE,VLOC,TIEN)),U,1)
+3 ;already have a medical care visit on this date
IF D]""
IF D'>$PIECE(^AUPNVSIT(VSIT,0),U)
SET S=1
QUIT
+4 SET A("MEDCARE",P,VDATE,VLOC,TIEN)=$PIECE(^AUPNVSIT(VSIT,0),U)_U_VSIT
+5 SET MEDV=MEDV+1
SET MEDVI=VSIT
+6 QUIT
End DoDot:2
End DoDot:1
+7 QUIT MEDV
LDL(P,BDATE,EDATE,NORES) ;EP
+1 NEW BUDG,BUDT,BUDC,BUDLT,T,B,E,D,L,X,R,G,C,%
+2 KILL BUDG,BUDT,BUDC
+3 SET BUDC=0
+4 SET NORES=$GET(NORES)
+5 ;now get all loinc/taxonomy tests
+6 SET T=$ORDER(^ATXAX("B","BGP LDL LOINC CODES",0))
+7 SET BUDLT=$ORDER(^ATXLAB("B","DM AUDIT LDL CHOLESTEROL TAX",0))
+8 SET B=9999999-BDATE
SET E=9999999-EDATE
SET D=E-1
FOR
SET D=$ORDER(^AUPNVLAB("AE",P,D))
IF D'=+D!(D>B)
QUIT
Begin DoDot:1
+9 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+10 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+11 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+12 IF $PIECE(^AUPNVLAB(X,0),U,4)=""
QUIT
+13 ;must be a number
SET R=$PIECE(^AUPNVLAB(X,0),U,4)
IF R'=+R
QUIT
+14 IF BUDLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(BUDLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET BUDC=BUDC+1
SET BUDT(D,BUDC)=$PIECE(^AUPNVLAB(X,0),U,4)
QUIT
+15 IF 'T
QUIT
+16 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+17 IF '$$LOINC(J,T)
QUIT
+18 SET R=$PIECE(^AUPNVLAB(X,0),U,4)
+19 IF 'R
SET R=""
+20 SET BUDC=BUDC+1
SET BUDT(D,BUDC)=R
+21 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+22 ; now got though and set return value of done 1 or 0^VALUE^date
+23 SET D=0
SET G=""
FOR
SET D=$ORDER(BUDT(D))
IF D'=+D!(G]"")
QUIT
Begin DoDot:1
+24 SET C=0
FOR
SET C=$ORDER(BUDT(D,C))
IF C'=+C!(G]"")
QUIT
Begin DoDot:2
+25 SET X=BUDT(D,C)
+26 IF X=""
QUIT
+27 SET G=X_U_(9999999-D)
+28 QUIT
End DoDot:2
End DoDot:1
+29 QUIT G
+30 ;
LOINC(A,B) ;EP
+1 NEW %
+2 SET %=$PIECE($GET(^LAB(95.3,A,9999999)),U,2)
+3 IF %]""
IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+4 SET %=$PIECE($GET(^LAB(95.3,A,0)),U)_"-"_$PIECE($GET(^LAB(95.3,A,0)),U,15)
+5 IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+6 QUIT ""