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();
}
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;
}
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;
}
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);
}
Aggregations