APCLD81D ; IHS/CMI/LAB - APCL Continuation of APCLD81C 1/11/2008 1:54:57 PM ;
;;2.0;IHS PCC SUITE;;MAY 14, 2009
;
;
;
MICRO ;EP
NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
K APCL S APCLC=0
S APCLOT=$O(^ATXAX("B","DM AUDIT MICROALBUMIN LOINC",0))
S APCLLT=$O(^ATXLAB("B","DM AUDIT MICROALBUMINURIA 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))
...I APCLLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCLLT,21,"B",$P(^AUPNVLAB(X,0),U))) D SETV Q
...Q:'APCLOT
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,APCLOT)
...D SETV
...Q
I '$D(APCL(1)) S %1="" D ACRATIOM^APCLD81C Q %1
D SETN
NEW % S %=$P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)
S %1=$S(%="":"No result",%["+":"Pos ",%[">":"Pos ",$E(%)="P":"Pos ",$E(%)="p":"Pos ",$E(%)="c":"No result ",$E(%)="C":"No result ",+%>29:"Pos ",1:"Neg ")
Q %1_%_" "_$$FMTE^XLFDT($P(APCL(N),U),"5")_" "_$P(APCL(N),U,3)
HGBA1C ;EP
NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
K APCL
S APCLC=0
S APCLOT=$O(^ATXAX("B","BGP HGBA1C LOINC CODES",0))
S APCLLT=$O(^ATXLAB("B","DM AUDIT HGB A1C 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))
...I APCLLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCLLT,21,"B",$P(^AUPNVLAB(X,0),U))) D SETV Q
...Q:'APCLOT
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,APCLOT)
...D SETV
...Q
D SET3
K X S (%,C,R)="" F S %=$O(APCL(%)) Q:%'=+%!(C>1) S X(9999999-$P(APCL(%),U),1)=$P(^AUPNVLAB(+$P(APCL(%),U,4),0),U,4)
S %=0,R="" F S %=$O(X(%)) Q:%="" S V=0 F S V=$O(X(%,V)) Q:V="" S R=R_X(%,V)_"^"_$$FMTE^XLFDT(9999999-%)_"^"_(9999999-%)_"^"
Q R
BS ;EP
NEW APCL,X,%,E,R,V,C
K APCL
S %=P_"^LAST 200 LAB [DM AUDIT GLUCOSE TESTS TAX;DURING "_BDATE_"-"_EDATE,E=$$START1^APCLDF(%,"APCL(")
I '$D(APCL(1)) Q ""
D SET3
S (%,C,R)="" F S %=$O(APCL(%)) Q:%=""!(C>2) S R=R_$P(^AUPNVLAB(+$P(APCL(%),U,4),0),U,4)_$S($P(^AUPNVLAB(+$P(APCL(%),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($P(APCL(%),U))_"^",C=C+1
Q R
;
FGLUCOSE ;EP
I $G(F)="" S F="E"
NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
K APCL
S APCLC=0
S APCLOT=$O(^ATXAX("B","DM AUDIT FASTING GLUC LOINC",0))
S APCLLT=$O(^ATXLAB("B","DM AUDIT FASTING GLUCOSE TESTS",0))
D GATHER
I '$D(APCL(1)) Q ""
D SETN
I F="I" Q $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)_"^"_$P(APCL(N),U)
Q $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)_$S($P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($P(APCL(N),U),5)
G75 ;EP
I $G(F)="" S F="E"
NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
K APCL
S APCLC=0
S APCLOT=$O(^ATXAX("B","DM AUDIT 75GM 2HR LOINC",0))
S APCLLT=$O(^ATXLAB("B","DM AUDIT 75GM 2HR GLUCOSE",0))
D GATHER
I '$D(APCL(1)) Q ""
D SETN
I F="I" Q $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)_"^"_$P(APCL(N),U)
Q $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)_$S($P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($P(APCL(N),U),5)
;
GATHER ;
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(APCL)) 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))
...I APCLLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCLLT,21,"B",$P(^AUPNVLAB(X,0),U))) D SETV Q
...Q:'APCLOT
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,APCLOT)
...D SETV
...Q
I '$D(APCL(1)) Q
S D=$P(APCL(1),U),D=9999999-D
K APCL S APCLC=0
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))
..I APCLLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCLLT,21,"B",$P(^AUPNVLAB(X,0),U))) D SETV Q
..Q:'APCLOT
..S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
..Q:'$$LOINC(J,APCLOT)
..D SETV
..Q
Q
LOINC(A,B) ;EP - is loinc code A in taxonomy B
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 ""
SETV ;
S APCLC=APCLC+1
S V=$P(^AUPNVLAB(X,0),U,3),APCLV=$P($P($G(^AUPNVSIT(V,0)),U),".") Q:'APCLV
S APCL(APCLC)=APCLV_"^"_$S($P(^AUPNVLAB(X,0),U,4)]"":$P(^AUPNVLAB(X,0),U,4),1:"?")_"^"_$$VAL^XBDIQ1(9000010.09,X,.01)_"^"_X_";AUPNVLAB^"_V
Q
SETN ;
S N="" NEW A,G S (A,G)=0 F S A=$O(APCL(A)) Q:A'=+A!(G) S R=$P(^AUPNVLAB(+$P(APCL(A),U,4),0),U,4) I R]"",$$UP^XLFSTR(R)'="COMMENT" S G=A
S N=$S(G:G,1:1)
Q
SET3 ;
NEW X,N1,N2,N3,A,T
K A
S X=0 F S X=$O(APCL(X)) Q:X'=+X S A($P(APCL(X),U),X)=""
NEW D S D=0 F S D=$O(A(D)) Q:D'=+D D
.S G=0,N=0 F S N=$O(A(D,N)) Q:N'=+N D
..I $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)]"",$$UP^XLFSTR($P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4))'="COMMENT" S G=1 Q
.I G S N=0 F S N=$O(A(D,N)) Q:N'=+N I $P(^AUPNVLAB(+$P(APCL(N),U,4),0),U,4)="" K APCL(N)
.Q
Q
APCLD81D ; IHS/CMI/LAB - APCL Continuation of APCLD81C 1/11/2008 1:54:57 PM ;
+1 ;;2.0;IHS PCC SUITE;;MAY 14, 2009
+2 ;
+3 ;
+4 ;
MICRO ;EP
+1 NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
+2 KILL APCL
SET APCLC=0
+3 SET APCLOT=$ORDER(^ATXAX("B","DM AUDIT MICROALBUMIN LOINC",0))
+4 SET APCLLT=$ORDER(^ATXLAB("B","DM AUDIT MICROALBUMINURIA TAX",0))
+5 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
+6 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+7 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+8 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+9 IF APCLLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCLLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
DO SETV
QUIT
+10 IF 'APCLOT
QUIT
+11 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+12 IF '$$LOINC(J,APCLOT)
QUIT
+13 DO SETV
+14 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+15 IF '$DATA(APCL(1))
SET %1=""
DO ACRATIOM^APCLD81C
QUIT %1
+16 DO SETN
+17 NEW %
SET %=$PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)
+18 SET %1=$SELECT(%="":"No result",%["+":"Pos ",%[">":"Pos ",$EXTRACT(%)="P":"Pos ",$EXTRACT(%)="p":"Pos ",$EXTRACT(%)="c":"No result ",$EXTRACT(%)="C":"No result ",+%>29:"Pos ",1:"Neg ")
+19 QUIT %1_%_" "_$$FMTE^XLFDT($PIECE(APCL(N),U),"5")_" "_$PIECE(APCL(N),U,3)
HGBA1C ;EP
+1 NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
+2 KILL APCL
+3 SET APCLC=0
+4 SET APCLOT=$ORDER(^ATXAX("B","BGP HGBA1C LOINC CODES",0))
+5 SET APCLLT=$ORDER(^ATXLAB("B","DM AUDIT HGB A1C TAX",0))
+6 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
+7 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+8 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+9 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+10 IF APCLLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCLLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
DO SETV
QUIT
+11 IF 'APCLOT
QUIT
+12 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+13 IF '$$LOINC(J,APCLOT)
QUIT
+14 DO SETV
+15 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+16 DO SET3
+17 KILL X
SET (%,C,R)=""
FOR
SET %=$ORDER(APCL(%))
IF %'=+%!(C>1)
QUIT
SET X(9999999-$PIECE(APCL(%),U),1)=$PIECE(^AUPNVLAB(+$PIECE(APCL(%),U,4),0),U,4)
+18 SET %=0
SET R=""
FOR
SET %=$ORDER(X(%))
IF %=""
QUIT
SET V=0
FOR
SET V=$ORDER(X(%,V))
IF V=""
QUIT
SET R=R_X(%,V)_"^"_$$FMTE^XLFDT(9999999-%)_"^"_(9999999-%)_"^"
+19 QUIT R
BS ;EP
+1 NEW APCL,X,%,E,R,V,C
+2 KILL APCL
+3 SET %=P_"^LAST 200 LAB [DM AUDIT GLUCOSE TESTS TAX;DURING "_BDATE_"-"_EDATE
SET E=$$START1^APCLDF(%,"APCL(")
+4 IF '$DATA(APCL(1))
QUIT ""
+5 DO SET3
+6 SET (%,C,R)=""
FOR
SET %=$ORDER(APCL(%))
IF %=""!(C>2)
QUIT
SET R=R_$PIECE(^AUPNVLAB(+$PIECE(APCL(%),U,4),0),U,4)_$SELECT($PIECE(^AUPNVLAB(+$PIECE(APCL(%),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($PIECE(APCL(%),U))_"^"
SET C=C+1
+7 QUIT R
+8 ;
FGLUCOSE ;EP
+1 IF $GET(F)=""
SET F="E"
+2 NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
+3 KILL APCL
+4 SET APCLC=0
+5 SET APCLOT=$ORDER(^ATXAX("B","DM AUDIT FASTING GLUC LOINC",0))
+6 SET APCLLT=$ORDER(^ATXLAB("B","DM AUDIT FASTING GLUCOSE TESTS",0))
+7 DO GATHER
+8 IF '$DATA(APCL(1))
QUIT ""
+9 DO SETN
+10 IF F="I"
QUIT $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)_"^"_$PIECE(APCL(N),U)
+11 QUIT $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)_$SELECT($PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($PIECE(APCL(N),U),5)
G75 ;EP
+1 IF $GET(F)=""
SET F="E"
+2 NEW APCL,X,%,E,R,V,APCLLT,APCLOT,B,D,L,J,APCLC,APCLV,V
+3 KILL APCL
+4 SET APCLC=0
+5 SET APCLOT=$ORDER(^ATXAX("B","DM AUDIT 75GM 2HR LOINC",0))
+6 SET APCLLT=$ORDER(^ATXLAB("B","DM AUDIT 75GM 2HR GLUCOSE",0))
+7 DO GATHER
+8 IF '$DATA(APCL(1))
QUIT ""
+9 DO SETN
+10 IF F="I"
QUIT $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)_"^"_$PIECE(APCL(N),U)
+11 QUIT $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)_$SELECT($PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)]"":" mg/dl ",1:"")_$$FMTE^XLFDT($PIECE(APCL(N),U),5)
+12 ;
GATHER ;
+1 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)!($DATA(APCL))
QUIT
Begin DoDot:1
+2 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+3 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+4 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+5 IF APCLLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCLLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
DO SETV
QUIT
+6 IF 'APCLOT
QUIT
+7 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+8 IF '$$LOINC(J,APCLOT)
QUIT
+9 DO SETV
+10 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+11 IF '$DATA(APCL(1))
QUIT
+12 SET D=$PIECE(APCL(1),U)
SET D=9999999-D
+13 KILL APCL
SET APCLC=0
+14 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:1
+15 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:2
+16 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+17 IF APCLLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCLLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
DO SETV
QUIT
+18 IF 'APCLOT
QUIT
+19 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+20 IF '$$LOINC(J,APCLOT)
QUIT
+21 DO SETV
+22 QUIT
End DoDot:2
End DoDot:1
+23 QUIT
LOINC(A,B) ;EP - is loinc code A in taxonomy B
+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 ""
SETV ;
+1 SET APCLC=APCLC+1
+2 SET V=$PIECE(^AUPNVLAB(X,0),U,3)
SET APCLV=$PIECE($PIECE($GET(^AUPNVSIT(V,0)),U),".")
IF 'APCLV
QUIT
+3 SET APCL(APCLC)=APCLV_"^"_$SELECT($PIECE(^AUPNVLAB(X,0),U,4)]"":$PIECE(^AUPNVLAB(X,0),U,4),1:"?")_"^"_$$VAL^XBDIQ1(9000010.09,X,.01)_"^"_X_";AUPNVLAB^"_V
+4 QUIT
SETN ;
+1 SET N=""
NEW A,G
SET (A,G)=0
FOR
SET A=$ORDER(APCL(A))
IF A'=+A!(G)
QUIT
SET R=$PIECE(^AUPNVLAB(+$PIECE(APCL(A),U,4),0),U,4)
IF R]""
IF $$UP^XLFSTR(R)'="COMMENT"
SET G=A
+2 SET N=$SELECT(G:G,1:1)
+3 QUIT
SET3 ;
+1 NEW X,N1,N2,N3,A,T
+2 KILL A
+3 SET X=0
FOR
SET X=$ORDER(APCL(X))
IF X'=+X
QUIT
SET A($PIECE(APCL(X),U),X)=""
+4 NEW D
SET D=0
FOR
SET D=$ORDER(A(D))
IF D'=+D
QUIT
Begin DoDot:1
+5 SET G=0
SET N=0
FOR
SET N=$ORDER(A(D,N))
IF N'=+N
QUIT
Begin DoDot:2
+6 IF $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)]""
IF $$UP^XLFSTR($PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4))'="COMMENT"
SET G=1
QUIT
End DoDot:2
+7 IF G
SET N=0
FOR
SET N=$ORDER(A(D,N))
IF N'=+N
QUIT
IF $PIECE(^AUPNVLAB(+$PIECE(APCL(N),U,4),0),U,4)=""
KILL APCL(N)
+8 QUIT
End DoDot:1
+9 QUIT