Search in sources :

Example 1 with Vaccination

use of de.symeda.sormas.app.backend.vaccination.Vaccination in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantEditVaccinationListFragment method onListItemClick.

@Override
public void onListItemClick(View view, int position, Object item) {
    Vaccination vaccination = (Vaccination) item;
    VaccinationEditActivity.startActivity(getActivity(), vaccination.getUuid());
}
Also used : Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination)

Example 2 with Vaccination

use of de.symeda.sormas.app.backend.vaccination.Vaccination in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationDtoHelper method fillInnerFromDto.

@Override
protected void fillInnerFromDto(Immunization target, ImmunizationDto source) {
    target.setDisease(source.getDisease());
    target.setDiseaseDetails(source.getDiseaseDetails());
    target.setPerson(DatabaseHelper.getPersonDao().getByReferenceDto(source.getPerson()));
    target.setReportDate(source.getReportDate());
    target.setReportingUser(DatabaseHelper.getUserDao().getByReferenceDto(source.getReportingUser()));
    target.setArchived(source.isArchived());
    target.setImmunizationStatus(source.getImmunizationStatus());
    target.setMeansOfImmunization(source.getMeansOfImmunization());
    target.setMeansOfImmunizationDetails(source.getMeansOfImmunizationDetails());
    target.setImmunizationManagementStatus(source.getImmunizationManagementStatus());
    target.setExternalId(source.getExternalId());
    target.setResponsibleRegion(DatabaseHelper.getRegionDao().getByReferenceDto(source.getResponsibleRegion()));
    target.setResponsibleDistrict(DatabaseHelper.getDistrictDao().getByReferenceDto(source.getResponsibleDistrict()));
    target.setResponsibleCommunity(DatabaseHelper.getCommunityDao().getByReferenceDto(source.getResponsibleCommunity()));
    target.setFacilityType(source.getFacilityType());
    target.setHealthFacility(DatabaseHelper.getFacilityDao().getByReferenceDto(source.getHealthFacility()));
    target.setHealthFacilityDetails(source.getHealthFacilityDetails());
    target.setCountry(DatabaseHelper.getCountryDao().getByReferenceDto(source.getCountry()));
    target.setStartDate(source.getStartDate());
    target.setEndDate(source.getEndDate());
    target.setValidFrom(source.getValidFrom());
    target.setValidUntil(source.getValidUntil());
    target.setNumberOfDoses(source.getNumberOfDoses());
    target.setPreviousInfection(source.getPreviousInfection());
    target.setLastInfectionDate(source.getLastInfectionDate());
    target.setAdditionalDetails(source.getAdditionalDetails());
    target.setPositiveTestResultDate(source.getPositiveTestResultDate());
    target.setRecoveryDate(source.getRecoveryDate());
    target.setRelatedCase(DatabaseHelper.getCaseDao().getByReferenceDto(source.getRelatedCase()));
    List<Vaccination> vaccinations = new ArrayList<>();
    if (!source.getVaccinations().isEmpty()) {
        for (VaccinationDto vaccinationDto : source.getVaccinations()) {
            Vaccination vaccination = vaccinationDtoHelper.fillOrCreateFromDto(null, vaccinationDto);
            vaccination.setImmunization(target);
            vaccinations.add(vaccination);
        }
    }
    target.setVaccinations(vaccinations);
    target.setSormasToSormasOriginInfo(sormasToSormasOriginInfoDtoHelper.fillOrCreateFromDto(target.getSormasToSormasOriginInfo(), source.getSormasToSormasOriginInfo()));
    target.setOwnershipHandedOver(source.isOwnershipHandedOver());
    target.setPseudonymized(source.isPseudonymized());
}
Also used : Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) ArrayList(java.util.ArrayList) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto)

Example 3 with Vaccination

use of de.symeda.sormas.app.backend.vaccination.Vaccination 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 4 with Vaccination

use of de.symeda.sormas.app.backend.vaccination.Vaccination 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 5 with Vaccination

use of de.symeda.sormas.app.backend.vaccination.Vaccination in project SORMAS-Project by hzi-braunschweig.

the class VaccinationListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    if (getItemViewType(position) == TYPE_ITEM) {
        BindingViewHolder<Vaccination, RowVaccinationListItemLayoutBinding> pagedHolder = (BindingViewHolder) holder;
        Vaccination item = getItem(position);
        pagedHolder.setOnListItemClickListener(this.mOnListItemClickListener);
        if (item.isModifiedOrChildModified()) {
            pagedHolder.binding.imgSyncIcon.setVisibility(View.VISIBLE);
            pagedHolder.binding.imgSyncIcon.setImageResource(R.drawable.ic_sync_blue_24dp);
        } else {
            pagedHolder.binding.imgSyncIcon.setVisibility(View.GONE);
        }
    }
}
Also used : BindingViewHolder(de.symeda.sormas.app.core.adapter.databinding.BindingViewHolder) RowVaccinationListItemLayoutBinding(de.symeda.sormas.app.databinding.RowVaccinationListItemLayoutBinding) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination)

Aggregations

Vaccination (de.symeda.sormas.app.backend.vaccination.Vaccination)18 Immunization (de.symeda.sormas.app.backend.immunization.Immunization)6 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)5 Case (de.symeda.sormas.app.backend.caze.Case)5 Person (de.symeda.sormas.app.backend.person.Person)5 District (de.symeda.sormas.app.backend.region.District)5 Region (de.symeda.sormas.app.backend.region.Region)5 Contact (de.symeda.sormas.app.backend.contact.Contact)4 EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)4 Facility (de.symeda.sormas.app.backend.facility.Facility)4 Community (de.symeda.sormas.app.backend.region.Community)4 Country (de.symeda.sormas.app.backend.region.Country)4 User (de.symeda.sormas.app.backend.user.User)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