class ConditionCohortDefinitionEvaluator implements CohortDefinitionEvaluator {

	@Override
	public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) {
		
		ConditionCohortDefinition cd = (ConditionCohortDefinition) cohortDefinition;
		
		HqlQueryBuilder query = new HqlQueryBuilder();
		query.select("c.patient.patientId")
				.from(Condition.class, "c")
				.wherePatientIn("c.patient.patientId", context)
		        .whereEqual("c.condition.coded", cd.getConditionCoded())
		        .whereEqual("c.condition.nonCoded", cd.getConditionNonCoded())
		        .whereGreaterOrEqualTo("c.dateCreated", cd.getCreatedOnOrAfter())
		        .whereLessOrEqualTo("c.dateCreated", cd.getCreatedOnOrBefore())
		        .whereGreaterOrEqualTo("c.onsetDate", cd.getOnsetDateOnOrAfter())
		        .whereLessOrEqualTo("c.onsetDate", cd.getOnsetDateOnOrBefore())
		        .whereGreaterOrEqualTo("c.endDate", cd.getEndDateOnOrAfter())
		        .whereLessOrEqualTo("c.endDate", cd.getEndDateOnOrBefore())
				.whereGreaterOrEqualTo("c.endDate", cd.getActiveOnDate())
				.whereLessOrEqualTo("c.onsetDate", cd.getActiveOnDate());	
		List<Integer> patientIds = evaluationService.evaluateToList(query, Integer.class, context);
		Cohort cohort = new Cohort(patientIds);
		return new EvaluatedCohort(cohort, cd, context);
	}

}