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());
}
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());
}
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;
}
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();
}
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);
}
}
}
Aggregations