Search in sources :

Example 1 with FacilityIndexDto

use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.

the class FacilityFacadeEjb method getIndexList.

@Override
public List<FacilityIndexDto> getIndexList(FacilityCriteria facilityCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<FacilityIndexDto> cq = cb.createQuery(FacilityIndexDto.class);
    Root<Facility> facility = cq.from(Facility.class);
    Join<Facility, Region> region = facility.join(Facility.REGION, JoinType.LEFT);
    Join<Facility, District> district = facility.join(Facility.DISTRICT, JoinType.LEFT);
    Join<Facility, Community> community = facility.join(Facility.COMMUNITY, JoinType.LEFT);
    Predicate filter = service.buildCriteriaFilter(facilityCriteria, cb, facility);
    Predicate excludeFilter = cb.and(cb.notEqual(facility.get(Facility.UUID), FacilityDto.OTHER_FACILITY_UUID), cb.notEqual(facility.get(Facility.UUID), FacilityDto.NONE_FACILITY_UUID));
    if (filter != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, excludeFilter);
    } else {
        filter = excludeFilter;
    }
    if (filter != null) {
        cq.where(filter);
    }
    if (CollectionUtils.isNotEmpty(sortProperties)) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case Facility.NAME:
                case Facility.CITY:
                case Facility.LATITUDE:
                case Facility.LONGITUDE:
                case Facility.EXTERNAL_ID:
                case Facility.TYPE:
                    expression = facility.get(sortProperty.propertyName);
                    break;
                case Facility.REGION:
                    expression = region.get(Region.NAME);
                    break;
                case Facility.DISTRICT:
                    expression = district.get(District.NAME);
                    break;
                case Facility.COMMUNITY:
                    expression = community.get(Community.NAME);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.asc(region.get(Region.NAME)), cb.asc(district.get(District.NAME)), cb.asc(community.get(Community.NAME)), cb.asc(facility.get(Facility.NAME)));
    }
    cq.multiselect(facility.get(Facility.UUID), facility.get(Facility.NAME), facility.get(Facility.TYPE), region.get(Region.UUID), region.get(Region.NAME), district.get(District.UUID), district.get(District.NAME), community.get(Community.UUID), community.get(Community.NAME), facility.get(Facility.CITY), facility.get(Facility.LATITUDE), facility.get(Facility.LONGITUDE), facility.get(Facility.EXTERNAL_ID));
    return QueryHelper.getResultList(em, cq, first, max);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 2 with FacilityIndexDto

use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.

the class FacilityFacadeEjbTest method testGetIndexListMappedSorting.

@Test
public void testGetIndexListMappedSorting() {
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    // 0. No sortProperties
    List<FacilityIndexDto> result = getFacilityFacade().getIndexList(facilityCriteria, null, null, new ArrayList<>());
    assertThat(result, is(empty()));
    List<SortProperty> allSortProperties = new ArrayList<>();
    allSortProperties.add(new SortProperty(FacilityDto.NAME));
    allSortProperties.add(new SortProperty(FacilityDto.TYPE));
    allSortProperties.add(new SortProperty(FacilityDto.REGION));
    allSortProperties.add(new SortProperty(FacilityDto.DISTRICT));
    allSortProperties.add(new SortProperty(FacilityDto.COMMUNITY));
    allSortProperties.add(new SortProperty(FacilityDto.CITY));
    allSortProperties.add(new SortProperty(FacilityDto.LATITUDE));
    allSortProperties.add(new SortProperty(FacilityDto.LONGITUDE));
    allSortProperties.add(new SortProperty(FacilityDto.EXTERNAL_ID));
    // 1. Sort by every property
    for (SortProperty sortProperty : allSortProperties) {
        getFacilityFacade().getIndexList(facilityCriteria, null, null, Collections.singletonList(sortProperty));
        assertThat(sortProperty.toString(), result, is(empty()));
    }
    // 2. Sort by all properties at once
    getFacilityFacade().getIndexList(facilityCriteria, null, null, allSortProperties);
    assertThat(result, is(empty()));
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) ArrayList(java.util.ArrayList) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 3 with FacilityIndexDto

use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.

