Search in sources :

Example 1 with DistrictCriteria

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

the class DevModeView method generateContacts.

private void generateContacts() {
    initializeRandomGenerator();
    ContactGenerationConfig config = contactGeneratorConfigBinder.getBean();
    Disease disease = config.getDisease();
    List<Disease> diseases = disease == null ? FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true) : null;
    if (disease == null) {
        disease = random(diseases);
        Notification.show("", "Automatically chosen disease: " + disease.getName(), Notification.Type.TRAY_NOTIFICATION);
    }
    List<String> personUuids = new ArrayList<>();
    List<CaseReferenceDto> cases = null;
    List<DistrictIndexDto> districts = config.getDistrict() == null ? FacadeProvider.getDistrictFacade().getIndexList(new DistrictCriteria().region(config.getRegion()), 0, Math.min(config.getContactCount() * 2, 50), Arrays.asList(new SortProperty(DistrictDto.NAME))) : null;
    if (!config.isCreateWithoutSourceCases()) {
        cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(disease), config.getContactCount() * 2, random());
        if (cases == null) {
            Notification.show("Error", I18nProperties.getString(Strings.messageMissingCases), Notification.Type.ERROR_MESSAGE);
            return;
        }
    }
    float baseOffset = random().nextFloat();
    int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
    long dt = System.nanoTime();
    for (int i = 0; i < config.getContactCount(); i++) {
        fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getContactCount(), baseOffset, disease, config.getStartDate(), daysBetween);
        PersonDto person;
        if (config.isCreateMultipleContactsPerPerson() && !personUuids.isEmpty() && randomPercent(25)) {
            String personUuid = random(personUuids);
            person = FacadeProvider.getPersonFacade().getPersonByUuid(personUuid);
        } else {
            person = PersonDto.build();
            fillEntity(person, referenceDateTime);
            person.setSymptomJournalStatus(null);
            setPersonName(person);
            if (config.isCreateMultipleContactsPerPerson()) {
                personUuids.add(person.getUuid());
            }
        }
        CaseReferenceDto contactCase = null;
        if (!config.isCreateWithoutSourceCases()) {
            contactCase = random(cases);
        }
        ContactDto contact = ContactDto.build();
        contact.setPerson(person.toReference());
        fillEntity(contact, referenceDateTime);
        if (contactCase != null) {
            contact.setCaze(contactCase);
        }
        contact.setDisease(disease);
        if (contact.getDisease() == Disease.OTHER) {
            contact.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
        }
        UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
        contact.setReportingUser(userReference);
        contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        if (districts != null) {
            DistrictIndexDto district = random(districts);
            contact.setRegion(district.getRegion());
            contact.setDistrict(district.toReference());
        } else {
            contact.setRegion(config.getRegion());
            contact.setDistrict(config.getDistrict());
        }
        if (contact.getLastContactDate() != null && contact.getLastContactDate().after(contact.getReportDateTime())) {
            contact.setLastContactDate(contact.getReportDateTime());
        }
        if (FollowUpStatus.CANCELED.equals(contact.getFollowUpStatus()) || FollowUpStatus.LOST.equals(contact.getFollowUpStatus())) {
            contact.setFollowUpComment("-");
        }
        // description
        contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
        FacadeProvider.getPersonFacade().savePerson(person);
        contact = FacadeProvider.getContactFacade().save(contact);
        if (FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(contact.getDisease())) {
            contact.setFollowUpStatus(random(FollowUpStatus.values()));
        } else {
            contact.setFollowUpStatus(FollowUpStatus.NO_FOLLOW_UP);
        }
        contact.setFollowUpUntil(contact.getFollowUpStatus() == FollowUpStatus.NO_FOLLOW_UP ? null : randomDate(referenceDateTime));
        // Create visits
        if (config.isCreateWithVisits() && FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(contact.getDisease()) && FollowUpStatus.NO_FOLLOW_UP != contact.getFollowUpStatus()) {
            Date latestFollowUpDate = contact.getFollowUpUntil().before(new Date()) ? contact.getFollowUpUntil() : new Date();
            Date contactStartDate = ContactLogic.getStartDate(contact);
            int followUpCount = random().nextInt(DateHelper.getDaysBetween(contactStartDate, latestFollowUpDate) + 1);
            if (followUpCount > 0) {
                int[] followUpDays = random().ints(1, followUpCount + 1).distinct().limit(followUpCount).toArray();
                List<LocalDateTime> followUpDates = new ArrayList<>();
                for (int day : followUpDays) {
                    followUpDates.add(DateHelper8.toLocalDate(contactStartDate).atStartOfDay().plusDays(day - 1).plusMinutes(random().nextInt(60 * 24 + 1)));
                }
                for (LocalDateTime date : followUpDates) {
                    VisitDto visit = VisitDto.build(contact.getPerson(), contact.getDisease(), VisitOrigin.USER);
                    fillEntity(visit, date);
                    visit.setVisitUser(userReference);
                    visit.setVisitDateTime(DateHelper8.toDate(date));
                    visit.setDisease(contact.getDisease());
                    if (visit.getVisitStatus() == null) {
                        visit.setVisitStatus(VisitStatus.COOPERATIVE);
                    }
                    FacadeProvider.getVisitFacade().saveVisit(visit);
                }
            }
        }
    }
    dt = System.nanoTime() - dt;
    long perContact = dt / config.getContactCount();
    String msg = String.format("Generating %,d contacts took %,d  ms (%,d ms per contact)", config.getContactCount(), dt / 1_000_000, perContact / 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) DistrictIndexDto(de.symeda.sormas.api.infrastructure.district.DistrictIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 2 with DistrictCriteria

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

the class InfrastructureImporterTest method testDontImportDuplicateInfrastructure.

@Test
public void testDontImportDuplicateInfrastructure() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    RDCF rdcf = new TestDataCreator().createRDCF("Default Region", "Default District", "Default Community", "Default Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Default", "User", UserRole.ADMIN);
    // Import region
    File regionCsvFile = new File(getClass().getClassLoader().getResource("sormas_region_import_test.csv").toURI());
    InfrastructureImporter importer = new InfrastructureImporterExtension(regionCsvFile, user, InfrastructureType.REGION);
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
    assertEquals(2, getRegionFacade().count(new RegionCriteria()));
    // Import district
    File districtCsvFile = new File(getClass().getClassLoader().getResource("sormas_district_import_test.csv").toURI());
    importer = new InfrastructureImporterExtension(districtCsvFile, user, InfrastructureType.DISTRICT);
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
    assertEquals(2, getDistrictFacade().count(new DistrictCriteria()));
    // Import community
    File communityCsvFile = new File(getClass().getClassLoader().getResource("sormas_community_import_test.csv").toURI());
    importer = new InfrastructureImporterExtension(communityCsvFile, user, InfrastructureType.COMMUNITY);
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
    assertEquals(2, getCommunityFacade().count(new CommunityCriteria()));
    // Import facility
    File facilityCsvFile = new File(getClass().getClassLoader().getResource("sormas_facility_import_test.csv").toURI());
    importer = new InfrastructureImporterExtension(facilityCsvFile, user, InfrastructureType.FACILITY);
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
    assertEquals(3, getFacilityFacade().count(new FacilityCriteria()));
    // Import point of entry
    File poeCsvFile = new File(getClass().getClassLoader().getResource("sormas_poe_import_test.csv").toURI());
    importer = new InfrastructureImporterExtension(poeCsvFile, user, InfrastructureType.POINT_OF_ENTRY);
    assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
    assertEquals(1, getPointOfEntryFacade().count(new PointOfEntryCriteria()));
}
Also used : PointOfEntryCriteria(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryCriteria) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) RegionCriteria(de.symeda.sormas.api.infrastructure.region.RegionCriteria) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) File(java.io.File) CommunityCriteria(de.symeda.sormas.api.infrastructure.community.CommunityCriteria) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 3 with DistrictCriteria

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

