<commit_before>package com.servinglynk.hmis.warehouse.dao.helper;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.apache.hadoop.hbase.thrift2.generated.THBaseService.Iface;
import org.springframework.stereotype.Component;

import com.servinglynk.hmis.warehouse.dao.ParentDaoImpl;
import com.servinglynk.hmis.warehouse.domain.ExportDomain;
import com.servinglynk.hmis.warehouse.enums.DisabilitiesIndefiniteandimpairsEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentContinuouslyhomelessoneyearEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentDisablingconditionEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentResidencepriorEnum;
import com.servinglynk.hmis.warehouse.model.v2014.Disabilities;
import com.servinglynk.hmis.warehouse.model.v2014.Enrollment;

@Component
public class ChronicHomelessCalcHelper{
	/*
	 * [Age @ Entry]>=18 AND ( [DisablingCondition] = 1 or [expected to be of
	 * long–continued and indefinite duration and substantially impairs ability
	 * to live independently] = “Yes” (1) for any of the following: physical
	 * disability, developmental disability, chronic health condition, HIV/AIDS,
	 * mental health problem, substance abuse ) and ( [client entering from the
	 * streets, es or sh] = yes or [ProjectType] = 1 or 4 or 8 ) and (
	 * [approximate date started] <= [project entry date] – 365 days or (
	 * [TimesHomelessPastThreeYears] = 4 AND [MonthsHomelessPastThreeYears] = 7
	 * ) )
	 */
	public boolean isEnrollmentChronicHomeless(Enrollment enrollment) {
		if(enrollment !=null) {
			if(enrollment.getAgeAtEntry()>=18) {
				if( (EnrollmentDisablingconditionEnum.ONE.equals(enrollment.getDisablingcondition()) || isChronicDisAbilities(enrollment))
					&& (enrollment.getResidenceprior().equals(EnrollmentResidencepriorEnum.ONE) || EnrollmentResidencepriorEnum.SIXTEEN.equals(enrollment.getResidenceprior()) || 
							EnrollmentResidencepriorEnum.EIGHTEEN.equals(enrollment.getResidenceprior())) 
					&&
					(EnrollmentContinuouslyhomelessoneyearEnum.ONE.equals(enrollment.getContinuouslyhomelessoneyear())||
							EnrollmentContinuouslyhomelessoneyearEnum.FOUR.equals(enrollment.getTimeshomelesspastthreeyears()))){
					return true;
				}
			}
		}
		return false;
	}
	
	private boolean isChronicDisAbilities(Enrollment enrollment) {
		Set<Disabilities> disabilitieses = enrollment.getDisabilitieses();
		if(disabilitieses !=null) {
			for(Disabilities disabilities : disabilitieses) {
				Integer disabilityType = new Integer(disabilities.getDisabilitytype().getValue()) ;
				if(disabilityType >= 5 && disabilityType <= 10  &&
				 DisabilitiesIndefiniteandimpairsEnum.ONE.equals(disabilities.getDisabilitytype())) {
					return true;
				} 
			}
		}
		return false;
	}
}<commit_msg>Fixing an NPE in Chronic Homeless calculation<commit_after>package com.servinglynk.hmis.warehouse.dao.helper;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.apache.hadoop.hbase.thrift2.generated.THBaseService.Iface;
import org.springframework.stereotype.Component;

import com.servinglynk.hmis.warehouse.dao.ParentDaoImpl;
import com.servinglynk.hmis.warehouse.domain.ExportDomain;
import com.servinglynk.hmis.warehouse.enums.DisabilitiesIndefiniteandimpairsEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentContinuouslyhomelessoneyearEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentDisablingconditionEnum;
import com.servinglynk.hmis.warehouse.enums.EnrollmentResidencepriorEnum;
import com.servinglynk.hmis.warehouse.model.v2014.Disabilities;
import com.servinglynk.hmis.warehouse.model.v2014.Enrollment;

@Component
public class ChronicHomelessCalcHelper{
	/*
	 * [Age @ Entry]>=18 AND ( [DisablingCondition] = 1 or [expected to be of
	 * long–continued and indefinite duration and substantially impairs ability
	 * to live independently] = “Yes” (1) for any of the following: physical
	 * disability, developmental disability, chronic health condition, HIV/AIDS,
	 * mental health problem, substance abuse ) and ( [client entering from the
	 * streets, es or sh] = yes or [ProjectType] = 1 or 4 or 8 ) and (
	 * [approximate date started] <= [project entry date] – 365 days or (
	 * [TimesHomelessPastThreeYears] = 4 AND [MonthsHomelessPastThreeYears] = 7
	 * ) )
	 */
	public boolean isEnrollmentChronicHomeless(Enrollment enrollment) {
		if(enrollment !=null) {
			if(enrollment.getAgeAtEntry()>=18) {
				if( (EnrollmentDisablingconditionEnum.ONE.equals(enrollment.getDisablingcondition()) || isChronicDisAbilities(enrollment))
					&& (EnrollmentResidencepriorEnum.ONE.equals(enrollment.getResidenceprior()) || EnrollmentResidencepriorEnum.SIXTEEN.equals(enrollment.getResidenceprior()) || 
							EnrollmentResidencepriorEnum.EIGHTEEN.equals(enrollment.getResidenceprior())) 
					&&
					(EnrollmentContinuouslyhomelessoneyearEnum.ONE.equals(enrollment.getContinuouslyhomelessoneyear())||
							EnrollmentContinuouslyhomelessoneyearEnum.FOUR.equals(enrollment.getTimeshomelesspastthreeyears()))){
					return true;
				}
			}
		}
		return false;
	}
	
	private boolean isChronicDisAbilities(Enrollment enrollment) {
		Set<Disabilities> disabilitieses = enrollment.getDisabilitieses();
		if(disabilitieses !=null) {
			for(Disabilities disabilities : disabilitieses) {
				Integer disabilityType = new Integer(disabilities.getDisabilitytype().getValue()) ;
				if(disabilityType >= 5 && disabilityType <= 10  &&
				 DisabilitiesIndefiniteandimpairsEnum.ONE.equals(disabilities.getDisabilitytype())) {
					return true;
				} 
			}
		}
		return false;
	}
}
{'fraction_non_alphanumeric': 0.10232886379675371, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 5.614935822637106, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6653247', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1732, 'n_words': 310}