Search in sources :

Example 11 with Disease

use of de.symeda.sormas.api.Disease 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 12 with Disease

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

the class DevModeView method generateSamples.

private void generateSamples() {
    initializeRandomGenerator();
    SampleGenerationConfig config = sampleGeneratorConfigBinder.getBean();
    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());
    long dt = System.nanoTime();
    UserReferenceDto user = UserProvider.getCurrent().getUserReference();
    List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(config.getDisease()), config.getSampleCount() * 2, random());
    if (nonNull(cases)) {
        for (int i = 0; i < config.getSampleCount(); i++) {
            CaseReferenceDto caseReference = random(cases);
            List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true);
            Disease disease = config.getDisease();
            if (disease == null) {
                disease = random(diseases);
                config.setDisease(disease);
            }
            LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getSampleCount(), baseOffset, config.getDisease(), config.getStartDate(), daysBetween);
            SampleDto sample = SampleDto.build(user, caseReference);
            sample.setSamplePurpose(config.getSamplePurpose());
            Date date = Date.from(referenceDateTime.toLocalDate().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
            sample.setSampleDateTime(date);
            sample.setSampleMaterial(config.getSampleMaterial());
            sample.setFieldSampleID(UUID.randomUUID().toString());
            sample.setComment(random(sampleComments));
            sample.setLab(config.getLaboratory());
            if (config.isRequestPathogenTestsToBePerformed()) {
                Set pathogenTestTypes = new HashSet<PathogenTestType>();
                int until = randomInt(1, PathogenTestType.values().length);
                for (int j = 0; j < until; j++) {
                    pathogenTestTypes.add(PathogenTestType.values()[j]);
                }
                sample.setPathogenTestingRequested(true);
                sample.setRequestedPathogenTests(pathogenTestTypes);
            }
            if (config.isRequestAdditionalTestsToBePerformed()) {
                Set additionalTestTypes = new HashSet<AdditionalTestType>();
                int until = randomInt(1, AdditionalTestType.values().length);
                for (int j = 0; j < until; j++) {
                    additionalTestTypes.add(AdditionalTestType.values()[j]);
                }
                sample.setAdditionalTestingRequested(true);
                sample.setRequestedAdditionalTests(additionalTestTypes);
            }
            if (config.isSendDispatch()) {
                sample.setShipped(true);
                sample.setShipmentDate(date);
                sample.setShipmentDetails(random(sampleShipmentDetails));
            }
            if (config.isReceived()) {
                sample.setReceived(true);
                sample.setReceivedDate(date);
                sample.setSpecimenCondition(random(SpecimenCondition.values()));
            }
            SampleDto sampleDto = FacadeProvider.getSampleFacade().saveSample(sample);
            if (config.isRequestAdditionalTestsToBePerformed()) {
                createAdditionalTest(sampleDto, date);
            }
        }
        dt = System.nanoTime() - dt;
        long perSample = dt / config.getSampleCount();
        String msg = String.format("Generating %d samples took %.2f  s (%.1f ms per sample)", config.getSampleCount(), (double) dt / 1_000_000_000, (double) perSample / 1_000_000);
        logger.info(msg);
        Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
    } else {
        String msg = "No Sample has been generated because cases is null ";
        logger.info(msg);
        Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) HashSet(java.util.HashSet) Disease(de.symeda.sormas.api.Disease) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) HashSet(java.util.HashSet)

Example 13 with Disease

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

the class DevModeView method createContactGeneratorLayout.

