Search in sources :

Example 1 with CaseImportEntities

use of de.symeda.sormas.api.caze.caseimport.CaseImportEntities in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method validateEntities.

private ImportLineResultDto<CaseImportEntities> validateEntities(CaseImportEntities entities) {
    ImportLineResultDto<CaseImportEntities> validationResult = importFacade.validateConstraints(entities);
    if (validationResult.isError()) {
        return validationResult;
    }
    try {
        personFacade.validate(entities.getPerson());
        caseFacade.validate(entities.getCaze());
        for (SampleDto sample : entities.getSamples()) {
            sampleFacade.validate(sample);
        }
        for (PathogenTestDto pathogenTest : entities.getPathogenTests()) {
            pathogenTestFacade.validate(pathogenTest);
        }
    } catch (ValidationRuntimeException e) {
        return ImportLineResultDto.errorResult(e.getMessage());
    }
    return ImportLineResultDto.successResult();
}
Also used : CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Example 2 with CaseImportEntities

use of de.symeda.sormas.api.caze.caseimport.CaseImportEntities in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method buildEntities.

private ImportLineResultDto<CaseImportEntities> buildEntities(String[] values, String[] entityClasses, String[][] entityPropertyPaths, boolean ignoreEmptyEntries, CaseImportEntities entities) {
    final UserReferenceDto currentUserRef = userService.getCurrentUser().toReference();
    final List<SampleDto> samples = entities.getSamples();
    final List<PathogenTestDto> pathogenTests = entities.getPathogenTests();
    final List<VaccinationDto> vaccinations = entities.getVaccinations();
    ImportRelatedObjectsMapper.Builder relatedObjectsMapperBuilder = new ImportRelatedObjectsMapper.Builder().addMapper(SampleDto.class, samples, () -> SampleDto.build(currentUserRef, new CaseReferenceDto(entities.getCaze().getUuid())), this::insertColumnEntryIntoRelatedObject).addMapper(PathogenTestDto.class, pathogenTests, () -> {
        if (samples.isEmpty()) {
            return null;
        }
        SampleDto referenceSample = samples.get(samples.size() - 1);
        return PathogenTestDto.build(new SampleReferenceDto(referenceSample.getUuid()), currentUserRef);
    }, this::insertColumnEntryIntoRelatedObject);
    if (featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
        relatedObjectsMapperBuilder.addMapper(VaccinationDto.class, vaccinations, () -> VaccinationDto.build(currentUserRef), this::insertColumnEntryIntoRelatedObject);
    }
    ImportRelatedObjectsMapper relatedMapper = relatedObjectsMapperBuilder.build();
    final ImportLineResultDto<CaseImportEntities> result = insertRowIntoData(values, entityClasses, entityPropertyPaths, ignoreEmptyEntries, (cellData) -> {
        try {
            CaseDataDto caze = entities.getCaze();
            if (!relatedMapper.map(cellData)) {
                if (StringUtils.isNotEmpty(cellData.getValue())) {
                    // If the cell entry is not empty, try to insert it into the current case or its person
                    insertColumnEntryIntoData(caze, entities.getPerson(), cellData.getValue(), cellData.getEntityPropertyPath());
                }
            }
        } catch (ImportErrorException | InvalidColumnException e) {
            return e;
        }
        return null;
    });
    // Sanitize non-HOME address
    PersonHelper.sanitizeNonHomeAddress(entities.getPerson());
    return result;
}
Also used : SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) SampleDto(de.symeda.sormas.api.sample.SampleDto) ImportRelatedObjectsMapper(de.symeda.sormas.api.importexport.ImportRelatedObjectsMapper) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 3 with CaseImportEntities

use of de.symeda.sormas.api.caze.caseimport.CaseImportEntities in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method importCaseData.

@Override
@Transactional
public ImportLineResultDto<CaseImportEntities> importCaseData(String[] values, String[] entityClasses, String[] entityProperties, String[][] entityPropertyPaths, boolean ignoreEmptyEntries) throws InvalidColumnException {
    // Check whether the new line has the same length as the header line
    if (values.length > entityProperties.length) {
        return ImportLineResultDto.errorResult(I18nProperties.getValidationError(Validations.importLineTooLong));
    }
    final CaseImportEntities entities = new CaseImportEntities(userService.getCurrentUser().toReference());
    ImportLineResultDto<CaseImportEntities> importResult = buildEntities(values, entityClasses, entityPropertyPaths, ignoreEmptyEntries, entities);
    if (importResult.isError()) {
        return importResult;
    }
    ImportLineResultDto<CaseImportEntities> validationResult = validateEntities(entities);
    if (validationResult.isError()) {
        return validationResult;
    }
    PersonDto person = entities.getPerson();
    if (personFacade.isPersonSimilarToExisting(person)) {
        return ImportLineResultDto.duplicateResult(entities);
    }
    ImportLineResultDto<CaseImportEntities> result = saveImportedEntities(entities, false);
    return result;
}
Also used : CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) PersonDto(de.symeda.sormas.api.person.PersonDto) Transactional(javax.transaction.Transactional)

Example 4 with CaseImportEntities

use of de.symeda.sormas.api.caze.caseimport.CaseImportEntities in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method updateCaseWithImportData.

@Override
public ImportLineResultDto<CaseImportEntities> updateCaseWithImportData(String personUuid, String caseUuid, String[] values, String[] entityClasses, String[][] entityPropertyPaths, boolean skipPersonValidation) throws InvalidColumnException {
    final PersonDto person;
    if (personUuid != null) {
        person = personFacade.getPersonByUuid(personUuid);
    } else {
        person = PersonDto.buildImportEntity();
    }
    final CaseDataDto caze;
    if (caseUuid != null) {
        caze = caseFacade.getCaseDataByUuid(caseUuid);
    } else {
        caze = CaseImportEntities.createCase(person, userService.getCurrentUser().toReference());
    }
    CaseImportEntities entities = new CaseImportEntities(person, caze);
    ImportLineResultDto<CaseImportEntities> importResult = buildEntities(values, entityClasses, entityPropertyPaths, true, entities);
    if (importResult.isError()) {
        return importResult;
    }
    return saveImportedEntities(entities, skipPersonValidation);
}
Also used : CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto)

Aggregations

CaseImportEntities (de.symeda.sormas.api.caze.caseimport.CaseImportEntities)4 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 PersonDto (de.symeda.sormas.api.person.PersonDto)2 PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)2 SampleDto (de.symeda.sormas.api.sample.SampleDto)2 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)1 ImportRelatedObjectsMapper (de.symeda.sormas.api.importexport.ImportRelatedObjectsMapper)1 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)1 SampleReferenceDto (de.symeda.sormas.api.sample.SampleReferenceDto)1 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)1 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)1 VaccinationDto (de.symeda.sormas.api.vaccination.VaccinationDto)1 Transactional (javax.transaction.Transactional)1