RORX020 ;BPOIFO/ACS - RENAL FUNCTION BY RANGE ;6/2/11 4:19pm
;;1.5;CLINICAL CASE REGISTRIES;**10,13,14,15,19,21,31,33,39**;Feb 17, 2006;Build 4
;
; This routine uses the following IAs:
;
; #4290 ^PXRMINDX(120.5 (controlled)
; #3647 $$EN^GMVPXRM (controlled)
; #10061 DEM^VADPT (supported)
; #10105 PWR^XLFMTH (supported)
; #5047 $$GETIEN^GMVGETVT (supported)
; #3556 GCPR^LA7QRY (supported)
;
;******************************************************************************
;******************************************************************************
; --- ROUTINE MODIFICATION LOG ---
;
;PKG/PATCH DATE DEVELOPER MODIFICATION
;----------- ---------- ----------- ----------------------------------------
;ROR*1.5*10 MAR 2010 A SAUNDERS Routine created.
;ROR*1.5*13 DEC 2010 A SAUNDERS User can select specific patients,
; clinics, or divisions for the report.
; Modified XML tags for sort.
;ROR*1.5*14 APR 2011 A SAUNDERS CALCRF: Age calculation now uses
; $$AGE^RORX019A.
;ROR*1.5*15 JUN 2011 C RAY Added calculation for eGRF by CKD-EPI.
;ROR*1.5*19 FEB 2012 J SCOTT Support for ICD-10 Coding System.
;ROR*1.5*21 SEP 2013 T KOPP Add ICN column if Additional Identifier
; requested.
;ROR*1.5*31 MAY 2017 M FERRARESE Adding PACT ,PCP,and AGE/DOB as additional
;ROR*1.5*33 APR 2018 F TRAXLER Add FUT_APPT column if requested
;ROR*1.5*39 JUN 2021 F TRAXLER Replace real SSN with zeroes.
;******************************************************************************
;******************************************************************************
Q
;
;************************************************************************
;COMPILE THE "RENAL FUNCTION BY RANGE" REPORT
;REPORT CODE: 020
;
;Called by entry "Renal Function by Range" in ROR REPORT PARAMETERS (#799.34)
;
;INPUT
; RORTSK Task number and task parameters
;
; Below is a sample RORTSK input array for utilization in 2003, most recent
; scores, CrCL range from 20 to 50, eGFR range from 30 to 60:
;
; RORTSK=nnn (the task number)
; RORTSK("EP")="$$RFRANGE^RORX020"
; RORTSK("PARAMS","DATE_RANGE_3","A","END")=3031231
; RORTSK("PARAMS","DATE_RANGE_3","A","START")=3030101
; RORTSK("PARAMS","IC9FILT","A","FILTER")="ALL"
; RORTSK("PARAMS","LRGRANGES","C",1)=""
; RORTSK("PARAMS","LRGRANGES","C",1,"H")=50
; RORTSK("PARAMS","LRGRANGES","C",1,"L")=20
; RORTSK("PARAMS","LRGRANGES","C",2)=""
; RORTSK("PARAMS","LRGRANGES","C",2,"H")=60
; RORTSK("PARAMS","LRGRANGES","C",2,"L")=30
; RORTSK("PARAMS","OPTIONS","A","COMPLETE")=1
; RORTSK("PARAMS","OPTIONS","A","MOST_RECENT")=1
; RORTSK("PARAMS","PATIENTS","A","DE_AFTER")=1
; RORTSK("PARAMS","PATIENTS","A","DE_BEFORE")=1
; RORTSK("PARAMS","PATIENTS","A","DE_DURING")=1
; RORTSK("PARAMS","REGIEN")=1
;
; If the user selected an 'as of' date = 12/31/2005:
; RORTSK("PARAMS","OPTIONS","A","MOST_RECENT")=1
; is replaced with:
; RORTSK("PARAMS","OPTIONS","A","MAX_DATE")=3051231
;
;OUTPUT
; <0 Error code
; 0 Ok
;************************************************************************
RFRANGE(RORTSK) ;
N RORDATA ; array to hold ROR data and summary totals
N RORREG ; Registry IEN
N RORSDT ; report start date
N ROREDT ; report end date
N RORPTIEN ; IEN of patient in the ROR registry
N DFN ; DFN of patient in the PATIENT file (#2)
N RORLC ; sub-file and array of LOINC codes to search Lab data
N RORCDLIST ; Flag to indicate whether a clinic or division list exists
N RORCDSTDT ; Start date for clinic/division utilization search
N RORCDENDT ; End date for clinic/division utilization search
;
N REPORT,RC,I,SFLAGS,PARAMS
;--- Establish the root XML Node of the report and put into output
S REPORT=$$ADDVAL^RORTSK11(RORTSK,"REPORT")
Q:REPORT<0 REPORT
;
;--- Get registry IEN
S RORREG=$$PARAM^RORTSK01("REGIEN") ; Registry IEN
;
;--- Set standard report parameters data into output:
;registry, comment, patients (before, during, after), options (summary vs.
;complete), other registries, and other diagnoses
S PARAMS=$$PARAMS^RORXU002(.RORTSK,REPORT,.RORSDT,.ROREDT,.SFLAGS) Q:PARAMS<0 PARAMS
;
;--- Add range parameters to output
S RC=$$PARAMS^RORX020A(PARAMS,.RORDATA) Q:RC<0 RC
;
;--- Put report header data into output:
;report creation date, task number, last registry update date, and
;last data extraction date
S RC=$$HEADER^RORX020A(REPORT,.RORTSK) Q:RC<0 RC
;
;--- Get Renal ranges requested
;I=1 ==> report = CrCL I=2 ==> report = eGFR by MDRD
S I=0 F S I=$O(RORTSK("PARAMS","LRGRANGES","C",I)) Q:I="" D
. S RORDATA("L",I)=$G(RORTSK("PARAMS","LRGRANGES","C",I,"L")) ;low range
. S RORDATA("H",I)=$G(RORTSK("PARAMS","LRGRANGES","C",I,"H")) ;high range
;
;--- Get GMRV VITAL TYPE pointer for HEIGHT
S RORDATA("HGTP")=$$GETIEN^GMVGETVT("HEIGHT",1)
I '$G(RORDATA("HGTP")) Q -1
;
;--- Get Max Date OUTPUT: RORDATA("DATE") - Max Date for test scores
S RORDATA("DATE")=$$PARAM^RORTSK01("OPTIONS","MAX_DATE")
I $G(RORDATA("DATE"))="" S RORDATA("DATE")=DT
;
;--- Summary vs. complete report requested
S RORDATA("COMPLETE")=0 ;default to 'summary' only
I $$PARAM^RORTSK01("OPTIONS","COMPLETE") S RORDATA("COMPLETE")=1
;
;--- Set the number of Renal ranges and initialize their values to 0
S RORDATA("RCNT")=5 D INIT^RORX020A(.RORDATA)
;
;--- Create 'patients' table
N RORBODY S RORBODY=$$ADDVAL^RORTSK11(RORTSK,"PATIENTS",,REPORT)
D ADDATTR^RORTSK11(RORTSK,RORBODY,"TABLE","PATIENTS")
;
;--- Check utilization
N CNT,ECNT,UTSDT,UTEDT,SKIPSDT,SKIPEDT
S (CNT,ECNT,RC)=0,SKIPEDT=ROREDT,SKIPSDT=RORSDT
; Utilization date range is always sent
S UTSDT=$$PARAM^RORTSK01("DATE_RANGE_3","START")\1
S UTEDT=$$PARAM^RORTSK01("DATE_RANGE_3","END")\1
; Combined date range
S SKIPSDT=$$DTMIN^RORUTL18(SKIPSDT,$G(UTSDT))
S SKIPEDT=$$DTMAX^RORUTL18(SKIPEDT,$G(UTEDT))
;
;--- Number of patients in the registry - used for calculating the
;task progress percentage (shown on the GUI screen)
N RORPTCNT S RORPTCNT=$$REGSIZE^RORUTL02(+RORREG) S:RORPTCNT<0 RORPTCNT=0
;
;--- LOINC codes for Creatinine
;create list for future comparison
S RORDATA("LOINC")=";15045-8;21232-4;2160-0;"
;set up array for future call to Lab API
S RORLC="CH" ;chemistry sub-file to search in #63
S RORLC(1)="15045-8^LN" ;Creatinine LOINC
S RORLC(2)="21232-4^LN" ;Creatinine LOINC
S RORLC(3)="2160-0^LN" ;Creatinine LOINC
;
;--- RACE code 2054-5 = 'black or african american' in RACE file (IEN=9)
S RORDATA("BAM")=";9;"
;
;=== Set up Clinic/Division list parameters
S RORCDLIST=$$CDPARMS^RORXU001(.RORTSK,.RORCDSTDT,.RORCDENDT,1)
;
;--- Get registry records
N RCC,FLAG,SKIP,TMP
S (CNT,RORPTIEN,RC)=0
S FLAG=$G(RORTSK("PARAMS","ICDFILT","A","FILTER"))
F S RORPTIEN=$O(^RORDATA(798,"AC",RORREG,RORPTIEN)) Q:RORPTIEN'>0 D Q:RC<0
. ;--- Calculate 'progress' for the GUI display
. S TMP=$S(RORPTCNT>0:CNT/RORPTCNT,1:"")
. S RC=$$LOOP^RORTSK01(TMP) Q:RC<0
. S CNT=CNT+1
. ;--- Get the patient DFN
. S DFN=$$PTIEN^RORUTL01(RORPTIEN) Q:DFN'>0
. ;--- Check for patient list and quit if not on list
. I $D(RORTSK("PARAMS","PATIENTS","C")),'$D(RORTSK("PARAMS","PATIENTS","C",DFN)) Q
. ;--- Check if the patient should be skipped
. Q:$$SKIP^RORXU005(RORPTIEN,SFLAGS,SKIPSDT,SKIPEDT)
. ;--- Check if patient has passed the ICD filter
. S RCC=0
. I FLAG'="ALL" D
. . S RCC=$$ICD^RORXU010(DFN)
. I (FLAG="INCLUDE")&(RCC=0) Q
. I (FLAG="EXCLUDE")&(RCC=1) Q
. ;
. ;--- Check for Clinic or Division list and quit if not in list
. I RORCDLIST,'$$CDUTIL^RORXU001(.RORTSK,DFN,RORCDSTDT,RORCDENDT) Q
. ;
. ;--- Check for utilization in the corresponding 'utilization' date range
. S SKIP=0 I $G(UTSDT)>0 D
.. N UTIL K TMP S TMP("ALL")=1
.. S UTIL=+$$UTIL^RORXU003(UTSDT,UTEDT,DFN,.TMP)
.. I 'UTIL S SKIP=1
. ;--- Skip the patient if they have no utilization in the range
. I $G(SKIP) Q
. ;
. ;--- For each patient, process the registry record and create report
. I $$PATIENT(DFN,RORBODY,.RORDATA,RORPTIEN,.RORLC)<0 S ECNT=ECNT+1 ;error count
;
;--- If user selected eGFR by MDRD (ID=2) or eGFR by CKD-EPI (ID=3), create summary report
I RORDATA("IDLST")[2!(RORDATA("IDLST")[3) S RC=$$SUMMARY^RORX020A(RORTSK,REPORT,.RORDATA)
Q:RC<0 RC
K ^TMP("RORX020",$J),^TMP("ROROUT",$J)
Q $S(RC<0:RC,ECNT>0:-43,1:0)
;
;************************************************************************
;ADD THE PATIENT DATA TO THE REPORT
;
;INPUT
; DFN Patient DFN in PATIENT file (#2)
; PTAG Reference IEN to the 'body' parent XML tag
; RORDATA Array with ROR data
; RORPTIEN Patient IEN in the ROR registry
; RORLC sub-file and LOINC codes to search for
;
;OUTPUT
; 1 ok
; <0 error
;************************************************************************
PATIENT(DFN,PTAG,RORDATA,RORPTIEN,RORLC) ;
;calculate Renal Function scores
I $$CALCRF^RORX020B(DFN,.RORDATA,RORPTIEN,.RORLC)<0 Q 1 ;quit if patient data not available
I '$$INRANGE^RORX020A(.RORDATA) Q 1 ;quit if score(s) out of requested range
;if eGFR by MDRD requested, add 1 to appropriate category count
I RORDATA("IDLST")[2 D MDRDCAT^RORX020A(.RORDATA)
;if eGFR by CKD-EPI requested, add 1 to appropriate category count
I RORDATA("IDLST")[3 D CKDCAT^RORX020A(.RORDATA)
Q:'RORDATA("COMPLETE") 1 ;continue only if 'complete' report is requested
;--- Get patient data and put into the report
N VADM,VA,RORDOD,TTAG,RTAG,TMP,AGETYPE,AGE
D VADEM^RORUTL05(DFN,1) S VA("BID")="0000"
;--- The <PATIENT> tag
S PTAG=$$ADDVAL^RORTSK11(RORTSK,"PATIENT",,PTAG,,DFN)
I PTAG<0 Q PTAG
;--- Patient Name
D ADDVAL^RORTSK11(RORTSK,"NAME",VADM(1),PTAG,1)
;--- Last 4 digits of the SSN
D ADDVAL^RORTSK11(RORTSK,"LAST4",VA("BID"),PTAG,2)
;--- Age/DOB
S AGETYPE=$$PARAM^RORTSK01("AGE_RANGE","TYPE") I AGETYPE'="ALL" D
. S AGE=$S(AGETYPE="AGE":$P(VADM(4),U),AGETYPE="DOB":$$DATE^RORXU002($P(VADM(3),U)\1),1:"")
. D ADDVAL^RORTSK11(RORTSK,AGETYPE,AGE,PTAG,1)
;--- Date of death
S RORDOD=$$DATE^RORXU002($P(VADM(6),U)\1)
D ADDVAL^RORTSK11(RORTSK,"DOD",$G(RORDOD),PTAG,1)
;--- RENAL DATA tag
S RTAG=$$ADDVAL^RORTSK11(RORTSK,"RNLDATA",,PTAG)
Q:RTAG<0 RTAG
;--- CR Test Tag
S TTAG=$$ADDVAL^RORTSK11(RORTSK,"TEST",,RTAG)
Q:TTAG<0 TTAG
;--- Date Cr Test Taken
D ADDVAL^RORTSK11(RORTSK,"DATE",$G(RORDATA("CRDATE")),TTAG)
;--- Cr Test Value
D ADDVAL^RORTSK11(RORTSK,"RESULT",$G(RORDATA("CR")),TTAG)
;--- Height tag
S TTAG=$$ADDVAL^RORTSK11(RORTSK,"HEIGHT",,RTAG)
Q:TTAG<0 TTAG
;--- Date Height Taken
D ADDVAL^RORTSK11(RORTSK,"DATE",$G(RORDATA("HDATE")),TTAG)
;--- Height value
D ADDVAL^RORTSK11(RORTSK,"RESULT",$G(RORDATA("HGT")),TTAG)
;--- Calculated CRCL
I RORDATA("IDLST")[1 D ADDVAL^RORTSK11(RORTSK,"CRCL",$G(RORDATA("SCORE",1)),PTAG,3)
;--- Calculated eGFR by MDRD
I RORDATA("IDLST")[2 D ADDVAL^RORTSK11(RORTSK,"MDRD",$G(RORDATA("SCORE",2)),PTAG,3)
;--- Calculated eGFR by CKD-EPI
I RORDATA("IDLST")[3 D ADDVAL^RORTSK11(RORTSK,"CKD",$G(RORDATA("SCORE",3)),PTAG,3)
;--- ICN,PACT,PCP
I $$PARAM^RORTSK01("PATIENTS","ICN") D ICNDATA^RORXU006(RORTSK,DFN,PTAG)
I $$PARAM^RORTSK01("PATIENTS","PACT") D PACTDATA^RORXU006(RORTSK,DFN,PTAG)
I $$PARAM^RORTSK01("PATIENTS","PCP") D PCPDATA^RORXU006(RORTSK,DFN,PTAG)
;--- If only patients with future appointments ; PATCH 33
I $$PARAM^RORTSK01("OPTIONS","FUT_APPT") D FUTAPPT^RORXU006(.RORTSK,DFN,$$PARAM^RORTSK01("OPTIONS","FUT_APPT"),PTAG)
Q ($S(TTAG<0:TTAG,1:1))
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORX020 12083 printed Nov 22, 2024@16:55:05 Page 2
RORX020 ;BPOIFO/ACS - RENAL FUNCTION BY RANGE ;6/2/11 4:19pm
+1 ;;1.5;CLINICAL CASE REGISTRIES;**10,13,14,15,19,21,31,33,39**;Feb 17, 2006;Build 4
+2 ;
+3 ; This routine uses the following IAs:
+4 ;
+5 ; #4290 ^PXRMINDX(120.5 (controlled)
+6 ; #3647 $$EN^GMVPXRM (controlled)
+7 ; #10061 DEM^VADPT (supported)
+8 ; #10105 PWR^XLFMTH (supported)
+9 ; #5047 $$GETIEN^GMVGETVT (supported)
+10 ; #3556 GCPR^LA7QRY (supported)
+11 ;
+12 ;******************************************************************************
+13 ;******************************************************************************
+14 ; --- ROUTINE MODIFICATION LOG ---
+15 ;
+16 ;PKG/PATCH DATE DEVELOPER MODIFICATION
+17 ;----------- ---------- ----------- ----------------------------------------
+18 ;ROR*1.5*10 MAR 2010 A SAUNDERS Routine created.
+19 ;ROR*1.5*13 DEC 2010 A SAUNDERS User can select specific patients,
+20 ; clinics, or divisions for the report.
+21 ; Modified XML tags for sort.
+22 ;ROR*1.5*14 APR 2011 A SAUNDERS CALCRF: Age calculation now uses
+23 ; $$AGE^RORX019A.
+24 ;ROR*1.5*15 JUN 2011 C RAY Added calculation for eGRF by CKD-EPI.
+25 ;ROR*1.5*19 FEB 2012 J SCOTT Support for ICD-10 Coding System.
+26 ;ROR*1.5*21 SEP 2013 T KOPP Add ICN column if Additional Identifier
+27 ; requested.
+28 ;ROR*1.5*31 MAY 2017 M FERRARESE Adding PACT ,PCP,and AGE/DOB as additional
+29 ;ROR*1.5*33 APR 2018 F TRAXLER Add FUT_APPT column if requested
+30 ;ROR*1.5*39 JUN 2021 F TRAXLER Replace real SSN with zeroes.
+31 ;******************************************************************************
+32 ;******************************************************************************
+33 QUIT
+34 ;
+35 ;************************************************************************
+36 ;COMPILE THE "RENAL FUNCTION BY RANGE" REPORT
+37 ;REPORT CODE: 020
+38 ;
+39 ;Called by entry "Renal Function by Range" in ROR REPORT PARAMETERS (#799.34)
+40 ;
+41 ;INPUT
+42 ; RORTSK Task number and task parameters
+43 ;
+44 ; Below is a sample RORTSK input array for utilization in 2003, most recent
+45 ; scores, CrCL range from 20 to 50, eGFR range from 30 to 60:
+46 ;
+47 ; RORTSK=nnn (the task number)
+48 ; RORTSK("EP")="$$RFRANGE^RORX020"
+49 ; RORTSK("PARAMS","DATE_RANGE_3","A","END")=3031231
+50 ; RORTSK("PARAMS","DATE_RANGE_3","A","START")=3030101
+51 ; RORTSK("PARAMS","IC9FILT","A","FILTER")="ALL"
+52 ; RORTSK("PARAMS","LRGRANGES","C",1)=""
+53 ; RORTSK("PARAMS","LRGRANGES","C",1,"H")=50
+54 ; RORTSK("PARAMS","LRGRANGES","C",1,"L")=20
+55 ; RORTSK("PARAMS","LRGRANGES","C",2)=""
+56 ; RORTSK("PARAMS","LRGRANGES","C",2,"H")=60
+57 ; RORTSK("PARAMS","LRGRANGES","C",2,"L")=30
+58 ; RORTSK("PARAMS","OPTIONS","A","COMPLETE")=1
+59 ; RORTSK("PARAMS","OPTIONS","A","MOST_RECENT")=1
+60 ; RORTSK("PARAMS","PATIENTS","A","DE_AFTER")=1
+61 ; RORTSK("PARAMS","PATIENTS","A","DE_BEFORE")=1
+62 ; RORTSK("PARAMS","PATIENTS","A","DE_DURING")=1
+63 ; RORTSK("PARAMS","REGIEN")=1
+64 ;
+65 ; If the user selected an 'as of' date = 12/31/2005:
+66 ; RORTSK("PARAMS","OPTIONS","A","MOST_RECENT")=1
+67 ; is replaced with:
+68 ; RORTSK("PARAMS","OPTIONS","A","MAX_DATE")=3051231
+69 ;
+70 ;OUTPUT
+71 ; <0 Error code
+72 ; 0 Ok
+73 ;************************************************************************
RFRANGE(RORTSK) ;
+1 ; array to hold ROR data and summary totals
NEW RORDATA
+2 ; Registry IEN
NEW RORREG
+3 ; report start date
NEW RORSDT
+4 ; report end date
NEW ROREDT
+5 ; IEN of patient in the ROR registry
NEW RORPTIEN
+6 ; DFN of patient in the PATIENT file (#2)
NEW DFN
+7 ; sub-file and array of LOINC codes to search Lab data
NEW RORLC
+8 ; Flag to indicate whether a clinic or division list exists
NEW RORCDLIST
+9 ; Start date for clinic/division utilization search
NEW RORCDSTDT
+10 ; End date for clinic/division utilization search
NEW RORCDENDT
+11 ;
+12 NEW REPORT,RC,I,SFLAGS,PARAMS
+13 ;--- Establish the root XML Node of the report and put into output
+14 SET REPORT=$$ADDVAL^RORTSK11(RORTSK,"REPORT")
+15 if REPORT<0
QUIT REPORT
+16 ;
+17 ;--- Get registry IEN
+18 ; Registry IEN
SET RORREG=$$PARAM^RORTSK01("REGIEN")
+19 ;
+20 ;--- Set standard report parameters data into output:
+21 ;registry, comment, patients (before, during, after), options (summary vs.
+22 ;complete), other registries, and other diagnoses
+23 SET PARAMS=$$PARAMS^RORXU002(.RORTSK,REPORT,.RORSDT,.ROREDT,.SFLAGS)
if PARAMS<0
QUIT PARAMS
+24 ;
+25 ;--- Add range parameters to output
+26 SET RC=$$PARAMS^RORX020A(PARAMS,.RORDATA)
if RC<0
QUIT RC
+27 ;
+28 ;--- Put report header data into output:
+29 ;report creation date, task number, last registry update date, and
+30 ;last data extraction date
+31 SET RC=$$HEADER^RORX020A(REPORT,.RORTSK)
if RC<0
QUIT RC
+32 ;
+33 ;--- Get Renal ranges requested
+34 ;I=1 ==> report = CrCL I=2 ==> report = eGFR by MDRD
+35 SET I=0
FOR
SET I=$ORDER(RORTSK("PARAMS","LRGRANGES","C",I))
if I=""
QUIT
Begin DoDot:1
+36 ;low range
SET RORDATA("L",I)=$GET(RORTSK("PARAMS","LRGRANGES","C",I,"L"))
+37 ;high range
SET RORDATA("H",I)=$GET(RORTSK("PARAMS","LRGRANGES","C",I,"H"))
End DoDot:1
+38 ;
+39 ;--- Get GMRV VITAL TYPE pointer for HEIGHT
+40 SET RORDATA("HGTP")=$$GETIEN^GMVGETVT("HEIGHT",1)
+41 IF '$GET(RORDATA("HGTP"))
QUIT -1
+42 ;
+43 ;--- Get Max Date OUTPUT: RORDATA("DATE") - Max Date for test scores
+44 SET RORDATA("DATE")=$$PARAM^RORTSK01("OPTIONS","MAX_DATE")
+45 IF $GET(RORDATA("DATE"))=""
SET RORDATA("DATE")=DT
+46 ;
+47 ;--- Summary vs. complete report requested
+48 ;default to 'summary' only
SET RORDATA("COMPLETE")=0
+49 IF $$PARAM^RORTSK01("OPTIONS","COMPLETE")
SET RORDATA("COMPLETE")=1
+50 ;
+51 ;--- Set the number of Renal ranges and initialize their values to 0
+52 SET RORDATA("RCNT")=5
DO INIT^RORX020A(.RORDATA)
+53 ;
+54 ;--- Create 'patients' table
+55 NEW RORBODY
SET RORBODY=$$ADDVAL^RORTSK11(RORTSK,"PATIENTS",,REPORT)
+56 DO ADDATTR^RORTSK11(RORTSK,RORBODY,"TABLE","PATIENTS")
+57 ;
+58 ;--- Check utilization
+59 NEW CNT,ECNT,UTSDT,UTEDT,SKIPSDT,SKIPEDT
+60 SET (CNT,ECNT,RC)=0
SET SKIPEDT=ROREDT
SET SKIPSDT=RORSDT
+61 ; Utilization date range is always sent
+62 SET UTSDT=$$PARAM^RORTSK01("DATE_RANGE_3","START")\1
+63 SET UTEDT=$$PARAM^RORTSK01("DATE_RANGE_3","END")\1
+64 ; Combined date range
+65 SET SKIPSDT=$$DTMIN^RORUTL18(SKIPSDT,$GET(UTSDT))
+66 SET SKIPEDT=$$DTMAX^RORUTL18(SKIPEDT,$GET(UTEDT))
+67 ;
+68 ;--- Number of patients in the registry - used for calculating the
+69 ;task progress percentage (shown on the GUI screen)
+70 NEW RORPTCNT
SET RORPTCNT=$$REGSIZE^RORUTL02(+RORREG)
if RORPTCNT<0
SET RORPTCNT=0
+71 ;
+72 ;--- LOINC codes for Creatinine
+73 ;create list for future comparison
+74 SET RORDATA("LOINC")=";15045-8;21232-4;2160-0;"
+75 ;set up array for future call to Lab API
+76 ;chemistry sub-file to search in #63
SET RORLC="CH"
+77 ;Creatinine LOINC
SET RORLC(1)="15045-8^LN"
+78 ;Creatinine LOINC
SET RORLC(2)="21232-4^LN"
+79 ;Creatinine LOINC
SET RORLC(3)="2160-0^LN"
+80 ;
+81 ;--- RACE code 2054-5 = 'black or african american' in RACE file (IEN=9)
+82 SET RORDATA("BAM")=";9;"
+83 ;
+84 ;=== Set up Clinic/Division list parameters
+85 SET RORCDLIST=$$CDPARMS^RORXU001(.RORTSK,.RORCDSTDT,.RORCDENDT,1)
+86 ;
+87 ;--- Get registry records
+88 NEW RCC,FLAG,SKIP,TMP
+89 SET (CNT,RORPTIEN,RC)=0
+90 SET FLAG=$GET(RORTSK("PARAMS","ICDFILT","A","FILTER"))
+91 FOR
SET RORPTIEN=$ORDER(^RORDATA(798,"AC",RORREG,RORPTIEN))
if RORPTIEN'>0
QUIT
Begin DoDot:1
+92 ;--- Calculate 'progress' for the GUI display
+93 SET TMP=$SELECT(RORPTCNT>0:CNT/RORPTCNT,1:"")
+94 SET RC=$$LOOP^RORTSK01(TMP)
if RC<0
QUIT
+95 SET CNT=CNT+1
+96 ;--- Get the patient DFN
+97 SET DFN=$$PTIEN^RORUTL01(RORPTIEN)
if DFN'>0
QUIT
+98 ;--- Check for patient list and quit if not on list
+99 IF $DATA(RORTSK("PARAMS","PATIENTS","C"))
IF '$DATA(RORTSK("PARAMS","PATIENTS","C",DFN))
QUIT
+100 ;--- Check if the patient should be skipped
+101 if $$SKIP^RORXU005(RORPTIEN,SFLAGS,SKIPSDT,SKIPEDT)
QUIT
+102 ;--- Check if patient has passed the ICD filter
+103 SET RCC=0
+104 IF FLAG'="ALL"
Begin DoDot:2
+105 SET RCC=$$ICD^RORXU010(DFN)
End DoDot:2
+106 IF (FLAG="INCLUDE")&(RCC=0)
QUIT
+107 IF (FLAG="EXCLUDE")&(RCC=1)
QUIT
+108 ;
+109 ;--- Check for Clinic or Division list and quit if not in list
+110 IF RORCDLIST
IF '$$CDUTIL^RORXU001(.RORTSK,DFN,RORCDSTDT,RORCDENDT)
QUIT
+111 ;
+112 ;--- Check for utilization in the corresponding 'utilization' date range
+113 SET SKIP=0
IF $GET(UTSDT)>0
Begin DoDot:2
+114 NEW UTIL
KILL TMP
SET TMP("ALL")=1
+115 SET UTIL=+$$UTIL^RORXU003(UTSDT,UTEDT,DFN,.TMP)
+116 IF 'UTIL
SET SKIP=1
End DoDot:2
+117 ;--- Skip the patient if they have no utilization in the range
+118 IF $GET(SKIP)
QUIT
+119 ;
+120 ;--- For each patient, process the registry record and create report
+121 ;error count
IF $$PATIENT(DFN,RORBODY,.RORDATA,RORPTIEN,.RORLC)<0
SET ECNT=ECNT+1
End DoDot:1
if RC<0
QUIT
+122 ;
+123 ;--- If user selected eGFR by MDRD (ID=2) or eGFR by CKD-EPI (ID=3), create summary report
+124 IF RORDATA("IDLST")[2!(RORDATA("IDLST")[3)
SET RC=$$SUMMARY^RORX020A(RORTSK,REPORT,.RORDATA)
+125 if RC<0
QUIT RC
+126 KILL ^TMP("RORX020",$JOB),^TMP("ROROUT",$JOB)
+127 QUIT $SELECT(RC<0:RC,ECNT>0:-43,1:0)
+128 ;
+129 ;************************************************************************
+130 ;ADD THE PATIENT DATA TO THE REPORT
+131 ;
+132 ;INPUT
+133 ; DFN Patient DFN in PATIENT file (#2)
+134 ; PTAG Reference IEN to the 'body' parent XML tag
+135 ; RORDATA Array with ROR data
+136 ; RORPTIEN Patient IEN in the ROR registry
+137 ; RORLC sub-file and LOINC codes to search for
+138 ;
+139 ;OUTPUT
+140 ; 1 ok
+141 ; <0 error
+142 ;************************************************************************
PATIENT(DFN,PTAG,RORDATA,RORPTIEN,RORLC) ;
+1 ;calculate Renal Function scores
+2 ;quit if patient data not available
IF $$CALCRF^RORX020B(DFN,.RORDATA,RORPTIEN,.RORLC)<0
QUIT 1
+3 ;quit if score(s) out of requested range
IF '$$INRANGE^RORX020A(.RORDATA)
QUIT 1
+4 ;if eGFR by MDRD requested, add 1 to appropriate category count
+5 IF RORDATA("IDLST")[2
DO MDRDCAT^RORX020A(.RORDATA)
+6 ;if eGFR by CKD-EPI requested, add 1 to appropriate category count
+7 IF RORDATA("IDLST")[3
DO CKDCAT^RORX020A(.RORDATA)
+8 ;continue only if 'complete' report is requested
if 'RORDATA("COMPLETE")
QUIT 1
+9 ;--- Get patient data and put into the report
+10 NEW VADM,VA,RORDOD,TTAG,RTAG,TMP,AGETYPE,AGE
+11 DO VADEM^RORUTL05(DFN,1)
SET VA("BID")="0000"
+12 ;--- The <PATIENT> tag
+13 SET PTAG=$$ADDVAL^RORTSK11(RORTSK,"PATIENT",,PTAG,,DFN)
+14 IF PTAG<0
QUIT PTAG
+15 ;--- Patient Name
+16 DO ADDVAL^RORTSK11(RORTSK,"NAME",VADM(1),PTAG,1)
+17 ;--- Last 4 digits of the SSN
+18 DO ADDVAL^RORTSK11(RORTSK,"LAST4",VA("BID"),PTAG,2)
+19 ;--- Age/DOB
+20 SET AGETYPE=$$PARAM^RORTSK01("AGE_RANGE","TYPE")
IF AGETYPE'="ALL"
Begin DoDot:1
+21 SET AGE=$SELECT(AGETYPE="AGE":$PIECE(VADM(4),U),AGETYPE="DOB":$$DATE^RORXU002($PIECE(VADM(3),U)\1),1:"")
+22 DO ADDVAL^RORTSK11(RORTSK,AGETYPE,AGE,PTAG,1)
End DoDot:1
+23 ;--- Date of death
+24 SET RORDOD=$$DATE^RORXU002($PIECE(VADM(6),U)\1)
+25 DO ADDVAL^RORTSK11(RORTSK,"DOD",$GET(RORDOD),PTAG,1)
+26 ;--- RENAL DATA tag
+27 SET RTAG=$$ADDVAL^RORTSK11(RORTSK,"RNLDATA",,PTAG)
+28 if RTAG<0
QUIT RTAG
+29 ;--- CR Test Tag
+30 SET TTAG=$$ADDVAL^RORTSK11(RORTSK,"TEST",,RTAG)
+31 if TTAG<0
QUIT TTAG
+32 ;--- Date Cr Test Taken
+33 DO ADDVAL^RORTSK11(RORTSK,"DATE",$GET(RORDATA("CRDATE")),TTAG)
+34 ;--- Cr Test Value
+35 DO ADDVAL^RORTSK11(RORTSK,"RESULT",$GET(RORDATA("CR")),TTAG)
+36 ;--- Height tag
+37 SET TTAG=$$ADDVAL^RORTSK11(RORTSK,"HEIGHT",,RTAG)
+38 if TTAG<0
QUIT TTAG
+39 ;--- Date Height Taken
+40 DO ADDVAL^RORTSK11(RORTSK,"DATE",$GET(RORDATA("HDATE")),TTAG)
+41 ;--- Height value
+42 DO ADDVAL^RORTSK11(RORTSK,"RESULT",$GET(RORDATA("HGT")),TTAG)
+43 ;--- Calculated CRCL
+44 IF RORDATA("IDLST")[1
DO ADDVAL^RORTSK11(RORTSK,"CRCL",$GET(RORDATA("SCORE",1)),PTAG,3)
+45 ;--- Calculated eGFR by MDRD
+46 IF RORDATA("IDLST")[2
DO ADDVAL^RORTSK11(RORTSK,"MDRD",$GET(RORDATA("SCORE",2)),PTAG,3)
+47 ;--- Calculated eGFR by CKD-EPI
+48 IF RORDATA("IDLST")[3
DO ADDVAL^RORTSK11(RORTSK,"CKD",$GET(RORDATA("SCORE",3)),PTAG,3)
+49 ;--- ICN,PACT,PCP
+50 IF $$PARAM^RORTSK01("PATIENTS","ICN")
DO ICNDATA^RORXU006(RORTSK,DFN,PTAG)
+51 IF $$PARAM^RORTSK01("PATIENTS","PACT")
DO PACTDATA^RORXU006(RORTSK,DFN,PTAG)
+52 IF $$PARAM^RORTSK01("PATIENTS","PCP")
DO PCPDATA^RORXU006(RORTSK,DFN,PTAG)
+53 ;--- If only patients with future appointments ; PATCH 33
+54 IF $$PARAM^RORTSK01("OPTIONS","FUT_APPT")
DO FUTAPPT^RORXU006(.RORTSK,DFN,$$PARAM^RORTSK01("OPTIONS","FUT_APPT"),PTAG)
+55 QUIT ($SELECT(TTAG<0:TTAG,1:1))
+56 ;