use of de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method onSampleChanged.
private void onSampleChanged(SampleDto existingSample, Sample newSample, boolean syncShares) {
// Change pathogenTestResultChangeDate if the pathogen test result has changed
if (existingSample != null && existingSample.getPathogenTestResult() != null && existingSample.getPathogenTestResult() != newSample.getPathogenTestResult()) {
Date latestPathogenTestDate = pathogenTestFacade.getLatestPathogenTestDate(newSample.getUuid());
if (latestPathogenTestDate != null) {
newSample.setPathogenTestResultChangeDate(latestPathogenTestDate);
}
}
handleAssotiatedObjectChanges(newSample, syncShares);
// Send an email to the lab user when a sample has been shipped to their lab
if (newSample.isShipped() && (existingSample == null || !existingSample.isShipped()) && !StringUtils.equals(newSample.getLab().getUuid(), FacilityDto.OTHER_FACILITY_UUID)) {
try {
final String messageContent = getSampleShippedNotificationMessage(newSample);
notificationService.sendNotifications(NotificationType.LAB_SAMPLE_SHIPPED, MessageSubject.LAB_SAMPLE_SHIPPED, () -> userService.getLabUsersOfLab(newSample.getLab()).stream().collect(Collectors.toMap(Function.identity(), (e) -> messageContent)));
} catch (NotificationDeliveryFailedException e) {
logger.error("EmailDeliveryFailedException when trying to notify supervisors about " + "the shipment of a lab sample.");
}
}
}
use of de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method sendMessage.
@Override
public void sendMessage(List<String> caseUuids, String subject, String messageContent, MessageType... messageTypes) {
caseUuids.forEach(uuid -> {
final Case aCase = service.getByUuid(uuid);
final Person person = aCase.getPerson();
try {
messagingService.sendManualMessage(person, subject, messageContent, messageTypes);
} catch (NotificationDeliveryFailedException e) {
logger.error(String.format("NotificationDeliveryFailedException when trying to notify person about: %s" + "Failed to send " + e.getMessageType() + " to person with UUID %s.", subject, person.getUuid()));
}
});
}
use of de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method sendConfirmedCaseNotificationsForEvents.
private void sendConfirmedCaseNotificationsForEvents(Case caze) {
try {
notificationService.sendNotifications(NotificationType.EVENT_PARTICIPANT_CASE_CLASSIFICATION_CONFIRMED, MessageSubject.EVENT_PARTICIPANT_CASE_CLASSIFICATION_CONFIRMED, new Object[] { caze.getDisease().getName() }, () -> {
final Date fromDate = Date.from(Instant.now().minus(Duration.ofDays(30)));
Map<String, User> eventResponsibleUsers = eventService.getAllEventUuidWithResponsibleUserByCaseAfterDateForNotification(caze, fromDate);
return eventResponsibleUsers.keySet().stream().collect(Collectors.toMap(eventResponsibleUsers::get, eventUuid -> String.format(I18nProperties.getString(MessageContents.CONTENT_EVENT_PARTICIPANT_CASE_CLASSIFICATION_CONFIRMED), DataHelper.getShortUuid(eventUuid), caze.getDisease().getName(), DataHelper.getShortUuid(caze.getUuid()))));
});
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify event responsible user about a newly confirmed case.");
}
}
use of de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method onCaseChanged.
public void onCaseChanged(CaseDataDto existingCase, Case newCase, boolean syncShares) {
// If its a new case and the case is new and the geo coordinates of the case's
// health facility are null, set its coordinates to the case's report
// coordinates, if available. Else if case report coordinates are null set them
// to the facility's coordinates
Facility facility = newCase.getHealthFacility();
if (existingCase == null && facility != null && !FacilityHelper.isOtherOrNoneHealthFacility(facility.getUuid())) {
if ((facility.getLatitude() == null || facility.getLongitude() == null) && newCase.getReportLat() != null && newCase.getReportLon() != null) {
facility.setLatitude(newCase.getReportLat());
facility.setLongitude(newCase.getReportLon());
facilityService.ensurePersisted(facility);
} else if (newCase.getReportLat() == null && newCase.getReportLon() == null && newCase.getReportLatLonAccuracy() == null) {
newCase.setReportLat(facility.getLatitude());
newCase.setReportLon(facility.getLongitude());
}
}
// Clear facility type if no facility or home was selected
if (newCase.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(newCase.getHealthFacility().getUuid())) {
newCase.setFacilityType(null);
}
// Generate epid number if missing or incomplete
FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withCountry(configFacade.getCountryLocale());
if (fieldVisibilityCheckers.isVisible(CaseDataDto.class, CaseDataDto.EPID_NUMBER) && !CaseLogic.isCompleteEpidNumber(newCase.getEpidNumber())) {
newCase.setEpidNumber(generateEpidNumber(newCase.getEpidNumber(), newCase.getUuid(), newCase.getDisease(), newCase.getReportDate(), newCase.getResponsibleDistrict().getUuid()));
}
// update the plague type based on symptoms
if (newCase.getDisease() == Disease.PLAGUE) {
PlagueType plagueType = DiseaseHelper.getPlagueTypeForSymptoms(SymptomsFacadeEjb.toDto(newCase.getSymptoms()));
if (plagueType != newCase.getPlagueType() && plagueType != null) {
newCase.setPlagueType(plagueType);
}
}
District survOffDistrict = newCase.getSurveillanceOfficer() != null ? newCase.getSurveillanceOfficer().getDistrict() : null;
if (survOffDistrict == null || (!survOffDistrict.equals(newCase.getResponsibleDistrict()) && !survOffDistrict.equals(newCase.getDistrict()))) {
setResponsibleSurveillanceOfficer(newCase);
}
updateInvestigationByStatus(existingCase, newCase);
updatePersonAndCaseByOutcome(existingCase, newCase);
updateCaseAge(existingCase, newCase);
// Change the disease of all contacts if the case disease or disease details have changed
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !StringUtils.equals(newCase.getDiseaseDetails(), existingCase.getDiseaseDetails()))) {
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
if (contact.getDisease() != newCase.getDisease() || !StringUtils.equals(contact.getDiseaseDetails(), newCase.getDiseaseDetails())) {
// Only do the change if it hasn't been done in the mobile app before
contact.setDisease(newCase.getDisease());
contact.setDiseaseDetails(newCase.getDiseaseDetails());
contactService.ensurePersisted(contact);
}
}
}
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !Objects.equals(newCase.getReportDate(), existingCase.getReportDate()) || !Objects.equals(newCase.getSymptoms().getOnsetDate(), existingCase.getSymptoms().getOnsetDate()))) {
// Update follow-up until and status of all contacts
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
for (Contact contact : contactService.getAllByResultingCase(newCase)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
}
updateTasksOnCaseChanged(newCase, existingCase);
// Update case classification if the feature is enabled
CaseClassification classification = null;
if (configFacade.isFeatureAutomaticCaseClassification()) {
if (newCase.getCaseClassification() != CaseClassification.NO_CASE) {
// calculate classification
CaseDataDto newCaseDto = toDto(newCase);
classification = caseClassificationFacade.getClassification(newCaseDto);
// only update when classification by system changes - user may overwrite this
if (classification != newCase.getSystemCaseClassification()) {
newCase.setSystemCaseClassification(classification);
// really a change? (user may have already set it)
if (classification != newCase.getCaseClassification()) {
newCase.setCaseClassification(classification);
newCase.setClassificationUser(null);
newCase.setClassificationDate(new Date());
}
}
}
}
// calculate reference definition for cases
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
boolean fulfilled = evaluateFulfilledCondition(toDto(newCase), classification);
newCase.setCaseReferenceDefinition(fulfilled ? CaseReferenceDefinition.FULFILLED : CaseReferenceDefinition.NOT_FULFILLED);
}
// are not empty
if (!newCase.getHospitalization().getPreviousHospitalizations().isEmpty() && YesNoUnknown.YES != newCase.getHospitalization().getHospitalizedPreviously()) {
newCase.getHospitalization().setHospitalizedPreviously(YesNoUnknown.YES);
}
if (!newCase.getEpiData().getExposures().isEmpty() && !YesNoUnknown.YES.equals(newCase.getEpiData().getExposureDetailsKnown())) {
newCase.getEpiData().setExposureDetailsKnown(YesNoUnknown.YES);
}
// Update completeness value
newCase.setCompleteness(null);
// changed
if (existingCase != null && existingCase.getCaseClassification() != newCase.getCaseClassification()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_CASE_CLASSIFICATION_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), newCase.getCaseClassification().toString());
notificationService.sendNotifications(NotificationType.CASE_CLASSIFICATION_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.CASE_CLASSIFICATION_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case classification. ");
}
}
// Unspecified VHF case has changed
if (existingCase != null && existingCase.getDisease() == Disease.UNSPECIFIED_VHF && existingCase.getDisease() != newCase.getDisease()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_DISEASE_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), existingCase.getDisease().toString(), newCase.getDisease().toString());
notificationService.sendNotifications(NotificationType.DISEASE_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.DISEASE_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case disease.");
}
}
// If the case is a newly created case or if it was not in a CONFIRMED status
// and now the case is in a CONFIRMED status, notify related surveillance officers
Set<CaseClassification> confirmedClassifications = CaseClassification.getConfirmedClassifications();
if ((existingCase == null || !confirmedClassifications.contains(existingCase.getCaseClassification())) && confirmedClassifications.contains(newCase.getCaseClassification())) {
sendConfirmedCaseNotificationsForEvents(newCase);
}
if (existingCase != null && syncShares && sormasToSormasFacade.isFeatureConfigured()) {
syncSharesAsync(new ShareTreeCriteria(existingCase.getUuid()));
}
// This logic should be consistent with CaseDataForm.onQuarantineEndChange
if (existingCase != null && existingCase.getQuarantineTo() != null && !existingCase.getQuarantineTo().equals(newCase.getQuarantineTo())) {
newCase.setPreviousQuarantineTo(existingCase.getQuarantineTo());
}
if (existingCase == null) {
vaccinationFacade.updateVaccinationStatuses(newCase);
}
// On German systems, correct and clean up reinfection data
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
newCase.setReinfectionDetails(cleanUpReinfectionDetails(newCase.getReinfectionDetails()));
newCase.setReinfectionStatus(CaseLogic.calculateReinfectionStatus(newCase.getReinfectionDetails()));
}
}
use of de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException in project SORMAS-Project by hzi-braunschweig.
the class VisitFacadeEjb method onVisitChanged.
private void onVisitChanged(VisitDto existingVisit, Visit newVisit) {
updateContactVisitAssociations(existingVisit, newVisit);
updateCaseVisitAssociations(existingVisit, newVisit);
// Send an email to all responsible supervisors when the contact has become
// symptomatic
boolean previousSymptomaticStatus = existingVisit != null && Boolean.TRUE.equals(existingVisit.getSymptoms().getSymptomatic());
if (newVisit.getContacts() != null && previousSymptomaticStatus == false && Boolean.TRUE.equals(newVisit.getSymptoms().getSymptomatic())) {
for (Contact contact : newVisit.getContacts()) {
// Skip if there is already a symptomatic visit for this contact
if (contact.getVisits().stream().filter(v -> !v.equals(newVisit)).filter(v -> Boolean.TRUE.equals(v.getSymptoms().getSymptomatic())).count() > 0) {
continue;
}
Case contactCase = contact.getCaze();
try {
String messageContent;
if (contactCase != null) {
messageContent = String.format(I18nProperties.getString(MessageContents.CONTENT_CONTACT_SYMPTOMATIC), DataHelper.getShortUuid(contact.getUuid()), DataHelper.getShortUuid(contactCase.getUuid()));
} else {
messageContent = String.format(I18nProperties.getString(MessageContents.CONTENT_CONTACT_WITHOUT_CASE_SYMPTOMATIC), DataHelper.getShortUuid(contact.getUuid()));
}
notificationService.sendNotifications(NotificationType.CONTACT_SYMPTOMATIC, JurisdictionHelper.getContactRegions(contact), null, MessageSubject.CONTACT_SYMPTOMATIC, messageContent);
} catch (NotificationDeliveryFailedException e) {
logger.error("EmailDeliveryFailedException when trying to notify supervisors about a contact that has become symptomatic.");
}
}
}
if (newVisit.getContacts() != null) {
for (Contact contact : newVisit.getContacts()) {
contactService.updateFollowUpDetails(contact, false);
}
}
if (newVisit.getCaze() != null) {
// Update case symptoms
CaseDataDto caze = caseFacade.toDto(newVisit.getCaze());
SymptomsDto caseSymptoms = caze.getSymptoms();
SymptomsHelper.updateSymptoms(toDto(newVisit).getSymptoms(), caseSymptoms);
caseFacade.save(caze, true);
}
}
Aggregations