Search in sources :

Example 6 with VaccinationDto

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

the class EventParticipantFacadeEjbTest method testGetExportList.

@Test
public void testGetExportList() {
    TestDataCreator.RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    EventDto event = creator.createEvent(EventStatus.SIGNAL, EventInvestigationStatus.PENDING, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district);
    PersonDto eventPerson = creator.createPerson("Event", "Organizer");
    creator.createEventParticipant(event.toReference(), eventPerson, "event Director", user.toReference());
    PersonDto eventPerson1 = creator.createPerson("Event", "Participant");
    creator.createEventParticipant(event.toReference(), eventPerson1, "event fan", user.toReference());
    ImmunizationDto immunization = creator.createImmunization(event.getDisease(), eventPerson.toReference(), event.getReportingUser(), ImmunizationStatus.ACQUIRED, MeansOfImmunization.VACCINATION, ImmunizationManagementStatus.COMPLETED, rdcf, DateHelper.subtractDays(new Date(), 10), DateHelper.subtractDays(new Date(), 5), DateHelper.subtractDays(new Date(), 1), null);
    creator.createImmunization(event.getDisease(), eventPerson.toReference(), event.getReportingUser(), ImmunizationStatus.ACQUIRED, MeansOfImmunization.VACCINATION, ImmunizationManagementStatus.COMPLETED, rdcf, DateHelper.subtractDays(new Date(), 8), DateHelper.subtractDays(new Date(), 7), null, null);
    VaccinationDto firstVaccination = creator.createVaccination(event.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), DateHelper.subtractDays(new Date(), 7), Vaccine.OXFORD_ASTRA_ZENECA, VaccineManufacturer.ASTRA_ZENECA);
    creator.createVaccination(event.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), DateHelper.subtractDays(new Date(), 4), Vaccine.MRNA_1273, VaccineManufacturer.MODERNA);
    VaccinationDto thirdVaccination = creator.createVaccination(event.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), new Date(), Vaccine.COMIRNATY, VaccineManufacturer.BIONTECH_PFIZER);
    EventParticipantCriteria eventParticipantCriteria = new EventParticipantCriteria();
    eventParticipantCriteria.withEvent(event.toReference());
    List<EventParticipantExportDto> results = getEventParticipantFacade().getExportList(eventParticipantCriteria, Collections.emptySet(), 0, 100, Language.EN, null);
    // List should have two entries
    assertThat(results, Matchers.hasSize(2));
    assertEquals(VaccinationStatus.VACCINATED, results.get(0).getVaccinationStatus());
    assertEquals(thirdVaccination.getVaccineName(), results.get(0).getVaccineName());
    assertEquals(firstVaccination.getVaccinationDate(), results.get(0).getFirstVaccinationDate());
    assertEquals(thirdVaccination.getVaccinationDate(), results.get(0).getLastVaccinationDate());
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) EventParticipantExportDto(de.symeda.sormas.api.event.EventParticipantExportDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 7 with VaccinationDto

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

the class ContactImporter 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, ContactDto.UUID);
    if (uuidIndex >= 0) {
        values[uuidIndex] = DataHelper.createUuid();
    }
    final PersonDto newPersonTemp = PersonDto.buildImportEntity();
    final ContactDto newContactTemp = caze != null ? ContactDto.build(caze) : ContactDto.build();
    newContactTemp.setReportingUser(currentUser.toReference());
    final List<VaccinationDto> vaccinations = new ArrayList<>();
    ImportRelatedObjectsMapper.Builder relatedObjectsMapperBuilder = new ImportRelatedObjectsMapper.Builder();
    if (FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
        relatedObjectsMapperBuilder.addMapper(VaccinationDto.class, vaccinations, () -> VaccinationDto.build(currentUser.toReference()), this::insertColumnEntryIntoRelatedObject);
    }
    ImportRelatedObjectsMapper relatedMapper = relatedObjectsMapperBuilder.build();
    boolean contactHasImportError = 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(newContactTemp, newPersonTemp, importColumnInformation.getValue(), importColumnInformation.getEntityPropertyPath());
                }
            }
        } catch (ImportErrorException | InvalidColumnException e) {
            return e;
        }
        return null;
    });
    // try to assign the contact to an existing case
    if (caze == null && newContactTemp.getCaseIdExternalSystem() != null) {
        CaseDataDto existingCase = FacadeProvider.getCaseFacade().getCaseDataByUuid(newContactTemp.getCaseIdExternalSystem().trim());
        if (existingCase != null) {
            newContactTemp.assignCase(existingCase);
            newContactTemp.setCaseIdExternalSystem(null);
        }
    }
    // If the row does not have any import errors, call the backend validation of all associated entities
    if (!contactHasImportError) {
        try {
            FacadeProvider.getPersonFacade().validate(newPersonTemp);
            FacadeProvider.getContactFacade().validate(newContactTemp);
        } catch (ValidationRuntimeException e) {
            contactHasImportError = 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 (!contactHasImportError) {
        try {
            ContactImportConsumer consumer = new ContactImportConsumer();
            ImportSimilarityResultOption resultOption = null;
            ContactImportLock personSelectLock = new ContactImportLock();
            // 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 ContactImportSimilarityResult(person, null, similarityResultOption), Strings.infoSelectOrCreatePersonForImport, currentUI);
                try {
                    if (!personSelectLock.wasNotified) {
                        personSelectLock.wait();
                    }
                } catch (InterruptedException e) {
                    logger.error("InterruptedException when trying to perform LOCK.wait() in contact import: " + e.getMessage());
                    throw e;
                }
                if (consumer.result != null) {
                    resultOption = consumer.result.getResultOption();
                }
                // If the user picked an existing person, override the contact person with it
                if (ImportSimilarityResultOption.PICK.equals(resultOption)) {
                    newPerson = FacadeProvider.getPersonFacade().getPersonByUuid(consumer.result.getMatchingPerson().getUuid());
                }
            }
            // or an existing person was picked, save the contact and person to the database
            if (ImportSimilarityResultOption.SKIP.equals(resultOption)) {
                return ImportLineResult.SKIPPED;
            } else {
                boolean skipPersonValidation = ImportSimilarityResultOption.PICK.equals(resultOption);
                final PersonDto savedPerson = FacadeProvider.getPersonFacade().savePerson(newPerson, skipPersonValidation);
                newContactTemp.setPerson(savedPerson.toReference());
                ContactDto newContact = newContactTemp;
                final ContactImportLock contactSelectLock = new ContactImportLock();
                synchronized (contactSelectLock) {
                    handleContactSimilarity(newContactTemp, savedPerson, result -> consumer.onImportResult(result, contactSelectLock));
                    try {
                        if (!contactSelectLock.wasNotified) {
                            contactSelectLock.wait();
                        }
                    } catch (InterruptedException e) {
                        logger.error("InterruptedException when trying to perform LOCK.wait() in contact import: " + e.getMessage());
                        throw e;
                    }
                    if (consumer.result != null) {
                        resultOption = consumer.result.getResultOption();
                    }
                    if (ImportSimilarityResultOption.PICK.equals(resultOption)) {
                        newContact = FacadeProvider.getContactFacade().getByUuid(consumer.result.getMatchingContact().getUuid());
                    }
                }
                // Workaround: Reset the change date to avoid OutdatedEntityExceptions
                newContact.setChangeDate(new Date());
                FacadeProvider.getContactFacade().save(newContact, true, false);
                for (VaccinationDto vaccination : vaccinations) {
                    FacadeProvider.getVaccinationFacade().createWithImmunization(vaccination, newContact.getRegion(), newContact.getDistrict(), newContact.getPerson(), newContact.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) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) 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) ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) ContactImportSimilarityResult(de.symeda.sormas.ui.importer.ContactImportSimilarityResult) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) ImportRelatedObjectsMapper(de.symeda.sormas.api.importexport.ImportRelatedObjectsMapper)

Example 8 with VaccinationDto

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

the class ContactImporterTest method testImportContactsWithVaccinations.

@Test
@Ignore("Remove ignore once we have replaced H2, and feature properties can be changed by code")
public void testImportContactsWithVaccinations() throws IOException, InterruptedException, CsvValidationException, InvalidColumnException, URISyntaxException {
    RDCF rdcf = creator.createRDCF("Abia", "Umuahia North", "Urban Ward 2", "Anelechi Hospital");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_contact_import_test_vaccinations.csv").toURI());
    ContactImporterExtension contactImporter = new ContactImporterExtension(csvFile, user, null);
    ImportResultStatus importResult = contactImporter.runImport();
    assertEquals(contactImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
    List<ContactDto> contacts = getContactFacade().getAllAfter(null);
    assertEquals(3, contacts.size());
    ContactDto contact1 = contacts.stream().filter(c -> c.getCaseIdExternalSystem().equals("case1")).findFirst().get();
    ContactDto contact2 = contacts.stream().filter(c -> c.getCaseIdExternalSystem().equals("case2")).findFirst().get();
    ContactDto contact3 = contacts.stream().filter(c -> c.getCaseIdExternalSystem().equals("case3")).findFirst().get();
    List<VaccinationDto> case1Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(contact1.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(0, case1Vaccinations.size());
    List<VaccinationDto> case2Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(contact2.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(1, case2Vaccinations.size());
    assertEquals(Vaccine.COMIRNATY, case2Vaccinations.get(0).getVaccineName());
    assertNull(case2Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
    List<VaccinationDto> case3Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(contact3.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(2, case3Vaccinations.size());
    assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(0).getVaccineName());
    assertEquals(YesNoUnknown.YES, case3Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
    assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(1).getVaccineName());
    assertNull(case3Vaccinations.get(1).getHealthConditions().getChronicPulmonaryDisease());
}
Also used : RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) File(java.io.File) Ignore(org.junit.Ignore) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 9 with VaccinationDto

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

the class CaseImporterTest method testImportWithVaccinations.

@Test
@Ignore("Remove ignore once we have replaced H2, and feature properties can be changed by code")
public void testImportWithVaccinations() throws IOException, InterruptedException, CsvValidationException, InvalidColumnException, URISyntaxException {
    TestDataCreator creator = new TestDataCreator();
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    creator.createFacility("Lab", FacilityType.LABORATORY, rdcf.region.toReference(), rdcf.district.toReference(), rdcf.community.toReference());
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    // import of 3 cases with different number of vaccinations
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_test_vaccinations.csv").toURI());
    CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
    ImportResultStatus importResult = caseImporter.runImport();
    assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
    CaseDataDto case1 = getCaseFacade().getByExternalId("case1").get(0);
    CaseDataDto case2 = getCaseFacade().getByExternalId("case2").get(0);
    CaseDataDto case3 = getCaseFacade().getByExternalId("case3").get(0);
    List<VaccinationDto> case1Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case1.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(0, case1Vaccinations.size());
    List<VaccinationDto> case2Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case2.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(1, case2Vaccinations.size());
    assertEquals(Vaccine.COMIRNATY, case2Vaccinations.get(0).getVaccineName());
    assertNull(case2Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
    List<VaccinationDto> case3Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case3.getPerson().getUuid(), Disease.CORONAVIRUS);
    assertEquals(2, case3Vaccinations.size());
    assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(0).getVaccineName());
    assertEquals(YesNoUnknown.YES, case3Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
    assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(1).getVaccineName());
    assertNull(case3Vaccinations.get(1).getHealthConditions().getChronicPulmonaryDisease());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) File(java.io.File) Ignore(org.junit.Ignore) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 10 with VaccinationDto

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

the class VaccinationsField method updateColumns.

@Override
protected void updateColumns() {
    Table table = getTable();
    table.addGeneratedColumn(Captions.columnVaccineName, (Table.ColumnGenerator) (source, item, columnId) -> {
        VaccinationDto vaccinationDto = (VaccinationDto) item;
        return Vaccine.OTHER.equals(vaccinationDto.getVaccineName()) ? vaccinationDto.getOtherVaccineName() : vaccinationDto.getVaccineName();
    });
    table.addGeneratedColumn(Captions.columnVaccineManufacturer, (Table.ColumnGenerator) (source, item, columnId) -> {
        VaccinationDto vaccinationDto = (VaccinationDto) item;
        return VaccineManufacturer.OTHER.equals(vaccinationDto.getVaccineManufacturer()) ? vaccinationDto.getOtherVaccineManufacturer() : vaccinationDto.getVaccineManufacturer();
    });
    table.setVisibleColumns(EDIT_COLUMN_ID, VaccinationDto.UUID, VaccinationDto.VACCINATION_DATE, VaccinationDto.VACCINE_NAME, VaccinationDto.VACCINE_MANUFACTURER, VaccinationDto.VACCINE_TYPE, VaccinationDto.VACCINE_DOSE);
    for (Object columnId : table.getVisibleColumns()) {
        if (columnId.equals(EDIT_COLUMN_ID)) {
            table.setColumnHeader(columnId, "&nbsp");
        } else if (columnId.equals(Captions.columnVaccineName)) {
            table.setColumnHeader(columnId, I18nProperties.getCaption(Captions.columnVaccineName));
        } else if (columnId.equals(Captions.columnVaccineManufacturer)) {
            table.setColumnHeader(columnId, I18nProperties.getCaption(Captions.columnVaccineManufacturer));
        } else {
            table.setColumnHeader(columnId, I18nProperties.getPrefixCaption(VaccinationDto.I18N_PREFIX, (String) columnId));
        }
    }
}
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) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto)

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