BQITNPH ;PRXM/HC/ALA-Nephropathy Definition ; 12 Apr 2006 2:13 PM
;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
Q
;
DEF(TTGLOB) ;EP -- Nephropathy Definition
;Description
; DEF.05 formerly CVDAL.DEF.DX.1
;Input
; TTGLOB - Global reference where patients matching high cholesterol
; will be place. Subscripted by patient IEN.
;
NEW BQREF,BQIRY,TAX,BQGLBT,TDFN,DFN,STOP
; Use taxonomy definitions
S BQREF="BQIRY" K @BQREF
S TAX="Nephropathy"
D ARY^BQITUTL(TAX,BQREF)
S BQGLBT=$NA(^TMP("BQITMP",UID))
K @BQGLBT
D POP^BQITDGN(.BQREF,BQGLBT)
S TDFN="" F S TDFN=$O(@BQGLBT@(TDFN)) Q:TDFN="" D
. NEW TX
. S TX="" F S TX=$O(@BQGLBT@(TDFN,"CRITERIA",TX)) Q:TX="" D
.. D STOR(TDFN,TX)
K @BQGLBT
;
;Creatinine Lab test value check
NEW CRDATA
S FREF=9000010.09,GREF=$$ROOT^DILFD(FREF,"",1)
S TREF=$NA(^TMP("BQITAX",UID)),CRDATA=$NA(^TMP("BQICREAT",UID))
K @TREF,@CRDATA
S TMFRAME="T-12M",ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1),EXDT=""
F TAX="DM AUDIT CREATININE TAX","BGP CREATININE LOINC CODES" D BLD^BQITUTL(TAX,TREF)
S TIEN="" F S TIEN=$O(@TREF@(TIEN)) Q:TIEN="" D
. S IEN=""
. F S IEN=$O(@GREF@("B",TIEN,IEN)) Q:IEN="" D
.. I $G(@GREF@(IEN,0))="" Q
.. S DFN=$$GET1^DIQ(FREF,IEN,.02,"I") Q:DFN=""
.. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") Q:VISIT=""
.. S RESULT=$$GET1^DIQ(FREF,IEN,.04,"E") Q:RESULT=""
.. I RESULT<2.0 Q
.. S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:'VSDTM
.. I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
.. I $G(TMFRAME)'="",VSDTM<ENDT Q
.. ; need to be separated by at least 90 days
.. I '$D(@CRDATA@(DFN,VSDTM)) S @CRDATA@(DFN)=$G(@CRDATA@(DFN))+1
.. S @CRDATA@(DFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
.. Q
;
S DFN="" F S DFN=$O(@CRDATA@(DFN)) Q:DFN="" D
. I @CRDATA@(DFN)<2 K @CRDATA@(DFN) Q
. S DATE="",STOP=0
. NEW DATE1,DATE2
. F S DATE=$O(@CRDATA@(DFN,DATE),-1) Q:DATE="" D Q:STOP
.. S DATE1=DATE,DATE2=$O(@CRDATA@(DFN,DATE1),-1) Q:DATE2=""
.. I $$FMDIFF^XLFDT(DATE1,DATE2,1)<90 Q
.. S RESULT=$P(@CRDATA@(DFN,DATE1),"^",1)
.. S VISIT=$P(@CRDATA@(DFN,DATE1),"^",2)
.. S IEN=$P(@CRDATA@(DFN,DATE1),"^",3)
.. S RESULT1=$P(@CRDATA@(DFN,DATE2),"^",1)
.. S VISIT1=$P(@CRDATA@(DFN,DATE2),"^",2)
.. S IEN1=$P(@CRDATA@(DFN,DATE2),"^",3)
.. S @BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
.. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
.. S $P(@BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN),U,2)=EXDT
.. S @BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
.. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
.. S $P(@BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1),U,2)=EXDT
.. S TX="Nephropathy-Creatinine Value"
.. D STOR(DFN,TX)
.. S STOP=1 ; Criteria has been met for this patient - stop searching
.. ;I RESULT'<2.0,RESULT1'<2.0 D STOR(DFN,TX)
;
K @BQGLBT
;GFR Lab test value check
NEW GFDATA
S FREF=9000010.09,GREF=$$ROOT^DILFD(FREF,"",1)
S TREF=$NA(^TMP("BQITAX",UID)),GFDATA=$NA(^TMP("BQIGFR",UID))
K @TREF,@GFDATA
S TMFRAME="T-12M",ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1),EXDT=""
F TAX="BGP GPRA ESTIMATED GFR TAX","BGP ESTIMATED GFR LOINC" D BLD^BQITUTL(TAX,TREF)
;D BLDSV^BQITUTL(95.3,"33914-3",TREF)
S TIEN="" F S TIEN=$O(@TREF@(TIEN)) Q:TIEN="" D
. S IEN=""
. F S IEN=$O(@GREF@("B",TIEN,IEN),-1) Q:IEN="" D
.. I $G(@GREF@(IEN,0))="" Q
.. S DFN=$$GET1^DIQ(FREF,IEN,.02,"I") Q:DFN=""
.. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") Q:VISIT=""
.. S RESULT=$$GET1^DIQ(FREF,IEN,.04,"E") Q:RESULT=""
.. I RESULT>30 Q
.. S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:'VSDTM
.. I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
.. I $G(TMFRAME)'="",VSDTM<ENDT Q
.. S @GFDATA@(DFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
.. S @GFDATA@(DFN)=$G(@GFDATA@(DFN))+1
.. Q
;
S DFN="" F S DFN=$O(@GFDATA@(DFN)) Q:DFN="" D
. I @GFDATA@(DFN)<2 K @GFDATA@(DFN) Q
. S DATE="",STOP=0
. NEW DATE1,DATE2
. F S DATE=$O(@GFDATA@(DFN,DATE),-1) Q:DATE="" D Q:STOP
.. S DATE1=DATE,DATE2=$O(@GFDATA@(DFN,DATE1),-1) Q:DATE2=""
.. ; need to be separated by at least 90 days
.. I $$FMDIFF^XLFDT(DATE1,DATE2,1)<90 Q
.. S RESULT=$P(@GFDATA@(DFN,DATE1),"^",1)
.. S VISIT=$P(@GFDATA@(DFN,DATE1),"^",2)
.. S IEN=$P(@GFDATA@(DFN,DATE1),"^",3)
.. S RESULT1=$P(@GFDATA@(DFN,DATE2),"^",1)
.. S VISIT1=$P(@GFDATA@(DFN,DATE2),"^",2)
.. S IEN1=$P(@GFDATA@(DFN,DATE2),"^",3)
.. S @BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
.. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
.. S $P(@BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN),U,2)=EXDT
.. S @BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
.. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
.. S $P(@BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1),U,2)=EXDT
.. S TX="Nephropathy-GFR Value"
.. D STOR(DFN,"Nephropathy-GFR Value")
.. S STOP=1 ; Criteria has been met for this patient - stop searching
.. ;I RESULT'>30,RESULT1'>30 D STOR(DFN,"Nephropathy-GFR Value")
;
K @GFDATA,@CRDATA,@TREF,DFN,RESULT,RESULT1,DATE,DATE1,DATE2
K TMFRAME,VISIT,VSDTM,ENDT,FREF,GREF,TREF,TAX,TIEN,IEN,TDFN,SDFN,@BQGLBT,IEN,IEN1
Q
;
STOR(SDFN,CRIT) ; Store the patient's met criteria
S @TTGLOB@(SDFN)=$G(@TTGLOB@(SDFN))+1
;S @TTGLOB@(SDFN,"CRITERIA",CRIT)=""
M @TTGLOB@(SDFN,"CRITERIA")=@BQGLBT@(SDFN,"CRITERIA")
Q
;
PAT(BTDFN,BTGLOB) ;EP -- Get nephropathy for a patient
NEW VISIT,VISIT1,BQGLBT,BQDXN,BQREF,FREF,GREF,TREF,TMFRAME,TAX,IEN
NEW TIEN,RESULT,VSDTM,RESULT1,DATE,DATE1,DATE2,ENDT,STOP
S BQGLBT=$NA(^TMP("BQITMP",UID))
S BQDXN=$$GDXN^BQITUTL("Nephropathy")
S BQREF="BQIRY"
D GDF^BQITUTL(BQDXN,BQREF)
I $$PAT^BQITDGN(BQREF,BQGLBT,BTDFN) D STOR^BQITD05(BTDFN,"Risk-Nephropathy",BQGLBT)
;
S FREF=9000010.09,GREF=$$ROOT^DILFD(FREF,"",1)
S TREF=$NA(^TMP("BQITAX",UID)),CRDATA=$NA(^TMP("BQICREAT",UID))
K @TREF,@CRDATA
S TMFRAME="T-12M",ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1),EXDT=""
F TAX="DM AUDIT CREATININE TAX","BGP CREATININE LOINC CODES" D BLD^BQITUTL(TAX,TREF)
S IEN=""
F S IEN=$O(@GREF@("AC",BTDFN,IEN)) Q:IEN="" D
. S TIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I TIEN="" Q
. I '$D(@TREF@(TIEN)) Q
. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") Q:VISIT=""
. S RESULT=$$GET1^DIQ(FREF,IEN,.04,"E") Q:RESULT=""
. I RESULT<2.0 Q
. S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:'VSDTM
. I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
. I $G(TMFRAME)'="",VSDTM<ENDT Q
. I '$D(@CRDATA@(BTDFN,VSDTM)) S @CRDATA@(BTDFN)=$G(@CRDATA@(BTDFN))+1
. S @CRDATA@(BTDFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
I $G(@CRDATA@(BTDFN))<2 K @CRDATA@(BTDFN)
S DATE="",STOP=0
NEW DATE1,DATE2
F S DATE=$O(@CRDATA@(BTDFN,DATE),-1) Q:DATE="" D Q:STOP
. S DATE1=DATE,DATE2=$O(@CRDATA@(BTDFN,DATE1),-1) Q:DATE2=""
. I $$FMDIFF^XLFDT(DATE1,DATE2,1)<90 Q
. S RESULT=$P(@CRDATA@(BTDFN,DATE1),"^",1)
. S VISIT=$P(@CRDATA@(BTDFN,DATE1),"^",2)
. S IEN=$P(@CRDATA@(BTDFN,DATE1),"^",3)
. S RESULT1=$P(@CRDATA@(BTDFN,DATE2),"^",1)
. S VISIT1=$P(@CRDATA@(BTDFN,DATE2),"^",2)
. S IEN1=$P(@CRDATA@(BTDFN,DATE2),"^",3)
. S @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
. S $P(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN),U,2)=EXDT
. S @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
. S $P(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1),U,2)=EXDT
. S TX="Nephropathy-Creatinine Value"
. D STOR^BQITD05(BTDFN,"Nephropathy-Creatinine Value",BQGLBT)
. S STOP=1 ; Criteria has been met - stop searching
;
S FREF=9000010.09,GREF=$$ROOT^DILFD(FREF,"",1)
S TREF=$NA(^TMP("BQITAX",UID)),GFDATA=$NA(^TMP("BQIGFR",UID))
K @GFDATA,@TREF
S TMFRAME="T-12M",ENDT=$$DATE^BQIUL1(TMFRAME),STDT=$$DT^XLFDT()
S DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1),EXDT=""
F TAX="BGP GPRA ESTIMATED GFR TAX","BGP ESTIMATED GFR LOINC" D BLD^BQITUTL(TAX,TREF)
;D BLDSV^BQITUTL(95.3,"33914-3",TREF)
S IEN=""
F S IEN=$O(@GREF@("AC",BTDFN,IEN)) Q:IEN="" D
. S TIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I TIEN="" Q
. I '$D(@TREF@(TIEN)) Q
. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") Q:VISIT=""
. S RESULT=$$GET1^DIQ(FREF,IEN,.04,"E") Q:RESULT=""
. I RESULT<30 Q
. S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:'VSDTM
. I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
. I $G(TMFRAME)'="",VSDTM<ENDT Q
. S @GFDATA@(BTDFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
. S @GFDATA@(BTDFN)=$G(@GFDATA@(BTDFN))+1
;
I $G(@GFDATA@(BTDFN))<2 K @GFDATA@(BTDFN)
S DATE="",STOP=0
NEW DATE1,DATE2
F S DATE=$O(@GFDATA@(BTDFN,DATE),-1) Q:DATE="" D Q:STOP
. S DATE1=DATE,DATE2=$O(@GFDATA@(BTDFN,DATE1),-1) Q:DATE2=""
. ; need to be separated by at least 90 days
. I $$FMDIFF^XLFDT(DATE1,DATE2,1)<90 Q
. S RESULT=$P(@GFDATA@(BTDFN,DATE1),"^",1)
. S VISIT=$P(@GFDATA@(BTDFN,DATE1),"^",2)
. S IEN=$P(@GFDATA@(BTDFN,DATE1),"^",3)
. S RESULT1=$P(@GFDATA@(BTDFN,DATE2),"^",1)
. S VISIT1=$P(@GFDATA@(BTDFN,DATE2),"^",2)
. S IEN1=$P(@GFDATA@(BTDFN,DATE2),"^",3)
. S @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
. S $P(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN),U,2)=EXDT
. S @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
. I DTDIF'="" S EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
. S $P(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1),U,2)=EXDT
. S TX="Nephropathy-GFR Value"
. D STOR^BQITD05(BTDFN,"Nephropathy-GFR Value",BQGLBT)
. S STOP=1 ; Criteria has been met - stop searching
Q
BQITNPH ;PRXM/HC/ALA-Nephropathy Definition ; 12 Apr 2006 2:13 PM
+1 ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
+2 QUIT
+3 ;
DEF(TTGLOB) ;EP -- Nephropathy Definition
+1 ;Description
+2 ; DEF.05 formerly CVDAL.DEF.DX.1
+3 ;Input
+4 ; TTGLOB - Global reference where patients matching high cholesterol
+5 ; will be place. Subscripted by patient IEN.
+6 ;
+7 NEW BQREF,BQIRY,TAX,BQGLBT,TDFN,DFN,STOP
+8 ; Use taxonomy definitions
+9 SET BQREF="BQIRY"
KILL @BQREF
+10 SET TAX="Nephropathy"
+11 DO ARY^BQITUTL(TAX,BQREF)
+12 SET BQGLBT=$NAME(^TMP("BQITMP",UID))
+13 KILL @BQGLBT
+14 DO POP^BQITDGN(.BQREF,BQGLBT)
+15 SET TDFN=""
FOR
SET TDFN=$ORDER(@BQGLBT@(TDFN))
IF TDFN=""
QUIT
Begin DoDot:1
+16 NEW TX
+17 SET TX=""
FOR
SET TX=$ORDER(@BQGLBT@(TDFN,"CRITERIA",TX))
IF TX=""
QUIT
Begin DoDot:2
+18 DO STOR(TDFN,TX)
End DoDot:2
End DoDot:1
+19 KILL @BQGLBT
+20 ;
+21 ;Creatinine Lab test value check
+22 NEW CRDATA
+23 SET FREF=9000010.09
SET GREF=$$ROOT^DILFD(FREF,"",1)
+24 SET TREF=$NAME(^TMP("BQITAX",UID))
SET CRDATA=$NAME(^TMP("BQICREAT",UID))
+25 KILL @TREF,@CRDATA
+26 SET TMFRAME="T-12M"
SET ENDT=$$DATE^BQIUL1(TMFRAME)
SET STDT=$$DT^XLFDT()
+27 SET DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
SET EXDT=""
+28 FOR TAX="DM AUDIT CREATININE TAX","BGP CREATININE LOINC CODES"
DO BLD^BQITUTL(TAX,TREF)
+29 SET TIEN=""
FOR
SET TIEN=$ORDER(@TREF@(TIEN))
IF TIEN=""
QUIT
Begin DoDot:1
+30 SET IEN=""
+31 FOR
SET IEN=$ORDER(@GREF@("B",TIEN,IEN))
IF IEN=""
QUIT
Begin DoDot:2
+32 IF $GET(@GREF@(IEN,0))=""
QUIT
+33 SET DFN=$$GET1^DIQ(FREF,IEN,.02,"I")
IF DFN=""
QUIT
+34 SET VISIT=$$GET1^DIQ(FREF,IEN,.03,"I")
IF VISIT=""
QUIT
+35 SET RESULT=$$GET1^DIQ(FREF,IEN,.04,"E")
IF RESULT=""
QUIT
+36 IF RESULT<2.0
QUIT
+37 SET VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1
IF 'VSDTM
QUIT
+38 IF $$GET1^DIQ(9000010,VISIT,.11,"I")=1
QUIT
+39 IF $GET(TMFRAME)'=""
IF VSDTM<ENDT
QUIT
+40 ; need to be separated by at least 90 days
+41 IF '$DATA(@CRDATA@(DFN,VSDTM))
SET @CRDATA@(DFN)=$GET(@CRDATA@(DFN))+1
+42 SET @CRDATA@(DFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
+43 QUIT
End DoDot:2
End DoDot:1
+44 ;
+45 SET DFN=""
FOR
SET DFN=$ORDER(@CRDATA@(DFN))
IF DFN=""
QUIT
Begin DoDot:1
+46 IF @CRDATA@(DFN)<2
KILL @CRDATA@(DFN)
QUIT
+47 SET DATE=""
SET STOP=0
+48 NEW DATE1,DATE2
+49 FOR
SET DATE=$ORDER(@CRDATA@(DFN,DATE),-1)
IF DATE=""
QUIT
Begin DoDot:2
+50 SET DATE1=DATE
SET DATE2=$ORDER(@CRDATA@(DFN,DATE1),-1)
IF DATE2=""
QUIT
+51 IF $$FMDIFF^XLFDT(DATE1,DATE2,1)<90
QUIT
+52 SET RESULT=$PIECE(@CRDATA@(DFN,DATE1),"^",1)
+53 SET VISIT=$PIECE(@CRDATA@(DFN,DATE1),"^",2)
+54 SET IEN=$PIECE(@CRDATA@(DFN,DATE1),"^",3)
+55 SET RESULT1=$PIECE(@CRDATA@(DFN,DATE2),"^",1)
+56 SET VISIT1=$PIECE(@CRDATA@(DFN,DATE2),"^",2)
+57 SET IEN1=$PIECE(@CRDATA@(DFN,DATE2),"^",3)
+58 SET @BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
+59 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
+60 SET $PIECE(@BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN),U,2)=EXDT
+61 SET @BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
+62 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
+63 SET $PIECE(@BQGLBT@(DFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1),U,2)=EXDT
+64 SET TX="Nephropathy-Creatinine Value"
+65 DO STOR(DFN,TX)
+66 ; Criteria has been met for this patient - stop searching
SET STOP=1
+67 ;I RESULT'<2.0,RESULT1'<2.0 D STOR(DFN,TX)
End DoDot:2
IF STOP
QUIT
End DoDot:1
+68 ;
+69 KILL @BQGLBT
+70 ;GFR Lab test value check
+71 NEW GFDATA
+72 SET FREF=9000010.09
SET GREF=$$ROOT^DILFD(FREF,"",1)
+73 SET TREF=$NAME(^TMP("BQITAX",UID))
SET GFDATA=$NAME(^TMP("BQIGFR",UID))
+74 KILL @TREF,@GFDATA
+75 SET TMFRAME="T-12M"
SET ENDT=$$DATE^BQIUL1(TMFRAME)
SET STDT=$$DT^XLFDT()
+76 SET DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
SET EXDT=""
+77 FOR TAX="BGP GPRA ESTIMATED GFR TAX","BGP ESTIMATED GFR LOINC"
DO BLD^BQITUTL(TAX,TREF)
+78 ;D BLDSV^BQITUTL(95.3,"33914-3",TREF)
+79 SET TIEN=""
FOR
SET TIEN=$ORDER(@TREF@(TIEN))
IF TIEN=""
QUIT
Begin DoDot:1
+80 SET IEN=""
+81 FOR
SET IEN=$ORDER(@GREF@("B",TIEN,IEN),-1)
IF IEN=""
QUIT
Begin DoDot:2
+82 IF $GET(@GREF@(IEN,0))=""
QUIT
+83 SET DFN=$$GET1^DIQ(FREF,IEN,.02,"I")
IF DFN=""
QUIT
+84 SET VISIT=$$GET1^DIQ(FREF,IEN,.03,"I")
IF VISIT=""
QUIT
+85 SET RESULT=$$GET1^DIQ(FREF,IEN,.04,"E")
IF RESULT=""
QUIT
+86 IF RESULT>30
QUIT
+87 SET VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1
IF 'VSDTM
QUIT
+88 IF $$GET1^DIQ(9000010,VISIT,.11,"I")=1
QUIT
+89 IF $GET(TMFRAME)'=""
IF VSDTM<ENDT
QUIT
+90 SET @GFDATA@(DFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
+91 SET @GFDATA@(DFN)=$GET(@GFDATA@(DFN))+1
+92 QUIT
End DoDot:2
End DoDot:1
+93 ;
+94 SET DFN=""
FOR
SET DFN=$ORDER(@GFDATA@(DFN))
IF DFN=""
QUIT
Begin DoDot:1
+95 IF @GFDATA@(DFN)<2
KILL @GFDATA@(DFN)
QUIT
+96 SET DATE=""
SET STOP=0
+97 NEW DATE1,DATE2
+98 FOR
SET DATE=$ORDER(@GFDATA@(DFN,DATE),-1)
IF DATE=""
QUIT
Begin DoDot:2
+99 SET DATE1=DATE
SET DATE2=$ORDER(@GFDATA@(DFN,DATE1),-1)
IF DATE2=""
QUIT
+100 ; need to be separated by at least 90 days
+101 IF $$FMDIFF^XLFDT(DATE1,DATE2,1)<90
QUIT
+102 SET RESULT=$PIECE(@GFDATA@(DFN,DATE1),"^",1)
+103 SET VISIT=$PIECE(@GFDATA@(DFN,DATE1),"^",2)
+104 SET IEN=$PIECE(@GFDATA@(DFN,DATE1),"^",3)
+105 SET RESULT1=$PIECE(@GFDATA@(DFN,DATE2),"^",1)
+106 SET VISIT1=$PIECE(@GFDATA@(DFN,DATE2),"^",2)
+107 SET IEN1=$PIECE(@GFDATA@(DFN,DATE2),"^",3)
+108 SET @BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
+109 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
+110 SET $PIECE(@BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN),U,2)=EXDT
+111 SET @BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
+112 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
+113 SET $PIECE(@BQGLBT@(DFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1),U,2)=EXDT
+114 SET TX="Nephropathy-GFR Value"
+115 DO STOR(DFN,"Nephropathy-GFR Value")
+116 ; Criteria has been met for this patient - stop searching
SET STOP=1
+117 ;I RESULT'>30,RESULT1'>30 D STOR(DFN,"Nephropathy-GFR Value")
End DoDot:2
IF STOP
QUIT
End DoDot:1
+118 ;
+119 KILL @GFDATA,@CRDATA,@TREF,DFN,RESULT,RESULT1,DATE,DATE1,DATE2
+120 KILL TMFRAME,VISIT,VSDTM,ENDT,FREF,GREF,TREF,TAX,TIEN,IEN,TDFN,SDFN,@BQGLBT,IEN,IEN1
+121 QUIT
+122 ;
STOR(SDFN,CRIT) ; Store the patient's met criteria
+1 SET @TTGLOB@(SDFN)=$GET(@TTGLOB@(SDFN))+1
+2 ;S @TTGLOB@(SDFN,"CRITERIA",CRIT)=""
+3 MERGE @TTGLOB@(SDFN,"CRITERIA")=@BQGLBT@(SDFN,"CRITERIA")
+4 QUIT
+5 ;
PAT(BTDFN,BTGLOB) ;EP -- Get nephropathy for a patient
+1 NEW VISIT,VISIT1,BQGLBT,BQDXN,BQREF,FREF,GREF,TREF,TMFRAME,TAX,IEN
+2 NEW TIEN,RESULT,VSDTM,RESULT1,DATE,DATE1,DATE2,ENDT,STOP
+3 SET BQGLBT=$NAME(^TMP("BQITMP",UID))
+4 SET BQDXN=$$GDXN^BQITUTL("Nephropathy")
+5 SET BQREF="BQIRY"
+6 DO GDF^BQITUTL(BQDXN,BQREF)
+7 IF $$PAT^BQITDGN(BQREF,BQGLBT,BTDFN)
DO STOR^BQITD05(BTDFN,"Risk-Nephropathy",BQGLBT)
+8 ;
+9 SET FREF=9000010.09
SET GREF=$$ROOT^DILFD(FREF,"",1)
+10 SET TREF=$NAME(^TMP("BQITAX",UID))
SET CRDATA=$NAME(^TMP("BQICREAT",UID))
+11 KILL @TREF,@CRDATA
+12 SET TMFRAME="T-12M"
SET ENDT=$$DATE^BQIUL1(TMFRAME)
SET STDT=$$DT^XLFDT()
+13 SET DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
SET EXDT=""
+14 FOR TAX="DM AUDIT CREATININE TAX","BGP CREATININE LOINC CODES"
DO BLD^BQITUTL(TAX,TREF)
+15 SET IEN=""
+16 FOR
SET IEN=$ORDER(@GREF@("AC",BTDFN,IEN))
IF IEN=""
QUIT
Begin DoDot:1
+17 SET TIEN=$$GET1^DIQ(FREF,IEN,.01,"I")
IF TIEN=""
QUIT
+18 IF '$DATA(@TREF@(TIEN))
QUIT
+19 SET VISIT=$$GET1^DIQ(FREF,IEN,.03,"I")
IF VISIT=""
QUIT
+20 SET RESULT=$$GET1^DIQ(FREF,IEN,.04,"E")
IF RESULT=""
QUIT
+21 IF RESULT<2.0
QUIT
+22 SET VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1
IF 'VSDTM
QUIT
+23 IF $$GET1^DIQ(9000010,VISIT,.11,"I")=1
QUIT
+24 IF $GET(TMFRAME)'=""
IF VSDTM<ENDT
QUIT
+25 IF '$DATA(@CRDATA@(BTDFN,VSDTM))
SET @CRDATA@(BTDFN)=$GET(@CRDATA@(BTDFN))+1
+26 SET @CRDATA@(BTDFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
End DoDot:1
+27 IF $GET(@CRDATA@(BTDFN))<2
KILL @CRDATA@(BTDFN)
+28 SET DATE=""
SET STOP=0
+29 NEW DATE1,DATE2
+30 FOR
SET DATE=$ORDER(@CRDATA@(BTDFN,DATE),-1)
IF DATE=""
QUIT
Begin DoDot:1
+31 SET DATE1=DATE
SET DATE2=$ORDER(@CRDATA@(BTDFN,DATE1),-1)
IF DATE2=""
QUIT
+32 IF $$FMDIFF^XLFDT(DATE1,DATE2,1)<90
QUIT
+33 SET RESULT=$PIECE(@CRDATA@(BTDFN,DATE1),"^",1)
+34 SET VISIT=$PIECE(@CRDATA@(BTDFN,DATE1),"^",2)
+35 SET IEN=$PIECE(@CRDATA@(BTDFN,DATE1),"^",3)
+36 SET RESULT1=$PIECE(@CRDATA@(BTDFN,DATE2),"^",1)
+37 SET VISIT1=$PIECE(@CRDATA@(BTDFN,DATE2),"^",2)
+38 SET IEN1=$PIECE(@CRDATA@(BTDFN,DATE2),"^",3)
+39 SET @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
+40 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
+41 SET $PIECE(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT,IEN),U,2)=EXDT
+42 SET @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
+43 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
+44 SET $PIECE(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-Creatinine Value","V",VISIT1,IEN1),U,2)=EXDT
+45 SET TX="Nephropathy-Creatinine Value"
+46 DO STOR^BQITD05(BTDFN,"Nephropathy-Creatinine Value",BQGLBT)
+47 ; Criteria has been met - stop searching
SET STOP=1
End DoDot:1
IF STOP
QUIT
+48 ;
+49 SET FREF=9000010.09
SET GREF=$$ROOT^DILFD(FREF,"",1)
+50 SET TREF=$NAME(^TMP("BQITAX",UID))
SET GFDATA=$NAME(^TMP("BQIGFR",UID))
+51 KILL @GFDATA,@TREF
+52 SET TMFRAME="T-12M"
SET ENDT=$$DATE^BQIUL1(TMFRAME)
SET STDT=$$DT^XLFDT()
+53 SET DTDIF=$$FMDIFF^XLFDT(STDT,ENDT,1)
SET EXDT=""
+54 FOR TAX="BGP GPRA ESTIMATED GFR TAX","BGP ESTIMATED GFR LOINC"
DO BLD^BQITUTL(TAX,TREF)
+55 ;D BLDSV^BQITUTL(95.3,"33914-3",TREF)
+56 SET IEN=""
+57 FOR
SET IEN=$ORDER(@GREF@("AC",BTDFN,IEN))
IF IEN=""
QUIT
Begin DoDot:1
+58 SET TIEN=$$GET1^DIQ(FREF,IEN,.01,"I")
IF TIEN=""
QUIT
+59 IF '$DATA(@TREF@(TIEN))
QUIT
+60 SET VISIT=$$GET1^DIQ(FREF,IEN,.03,"I")
IF VISIT=""
QUIT
+61 SET RESULT=$$GET1^DIQ(FREF,IEN,.04,"E")
IF RESULT=""
QUIT
+62 IF RESULT<30
QUIT
+63 SET VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1
IF 'VSDTM
QUIT
+64 IF $$GET1^DIQ(9000010,VISIT,.11,"I")=1
QUIT
+65 IF $GET(TMFRAME)'=""
IF VSDTM<ENDT
QUIT
+66 SET @GFDATA@(BTDFN,VSDTM)=RESULT_"^"_VISIT_"^"_IEN_"^"_FREF
+67 SET @GFDATA@(BTDFN)=$GET(@GFDATA@(BTDFN))+1
End DoDot:1
+68 ;
+69 IF $GET(@GFDATA@(BTDFN))<2
KILL @GFDATA@(BTDFN)
+70 SET DATE=""
SET STOP=0
+71 NEW DATE1,DATE2
+72 FOR
SET DATE=$ORDER(@GFDATA@(BTDFN,DATE),-1)
IF DATE=""
QUIT
Begin DoDot:1
+73 SET DATE1=DATE
SET DATE2=$ORDER(@GFDATA@(BTDFN,DATE1),-1)
IF DATE2=""
QUIT
+74 ; need to be separated by at least 90 days
+75 IF $$FMDIFF^XLFDT(DATE1,DATE2,1)<90
QUIT
+76 SET RESULT=$PIECE(@GFDATA@(BTDFN,DATE1),"^",1)
+77 SET VISIT=$PIECE(@GFDATA@(BTDFN,DATE1),"^",2)
+78 SET IEN=$PIECE(@GFDATA@(BTDFN,DATE1),"^",3)
+79 SET RESULT1=$PIECE(@GFDATA@(BTDFN,DATE2),"^",1)
+80 SET VISIT1=$PIECE(@GFDATA@(BTDFN,DATE2),"^",2)
+81 SET IEN1=$PIECE(@GFDATA@(BTDFN,DATE2),"^",3)
+82 SET @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN)=DATE1_U_U_IEN_U_FREF
+83 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE1,DTDIF)
+84 SET $PIECE(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT,IEN),U,2)=EXDT
+85 SET @BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1)=DATE2_U_U_IEN1_U_FREF
+86 IF DTDIF'=""
SET EXDT=$$FMADD^XLFDT(DATE2,DTDIF)
+87 SET $PIECE(@BQGLBT@(BTDFN,"CRITERIA","Nephropathy-GFR Value","V",VISIT1,IEN1),U,2)=EXDT
+88 SET TX="Nephropathy-GFR Value"
+89 DO STOR^BQITD05(BTDFN,"Nephropathy-GFR Value",BQGLBT)
+90 ; Criteria has been met - stop searching
SET STOP=1
End DoDot:1
IF STOP
QUIT
+91 QUIT