/**
   * @see PersonDataEvaluator#evaluate(PersonDataDefinition, EvaluationContext)
   * @should return the most preferred name for each person in the passed context
   * @should return empty result set for an empty base cohort
   * @should return the preferred name for all persons
   */
  public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context)
      throws EvaluationException {
    EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

    if (context.getBaseCohort() != null && context.getBaseCohort().isEmpty()) {
      return c;
    }

    HqlQueryBuilder q = new HqlQueryBuilder();
    q.select("pn.person.personId", "pn");
    q.from(PersonName.class, "pn");
    q.wherePersonIn("pn.person.personId", context);
    q.orderAsc("pn.preferred");

    Map<Integer, Object> data = evaluationService.evaluateToMap(q, Integer.class, Object.class);
    c.setData(data);

    return c;
  }
  /**
   * @see PersonDataEvaluator#evaluate(PersonDataDefinition, EvaluationContext)
   * @should return the vital status by person
   */
  public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context)
      throws EvaluationException {
    EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

    HqlQueryBuilder q = new HqlQueryBuilder();
    q.select("p.personId", "p.dead", "p.deathDate", "cod");
    q.from(Person.class, "p");
    q.leftOuterJoin("p.causeOfDeath", "cod");
    q.wherePersonIn("p.personId", context);

    List<Object[]> results = evaluationService.evaluateToList(q, context);
    for (Object[] row : results) {
      Integer pId = (Integer) row[0];
      boolean dead = (row[1] == Boolean.TRUE);
      Date deathDate = (dead ? (Date) row[2] : null);
      Concept causeOfDeath = (dead ? (Concept) row[3] : null);
      c.addData(pId, new VitalStatus(dead, deathDate, causeOfDeath));
    }

    return c;
  }