use of de.symeda.sormas.app.backend.immunization.ImmunizationCriteria in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationListViewModel method initializeViewModel.
public void initializeViewModel(EventParticipant eventParticipant) {
final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
immunizationCriteria.setPerson(eventParticipant.getPerson());
initializeModel(immunizationCriteria);
}
use of de.symeda.sormas.app.backend.immunization.ImmunizationCriteria in project SORMAS-Project by hzi-braunschweig.
the class VaccinationNewActivity method addImmunizationToVaccination.
private boolean addImmunizationToVaccination(Vaccination vaccination, Person person, Disease disease) {
ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
immunizationCriteria.setPerson(person);
immunizationCriteria.setDisease(disease);
List<Immunization> immunizations = DatabaseHelper.getImmunizationDao().queryAllByCriteria(immunizationCriteria);
if (immunizations.isEmpty()) {
return false;
}
if (immunizations.size() == 1) {
vaccination.setImmunization(immunizations.get(0));
return true;
}
// Case 1: If the vaccination date is empty, add the vaccination to the latest immunization
if (vaccination.getVaccinationDate() == null) {
immunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, true)));
vaccination.setImmunization(immunizations.get(immunizations.size() - 1));
return true;
}
// Case 2: Search for an immunization with start date < vaccination date < end date
Optional<Immunization> immunization = immunizations.stream().filter(i -> i.getStartDate() != null && i.getEndDate() != null && DateHelper.isBetween(vaccination.getVaccinationDate(), i.getStartDate(), i.getEndDate())).findFirst();
if (immunization.isPresent()) {
vaccination.setImmunization(immunization.get());
return true;
}
// Case 3: Search for the immunization with the nearest end or start date to the vaccination date
immunization = immunizations.stream().filter(i -> i.getEndDate() != null || i.getStartDate() != null).min((i1, i2) -> {
Integer i1Interval = Math.abs(DateHelper.getDaysBetween(i1.getEndDate() != null ? i1.getEndDate() : i1.getStartDate(), vaccination.getVaccinationDate()));
Integer i2Interval = Math.abs(DateHelper.getDaysBetween(i2.getEndDate() != null ? i2.getEndDate() : i2.getStartDate(), vaccination.getVaccinationDate()));
return i1Interval.compareTo(i2Interval);
});
if (immunization.isPresent()) {
vaccination.setImmunization(immunization.get());
return true;
}
// Case 4: Use the immunization with the nearest report date to the vaccination date
immunization = immunizations.stream().min((i1, i2) -> {
Integer i1Interval = Math.abs(DateHelper.getDaysBetween(i1.getReportDate(), vaccination.getVaccinationDate()));
Integer i2Interval = Math.abs(DateHelper.getDaysBetween(i2.getReportDate(), vaccination.getVaccinationDate()));
return i1Interval.compareTo(i2Interval);
});
if (immunization.isPresent()) {
vaccination.setImmunization(immunization.get());
return true;
}
return false;
}
use of de.symeda.sormas.app.backend.immunization.ImmunizationCriteria in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationListViewModel method initializeViewModel.
public void initializeViewModel(Case caze) {
final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
immunizationCriteria.setPerson(caze.getPerson());
initializeModel(immunizationCriteria);
}
use of de.symeda.sormas.app.backend.immunization.ImmunizationCriteria in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationListViewModel method initializeViewModel.
public void initializeViewModel(Contact contact) {
final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
immunizationCriteria.setPerson(contact.getPerson());
initializeModel(immunizationCriteria);
}
use of de.symeda.sormas.app.backend.immunization.ImmunizationCriteria in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationEditActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
// don't save multiple times
return;
}
final Immunization changedImmunization = getStoredRootEntity();
if (ImmunizationEditAuthorization.isImmunizationEditAllowed(changedImmunization)) {
final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
immunizationCriteria.setResponsibleRegion(changedImmunization.getResponsibleRegion());
final Disease disease = changedImmunization.getDisease();
immunizationCriteria.setDisease(disease);
immunizationCriteria.setMeansOfImmunization(changedImmunization.getMeansOfImmunization());
final ImmunizationSimilarityCriteria criteria = new ImmunizationSimilarityCriteria();
criteria.setImmunizationCriteria(immunizationCriteria);
criteria.setImmunizationUuid(changedImmunization.getUuid());
criteria.setPersonUuid(changedImmunization.getPerson().getUuid());
criteria.setStartDate(changedImmunization.getStartDate());
criteria.setEndDate(changedImmunization.getEndDate());
List<Immunization> similarImmunizations = DatabaseHelper.getImmunizationDao().getSimilarImmunizations(criteria);
if (!similarImmunizations.isEmpty() && getActivePage().getPosition() == ImmunizationSection.IMMUNIZATION_INFO.ordinal()) {
final ImmunizationOverlapsDto immunizationOverlapsDto = new ImmunizationOverlapsDto();
immunizationOverlapsDto.setStartDate(changedImmunization.getStartDate());
immunizationOverlapsDto.setEndDate(changedImmunization.getEndDate());
final Immunization existingSimilarImmunization = similarImmunizations.get(0);
immunizationOverlapsDto.setStartDateExisting(existingSimilarImmunization.getStartDate());
immunizationOverlapsDto.setEndDateExisting(existingSimilarImmunization.getEndDate());
immunizationOverlapsDto.setDisease(disease);
final ImmunizationEditOverrideDialog immunizationEditOverrideDialog = new ImmunizationEditOverrideDialog(getContext(), R.layout.dialog_immunization_overlaps_layout, immunizationOverlapsDto, () -> saveImmunization(changedImmunization));
immunizationEditOverrideDialog.show();
} else {
saveImmunization(changedImmunization);
}
} else {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_edit_forbidden));
}
}
Aggregations