Search in sources :

Example 26 with VaccinationDto

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

the class VaccinationFacadeEjbTest method testUpdateVaccinationStatuses.

// This is currently not executed because modifying immunizations leads to the entity not being attached to the persistence context anymore.
// This problem does not seem to occur on an actual server. See #6694
@Test
public void testUpdateVaccinationStatuses() {
    loginWith(nationalUser);
    Date today = DateHelper8.toDate(LocalDate.now().atTime(12, 0));
    PersonDto person1 = creator.createPerson("John", "Doe");
    PersonDto person2 = creator.createPerson("Jane", "Doe");
    CaseDataDto case11 = creator.createCase(nationalUser.toReference(), person1.toReference(), rdcf1, c -> c.getSymptoms().setOnsetDate(DateHelper.subtractDays(today, 10)));
    CaseDataDto case12 = creator.createCase(nationalUser.toReference(), person1.toReference(), rdcf1);
    CaseDataDto case2 = creator.createCase(nationalUser.toReference(), person1.toReference(), rdcf1, c -> c.setDisease(Disease.CORONAVIRUS));
    CaseDataDto case3 = creator.createCase(nationalUser.toReference(), person2.toReference(), rdcf1);
    ContactDto contact11 = creator.createContact(nationalUser.toReference(), person1.toReference(), Disease.EVD, c -> c.setLastContactDate(DateHelper.subtractDays(today, 10)));
    ContactDto contact12 = creator.createContact(nationalUser.toReference(), person1.toReference(), Disease.EVD);
    ContactDto contact2 = creator.createContact(nationalUser.toReference(), person1.toReference(), Disease.CORONAVIRUS);
    ContactDto contact3 = creator.createContact(nationalUser.toReference(), person2.toReference(), Disease.EVD);
    EventDto event11 = creator.createEvent(nationalUser.toReference(), Disease.EVD, e -> {
        e.setEndDate(DateHelper.subtractDays(today, 8));
        e.setStartDate(DateHelper.subtractDays(today, 12));
    });
    EventDto event12 = creator.createEvent(nationalUser.toReference(), Disease.EVD, e -> e.setEndDate(DateHelper.subtractDays(today, 8)));
    EventDto event13 = creator.createEvent(nationalUser.toReference(), Disease.EVD, e -> e.setStartDate(DateHelper.subtractDays(today, 8)));
    EventDto event14 = creator.createEvent(nationalUser.toReference(), Disease.EVD);
    EventDto event2 = creator.createEvent(nationalUser.toReference(), Disease.CORONAVIRUS);
    EventParticipantDto ep111 = creator.createEventParticipant(event11.toReference(), person1, nationalUser.toReference());
    EventParticipantDto ep112 = creator.createEventParticipant(event11.toReference(), person2, nationalUser.toReference());
    EventParticipantDto ep121 = creator.createEventParticipant(event12.toReference(), person1, nationalUser.toReference());
    EventParticipantDto ep131 = creator.createEventParticipant(event13.toReference(), person1, nationalUser.toReference());
    EventParticipantDto ep141 = creator.createEventParticipant(event14.toReference(), person1, nationalUser.toReference());
    EventParticipantDto ep21 = creator.createEventParticipant(event2.toReference(), person1, nationalUser.toReference());
    // Create a vaccination with vaccination date = today
    VaccinationDto vaccination1 = VaccinationDto.build(nationalUser.toReference());
    vaccination1.setVaccinationDate(DateHelper8.toDate(LocalDate.now().atTime(6, 0)));
    getVaccinationFacade().createWithImmunization(vaccination1, rdcf1.region, rdcf1.district, person1.toReference(), Disease.EVD);
    assertNull(getCaseFacade().getByUuid(case11.getUuid()).getVaccinationStatus());
    assertNull(getCaseFacade().getByUuid(case12.getUuid()).getVaccinationStatus());
    assertNull(getCaseFacade().getByUuid(case2.getUuid()).getVaccinationStatus());
    assertNull(getCaseFacade().getByUuid(case3.getUuid()).getVaccinationStatus());
    assertNull(getContactFacade().getByUuid(contact11.getUuid()).getVaccinationStatus());
    assertNull(getContactFacade().getByUuid(contact12.getUuid()).getVaccinationStatus());
    assertNull(getContactFacade().getByUuid(contact2.getUuid()).getVaccinationStatus());
    assertNull(getContactFacade().getByUuid(contact3.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep111.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep112.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep121.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep131.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep141.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep21.getUuid()).getVaccinationStatus());
    // Create a vaccination with vaccination date = yesterday
    VaccinationDto vaccination2 = VaccinationDto.build(nationalUser.toReference());
    vaccination2.setVaccinationDate(DateHelper.subtractDays(today, 1));
    getVaccinationFacade().createWithImmunization(vaccination2, rdcf1.region, rdcf1.district, person1.toReference(), Disease.EVD);
    assertNull(getCaseFacade().getByUuid(case11.getUuid()).getVaccinationStatus());
    assertThat(getCaseFacade().getByUuid(case12.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    assertNull(getContactFacade().getByUuid(contact11.getUuid()).getVaccinationStatus());
    assertThat(getContactFacade().getByUuid(contact12.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    assertNull(getEventParticipantFacade().getByUuid(ep111.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep121.getUuid()).getVaccinationStatus());
    assertNull(getEventParticipantFacade().getByUuid(ep131.getUuid()).getVaccinationStatus());
    assertThat(getEventParticipantFacade().getByUuid(ep141.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    // Create a vaccination with vaccination date = today - 11 days
    VaccinationDto vaccination3 = VaccinationDto.build(nationalUser.toReference());
    vaccination3.setVaccinationDate(DateHelper.subtractDays(today, 11));
    getVaccinationFacade().createWithImmunization(vaccination3, rdcf1.region, rdcf1.district, person1.toReference(), Disease.EVD);
    assertThat(getCaseFacade().getByUuid(case11.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    assertThat(getContactFacade().getByUuid(contact11.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    assertNull(getEventParticipantFacade().getByUuid(ep111.getUuid()).getVaccinationStatus());
    assertThat(getEventParticipantFacade().getByUuid(ep121.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    assertThat(getEventParticipantFacade().getByUuid(ep131.getUuid()).getVaccinationStatus(), is(VaccinationStatus.VACCINATED));
    // Create a vaccination with no vaccination date
    VaccinationDto vaccination4 = VaccinationDto.build(nationalUser.toReference());
    getVaccinationFacade().createWithImmunization(vaccination4, rdcf1.region, rdcf1.district, person1.toReference(), Disease.EVD);
    assertNull(getEventParticipantFacade().getByUuid(ep111.getUuid()).getVaccinationStatus());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 27 with VaccinationDto

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

the class VaccinationFacadeEjbTest method testGetAllVaccinations.

@Test
public void testGetAllVaccinations() {
    loginWith(nationalUser);
    PersonDto person1 = creator.createPerson("John", "Doe");
    PersonDto person2 = creator.createPerson("Jane", "Doe");
    Disease disease1 = Disease.CORONAVIRUS;
    Disease disease2 = Disease.CHOLERA;
    ImmunizationDto immunization11 = creator.createImmunization(disease1, person1.toReference(), nationalUser.toReference(), rdcf1);
    ImmunizationDto immunization12 = creator.createImmunization(disease1, person1.toReference(), nationalUser.toReference(), rdcf1);
    ImmunizationDto immunization13 = creator.createImmunization(disease2, person1.toReference(), nationalUser.toReference(), rdcf1);
    ImmunizationDto immunization21 = creator.createImmunization(disease1, person2.toReference(), nationalUser.toReference(), rdcf1);
    creator.createImmunization(disease2, person2.toReference(), nationalUser.toReference(), rdcf1);
    VaccinationDto vaccination111 = creator.createVaccination(nationalUser.toReference(), immunization11.toReference());
    VaccinationDto vaccination112 = creator.createVaccination(nationalUser.toReference(), immunization11.toReference());
    VaccinationDto vaccination121 = creator.createVaccination(nationalUser.toReference(), immunization12.toReference());
    VaccinationDto vaccination131 = creator.createVaccination(nationalUser.toReference(), immunization13.toReference());
    VaccinationDto vaccination211 = creator.createVaccination(nationalUser.toReference(), immunization21.toReference());
    VaccinationDto vaccination212 = creator.createVaccination(nationalUser.toReference(), immunization21.toReference());
    List<VaccinationDto> vaccinations = getVaccinationFacade().getAllVaccinations(person1.getUuid(), disease1);
    assertThat(vaccinations, hasSize(3));
    assertThat(vaccinations, contains(vaccination111, vaccination112, vaccination121));
    vaccinations = getVaccinationFacade().getAllVaccinations(person1.getUuid(), disease2);
    assertThat(vaccinations, hasSize(1));
    assertThat(vaccinations, contains(vaccination131));
    vaccinations = getVaccinationFacade().getAllVaccinations(person2.getUuid(), disease1);
    assertThat(vaccinations, hasSize(2));
    assertThat(vaccinations, contains(vaccination211, vaccination212));
    vaccinations = getVaccinationFacade().getAllVaccinations(person2.getUuid(), disease2);
    assertThat(vaccinations, hasSize(0));
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Disease(de.symeda.sormas.api.Disease) PersonDto(de.symeda.sormas.api.person.PersonDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 28 with VaccinationDto

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

the class VaccinationController method create.

private void create(ImmunizationReferenceDto immunization, RegionReferenceDto region, DistrictReferenceDto district, PersonReferenceDto person, Disease disease, UiFieldAccessCheckers fieldAccessCheckers, boolean doSave, Consumer<VaccinationDto> commitCallback) {
    VaccinationEditForm form = new VaccinationEditForm(true, disease, fieldAccessCheckers);
    VaccinationDto vaccination = VaccinationDto.build(UserProvider.getCurrent().getUserReference());
    if (immunization != null) {
        vaccination.setImmunization(immunization);
    }
    form.setValue(vaccination);
    final CommitDiscardWrapperComponent<VaccinationEditForm> cdwComponent = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_CREATE), form.getFieldGroup());
    cdwComponent.getCommitButton().setCaption(doSave ? I18nProperties.getCaption(Captions.actionSave) : I18nProperties.getString(Strings.done));
    VaadinUiUtil.showModalPopupWindow(cdwComponent, I18nProperties.getCaption(VaccinationDto.I18N_PREFIX));
    cdwComponent.addCommitListener(() -> {
        if (!form.getFieldGroup().isModified()) {
            if (doSave && immunization != null) {
                FacadeProvider.getVaccinationFacade().save(form.getValue());
            } else if (doSave) {
                FacadeProvider.getVaccinationFacade().createWithImmunization(form.getValue(), region, district, person, disease);
            }
            if (commitCallback != null) {
                commitCallback.accept(form.getValue());
            }
        }
    });
}
Also used : VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 29 with VaccinationDto

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

the class VaccinationsField method createTable.

@Override
protected Table createTable() {
    Table table = super.createTable();
    table.addGeneratedColumn(VaccinationDto.UUID, (Table.ColumnGenerator) (source, itemId, columnId) -> {
        Label textField = new Label(DataHelper.getShortUuid(((EntityDto) itemId).getUuid()));
        return textField;
    });
    table.addGeneratedColumn(VaccinationDto.VACCINATION_DATE, (Table.ColumnGenerator) (source, itemId, columnId) -> {
        Label textField = new Label(DateFormatHelper.formatDate(((VaccinationDto) itemId).getVaccinationDate()));
        return textField;
    });
    return table;
}
Also used : AbstractTableField(de.symeda.sormas.ui.caze.AbstractTableField) Table(com.vaadin.v7.ui.Table) DataHelper(de.symeda.sormas.api.utils.DataHelper) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UserDto(de.symeda.sormas.api.user.UserDto) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) Vaccine(de.symeda.sormas.api.caze.Vaccine) Captions(de.symeda.sormas.api.i18n.Captions) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) Consumer(java.util.function.Consumer) EntityDto(de.symeda.sormas.api.EntityDto) VaccineManufacturer(de.symeda.sormas.api.caze.VaccineManufacturer) Disease(de.symeda.sormas.api.Disease) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) Label(com.vaadin.ui.Label) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) UserProvider(de.symeda.sormas.ui.UserProvider) Table(com.vaadin.v7.ui.Table) Label(com.vaadin.ui.Label)

Example 30 with VaccinationDto

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

the class EventParticipantImporter method importDataFromCsvLine.

@Override
protected ImportLineResult importDataFromCsvLine(String[] values, String[] entityClasses, String[] entityProperties, String[][] entityPropertyPaths, boolean firstLine) throws IOException, InterruptedException {
    // Check whether the new line has the same length as the header line
    if (values.length > entityProperties.length) {
        writeImportError(values, I18nProperties.getValidationError(Validations.importLineTooLong));
        return ImportLineResult.ERROR;
    }
    // regenerate the UUID to prevent overwrite in case of export and import of the same entities
    int uuidIndex = ArrayUtils.indexOf(entityProperties, EventParticipantDto.UUID);
    if (uuidIndex >= 0) {
        values[uuidIndex] = DataHelper.createUuid();
    }
    int personUuidIndex = ArrayUtils.indexOf(entityProperties, String.join(".", EventParticipantDto.PERSON, PersonDto.UUID));
    if (personUuidIndex >= 0) {
        values[personUuidIndex] = DataHelper.createUuid();
    }
    final PersonDto newPersonTemp = PersonDto.buildImportEntity();
    final EventParticipantDto newEventParticipantTemp = EventParticipantDto.build(event.toReference(), currentUser.toReference());
    newEventParticipantTemp.setPerson(newPersonTemp);
    final List<VaccinationDto> vaccinations = new ArrayList<>();
    ImportRelatedObjectsMapper.Builder relatedObjectsMapperBuilder = new ImportRelatedObjectsMapper.Builder();
    if (FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED) && event.getDisease() != null) {
        relatedObjectsMapperBuilder.addMapper(VaccinationDto.class, vaccinations, () -> VaccinationDto.build(currentUser.toReference()), this::insertColumnEntryIntoRelatedObject);
    }
    ImportRelatedObjectsMapper relatedMapper = relatedObjectsMapperBuilder.build();
    boolean eventParticipantHasImportError = insertRowIntoData(values, entityClasses, entityPropertyPaths, true, importColumnInformation -> {
        try {
            if (!relatedMapper.map(importColumnInformation)) {
                // If the cell entry is not empty, try to insert it into the current contact or person object
                if (!StringUtils.isEmpty(importColumnInformation.getValue())) {
                    insertColumnEntryIntoData(newEventParticipantTemp, newPersonTemp, importColumnInformation.getValue(), importColumnInformation.getEntityPropertyPath());
                }
            }
        } catch (ImportErrorException | InvalidColumnException e) {
            return e;
        }
        return null;
    });
    // If the row does not have any import errors, call the backend validation of all associated entities
    if (!eventParticipantHasImportError) {
        try {
            personFacade.validate(newPersonTemp);
            eventParticipantFacade.validate(newEventParticipantTemp);
        } catch (ValidationRuntimeException e) {
            eventParticipantHasImportError = true;
            writeImportError(values, e.getMessage());
        }
    }
    PersonDto newPerson = newPersonTemp;
    // Sanitize non-HOME address
    PersonHelper.sanitizeNonHomeAddress(newPerson);
    // if there are any, display a window to resolve the conflict to the user
    if (!eventParticipantHasImportError) {
        EventParticipantDto newEventParticipant = newEventParticipantTemp;
        try {
            EventParticipantImportConsumer consumer = new EventParticipantImportConsumer();
            ImportSimilarityResultOption resultOption = null;
            EventParticipantImportLock personSelectLock = new EventParticipantImportLock();
            // We need to pause the current thread to prevent the import from continuing until the user has acted
            synchronized (personSelectLock) {
                // Call the logic that allows the user to handle the similarity; once this has been done, the LOCK should be notified
                // to allow the importer to resume
                handlePersonSimilarity(newPerson, result -> consumer.onImportResult(result, personSelectLock), (person, similarityResultOption) -> new PersonImportSimilarityResult(person, similarityResultOption), Strings.infoSelectOrCreatePersonForImport, currentUI);
                try {
                    if (!personSelectLock.wasNotified) {
                        personSelectLock.wait();
                    }
                } catch (InterruptedException e) {
                    logger.error("InterruptedException when trying to perform LOCK.wait() in eventparticipant import: " + e.getMessage());
                    throw e;
                }
                if (consumer.result != null) {
                    resultOption = consumer.result.getResultOption();
                }
                // If the user picked an existing person, override the eventparticipant person with it
                if (ImportSimilarityResultOption.PICK.equals(resultOption)) {
                    newPerson = personFacade.getPersonByUuid(consumer.result.getMatchingPerson().getUuid());
                    // get first eventparticipant for event and person
                    EventParticipantCriteria eventParticipantCriteria = new EventParticipantCriteria().withPerson(newPerson.toReference()).withEvent(event.toReference());
                    EventParticipantDto pickedEventParticipant = eventParticipantFacade.getFirst(eventParticipantCriteria);
                    if (pickedEventParticipant != null) {
                        // re-apply import on pickedEventParticipant
                        insertRowIntoData(values, entityClasses, entityPropertyPaths, true, importColumnInformation -> {
                            // If the cell entry is not empty, try to insert it into the current contact or person object
                            if (!StringUtils.isEmpty(importColumnInformation.getValue())) {
                                try {
                                    insertColumnEntryIntoData(pickedEventParticipant, newPersonTemp, importColumnInformation.getValue(), importColumnInformation.getEntityPropertyPath());
                                } catch (ImportErrorException | InvalidColumnException e) {
                                    return e;
                                }
                            }
                            return null;
                        });
                        newEventParticipant = pickedEventParticipant;
                    }
                }
            }
            // or an existing person was picked, save the eventparticipant and person to the database
            if (ImportSimilarityResultOption.SKIP.equals(resultOption)) {
                return ImportLineResult.SKIPPED;
            } else {
                // Workaround: Reset the change date to avoid OutdatedEntityExceptions
                newPerson.setChangeDate(new Date());
                boolean skipPersonValidation = ImportSimilarityResultOption.PICK.equals(resultOption);
                final PersonDto savedPerson = personFacade.savePerson(newPerson, skipPersonValidation);
                newEventParticipant.setPerson(savedPerson);
                newEventParticipant.setChangeDate(new Date());
                eventParticipantFacade.saveEventParticipant(newEventParticipant);
                for (VaccinationDto vaccination : vaccinations) {
                    FacadeProvider.getVaccinationFacade().createWithImmunization(vaccination, newEventParticipant.getRegion(), newEventParticipant.getDistrict(), newEventParticipant.getPerson().toReference(), event.getDisease());
                }
                consumer.result = null;
                return ImportLineResult.SUCCESS;
            }
        } catch (ValidationRuntimeException e) {
            writeImportError(values, e.getMessage());
            return ImportLineResult.ERROR;
        }
    } else {
        return ImportLineResult.ERROR;
    }
}
Also used : ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) Date(java.util.Date) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) ImportRelatedObjectsMapper(de.symeda.sormas.api.importexport.ImportRelatedObjectsMapper) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult)

Aggregations

VaccinationDto (de.symeda.sormas.api.vaccination.VaccinationDto)31 Date (java.util.Date)13 PersonDto (de.symeda.sormas.api.person.PersonDto)12 Test (org.junit.Test)11 ImmunizationDto (de.symeda.sormas.api.immunization.ImmunizationDto)10 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)9 ArrayList (java.util.ArrayList)9 UserDto (de.symeda.sormas.api.user.UserDto)8 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)8 Disease (de.symeda.sormas.api.Disease)5 ContactDto (de.symeda.sormas.api.contact.ContactDto)5 EventDto (de.symeda.sormas.api.event.EventDto)4 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)4 PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)4 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)4 LocalDate (java.time.LocalDate)4 EntityDto (de.symeda.sormas.api.EntityDto)3 Captions (de.symeda.sormas.api.i18n.Captions)3 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)3 ImmunizationReferenceDto (de.symeda.sormas.api.immunization.ImmunizationReferenceDto)3