private EncounterTypeDataRow getEncounterTypeDataRow(
      Provider provider, EncounterUtil.EncounterType encounterType) {

    EncounterTypeDataRow result = new EncounterTypeDataRow();

    Map<Integer, Integer> counts =
        populationReportDao.getCaseManagementNoteCountGroupedByIssueGroup(
            program.getId(), provider, encounterType, startDate, endDate);

    for (IssueGroup issueGroup : getIssueGroups()) {
      Integer count = counts.get(issueGroup.getId());
      result.put(issueGroup, (count != null ? count : 0));
    }

    result.rowTotalUniqueEncounters =
        populationReportDao.getCaseManagementNoteTotalUniqueEncounterCountInIssueGroups(
            program.getId(), provider, encounterType, startDate, endDate);
    result.rowTotalUniqueClients =
        populationReportDao.getCaseManagementNoteTotalUniqueClientCountInIssueGroups(
            program.getId(), provider, encounterType, startDate, endDate);

    return (result);
  }
  private EncounterTypeDataRow getEncounterTypeDataRow(
      Integer roleId, EncounterUtil.EncounterType encounterType) {

    EncounterTypeDataRow result = new EncounterTypeDataRow();
    Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
    int rowTotalUniqueEncounters = 0;
    int rowTotalUniqueClients = 0;

    if (functionalCentre != null) {
      List<Program> programList =
          programDao.getProgramsByFacilityIdAndFunctionalCentreId(
              loggedInInfo.getCurrentFacility().getId(), functionalCentre.getId());
      for (Program p : programList) {
        Map<Integer, Integer> counts1 =
            populationReportDao.getCaseManagementNoteCountGroupedByIssueGroup(
                p.getId(), roleId, encounterType, startDate, endDate);

        counts.putAll(addNewCounts(counts, counts1));

        rowTotalUniqueEncounters +=
            populationReportDao.getCaseManagementNoteTotalUniqueEncounterCountInIssueGroups(
                p.getId(), roleId, encounterType, startDate, endDate);
        rowTotalUniqueClients +=
            populationReportDao.getCaseManagementNoteTotalUniqueClientCountInIssueGroups(
                p.getId(), roleId, encounterType, startDate, endDate);
      }
    }
    if (program != null) {
      Map<Integer, Integer> counts2 =
          populationReportDao.getCaseManagementNoteCountGroupedByIssueGroup(
              program.getId(), roleId, encounterType, startDate, endDate);

      counts.putAll(addNewCounts(counts, counts2));

      rowTotalUniqueEncounters +=
          populationReportDao.getCaseManagementNoteTotalUniqueEncounterCountInIssueGroups(
              program.getId(), roleId, encounterType, startDate, endDate);
      rowTotalUniqueClients +=
          populationReportDao.getCaseManagementNoteTotalUniqueClientCountInIssueGroups(
              program.getId(), roleId, encounterType, startDate, endDate);
    }

    for (IssueGroup issueGroup : getIssueGroups()) {
      Integer count = counts.get(issueGroup.getId());
      result.put(issueGroup, (count != null ? count : 0));
    }

    result.rowTotalUniqueEncounters = rowTotalUniqueEncounters;
    result.rowTotalUniqueClients = rowTotalUniqueClients;

    return (result);
  }