Search in sources :

Example 1 with 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(EventParticipant eventParticipant) {
    final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
    immunizationCriteria.setPerson(eventParticipant.getPerson());
    initializeModel(immunizationCriteria);
}
Also used : ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria)

Example 2 with 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;
}
Also used : Context(android.content.Context) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) Bundle(android.os.Bundle) Date(java.util.Date) NonNull(androidx.annotation.NonNull) PageMenuItem(de.symeda.sormas.app.component.menu.PageMenuItem) DateHelper(de.symeda.sormas.api.utils.DateHelper) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) Region(de.symeda.sormas.app.backend.region.Region) DaoException(de.symeda.sormas.app.backend.common.DaoException) Contact(de.symeda.sormas.app.backend.contact.Contact) ERROR(de.symeda.sormas.app.core.notification.NotificationType.ERROR) Menu(android.view.Menu) ConfigProvider(de.symeda.sormas.app.backend.config.ConfigProvider) NotificationHelper(de.symeda.sormas.app.core.notification.NotificationHelper) BaseEditActivity(de.symeda.sormas.app.BaseEditActivity) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria) Bundler(de.symeda.sormas.app.util.Bundler) Case(de.symeda.sormas.app.backend.caze.Case) Person(de.symeda.sormas.app.backend.person.Person) AsyncTask(android.os.AsyncTask) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) ValidationException(de.symeda.sormas.api.utils.ValidationException) ImmunizationEntityHelper(de.symeda.sormas.app.backend.immunization.ImmunizationEntityHelper) R(de.symeda.sormas.app.R) FragmentValidator(de.symeda.sormas.app.component.validation.FragmentValidator) List(java.util.List) Disease(de.symeda.sormas.api.Disease) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) DatabaseHelper(de.symeda.sormas.app.backend.common.DatabaseHelper) District(de.symeda.sormas.app.backend.region.District) BaseEditFragment(de.symeda.sormas.app.BaseEditFragment) WARNING(de.symeda.sormas.app.core.notification.NotificationType.WARNING) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) Optional(java.util.Optional) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) Comparator(java.util.Comparator) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria)

Example 3 with 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(Case caze) {
    final ImmunizationCriteria immunizationCriteria = new ImmunizationCriteria();
    immunizationCriteria.setPerson(caze.getPerson());
    initializeModel(immunizationCriteria);
}
Also used : ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria)

Example 4 with 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);
}
Also used : ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria)

Example 5 with 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));
    }
}
Also used : ImmunizationSimilarityCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationSimilarityCriteria) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria) Disease(de.symeda.sormas.api.Disease)

Aggregations

ImmunizationCriteria (de.symeda.sormas.app.backend.immunization.ImmunizationCriteria)5 Disease (de.symeda.sormas.api.Disease)2 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)2 Immunization (de.symeda.sormas.app.backend.immunization.Immunization)2 Context (android.content.Context)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 Menu (android.view.Menu)1 NonNull (androidx.annotation.NonNull)1 ImmunizationManagementStatus (de.symeda.sormas.api.immunization.ImmunizationManagementStatus)1 ImmunizationStatus (de.symeda.sormas.api.immunization.ImmunizationStatus)1 DateHelper (de.symeda.sormas.api.utils.DateHelper)1 ValidationException (de.symeda.sormas.api.utils.ValidationException)1 BaseEditActivity (de.symeda.sormas.app.BaseEditActivity)1 BaseEditFragment (de.symeda.sormas.app.BaseEditFragment)1 R (de.symeda.sormas.app.R)1 Case (de.symeda.sormas.app.backend.caze.Case)1 DaoException (de.symeda.sormas.app.backend.common.DaoException)1 DatabaseHelper (de.symeda.sormas.app.backend.common.DatabaseHelper)1 ConfigProvider (de.symeda.sormas.app.backend.config.ConfigProvider)1