the class FeatureConfigurationFacadeEjb method getIndexPage.

public Page<FeatureConfigurationIndexDto> getIndexPage(FeatureConfigurationCriteria criteria, Integer offset, Integer size, List<SortProperty> sortProperties) {
    List<FeatureConfigurationIndexDto> featureConfigurationIndexList = getIndexList(criteria, offset, size, sortProperties);
    CountryReferenceDto serverCountry = countryFacadeEjb.getServerCountry();
    long totalElementCount = districtFacadeEjb.count(new DistrictCriteria().country(serverCountry).region(criteria.getRegion()));
    return new Page<>(featureConfigurationIndexList, offset, size, totalElementCount);
}
Also used : CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria) Page(de.symeda.sormas.api.common.Page) FeatureConfigurationIndexDto(de.symeda.sormas.api.feature.FeatureConfigurationIndexDto)

Example 4 with DistrictCriteria

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

the class DistrictsGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<DistrictIndexDto, DistrictCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getDistrictFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> {
        return (int) FacadeProvider.getDistrictFacade().count(query.getFilter().orElse(null));
    });
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) DistrictIndexDto(de.symeda.sormas.api.infrastructure.district.DistrictIndexDto) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria)

Example 5 with DistrictCriteria

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

the class InfrastructureImporterTest method testImportFromFileWithBom.

@Test
public void testImportFromFileWithBom() throws InterruptedException, InvalidColumnException, CsvValidationException, IOException, URISyntaxException {
    RDCF rdcf = new TestDataCreator().createRDCF("Default Region", "Default District", "Default Community", "Default Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Default", "User", UserRole.ADMIN);
    File districtCsvFile = new File(getClass().getClassLoader().getResource("sormas_district_bom_test.csv").toURI());
    InfrastructureImporter importer = new InfrastructureImporterExtension(districtCsvFile, user, InfrastructureType.DISTRICT);
    importer.runImport();
    // expected Default District + 2 imported districts
    assertEquals(3, getDistrictFacade().count(new DistrictCriteria()));
}
Also used : RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) DistrictCriteria(de.symeda.sormas.api.infrastructure.district.DistrictCriteria) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

DistrictCriteria (de.symeda.sormas.api.infrastructure.district.DistrictCriteria)5 DistrictIndexDto (de.symeda.sormas.api.infrastructure.district.DistrictIndexDto)2 UserDto (de.symeda.sormas.api.user.UserDto)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)2 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)2 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)2 File (java.io.File)2 Test (org.junit.Test)2 Disease (de.symeda.sormas.api.Disease)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 Page (de.symeda.sormas.api.common.Page)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 FeatureConfigurationIndexDto (de.symeda.sormas.api.feature.FeatureConfigurationIndexDto)1 CommunityCriteria (de.symeda.sormas.api.infrastructure.community.CommunityCriteria)1 CountryReferenceDto (de.symeda.sormas.api.infrastructure.country.CountryReferenceDto)1 FacilityCriteria (de.symeda.sormas.api.infrastructure.facility.FacilityCriteria)1 PointOfEntryCriteria (de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryCriteria)1 RegionCriteria (de.symeda.sormas.api.infrastructure.region.RegionCriteria)1