private VerticalLayout createContactGeneratorLayout() {
    VerticalLayout contactGeneratorLayout = new VerticalLayout();
    contactGeneratorLayout.setMargin(false);
    contactGeneratorLayout.setSpacing(false);
    Label heading = new Label(I18nProperties.getString(Strings.headingGenerateContacts));
    CssStyles.style(heading, CssStyles.H2);
    contactGeneratorLayout.addComponent(heading);
    HorizontalLayout contactOptionsFirstLineLayout = new HorizontalLayout();
    TextField contactCountField = new TextField();
    contactCountField.setCaption(I18nProperties.getCaption(Captions.devModeContactCount));
    contactGeneratorConfigBinder.forField(contactCountField).withConverter(new StringToIntegerConverter("Must be a number")).bind(ContactGenerationConfig::getContactCount, ContactGenerationConfig::setContactCount);
    contactOptionsFirstLineLayout.addComponent(contactCountField);
    DateField startDateField = new DateField();
    startDateField.setCaption(I18nProperties.getCaption(Captions.devModeContactStartDate));
    startDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    startDateField.setLenient(true);
    contactGeneratorConfigBinder.bind(startDateField, ContactGenerationConfig::getStartDate, ContactGenerationConfig::setStartDate);
    contactOptionsFirstLineLayout.addComponent(startDateField);
    DateField endDateField = new DateField();
    endDateField.setCaption(I18nProperties.getCaption(Captions.devModeContactEndDate));
    endDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    endDateField.setLenient(true);
    contactGeneratorConfigBinder.bind(endDateField, ContactGenerationConfig::getEndDate, ContactGenerationConfig::setEndDate);
    contactOptionsFirstLineLayout.addComponent(endDateField);
    ComboBox<Disease> diseaseField = new ComboBox<>(null, FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true));
    diseaseField.setCaption(I18nProperties.getCaption(Captions.devModeContactDisease));
    contactGeneratorConfigBinder.bind(diseaseField, ContactGenerationConfig::getDisease, ContactGenerationConfig::setDisease);
    contactOptionsFirstLineLayout.addComponent(diseaseField);
    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllActiveByServerCountry();
    ComboBox<RegionReferenceDto> regionField = new ComboBox<RegionReferenceDto>(null, regions);
    regionField.setCaption(I18nProperties.getCaption(Captions.devModeContactRegion));
    contactGeneratorConfigBinder.bind(regionField, ContactGenerationConfig::getRegion, ContactGenerationConfig::setRegion);
    contactOptionsFirstLineLayout.addComponent(regionField);
    ComboBox<DistrictReferenceDto> districtField = new ComboBox<DistrictReferenceDto>();
    districtField.setCaption(I18nProperties.getCaption(Captions.devModeContactDistrict));
    contactGeneratorConfigBinder.bind(districtField, ContactGenerationConfig::getDistrict, ContactGenerationConfig::setDistrict);
    contactOptionsFirstLineLayout.addComponent(districtField);
    regionField.addValueChangeListener(event -> {
        RegionReferenceDto region = event.getValue();
        if (region != null) {
            districtField.setItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        } else {
            districtField.setItems(new ArrayList<DistrictReferenceDto>());
        }
    });
    Button generateButton = ButtonHelper.createButton(Captions.devModeGenerateContacts, e -> generateContacts(), CssStyles.FORCE_CAPTION);
    contactOptionsFirstLineLayout.addComponent(generateButton);
    contactGeneratorLayout.addComponent(contactOptionsFirstLineLayout);
    HorizontalLayout contactOptionsSecondLineLayout = new HorizontalLayout();
    CheckBox createWithoutSourceCasesField = new CheckBox(I18nProperties.getCaption(Captions.devModeContactCreateWithoutSourceCases));
    contactGeneratorConfigBinder.bind(createWithoutSourceCasesField, ContactGenerationConfig::isCreateWithoutSourceCases, ContactGenerationConfig::setCreateWithoutSourceCases);
    contactOptionsSecondLineLayout.addComponent(createWithoutSourceCasesField);
    CheckBox createMultipleContactsPerPersonField = new CheckBox(I18nProperties.getCaption(Captions.devModeContactCreateMultipleContactsPerPerson));
    contactGeneratorConfigBinder.bind(createMultipleContactsPerPersonField, ContactGenerationConfig::isCreateMultipleContactsPerPerson, ContactGenerationConfig::setCreateMultipleContactsPerPerson);
    contactOptionsSecondLineLayout.addComponent(createMultipleContactsPerPersonField);
    CheckBox createWithVisitsField = new CheckBox(I18nProperties.getCaption(Captions.devModeContactCreateWithVisits));
    contactGeneratorConfigBinder.bind(createWithVisitsField, ContactGenerationConfig::isCreateWithVisits, ContactGenerationConfig::setCreateWithVisits);
    contactOptionsSecondLineLayout.addComponent(createWithVisitsField);
    contactGeneratorLayout.addComponent(contactOptionsSecondLineLayout);
    contactGenerationConfig.setRegion(regions.get(0));
    contactGeneratorConfigBinder.setBean(contactGenerationConfig);
    return contactGeneratorLayout;
}
Also used : Disease(de.symeda.sormas.api.Disease) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) DateField(com.vaadin.ui.DateField)

