Search in sources :

Example 1 with WeeklyReportDto

use of de.symeda.sormas.api.report.WeeklyReportDto in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjb method toDto.

public static WeeklyReportDto toDto(WeeklyReport source) {
    if (source == null) {
        return null;
    }
    WeeklyReportDto target = new WeeklyReportDto();
    DtoHelper.fillDto(target, source);
    target.setReportingUser(UserFacadeEjb.toReferenceDto(source.getReportingUser()));
    target.setReportDateTime(source.getReportDateTime());
    target.setDistrict(DistrictFacadeEjb.toReferenceDto(source.getDistrict()));
    target.setCommunity(CommunityFacadeEjb.toReferenceDto(source.getCommunity()));
    target.setHealthFacility(FacilityFacadeEjb.toReferenceDto(source.getHealthFacility()));
    target.setAssignedOfficer(UserFacadeEjb.toReferenceDto(source.getAssignedOfficer()));
    target.setTotalNumberOfCases(source.getTotalNumberOfCases());
    target.setYear(source.getYear());
    target.setEpiWeek(source.getEpiWeek());
    List<WeeklyReportEntryDto> entryDtos = new ArrayList<>();
    for (WeeklyReportEntry entry : source.getReportEntries()) {
        WeeklyReportEntryDto entryDto = toDto(entry);
        entryDtos.add(entryDto);
    }
    target.setReportEntries(entryDtos);
    return target;
}
Also used : ArrayList(java.util.ArrayList) WeeklyReportEntryDto(de.symeda.sormas.api.report.WeeklyReportEntryDto) WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto)

Example 2 with WeeklyReportDto

use of de.symeda.sormas.api.report.WeeklyReportDto in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjbTest method createOfficerReport.

private WeeklyReportDto createOfficerReport(UserDto reportingUser, Date reportDateTime, int epiWeek, int year, int numberOfCases) {
    WeeklyReportDto report = WeeklyReportDto.build(reportingUser.toReference());
    report.setDistrict(reportingUser.getDistrict());
    report.setReportDateTime(reportDateTime);
    report.setEpiWeek(epiWeek);
    report.setYear(year);
    report.setTotalNumberOfCases(numberOfCases);
    report = getWeeklyReportFacade().saveWeeklyReport(report);
    return report;
}
Also used : WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto)

Example 3 with WeeklyReportDto

use of de.symeda.sormas.api.report.WeeklyReportDto in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportInformantsGrid method reload.

public void reload() {
    getContainer().removeAllItems();
    List<WeeklyReportInformantSummary> reportDetailDtos = new ArrayList<>();
    List<UserDto> informants = FacadeProvider.getUserFacade().getUsersByAssociatedOfficer(officerRef, UserRight.WEEKLYREPORT_CREATE);
    // sort by...
    informants.sort((a, b) -> {
        // 1. community
        if (a.getCommunity() != null && b.getCommunity() != null) {
            int result = a.getCommunity().getCaption().compareTo(b.getCommunity().getCaption());
            if (result != 0)
                return result;
        } else if (a.getCommunity() != null) {
            return 1;
        } else if (b.getCommunity() != null) {
            return -1;
        }
        // 2. facility
        if (a.getHealthFacility() != null && b.getHealthFacility() != null) {
            int result = a.getHealthFacility().getCaption().compareTo(b.getHealthFacility().getCaption());
            if (result != 0)
                return result;
        }
        // 3. name
        return a.getName().compareTo(b.getName());
    });
    for (UserDto informant : informants) {
        WeeklyReportInformantSummary reportDetails = new WeeklyReportInformantSummary();
        reportDetails.setInformant(informant.toReference());
        reportDetails.setCommunity(informant.getCommunity());
        reportDetails.setFacility(informant.getHealthFacility());
        WeeklyReportDto weeklyReport = FacadeProvider.getWeeklyReportFacade().getByEpiWeekAndUser(epiWeek, informant.toReference());
        if (weeklyReport != null) {
            reportDetails.setFacility(weeklyReport.getHealthFacility());
            reportDetails.setCommunity(weeklyReport.getCommunity());
            reportDetails.setInformantReportDate(weeklyReport.getReportDateTime());
            reportDetails.setTotalCaseCount(weeklyReport.getTotalNumberOfCases());
        }
        reportDetailDtos.add(reportDetails);
    }
    getContainer().addAll(reportDetailDtos);
    this.setHeightByRows(reportDetailDtos.size());
}
Also used : UserDto(de.symeda.sormas.api.user.UserDto) ArrayList(java.util.ArrayList) WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto)

Example 4 with WeeklyReportDto

use of de.symeda.sormas.api.report.WeeklyReportDto in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjb method saveWeeklyReport.

@Override
@RolesAllowed(UserRight._WEEKLYREPORT_CREATE)
public WeeklyReportDto saveWeeklyReport(@Valid WeeklyReportDto dto) {
    // Don't create a new report if there already is one in the database for the user/epi week combination
    WeeklyReportDto existingReport = getByEpiWeekAndUser(new EpiWeek(dto.getYear(), dto.getEpiWeek()), dto.getReportingUser());
    if (existingReport != null && !dto.getUuid().equals(existingReport.getUuid())) {
        logger.warn("Tried to create a new report for an already existing user/epi week combination (existing UUID: " + existingReport.getUuid() + "); report was not created");
        return null;
    }
    WeeklyReport report = fromDto(dto, true);
    weeklyReportService.ensurePersisted(report);
    return toDto(report);
}
Also used : WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 5 with WeeklyReportDto

use of de.symeda.sormas.api.report.WeeklyReportDto in project SORMAS-Project by hzi-braunschweig.

the class WeeklyReportFacadeEjbTest method createFacilityInformantReport.

private WeeklyReportDto createFacilityInformantReport(UserDto reportingUser, Date reportDateTime, int epiWeek, int year, int numberOfCases) {
    WeeklyReportDto report = WeeklyReportDto.build(reportingUser.toReference());
    report.setAssignedOfficer(reportingUser.getAssociatedOfficer());
    report.setDistrict(reportingUser.getDistrict());
    report.setHealthFacility(reportingUser.getHealthFacility());
    report.setReportDateTime(reportDateTime);
    report.setEpiWeek(epiWeek);
    report.setYear(year);
    report.setTotalNumberOfCases(numberOfCases);
    report = getWeeklyReportFacade().saveWeeklyReport(report);
    return report;
}
Also used : WeeklyReportDto(de.symeda.sormas.api.report.WeeklyReportDto)

Aggregations

WeeklyReportDto (de.symeda.sormas.api.report.WeeklyReportDto)8 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)2 ArrayList (java.util.ArrayList)2 WeeklyReportEntryDto (de.symeda.sormas.api.report.WeeklyReportEntryDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 Date (java.util.Date)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Test (org.junit.Test)1