All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.imsweb.algorithms.ruralurban.RuralUrbanUtils Maven / Gradle / Ivy

Go to download

Java implementation of cancer-related algorithms (NHIA, NAPIIA, Survival Time, etc...)

There is a newer version: 5.0
Show newest version
/*
 * Copyright (C) 2014 Information Management Services, Inc.
 */
package com.imsweb.algorithms.ruralurban;

import java.util.Map;

/**
 * This class can be used to calculate the rural urban census code, the rural urban commuting area code, and the rural urban continuum code.
 * Created on Aug 12, 2014 by HoweW
 * @author howew
 */
public final class RuralUrbanUtils {

    public static final String ALG_NAME = "NAACCR Rural Urban Program";
    public static final String ALG_VERSION = "NAACCR 2015 Call for Data";
    public static final String ALG_INFO = "NAACCR Rural Urban Program, NAACCR 2015 Call for Data, released in August 2014";

    //NAACCR Items Used for calculation
    public static final String PROP_STATE_DX = "addressAtDxState";
    public static final String PROP_COUNTY_DX = "addressAtDxCounty";
    public static final String PROP_DIAGNOSIS_YEAR = "dateOfDiagnosisYear";
    public static final String PROP_CENSUS_TRACT_2000 = "censusTract2000";
    public static final String PROP_CENSUS_TRACT_2010 = "censusTract2010";

    //Unknown values for each code
    public static final String RURAL_URBAN_CENSUS_UNKNOWN = "98";
    public static final String RURAL_URBAN_COMMUTING_AREA_UNKNOWN = "98";
    public static final String RURAL_URBAN_CONTINUUM_UNKNOWN = "98";

    private static RuralUrbanDataProvider _PROVIDER;

