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

com.imsweb.algorithms.censustractpovertyindicator.CensusTractPovertyIndicatorUtils Maven / Gradle / Ivy

/*
 * Copyright (C) 2013 Information Management Services, Inc.
 */
package com.imsweb.algorithms.censustractpovertyindicator;

import java.time.LocalDate;
import java.util.Map;

import org.apache.commons.lang3.math.NumberUtils;

/**
 * This class can be used to calculate census tract poverty indicator.
 * Created on Oct 17, 2013 by BekeleS
 * @author bekeles
 */
public final class CensusTractPovertyIndicatorUtils {

    public static final String ALG_NAME = "NAACCR Poverty Linkage Program";
    public static final String ALG_VERSION = "9.0";
    public static final String ALG_INFO = "NAACCR Poverty Linkage Program version 9.0, released in August 2019";

    //Naaccr Items Used for calculation
    public static final String PROP_STATE_DX = "addressAtDxState";
    public static final String PROP_COUNTY_DX_ANALYSIS = "countyAtDxAnalysis";
    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 value for census tract poverty indicator
    public static final String POVERTY_INDICATOR_UNKNOWN = "9";

    private static CensusTractPovertyIndicatorDataProvider _PROVIDER;

    /**
     * Calculates the census tract poverty indicator 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)
  • *
  • countyAtDxAnalysis (#89)
  • *
  • dateOfDiagnosisYear (#390)
  • *
  • censusTract2000 (#130)
  • *
  • censusTract2010 (#135)
  • *
* All those properties are defined as constants in this class. *

* The returned poverty indicator will have the following values: * 1 = less than 5% * 2 = greater or equal to 5%, but less than 10% * 3 = greater or equal to 10%, but less than 20% * 4 = greater or equal to 20% * 9 = Unknown *

* @param record a map of properties representing a NAACCR line * @return the computed poverty indicator value * @deprecated use the method that takes a CensusTractPovertyIndicatorInputDto parameter */ @Deprecated public static CensusTractPovertyIndicatorOutputDto computePovertyIndicator(Map record) { CensusTractPovertyIndicatorInputDto input = new CensusTractPovertyIndicatorInputDto(); input.setAddressAtDxState(record.get(PROP_STATE_DX)); input.setCountyAtDxAnalysis(record.get(PROP_COUNTY_DX_ANALYSIS)); input.setDateOfDiagnosisYear(record.get(PROP_DIAGNOSIS_YEAR)); input.setCensusTract2000(record.get(PROP_CENSUS_TRACT_2000)); input.setCensusTract2010(record.get(PROP_CENSUS_TRACT_2010)); return computePovertyIndicator(input, true); } /** * Calculates the census tract poverty indicator for the provided record. * If the boolean includeRecentYears is set to true, The algorithm uses 2009-2011 data for 2012+ diagnosis years. *

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

* The returned poverty indicator will have the following values: * 1 = less than 5% * 2 = greater or equal to 5%, but less than 10% * 3 = greater or equal to 10%, but less than 20% * 4 = greater or equal to 20% * 9 = Unknown *

* @param record a map of properties representing a NAACCR line * @param includeRecentYears if true, the years 2012+ will be calculated using the year category 4 logic, otherwise they will be set to 9 * @return the computed poverty indicator value * @deprecated use the method that takes a CensusTractPovertyIndicatorInputDto parameter */ @Deprecated public static CensusTractPovertyIndicatorOutputDto computePovertyIndicator(Map record, boolean includeRecentYears) { CensusTractPovertyIndicatorInputDto input = new CensusTractPovertyIndicatorInputDto(); input.setAddressAtDxState(record.get(PROP_STATE_DX)); input.setCountyAtDxAnalysis(record.get(PROP_COUNTY_DX_ANALYSIS)); input.setDateOfDiagnosisYear(record.get(PROP_DIAGNOSIS_YEAR)); input.setCensusTract2000(record.get(PROP_CENSUS_TRACT_2000)); input.setCensusTract2010(record.get(PROP_CENSUS_TRACT_2010)); return computePovertyIndicator(input, includeRecentYears); } /** * Calculates the census tract poverty indicator for the provided census tract poverty indicator input dto *

* The provided input dto has the following parameters used in the calculation: *
    *
  • _addressAtDxState
  • *
  • _countyAtDxAnalysis
  • *
  • _dateOfDiagnosisYear
  • *
  • _censusTract2000
  • *
  • _censusTract2010
  • *
* All those properties are defined as constants in this class. *

* The returned poverty indicator will have the following values: * 1 = less than 5% * 2 = greater or equal to 5%, but less than 10% * 3 = greater or equal to 10%, but less than 20% * 4 = greater or equal to 20% * 9 = Unknown *

* @param input a CensusTractPovertyIndicatorInputDto input object * @return the computed poverty indicator value */ public static CensusTractPovertyIndicatorOutputDto computePovertyIndicator(CensusTractPovertyIndicatorInputDto input) { return computePovertyIndicator(input, true); } /** * Calculates the census tract poverty indicator for the provided census tract poverty indicator input dto * If the boolean includeRecentYears is set to true, The algorithm uses 2009-2011 data for 2012+ diagnosis years. *

* The provided input dto has the following parameters used in the calculation: *
    *
  • _addressAtDxState
  • *
  • _countyAtDxAnalysis
  • *
  • _dateOfDiagnosisYear
  • *
  • _censusTract2000
  • *
  • _censusTract2010
  • *
* All those properties are defined as constants in this class. *

* The returned poverty indicator will have the following values: * 1 = less than 5% * 2 = greater or equal to 5%, but less than 10% * 3 = greater or equal to 10%, but less than 20% * 4 = greater or equal to 20% * 9 = Unknown *

* @param input a CensusTractPovertyIndicatorInputDto input object * @param includeRecentYears if true, the indicator will be calculated for the past 2-3 years using the latest data, otherwise they will be set to 9 * @return the computed poverty indicator value */ public static CensusTractPovertyIndicatorOutputDto computePovertyIndicator(CensusTractPovertyIndicatorInputDto input, boolean includeRecentYears) { CensusTractPovertyIndicatorOutputDto result = new CensusTractPovertyIndicatorOutputDto(); // if poverty indicator can not be calculated set it to unknown result.setCensusTractPovertyIndicator(POVERTY_INDICATOR_UNKNOWN); String dxYear = input.getDateOfDiagnosisYear(); if (!NumberUtils.isDigits(dxYear) || input.getAddressAtDxState() == null || input.getCountyAtDxAnalysis() == null) return result; String censusTract, yearCategory; int year = Integer.parseInt(dxYear); if (year >= 1995 && year <= 2004) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_1; censusTract = input.getCensusTract2000(); } else if (year >= 2005 && year <= 2007) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_2; censusTract = input.getCensusTract2000(); } else if (year == 2008) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_3; censusTract = input.getCensusTract2010(); } else if (year == 2009) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_4; censusTract = input.getCensusTract2010(); } else if (year == 2010) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_5; censusTract = input.getCensusTract2010(); } else if (year == 2011) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_6; censusTract = input.getCensusTract2010(); } else if (year == 2012) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_7; censusTract = input.getCensusTract2010(); } else if (year == 2013) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_8; censusTract = input.getCensusTract2010(); } else if (year == 2014) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_9; censusTract = input.getCensusTract2010(); } else if (year >= 2015 && (year <= 2017 || (includeRecentYears && year <= LocalDate.now().getYear()))) { yearCategory = CensusTractPovertyIndicatorDataProvider.YEAR_CATEGORY_10; censusTract = input.getCensusTract2010(); } else return result; if (censusTract != null) { if (_PROVIDER == null) initializeInternalDataProvider(); result.setCensusTractPovertyIndicator(_PROVIDER.getPovertyIndicator(yearCategory, input.getAddressAtDxState(), input.getCountyAtDxAnalysis(), censusTract)); } // getPovertyIndicator method never returns null, but lets make sure we don't return null value anyways if (result.getCensusTractPovertyIndicator() == null) result.setCensusTractPovertyIndicator(POVERTY_INDICATOR_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 CensusTractPovertyIndicatorDataProvider to set */ public static synchronized void setDataProvider(CensusTractPovertyIndicatorDataProvider 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 CensusTractPovertyIndicatorCsvData(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy