Skip to content

Commit d448ac3

Browse files
committed
🚧 prepared storing vaccinations
1 parent db631d4 commit d448ac3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/patch/BusinessDtoFacade.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private void registerFetchByI18nOperationsCreateUpdate() {
110110
registerFetchByI18nCreateUpdate(
111111
PersonDto.I18N_PREFIX,
112112
caseDataDto -> personFacade.getByUuid(caseDataDto.getPerson().getUuid()));
113+
113114
registerFetchByI18nCreateUpdate(
114115
ImmunizationDto.I18N_PREFIX,
115116
createImmunizationDtoFromCaseFct());
@@ -123,6 +124,7 @@ private static Function<CaseDataDto, EntityDto> createImmunizationDtoFromCaseFct
123124
return caseDataDto -> {
124125
ImmunizationDto build = ImmunizationDto.build(caseDataDto.getPerson());
125126
build.setRelatedCase(caseDataDto.toReference());
127+
build.setPerson(caseDataDto.getPerson());
126128
return build;
127129
};
128130
}
@@ -226,7 +228,28 @@ public <T extends EntityDto> T save(@NotNull EntityDto entityDto) {
226228
}
227229

228230
public void save(@NotNull List<EntityDto> entityDtos) {
231+
232+
Optional<ImmunizationDto> immunizationDto = fetchType(entityDtos, ImmunizationDto.class);
233+
Optional<VaccinationDto> vaccinationDto = fetchType(entityDtos, VaccinationDto.class);
234+
Optional<CaseDataDto> caseDataDtoOpt = fetchType(entityDtos, CaseDataDto.class);
235+
236+
if (vaccinationDto.isPresent()) {
237+
ImmunizationDto actualImmunizationDto;
238+
if (immunizationDto.isPresent()) {
239+
actualImmunizationDto = immunizationDto.orElseThrow();
240+
} else {
241+
actualImmunizationDto = (ImmunizationDto) createImmunizationDtoFromCaseFct().apply(caseDataDtoOpt.orElseThrow());
242+
}
243+
244+
actualImmunizationDto.getVaccinations().add(vaccinationDto.orElseThrow());
245+
}
246+
247+
// TODO: filter out those that are already done through "case-drilling"
229248
entityDtos.forEach(this::save);
230249
}
231250

251+
private static @NotNull <T> Optional<T> fetchType(List<EntityDto> entityDtos, Class<T> targetClass) {
252+
return entityDtos.stream().filter(targetClass::isInstance).map(targetClass::cast).findAny();
253+
}
254+
232255
}

0 commit comments

Comments
 (0)