@Override
  public CalculationResultMap evaluate(
      Collection<Integer> cohort, Map<String, Object> map, PatientCalculationContext context) {
    CalculationResultMap ret = new CalculationResultMap();
    PersonService personService = Context.getPersonService();
    PersonAttributeType personAttributeType =
        personService.getPersonAttributeTypeByUuid(
            CommonMetadata._PersonAttributeType.TELEPHONE_CONTACT);

    PersonAttributeCohortDefinition cd = new PersonAttributeCohortDefinition();
    cd.setAttributeType(personAttributeType);

    EvaluatedCohort peopleWithPhoneNumbersCohort =
        CalculationUtils.evaluateWithReporting(cd, cohort, null, context);

    PersonAttributeDataDefinition personAttributeDataDefinition =
        new PersonAttributeDataDefinition();
    personAttributeDataDefinition.setPersonAttributeType(personAttributeType);

    CalculationResultMap data =
        CalculationUtils.evaluateWithReporting(
            personAttributeDataDefinition, cohort, map, null, context);

    for (Integer ptId : cohort) {
      String phoneNumber = null;
      if (peopleWithPhoneNumbersCohort.contains(ptId)) {
        phoneNumber = data.get(ptId).toString();
      }
      ret.put(ptId, new SimpleResult(phoneNumber, this));
    }
    return ret;
  }
  @Override
  public CalculationResultMap evaluate(
      Collection<Integer> cohort,
      Map<String, Object> parameterValues,
      PatientCalculationContext context) {
    //		Date date = (Date) parameterValues.get("date");
    //		if (date == null) {
    //			date = new Date();
    //		}

    if (parameterValues != null) {
      logger.info("Parameter Values is NOT null");
      logger.info(parameterValues.toString());
    } else {

      logger.info("Parameter Values is null");
    }
    Date date = new Date();

    Date startOfDay = DateUtil.getStartOfDay(date);
    Date endOfDay = DateUtil.getEndOfDay(date);
    Concept returnVisitDate = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE);
    // EncounterType tbFollowup = MetadataUtils.existing(EncounterType.class,
    // TbMetadata._EncounterType.TB_CONSULTATION);

    DateObsCohortDefinition cd = new DateObsCohortDefinition();
    cd.setTimeModifier(TimeModifier.ANY);
    cd.setQuestion(returnVisitDate);
    cd.setOperator1(RangeComparator.GREATER_EQUAL);
    cd.setValue1(startOfDay);
    cd.setOperator2(RangeComparator.LESS_EQUAL);
    cd.setValue2(endOfDay);
    // cd.setEncounterTypeList(Collections.singletonList(tbFollowup));

    EvaluatedCohort withScheduledVisit =
        CalculationUtils.evaluateWithReporting(cd, cohort, null, context);

    CalculationResultMap ret = new CalculationResultMap();

    for (Integer ptId : cohort) {
      ret.put(ptId, new BooleanResult(withScheduledVisit.contains(ptId), this));
    }

    return ret;
  }
  /**
   * @see CohortDefinitionEvaluator#evaluateCohort(CohortDefinition, EvaluationContext)
   * @should return patients who have identifiers of the passed types
   * @should return patients who have identifiers matching the passed locations
   * @should return patients who have identifiers matching the passed text
   * @should return patients who have identifiers matching the passed regular expression
   */
  public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) {

    PatientIdentifierCohortDefinition picd = (PatientIdentifierCohortDefinition) cohortDefinition;

    StringBuilder hql = new StringBuilder();
    Map<String, Object> params = new HashMap<String, Object>();

    hql.append("select 	patient.patientId");

    hql.append(ObjectUtil.notNull(picd.getRegexToMatch()) ? ", identifier " : " ");

    hql.append("from	PatientIdentifier ");
    hql.append("where	voided = false ");

    if (picd.getTypesToMatch() != null) {
      Set<Integer> typeIds = new HashSet<Integer>();
      for (PatientIdentifierType t : picd.getTypesToMatch()) {
        typeIds.add(t.getPatientIdentifierTypeId());
      }
      hql.append("and identifierType.patientIdentifierTypeId in (:idTypes) ");
      params.put("idTypes", typeIds);
    }

    if (picd.getLocationsToMatch() != null) {
      Set<Integer> locationIds = new HashSet<Integer>();
      for (Location l : picd.getLocationsToMatch()) {
        locationIds.add(l.getLocationId());
      }
      hql.append("and location.locationId in (:locationIds) ");
      params.put("locationIds", locationIds);
    }

    if (ObjectUtil.notNull(picd.getTextToMatch())) {
      if (picd.getTextToMatch().contains("%")) {
        hql.append("and identifier like :textToMatch ");
      } else {
        hql.append("and identifier = :textToMatch ");
      }
      params.put("textToMatch", picd.getTextToMatch());
    }

    List<Object> results =
        Context.getService(DataSetQueryService.class).executeHqlQuery(hql.toString(), params);
    EvaluatedCohort ret = new EvaluatedCohort(null, picd, context);

    if (ObjectUtil.notNull(
        picd.getRegexToMatch())) { // Query will return an array containing patientId and identifier
      for (Object o : results) {
        Object[] row = (Object[]) o;
        if (row.length == 2
            && row[1] != null
            && row[1].toString().matches(picd.getRegexToMatch())) {
          ret.addMember((Integer) row[0]);
        }
      }
    } else { // Query returns only a patientId
      for (Object o : results) {
        ret.addMember((Integer) o);
      }
    }

    return ret;
  }