use of de.symeda.sormas.app.backend.immunization.Immunization in project SORMAS-Project by hzi-braunschweig.
the class VaccinationDtoHelper method fillInnerFromAdo.
@Override
protected void fillInnerFromAdo(VaccinationDto target, Vaccination source) {
if (source.getImmunization() != null) {
Immunization immunization = DatabaseHelper.getImmunizationDao().queryForId(source.getImmunization().getId());
target.setImmunization(ImmunizationDtoHelper.toReferenceDto(immunization));
}
if (source.getHealthConditions() != null) {
HealthConditions healthConditions = DatabaseHelper.getHealthConditionsDao().queryForId(source.getHealthConditions().getId());
target.setHealthConditions(healthConditionsDtoHelper.adoToDto(healthConditions));
} else {
target.setHealthConditions(null);
}
target.setReportDate(source.getReportDate());
if (source.getReportingUser() != null) {
User user = DatabaseHelper.getUserDao().queryForId(source.getReportingUser().getId());
target.setReportingUser(UserDtoHelper.toReferenceDto(user));
} else {
target.setReportingUser(null);
}
target.setVaccinationDate(source.getVaccinationDate());
target.setVaccineName(source.getVaccineName());
target.setOtherVaccineName(source.getOtherVaccineName());
target.setVaccineManufacturer(source.getVaccineManufacturer());
target.setOtherVaccineManufacturer(source.getOtherVaccineManufacturer());
target.setVaccineType(source.getVaccineType());
target.setVaccineDose(source.getVaccineDose());
target.setVaccineInn(source.getVaccineInn());
target.setVaccineUniiCode(source.getVaccineUniiCode());
target.setVaccineAtcCode(source.getVaccineAtcCode());
target.setVaccinationInfoSource(source.getVaccinationInfoSource());
target.setPregnant(source.getPregnant());
target.setTrimester(source.getTrimester());
target.setPseudonymized(source.isPseudonymized());
}
use of de.symeda.sormas.app.backend.immunization.Immunization 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.Immunization in project SORMAS-Project by hzi-braunschweig.
the class VaccinationEditActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
return;
}
final Vaccination Vaccination = getStoredRootEntity();
try {
FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), Vaccination) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
final Vaccination savedVaccination = DatabaseHelper.getVaccinationDao().saveAndSnapshot(Vaccination);
final Immunization immunization = DatabaseHelper.getImmunizationDao().queryUuid(Vaccination.getImmunization().getUuid());
final List<Vaccination> vaccinations = immunization.getVaccinations();
for (Vaccination ve : vaccinations) {
if (ve.getUuid().equals(savedVaccination.getUuid())) {
vaccinations.remove(ve);
break;
}
}
vaccinations.add(savedVaccination);
DatabaseHelper.getImmunizationDao().saveAndSnapshot(immunization);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
if (getActivePage().getPosition() == VaccinationSection.HEALTH_CONDITIONS.ordinal()) {
finish();
} else {
goToNextPage();
}
} else {
// reload data
onResume();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.backend.immunization.Immunization in project SORMAS-Project by hzi-braunschweig.
the class PersonEditFragment method prepareFragmentData.
@Override
protected void prepareFragmentData() {
AbstractDomainObject ado = getActivityRootData();
if (ado instanceof Case) {
record = ((Case) ado).getPerson();
rootData = ado;
} else if (ado instanceof Contact) {
record = ((Contact) ado).getPerson();
rootData = ado;
} else if (ado instanceof Immunization) {
record = ((Immunization) ado).getPerson();
rootData = ado;
} else {
throw new UnsupportedOperationException("ActivityRootData of class " + ado.getClass().getSimpleName() + " does not support PersonEditFragment");
}
// Workaround because person is not an embedded entity and therefore the locations are not
// automatically loaded (because there's no additional queryForId call for person when the
// parent data is loaded)
DatabaseHelper.getPersonDao().initLocations(record);
DatabaseHelper.getPersonDao().initPersonContactDetails(record);
}
use of de.symeda.sormas.app.backend.immunization.Immunization in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationEditActivity method buildEditFragment.
@Override
protected BaseEditFragment buildEditFragment(PageMenuItem menuItem, Immunization activityRootData) {
ImmunizationSection section = ImmunizationSection.fromOrdinal(menuItem.getPosition());
BaseEditFragment fragment;
switch(section) {
case PERSON_INFO:
fragment = PersonEditFragment.newInstance(activityRootData);
break;
case IMMUNIZATION_INFO:
fragment = ImmunizationEditFragment.newInstance(activityRootData, meansOfImmunization -> {
this.updatePageMenuItems(meansOfImmunization);
updatePageMenu();
});
break;
case VACCINATIONS:
fragment = ImmunizationEditVaccinationListFragment.newInstance(activityRootData);
break;
default:
throw new IndexOutOfBoundsException(DataHelper.toStringNullable(section));
}
return fragment;
}
Aggregations