Example 14 with Disease

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

the class DevModeView method createSamplesGeneratorLayout.

private VerticalLayout createSamplesGeneratorLayout() {
    VerticalLayout sampleGeneratorLayout = new VerticalLayout();
    sampleGeneratorLayout.setMargin(false);
    sampleGeneratorLayout.setSpacing(false);
    Label heading = new Label(I18nProperties.getCaption(Captions.devModeGenerateSamples));
    CssStyles.style(heading, CssStyles.H2);
    sampleGeneratorLayout.addComponent(heading);
    HorizontalLayout sampleOptionsFirstLineLayout = new HorizontalLayout();
    TextField sampleCountField = new TextField();
    sampleCountField.setCaption(I18nProperties.getCaption(Captions.devModeSampleCount));
    sampleGeneratorConfigBinder.forField(sampleCountField).withConverter(new StringToIntegerConverter("Must be a number")).bind(SampleGenerationConfig::getSampleCount, SampleGenerationConfig::setSampleCount);
    sampleOptionsFirstLineLayout.addComponent(sampleCountField);
    DateField startDateField = new DateField();
    startDateField.setCaption(I18nProperties.getCaption(Captions.devModeSampleStartDate));
    startDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    startDateField.setLenient(true);
    sampleGeneratorConfigBinder.bind(startDateField, SampleGenerationConfig::getStartDate, SampleGenerationConfig::setStartDate);
    sampleOptionsFirstLineLayout.addComponent(startDateField);
    DateField endDateField = new DateField();
    endDateField.setCaption(I18nProperties.getCaption(Captions.devModeSampleEndDate));
    endDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    endDateField.setLenient(true);
    sampleGeneratorConfigBinder.bind(endDateField, SampleGenerationConfig::getEndDate, SampleGenerationConfig::setEndDate);
    sampleOptionsFirstLineLayout.addComponent(endDateField);
    ComboBox<Disease> diseaseField = new ComboBox<>(null, FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true));
    diseaseField.setCaption(I18nProperties.getCaption(Captions.devModeSampleDisease));
    sampleGeneratorConfigBinder.bind(diseaseField, SampleGenerationConfig::getDisease, SampleGenerationConfig::setDisease);
    diseaseField.setRequiredIndicatorVisible(true);
    sampleOptionsFirstLineLayout.addComponent(diseaseField);
    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllActiveByServerCountry();
    ComboBox<RegionReferenceDto> regionField = new ComboBox<>(null, regions);
    regionField.setCaption(I18nProperties.getCaption(Captions.devModeSampleRegion));
    sampleGeneratorConfigBinder.bind(regionField, SampleGenerationConfig::getRegion, SampleGenerationConfig::setRegion);
    sampleOptionsFirstLineLayout.addComponent(regionField);
    ComboBox<DistrictReferenceDto> districtField = new ComboBox<>();
    districtField.setCaption(I18nProperties.getCaption(Captions.devModeSampleDistrict));
    sampleGeneratorConfigBinder.bind(districtField, SampleGenerationConfig::getDistrict, SampleGenerationConfig::setDistrict);
    sampleOptionsFirstLineLayout.addComponent(districtField);
    regionField.addValueChangeListener(event -> {
        RegionReferenceDto region = event.getValue();
        if (region != null) {
            districtField.setItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        } else {
            districtField.setItems(new ArrayList<DistrictReferenceDto>());
        }
    });
    Button generateButton = ButtonHelper.createButton(I18nProperties.getCaption(Captions.devModeGenerateSamples), e -> generateSamples(), CssStyles.FORCE_CAPTION);
    sampleOptionsFirstLineLayout.addComponent(generateButton);
    sampleGeneratorLayout.addComponent(sampleOptionsFirstLineLayout);
    HorizontalLayout sampleOptionsSecondLineLayout = new HorizontalLayout();
    ComboBox<SampleMaterial> sampleMaterial = new ComboBox(null, Arrays.asList(SampleMaterial.values()));
    sampleMaterial.setCaption(I18nProperties.getCaption(Captions.devModeSampleMaterial));
    sampleGeneratorConfigBinder.bind(sampleMaterial, SampleGenerationConfig::getSampleMaterial, SampleGenerationConfig::setSampleMaterial);
    sampleMaterial.setRequiredIndicatorVisible(true);
    sampleOptionsSecondLineLayout.addComponent(sampleMaterial);
    ComboBox<FacilityReferenceDto> laboratory = new ComboBox(null, FacadeProvider.getFacilityFacade().getAllActiveLaboratories(true));
    laboratory.setCaption(I18nProperties.getCaption(Captions.devModeSampleLaboratory));
    sampleGeneratorConfigBinder.bind(laboratory, SampleGenerationConfig::getLaboratory, SampleGenerationConfig::setLaboratory);
    laboratory.setRequiredIndicatorVisible(true);
    sampleOptionsSecondLineLayout.addComponent(laboratory);
    sampleGeneratorLayout.addComponent(sampleOptionsSecondLineLayout);
    HorizontalLayout sampleOptionsThirdLineLayout = new HorizontalLayout();
    CheckBox externalLabTesting = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleExternalLabTesting));
    sampleGeneratorConfigBinder.bind(externalLabTesting, SampleGenerationConfig::isExternalLabOrInternalInHouseTesting, SampleGenerationConfig::setExternalLabOrInternalInHouseTesting);
    externalLabTesting.setValue(true);
    sampleOptionsThirdLineLayout.addComponent(externalLabTesting);
    CheckBox requestPathogenTestsToBePerformed = new CheckBox(I18nProperties.getCaption(Captions.devModeSamplePathogenTestsToBePerformed));
    sampleGeneratorConfigBinder.bind(requestPathogenTestsToBePerformed, SampleGenerationConfig::isRequestPathogenTestsToBePerformed, SampleGenerationConfig::setRequestPathogenTestsToBePerformed);
    sampleOptionsThirdLineLayout.addComponent(requestPathogenTestsToBePerformed);
    CheckBox requestAdditionalTestsToBePerformed = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleAdditionalTestsToBePerformed));
    sampleGeneratorConfigBinder.bind(requestAdditionalTestsToBePerformed, SampleGenerationConfig::isRequestAdditionalTestsToBePerformed, SampleGenerationConfig::setRequestAdditionalTestsToBePerformed);
    sampleOptionsThirdLineLayout.addComponent(requestAdditionalTestsToBePerformed);
    CheckBox sendDispatch = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleSendDispatch));
    sampleGeneratorConfigBinder.bind(sendDispatch, SampleGenerationConfig::isSendDispatch, SampleGenerationConfig::setSendDispatch);
    sampleOptionsThirdLineLayout.addComponent(sendDispatch);
    CheckBox received = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleReceived));
    sampleGeneratorConfigBinder.bind(received, SampleGenerationConfig::isReceived, SampleGenerationConfig::setReceived);
    sampleOptionsThirdLineLayout.addComponent(received);
    externalLabTesting.addValueChangeListener(event -> {
        if (externalLabTesting.getValue()) {
            requestPathogenTestsToBePerformed.setVisible(true);
            sendDispatch.setVisible(true);
            received.setVisible(true);
            laboratory.setVisible(true);
            sampleGenerationConfig.setSamplePurpose(SamplePurpose.EXTERNAL);
        } else {
            requestPathogenTestsToBePerformed.setVisible(false);
            sendDispatch.setVisible(false);
            received.setVisible(false);
            laboratory.setVisible(false);
            sampleGenerationConfig.setSamplePurpose(SamplePurpose.INTERNAL);
        }
    });
    sampleGeneratorLayout.addComponent(sampleOptionsThirdLineLayout);
    sampleGenerationConfig.setRegion(regions.get(0));
    sampleGenerationConfig.setDistrict(FacadeProvider.getDistrictFacade().getAllActiveByRegion(sampleGenerationConfig.getRegion().getUuid()).get(0));
    sampleGeneratorConfigBinder.setBean(sampleGenerationConfig);
    return sampleGeneratorLayout;
}
Also used : Disease(de.symeda.sormas.api.Disease) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) DateField(com.vaadin.ui.DateField)

