Search in sources :

Example 1 with Immunization

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());
}
Also used : HealthConditions(de.symeda.sormas.app.backend.clinicalcourse.HealthConditions) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) User(de.symeda.sormas.app.backend.user.User)

Example 2 with Immunization

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;
}
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 Immunization

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();
}
Also used : Immunization(de.symeda.sormas.app.backend.immunization.Immunization) ValidationException(de.symeda.sormas.api.utils.ValidationException) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 4 with Immunization

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);
}
Also used : Immunization(de.symeda.sormas.app.backend.immunization.Immunization) AbstractDomainObject(de.symeda.sormas.app.backend.common.AbstractDomainObject) Case(de.symeda.sormas.app.backend.caze.Case) Contact(de.symeda.sormas.app.backend.contact.Contact)

Example 5 with Immunization

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;
}
Also used : Context(android.content.Context) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) PageMenuItem(de.symeda.sormas.app.component.menu.PageMenuItem) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) ImmunizationEditAuthorization(de.symeda.sormas.app.backend.immunization.ImmunizationEditAuthorization) DaoException(de.symeda.sormas.app.backend.common.DaoException) ImmunizationSection(de.symeda.sormas.app.immunization.ImmunizationSection) ERROR(de.symeda.sormas.app.core.notification.NotificationType.ERROR) NotificationHelper(de.symeda.sormas.app.core.notification.NotificationHelper) PersonEditFragment(de.symeda.sormas.app.person.edit.PersonEditFragment) BaseEditActivity(de.symeda.sormas.app.BaseEditActivity) ImmunizationCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationCriteria) Bundler(de.symeda.sormas.app.util.Bundler) DataHelper(de.symeda.sormas.api.utils.DataHelper) AsyncTask(android.os.AsyncTask) VaccinationNewActivity(de.symeda.sormas.app.immunization.vaccination.VaccinationNewActivity) ValidationException(de.symeda.sormas.api.utils.ValidationException) BaseActivity(de.symeda.sormas.app.BaseActivity) R(de.symeda.sormas.app.R) FragmentValidator(de.symeda.sormas.app.component.validation.FragmentValidator) ImmunizationSimilarityCriteria(de.symeda.sormas.app.backend.immunization.ImmunizationSimilarityCriteria) 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) BaseEditFragment(de.symeda.sormas.app.BaseEditFragment) WARNING(de.symeda.sormas.app.core.notification.NotificationType.WARNING) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) ImmunizationSection(de.symeda.sormas.app.immunization.ImmunizationSection) BaseEditFragment(de.symeda.sormas.app.BaseEditFragment)

Aggregations

Immunization (de.symeda.sormas.app.backend.immunization.Immunization)23 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)9 Case (de.symeda.sormas.app.backend.caze.Case)8 Contact (de.symeda.sormas.app.backend.contact.Contact)8 EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)6 Person (de.symeda.sormas.app.backend.person.Person)6 Vaccination (de.symeda.sormas.app.backend.vaccination.Vaccination)6 Disease (de.symeda.sormas.api.Disease)5 ValidationException (de.symeda.sormas.api.utils.ValidationException)4 HealthConditions (de.symeda.sormas.app.backend.clinicalcourse.HealthConditions)4 District (de.symeda.sormas.app.backend.region.District)4 Region (de.symeda.sormas.app.backend.region.Region)4 ActivityAsCase (de.symeda.sormas.app.backend.activityascase.ActivityAsCase)3 Campaign (de.symeda.sormas.app.backend.campaign.Campaign)3 CampaignFormData (de.symeda.sormas.app.backend.campaign.data.CampaignFormData)3 CampaignFormMeta (de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta)3 MaternalHistory (de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistory)3 PortHealthInfo (de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfo)3 DiseaseClassificationCriteria (de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteria)3 ClinicalCourse (de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourse)3