the class InfrastructureController method archiveOrDearchiveAllSelectedItems.

@SuppressWarnings("unchecked")
public void archiveOrDearchiveAllSelectedItems(boolean archive, Collection<?> selectedRows, InfrastructureType infrastructureType, Runnable callback) {
    // Check that at least one entry is selected
    if (selectedRows.isEmpty()) {
        new Notification(I18nProperties.getString(Strings.headingNoRowsSelected), I18nProperties.getString(Strings.messageNoRowsSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
        return;
    }
    // Check if archiving/dearchiving is allowed concerning the hierarchy
    Set<String> selectedRowsUuids = selectedRows.stream().map(row -> ((HasUuid) row).getUuid()).collect(Collectors.toSet());
    if (InfrastructureType.AREA.equals(infrastructureType) && FacadeProvider.getAreaFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.CONTINENT.equals(infrastructureType) && FacadeProvider.getContinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.REGION.equals(infrastructureType) && FacadeProvider.getRegionFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().isUsedInOtherInfrastructureData(selectedRowsUuids)) {
        showArchivingNotPossibleWindow(infrastructureType, true);
        return;
    }
    if (InfrastructureType.COUNTRY.equals(infrastructureType) && FacadeProvider.getCountryFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.FACILITY.equals(infrastructureType) && FacadeProvider.getFacilityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.POINT_OF_ENTRY.equals(infrastructureType) && FacadeProvider.getPointOfEntryFacade().hasArchivedParentInfrastructure(selectedRowsUuids)) {
        showDearchivingNotPossibleWindow(infrastructureType, false);
        return;
    }
    final String confirmationMessage;
    final String notificationMessage;
    switch(infrastructureType) {
        case CONTINENT:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveContinents) : I18nProperties.getString(Strings.confirmationDearchiveContinents);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageContinentsArchived) : I18nProperties.getString(Strings.messageContinentsDearchived);
            break;
        case SUBCONTINENT:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveSubcontinents) : I18nProperties.getString(Strings.confirmationDearchiveSubcontinents);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageSubcontinentsArchived) : I18nProperties.getString(Strings.messageSubcontinentsDearchived);
            break;
        case AREA:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveAreas) : I18nProperties.getString(Strings.confirmationDearchiveAreas);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageAreasArchived) : I18nProperties.getString(Strings.messageAreasDearchived);
            break;
        case COUNTRY:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCountries) : I18nProperties.getString(Strings.confirmationDearchiveCountries);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageCountriesArchived) : I18nProperties.getString(Strings.messageCountriesDearchived);
            break;
        case REGION:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveRegions) : I18nProperties.getString(Strings.confirmationDearchiveRegions);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageRegionsArchived) : I18nProperties.getString(Strings.messageRegionsDearchived);
            break;
        case DISTRICT:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveDistricts) : I18nProperties.getString(Strings.confirmationDearchiveDistricts);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageDistrictsArchived) : I18nProperties.getString(Strings.messageDistrictsDearchived);
            break;
        case COMMUNITY:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCommunities) : I18nProperties.getString(Strings.confirmationDearchiveCommunities);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageCommunitiesArchived) : I18nProperties.getString(Strings.messageCommunitiesDearchived);
            break;
        case FACILITY:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveFacilities) : I18nProperties.getString(Strings.confirmationDearchiveFacilities);
            notificationMessage = archive ? I18nProperties.getString(Strings.messageFacilitiesArchived) : I18nProperties.getString(Strings.messageFacilitiesDearchived);
            break;
        case POINT_OF_ENTRY:
            confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchivePointsOfEntry) : I18nProperties.getString(Strings.confirmationDearchivePointsOfEntry);
            notificationMessage = archive ? I18nProperties.getString(Strings.messagePointsOfEntryArchived) : I18nProperties.getString(Strings.messagePointsOfEntryDearchived);
            break;
        default:
            throw new IllegalArgumentException(infrastructureType.name());
    }
    VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmArchiving), new Label(String.format(confirmationMessage, selectedRows.size())), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> {
        if (e.booleanValue()) {
            switch(infrastructureType) {
                case CONTINENT:
                    for (ContinentDto selectedRow : (Collection<ContinentDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getContinentFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getContinentFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case SUBCONTINENT:
                    for (SubcontinentDto selectedRow : (Collection<SubcontinentDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getSubcontinentFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getSubcontinentFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case AREA:
                    for (AreaDto selectedRow : (Collection<AreaDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getAreaFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getAreaFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case COUNTRY:
                    for (CountryIndexDto selectedRow : (Collection<CountryIndexDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getCountryFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getCountryFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case REGION:
                    for (RegionIndexDto selectedRow : (Collection<RegionIndexDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getRegionFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getRegionFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case DISTRICT:
                    for (DistrictIndexDto selectedRow : (Collection<DistrictIndexDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getDistrictFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getDistrictFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case COMMUNITY:
                    for (CommunityDto selectedRow : (Collection<CommunityDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getCommunityFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getCommunityFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case FACILITY:
                    for (FacilityIndexDto selectedRow : (Collection<FacilityIndexDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getFacilityFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getFacilityFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                case POINT_OF_ENTRY:
                    for (PointOfEntryDto selectedRow : (Collection<PointOfEntryDto>) selectedRows) {
                        if (archive) {
                            FacadeProvider.getPointOfEntryFacade().archive(selectedRow.getUuid());
                        } else {
                            FacadeProvider.getPointOfEntryFacade().dearchive(selectedRow.getUuid());
                        }
                    }
                    break;
                default:
                    throw new IllegalArgumentException(infrastructureType.name());
            }
            callback.run();
            Notification.show(notificationMessage, Type.ASSISTIVE_NOTIFICATION);
        }
    });
}
Also used : AreaDto(de.symeda.sormas.api.infrastructure.area.AreaDto) Arrays(java.util.Arrays) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener) CommunityDto(de.symeda.sormas.api.infrastructure.community.CommunityDto) Notification(com.vaadin.ui.Notification) SormasUI(de.symeda.sormas.ui.SormasUI) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) Page(com.vaadin.server.Page) Label(com.vaadin.ui.Label) ContinentDto(de.symeda.sormas.api.infrastructure.continent.ContinentDto) RegionIndexDto(de.symeda.sormas.api.infrastructure.region.RegionIndexDto) SubcontinentDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentDto) UserProvider(de.symeda.sormas.ui.UserProvider) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Collection(java.util.Collection) HasUuid(de.symeda.sormas.api.HasUuid) InfrastructureType(de.symeda.sormas.api.infrastructure.InfrastructureType) Set(java.util.Set) CountryIndexDto(de.symeda.sormas.api.infrastructure.country.CountryIndexDto) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) UserRight(de.symeda.sormas.api.user.UserRight) Button(com.vaadin.ui.Button) Type(com.vaadin.ui.Notification.Type) DistrictIndexDto(de.symeda.sormas.api.infrastructure.district.DistrictIndexDto) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) Strings(de.symeda.sormas.api.i18n.Strings) DistrictIndexDto(de.symeda.sormas.api.infrastructure.district.DistrictIndexDto) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) Label(com.vaadin.ui.Label) CountryIndexDto(de.symeda.sormas.api.infrastructure.country.CountryIndexDto) AreaDto(de.symeda.sormas.api.infrastructure.area.AreaDto) Notification(com.vaadin.ui.Notification) RegionIndexDto(de.symeda.sormas.api.infrastructure.region.RegionIndexDto) ContinentDto(de.symeda.sormas.api.infrastructure.continent.ContinentDto) HasUuid(de.symeda.sormas.api.HasUuid) SubcontinentDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentDto) CommunityDto(de.symeda.sormas.api.infrastructure.community.CommunityDto) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) Collection(java.util.Collection)

Example 4 with FacilityIndexDto

use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.

the class DevModeView method generateEvents.

private void generateEvents() {
    initializeRandomGenerator();
    EventGenerationConfig config = eventGeneratorConfigBinder.getBean();
    int generatedParticipants = 0;
    int generatedCases = 0;
    int generatedContacts = 0;
    Disease disease = config.getDisease();
    float baseOffset = random().nextFloat();
    int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
    // this should be adjusted to be much more complex
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    facilityCriteria.region(config.getRegion());
    facilityCriteria.district(config.getDistrict());
    List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, (int) (config.getMaxParticipantsPerEvent() * config.getPercentageOfCases() / 100), null);
    // Filter list, so that only health facilities meant for accomodation are selected
    healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
    long dt = System.nanoTime();
    for (int i = 0; i < config.getEventCount(); i++) {
        LocalDateTime referenceDateTime;
        EventDto event = EventDto.build();
        // disease
        if (disease != null) {
            // reset
            event.setDisease(disease);
            if (event.getDisease() == Disease.OTHER) {
                event.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
            }
            referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, disease, config.getStartDate(), daysBetween);
            fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        } else {
            referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, Disease.OTHER, config.getStartDate(), daysBetween);
            fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(Disease.OTHER).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        }
        // title
        event.setEventTitle(random(eventTitles));
        // description
        event.setEventDesc("Event generated using DevMode on " + LocalDate.now());
        // report
        UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
        event.setReportingUser(userReference);
        event.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        // region & district
        event.getEventLocation().setRegion(config.getRegion());
        event.getEventLocation().setDistrict(config.getDistrict());
        // status
        event.setEventStatus(EventStatus.EVENT);
        FacadeProvider.getEventFacade().save(event);
        // EventParticipants
        int numParticipants = randomInt(config.getMinParticipantsPerEvent(), config.getMaxParticipantsPerEvent());
        for (int j = 0; j < numParticipants; j++) {
            EventParticipantDto eventParticipant = EventParticipantDto.build(event.toReference(), UserProvider.getCurrent().getUserReference());
            // person
            // instead of creating new persons everytime, it would be nice if some persons came of the original database
            PersonDto person = PersonDto.build();
            fillEntity(person, referenceDateTime);
            person.setSymptomJournalStatus(null);
            setPersonName(person);
            FacadeProvider.getPersonFacade().savePerson(person);
            eventParticipant.setPerson(person);
            eventParticipant.setInvolvementDescription("Participant");
            if (disease != null) {
                // generate cases for some participants
                if (randomPercent(config.getPercentageOfCases()) && !healthFacilities.isEmpty()) {
                    CaseDataDto caze = CaseDataDto.buildFromEventParticipant(eventParticipant, person, event.getDisease());
                    fillEntity(caze, referenceDateTime);
                    caze.setDisease(event.getDisease());
                    caze.setReportingUser(UserProvider.getCurrent().getUserReference());
                    caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                    caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
                    caze.setResponsibleRegion(config.getRegion());
                    caze.setResponsibleDistrict(config.getDistrict());
                    FacilityIndexDto facility = random(healthFacilities);
                    caze.setHealthFacility(facility.toReference());
                    caze.setFacilityType(facility.getType());
                    caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
                    FacadeProvider.getCaseFacade().save(caze);
                    eventParticipant.setResultingCase(caze.toReference());
                    generatedCases++;
                }
                // generate contacts for some participants
                List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(event.getDisease()), numParticipants * 2, random());
                int numContacts = randomInt(config.getMinContactsPerParticipant(), config.getMaxContactsPerParticipant());
                for (int k = 0; (k < numContacts && (cases != null)); k++) {
                    ContactDto contact = ContactDto.build(eventParticipant);
                    contact.setDisease(event.getDisease());
                    contact.setCaze(random(cases));
                    contact.setReportingUser(UserProvider.getCurrent().getUserReference());
                    contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                    contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
                    FacadeProvider.getContactFacade().save(contact);
                    generatedContacts++;
                }
            }
            FacadeProvider.getEventParticipantFacade().saveEventParticipant(eventParticipant);
            generatedParticipants++;
        }
    }
    dt = System.nanoTime() - dt;
    long perCase = dt / config.getEventCount();
    String msg = String.format("Generating %d events with a total of %d participants (%d contacts, %d cases) took %.2f  s (%.1f ms per event)", config.getEventCount(), generatedParticipants, generatedContacts, generatedCases, (double) dt / 1_000_000_000, (double) perCase / 1_000_000);
    logger.info(msg);
    Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Also used : LocalDateTime(java.time.LocalDateTime) Disease(de.symeda.sormas.api.Disease) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 5 with FacilityIndexDto

use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.

the class DevModeView method generateCases.

private void generateCases() {
    initializeRandomGenerator();
    CaseGenerationConfig config = caseGeneratorConfigBinder.getBean();
    List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true);
    float baseOffset = random().nextFloat();
    int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    facilityCriteria.region(config.getRegion());
    facilityCriteria.district(config.getDistrict());
    // just load some health facilities. Alphabetical order is not random, but the best we can get
    List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, Math.min(config.getCaseCount() * 2, 300), Arrays.asList(new SortProperty(FacilityDto.NAME)));
    // Filter list, so that only health facilities meant for accomodation are selected
    healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
    long dt = System.nanoTime();
    for (int i = 0; i < config.getCaseCount(); i++) {
        Disease disease = config.getDisease();
        if (disease == null) {
            disease = random(diseases);
        }
        fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getCaseCount(), baseOffset, disease, config.getStartDate(), daysBetween);
        // person
        PersonDto person = PersonDto.build();
        fillEntity(person, referenceDateTime);
        person.setSymptomJournalStatus(null);
        setPersonName(person);
        CaseDataDto caze = CaseDataDto.build(person.toReference(), disease);
        fillEntity(caze, referenceDateTime);
        // reset
        caze.setDisease(disease);
        if (caze.getDisease() == Disease.OTHER) {
            caze.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
        }
        if (!QuarantineType.isQuarantineInEffect(caze.getQuarantine())) {
            caze.setQuarantineFrom(null);
            caze.setQuarantineTo(null);
            caze.setQuarantineExtended(false);
            caze.setQuarantineReduced(false);
        }
        // description
        caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
        // report
        UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
        caze.setReportingUser(userReference);
        caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        // region & facility
        if (healthFacilities.isEmpty() || randomPercent(20)) {
            FacilityReferenceDto noFacilityRef = FacadeProvider.getFacilityFacade().getByUuid(FacilityDto.NONE_FACILITY_UUID).toReference();
            caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
            caze.setHealthFacility(noFacilityRef);
            caze.setFacilityType(null);
            caze.setResponsibleRegion(config.getRegion());
            caze.setResponsibleDistrict(config.getDistrict());
        } else {
            FacilityIndexDto healthFacility = random(healthFacilities);
            caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
            caze.setResponsibleRegion(healthFacility.getRegion());
            caze.setResponsibleDistrict(healthFacility.getDistrict());
            caze.setResponsibleCommunity(healthFacility.getCommunity());
            caze.setHealthFacility(healthFacility.toReference());
            caze.setFacilityType(healthFacility.getType());
            caze.setReportLat(healthFacility.getLatitude());
            caze.setReportLon(healthFacility.getLongitude());
        }
        FacadeProvider.getPersonFacade().savePerson(person);
        FacadeProvider.getCaseFacade().save(caze);
    }
    dt = System.nanoTime() - dt;
    long perCase = dt / config.getCaseCount();
    String msg = String.format("Generating %,d cases took %,d  ms (%,d ms per case)", config.getCaseCount(), dt / 1_000_000, perCase / 1_000_000);
    logger.info(msg);
    Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Also used : LocalDateTime(java.time.LocalDateTime) Disease(de.symeda.sormas.api.Disease) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria)

Aggregations

FacilityIndexDto (de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto)6 FacilityCriteria (de.symeda.sormas.api.infrastructure.facility.FacilityCriteria)4 SortProperty (de.symeda.sormas.api.utils.SortProperty)4 Disease (de.symeda.sormas.api.Disease)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 PersonDto (de.symeda.sormas.api.person.PersonDto)2 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)2 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 Page (com.vaadin.server.Page)1 Alignment (com.vaadin.ui.Alignment)1 Button (com.vaadin.ui.Button)1 Label (com.vaadin.ui.Label)1 Notification (com.vaadin.ui.Notification)1 Type (com.vaadin.ui.Notification.Type)1 ValoTheme (com.vaadin.ui.themes.ValoTheme)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 HasUuid (de.symeda.sormas.api.HasUuid)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1