Example 15 with Disease

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

the class DevModeView method createCaseGeneratorLayout.

private VerticalLayout createCaseGeneratorLayout() {
    VerticalLayout caseGeneratorLayout = new VerticalLayout();
    caseGeneratorLayout.setMargin(false);
    caseGeneratorLayout.setSpacing(false);
    Label heading = new Label(I18nProperties.getString(Strings.headingGenerateCases));
    CssStyles.style(heading, CssStyles.H2);
    caseGeneratorLayout.addComponent(heading);
    HorizontalLayout caseOptionsLayout = new HorizontalLayout();
    TextField caseCountField = new TextField();
    caseCountField.setCaption(I18nProperties.getCaption(Captions.devModeCaseCount));
    caseGeneratorConfigBinder.forField(caseCountField).withConverter(new StringToIntegerConverter("Must be a number")).bind(CaseGenerationConfig::getCaseCount, CaseGenerationConfig::setCaseCount);
    caseOptionsLayout.addComponent(caseCountField);
    DateField startDateField = new DateField();
    startDateField.setCaption(I18nProperties.getCaption(Captions.devModeCaseStartDate));
    startDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    startDateField.setLenient(true);
    caseGeneratorConfigBinder.bind(startDateField, CaseGenerationConfig::getStartDate, CaseGenerationConfig::setStartDate);
    caseOptionsLayout.addComponent(startDateField);
    DateField endDateField = new DateField();
    endDateField.setCaption(I18nProperties.getCaption(Captions.devModeCaseEndDate));
    endDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    endDateField.setLenient(true);
    caseGeneratorConfigBinder.bind(endDateField, CaseGenerationConfig::getEndDate, CaseGenerationConfig::setEndDate);
    caseOptionsLayout.addComponent(endDateField);
    ComboBox<Disease> diseaseField = new ComboBox<>(null, FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true));
    diseaseField.setCaption(I18nProperties.getCaption(Captions.devModeCaseDisease));
    caseGeneratorConfigBinder.bind(diseaseField, CaseGenerationConfig::getDisease, CaseGenerationConfig::setDisease);
    caseOptionsLayout.addComponent(diseaseField);
    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllActiveByServerCountry();
    ComboBox<RegionReferenceDto> regionField = new ComboBox<RegionReferenceDto>(null, regions);
    regionField.setCaption(I18nProperties.getCaption(Captions.devModeCaseRegion));
    caseGeneratorConfigBinder.bind(regionField, CaseGenerationConfig::getRegion, CaseGenerationConfig::setRegion);
    caseOptionsLayout.addComponent(regionField);
    ComboBox<DistrictReferenceDto> districtField = new ComboBox<DistrictReferenceDto>();
    districtField.setCaption(I18nProperties.getCaption(Captions.devModeCaseDistrict));
    caseGeneratorConfigBinder.bind(districtField, CaseGenerationConfig::getDistrict, CaseGenerationConfig::setDistrict);
    caseOptionsLayout.addComponent(districtField);
    regionField.addValueChangeListener(event -> {
        RegionReferenceDto region = event.getValue();
        if (region != null) {
            districtField.setItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        } else {
            districtField.setItems(new ArrayList<DistrictReferenceDto>());
        }
    });
    Button generateButton = ButtonHelper.createButton(Captions.devModeGenerateCases, e -> generateCases(), CssStyles.FORCE_CAPTION);
    caseOptionsLayout.addComponent(generateButton);
    caseGeneratorLayout.addComponent(caseOptionsLayout);
    caseGenerationConfig.setRegion(regions.get(0));
    caseGeneratorConfigBinder.setBean(caseGenerationConfig);
    return caseGeneratorLayout;
}
Also used : Disease(de.symeda.sormas.api.Disease) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) DateField(com.vaadin.ui.DateField)

Aggregations

Disease (de.symeda.sormas.api.Disease)106 Date (java.util.Date)46 List (java.util.List)39 ArrayList (java.util.ArrayList)34 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)32 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)32 Collectors (java.util.stream.Collectors)29 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)26 Arrays (java.util.Arrays)25 Collections (java.util.Collections)25 UserRole (de.symeda.sormas.api.user.UserRole)24 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)23 DateHelper (de.symeda.sormas.api.utils.DateHelper)23 Map (java.util.Map)23 Label (com.vaadin.ui.Label)20 Strings (de.symeda.sormas.api.i18n.Strings)20 StringUtils (org.apache.commons.lang3.StringUtils)19 ContactDto (de.symeda.sormas.api.contact.ContactDto)18 District (de.symeda.sormas.backend.infrastructure.district.District)18 CollectionUtils (org.apache.commons.collections.CollectionUtils)18