    /**
     * Calculates the rural urban census for the provided record
     * 

* The provided record doesn't need to contain all the input variables, but the algorithm will use the following ones: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
  • censusTract2000 (#130)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural census will have the following values depending on the census tract (2000, or 2010): *
  • 01 = All urban - the percentage of the population in an urban area is 100%
  • *
  • 02 = Mostly urban - the percentage of the population in an urban area is between >=50% and <100%
  • *
  • 03 = Mostly rural - the percentage of the population in an urban area is between >0% and <50%
  • *
  • 04 = All rural - the percentage of the population in an urban area is 0%
  • *
  • 09 = The percentage of the population in an urban or rural area is unknown
  • *
  • 96 = Invalid state, county code, or census tract
  • *
  • 97 = Insufficient population data for county to determine census code
  • *
  • 98 = Valid state/county/tract combination but census code not found
  • *
  • 99 = Missing or unknown state, county, or census tract
*

* @param record a map of properties representing a NAACCR line * @return the computed rural urban census value */ public static RuralUrbanOutputDto computeRuralUrbanCensus(Map record) { RuralUrbanInputDto input = new RuralUrbanInputDto(); input.setAddressAtDxState(record.get(PROP_STATE_DX)); input.setAddressAtDxCounty(record.get(PROP_COUNTY_DX)); input.setCensusTract2000(record.get(PROP_CENSUS_TRACT_2000)); input.setCensusTract2010(record.get(PROP_CENSUS_TRACT_2010)); return computeRuralUrbanCensus(input); } /** * Calculates the rural urban census for the provided rural urban input dto *

* The provided input dto has the following parameters used in the calculation: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
  • censusTract2000 (#130)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural census will have the following values depending on the census tract (2000, or 2010): *
  • 01 = All urban - the percentage of the population in an urban area is 100%
  • *
  • 02 = Mostly urban - the percentage of the population in an urban area is between >=50% and <100%
  • *
  • 03 = Mostly rural - the percentage of the population in an urban area is between >0% and <50%
  • *
  • 04 = All rural - the percentage of the population in an urban area is 0%
  • *
  • 09 = The percentage of the population in an urban or rural area is unknown
  • *
  • 96 = Invalid state, county code, or census tract
  • *
  • 97 = Insufficient population data for county to determine census code
  • *
  • 98 = Valid state/county/tract combination but census code not found
  • *
  • 99 = Missing or unknown state, county, or census tract
*

* @param input a RuralUrbanContinuumInputDto input object * @return the computed rural urban census value */ public static RuralUrbanOutputDto computeRuralUrbanCensus(RuralUrbanInputDto input) { RuralUrbanOutputDto result = new RuralUrbanOutputDto(); input.applyRecodes(); // 2000 if (!input.isStateAtDxValidOrMissingOrUnknown() || !input.isCountyAtDxValidOrMissingOrUnknown() || !input.isCensusTract2000ValidOrMissingOrUnknown()) { result.setRuralUrbanCensus2000("96"); } else if (input.isStateAtDxMissingOrUnknown() || input.isCountyAtDxMissingOrUnknown() || input.isCensusTract2000MissingOrUnknown()) { result.setRuralUrbanCensus2000("99"); } else if (input.getAddressAtDxCounty().equals("000")) { result.setRuralUrbanCensus2000("97"); } else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setRuralUrbanCensus2000(_PROVIDER.getRuralUrbanCensus(RuralUrbanDataProvider.TRACT_CATEGORY_1, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2000())); result.setRuralUrbanCensus2000Percentage(_PROVIDER.getRuralUrbanCensusPercentage(RuralUrbanDataProvider.TRACT_CATEGORY_1, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2000())); } // 2010 if (!input.isStateAtDxValidOrMissingOrUnknown() || !input.isCountyAtDxValidOrMissingOrUnknown() || !input.isCensusTract2010ValidOrMissingOrUnknown()) { result.setRuralUrbanCensus2010("96"); } else if (input.isStateAtDxMissingOrUnknown() || input.isCountyAtDxMissingOrUnknown() || input.isCensusTract2010MissingOrUnknown()) { result.setRuralUrbanCensus2010("99"); } else if (input.getAddressAtDxCounty().equals("000")) { result.setRuralUrbanCensus2010("97"); } else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setRuralUrbanCensus2010(_PROVIDER.getRuralUrbanCensus(RuralUrbanDataProvider.TRACT_CATEGORY_2, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2010())); result.setRuralUrbanCensus2010Percentage(_PROVIDER.getRuralUrbanCensusPercentage(RuralUrbanDataProvider.TRACT_CATEGORY_2, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2010())); } // getRuralUrbanCensus method never returns null, but lets make sure we don't return null value anyways if (result.getRuralUrbanCensus2000() == null) result.setRuralUrbanCensus2000(RURAL_URBAN_CENSUS_UNKNOWN); if (result.getRuralUrbanCensus2010() == null) result.setRuralUrbanCensus2010(RURAL_URBAN_CENSUS_UNKNOWN); return result; } /** * Calculates the rural urban commuting area for the provided record *

* The provided record doesn't need to contain all the input variables, but the algorithm will use the following ones: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
  • censusTract2000 (#130)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural commuting area will have the following values depending on the census tract (2000, or 2010): *
  • 01 = Urban commuting area - RUCA codes 1.0, 1.1, 2.0, 2.1, 3.0, 4.1, 5.1, 7.1, 8.1, and 10.1
  • *
  • 02 = Not an urban commuting area - all other RUCA codes except 99
  • *
  • 09 = RUCA code is 99
  • *
  • 96 = Invalid state, county, or census tract
  • *
  • 97 = Insufficient population data for county to determine RUCA code
  • *
  • 98 = Valid state/county/tract combination but RUCA code not found
  • *
  • 99 = Missing or unknown state, county, or census tract
*

* @param record a map of properties representing a NAACCR line * @return the computed rural urban commuting area value */ public static RuralUrbanOutputDto computeRuralUrbanCommutingArea(Map record) { RuralUrbanInputDto input = new RuralUrbanInputDto(); input.setAddressAtDxState(record.get(PROP_STATE_DX)); input.setAddressAtDxCounty(record.get(PROP_COUNTY_DX)); input.setCensusTract2000(record.get(PROP_CENSUS_TRACT_2000)); input.setCensusTract2010(record.get(PROP_CENSUS_TRACT_2010)); return computeRuralUrbanCommutingArea(input); } /** * Calculates the rural urban commuting area for the provided rural urban input dto *

* The provided input dto has the following parameters used in the calculation: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
  • censusTract2000 (#130)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural commuting area will have the following values depending on the year (1993, 2003, or 2013): * The returned urban rural commuting area will have the following values depending on the census tract (2000, or 2010): *
  • 01 = Urban commuting area - RUCA codes 1.0, 1.1, 2.0, 2.1, 3.0, 4.1, 5.1, 7.1, 8.1, and 10.1
  • *
  • 02 = Not an urban commuting area - all other RUCA codes except 99
  • *
  • 09 = RUCA code is 99
  • *
  • 96 = Invalid state abbreviation, county code, or census tract
  • *
  • 97 = Insufficient population data for county to determine RUCA code
  • *
  • 98 = Valid state/county/tract combination but RUCA code not found
  • *
  • 99 = Missing or unknown state, county, or census tract
*

* @param input a RuralUrbanContinuumInputDto input object * @return the computed rural urban commuting area value */ public static RuralUrbanOutputDto computeRuralUrbanCommutingArea(RuralUrbanInputDto input) { RuralUrbanOutputDto result = new RuralUrbanOutputDto(); input.applyRecodes(); // 2000 if (!input.isStateAtDxValidOrMissingOrUnknown() || !input.isCountyAtDxValidOrMissingOrUnknown() || !input.isCensusTract2000ValidOrMissingOrUnknown()) { result.setRuralUrbanCommutingArea2000("96"); } else if (input.isStateAtDxMissingOrUnknown() || input.isCountyAtDxMissingOrUnknown() || input.isCensusTract2000MissingOrUnknown()) { result.setRuralUrbanCommutingArea2000("99"); } else if (input.getAddressAtDxCounty().equals("000")) { result.setRuralUrbanCommutingArea2000("97"); } else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setRuralUrbanCommutingArea2000(_PROVIDER.getRuralUrbanCommutingArea(RuralUrbanDataProvider.TRACT_CATEGORY_1, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2000())); } // 2010 if (!input.isStateAtDxValidOrMissingOrUnknown() || !input.isCountyAtDxValidOrMissingOrUnknown() || !input.isCensusTract2010ValidOrMissingOrUnknown()) { result.setRuralUrbanCommutingArea2010("96"); } else if (input.isStateAtDxMissingOrUnknown() || input.isCountyAtDxMissingOrUnknown() || input.isCensusTract2010MissingOrUnknown()) { result.setRuralUrbanCommutingArea2010("99"); } else if (input.getAddressAtDxCounty().equals("000")) { result.setRuralUrbanCommutingArea2010("97"); } else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setRuralUrbanCommutingArea2010(_PROVIDER.getRuralUrbanCommutingArea(RuralUrbanDataProvider.TRACT_CATEGORY_2, input.getAddressAtDxState(), input.getAddressAtDxCounty(), input.getCensusTract2010())); } // getRuralUrbanCommutingArea method never returns null, but lets make sure we don't return null value anyways if (result.getRuralUrbanCommutingArea2000() == null) result.setRuralUrbanCommutingArea2000(RURAL_URBAN_COMMUTING_AREA_UNKNOWN); if (result.getRuralUrbanCommutingArea2010() == null) result.setRuralUrbanCommutingArea2010(RURAL_URBAN_COMMUTING_AREA_UNKNOWN); return result; } /** * Calculates the rural urban continuum for the provided record *

* The provided record doesn't need to contain all the input variables, but the algorithm will use the following ones: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural continuum will have the following values depending on the year (1993, 2003, or 2013): *
  • 00 = Central counties of metro areas of 1 million population or more (1993 only)
  • *
  • 01 = Counties of metro areas of 1 million population or more
  • *
  • 02 = Counties in metro areas of 250,000 to 1 million population
  • *
  • 03 = Counties in metro areas of fewer than 250,000 population
  • *
  • 04 = Urban population of 20,000 or more, adjacent to a metro area
  • *
  • 05 = Urban population of 20,000 or more, not adjacent to a metro area
  • *
  • 06 = Urban population of 2,500 to 19,999, adjacent to a metro area
  • *
  • 07 = Urban population of 2,500 to 19,999, not adjacent to a metro area
  • *
  • 08 = Completely rural or less than 2,500 urban population, adjacent to a metro area
  • *
  • 09 = Completely rural or less than 2,500 urban population, not adjacent to a metro area
  • *
  • 96 = Invalid state abbreviation or county code
  • *
  • 97 = Insufficient population data for county to determine rural urban code
  • *
  • 98 = Valid state/county combination but rural urban code not found
  • *
  • 99 = Missing or unknown state or county
*

* @param record a map of properties representing a NAACCR line * @return the computed rural urban continuum value */ public static RuralUrbanOutputDto computeRuralUrbanContinuum(Map record) { RuralUrbanInputDto input = new RuralUrbanInputDto(); input.setAddressAtDxState(record.get(PROP_STATE_DX)); input.setAddressAtDxCounty(record.get(PROP_COUNTY_DX)); return computeRuralUrbanContinuum(input); } /** * Calculates the rural urban continuum for the provided rural urban continuum input dto *

* The provided input dto has the following parameters used in the calculation: *
    *
  • addressAtDxState (#80)
  • *
  • addressAtDxCounty (#90)
  • *
  • dateOfDiagnosisYear (#390)
  • *
* All those properties are defined as constants in this class. *

* The returned urban rural continuum will have the following values depending on the year (1993, 2003, or 2013): *
  • 00 = Central counties of metro areas of 1 million population or more (1993 only)
  • *
  • 01 = Counties of metro areas of 1 million population or more
  • *
  • 02 = Counties in metro areas of 250,000 to 1 million population
  • *
  • 03 = Counties in metro areas of fewer than 250,000 population
  • *
  • 04 = Urban population of 20,000 or more, adjacent to a metro area
  • *
  • 05 = Urban population of 20,000 or more, not adjacent to a metro area
  • *
  • 06 = Urban population of 2,500 to 19,999, adjacent to a metro area
  • *
  • 07 = Urban population of 2,500 to 19,999, not adjacent to a metro area
  • *
  • 08 = Completely rural or less than 2,500 urban population, adjacent to a metro area
  • *
  • 09 = Completely rural or less than 2,500 urban population, not adjacent to a metro area
  • *
  • 96 = Invalid state abbreviation or county code
  • *
  • 97 = Insufficient population data for county to determine rural urban code
  • *
  • 98 = Valid state/county combination but rural urban code not found
  • *
  • 99 = Missing or unknown state or county
*

* @param input a RuralUrbanContinuumInputDto input object * @return the computed rural urban continuum value */ public static RuralUrbanOutputDto computeRuralUrbanContinuum(RuralUrbanInputDto input) { RuralUrbanOutputDto result = new RuralUrbanOutputDto(); input.applyRecodes(); if (!input.isStateAtDxValidOrMissingOrUnknown() || !input.isCountyAtDxValidOrMissingOrUnknown()) { result.setRuralUrbanContinuum1993("96"); result.setRuralUrbanContinuum2003("96"); result.setRuralUrbanContinuum2013("96"); } else if (input.isStateAtDxMissingOrUnknown() || input.isCountyAtDxMissingOrUnknown()) { result.setRuralUrbanContinuum1993("99"); result.setRuralUrbanContinuum2003("99"); result.setRuralUrbanContinuum2013("99"); } else if (input.getAddressAtDxCounty().equals("000")) { result.setRuralUrbanContinuum1993("97"); result.setRuralUrbanContinuum2003("97"); result.setRuralUrbanContinuum2013("97"); } else { if (_PROVIDER == null) initializeInternalDataProvider(); result.setRuralUrbanContinuum1993(_PROVIDER.getRuralUrbanContinuum(RuralUrbanDataProvider.BEALE_CATEGORY_1, input.getAddressAtDxState(), input.getAddressAtDxCounty())); result.setRuralUrbanContinuum2003(_PROVIDER.getRuralUrbanContinuum(RuralUrbanDataProvider.BEALE_CATEGORY_2, input.getAddressAtDxState(), input.getAddressAtDxCounty())); result.setRuralUrbanContinuum2013(_PROVIDER.getRuralUrbanContinuum(RuralUrbanDataProvider.BEALE_CATEGORY_3, input.getAddressAtDxState(), input.getAddressAtDxCounty())); } // getRuralUrbanContinuum method never returns null, but lets make sure we don't return null value anyways if (result.getRuralUrbanContinuum1993() == null) result.setRuralUrbanContinuum1993(RURAL_URBAN_CONTINUUM_UNKNOWN); if (result.getRuralUrbanContinuum2003() == null) result.setRuralUrbanContinuum2003(RURAL_URBAN_CONTINUUM_UNKNOWN); if (result.getRuralUrbanContinuum2013() == null) result.setRuralUrbanContinuum2013(RURAL_URBAN_CONTINUUM_UNKNOWN); return result; } /** * Use this method to register your own data provider instead of using the internal one that is entirely in memory. *

* This has to be done before the first call to the compute method, or the internal one will be registered by default. *

* Once a provider has been set, this method cannot be called (it will throw an exception). * @param provider the RuralUrbanDataProvider to set */ public static synchronized void setDataProvider(RuralUrbanDataProvider provider) { if (_PROVIDER != null) throw new RuntimeException("The data provider has already been set!"); _PROVIDER = provider; } private static synchronized void initializeInternalDataProvider() { if (_PROVIDER != null) return; _PROVIDER = new RuralUrbanCsvData(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy