Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user Notifications when STAT orders are created #1285

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend/src/components/layout/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,15 @@ function OEHeader(props) {
position: "absolute",
top: "-5px",
right: "-5px",
backgroundColor: "#3A6B8D",
backgroundColor: "red",
color: "white",
borderRadius: "50%",
width: "16px",
height: "16px",
width: "22px",
height: "22px",
display: "flex",
alignItems: "center",
justifyContent: "center",
fontSize: "10px",
fontSize: "12px",
animation: "pulse 5s infinite",
opacity: 1,
transition:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/notifications/SlideOver.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const SlideOver = ({
onCloseClick && onCloseClick();
}}
>
←
→
</button>
<div className="slide-over-title">{title}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.openelisglobal.dataexchange.order.action;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand All @@ -22,12 +23,16 @@
import org.openelisglobal.address.service.PersonAddressService;
import org.openelisglobal.address.valueholder.AddressPart;
import org.openelisglobal.address.valueholder.PersonAddress;
import org.openelisglobal.common.constants.Constants;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.services.IStatusService;
import org.openelisglobal.common.services.StatusService.ExternalOrderStatus;
import org.openelisglobal.common.util.StringUtil;
import org.openelisglobal.dataexchange.order.valueholder.ElectronicOrder;
import org.openelisglobal.dataexchange.service.order.ElectronicOrderService;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.entity.Notification;
import org.openelisglobal.patient.service.PatientContactService;
import org.openelisglobal.patient.service.PatientService;
import org.openelisglobal.patient.valueholder.Patient;
Expand All @@ -38,9 +43,11 @@
import org.openelisglobal.patientidentitytype.valueholder.PatientIdentityType;
import org.openelisglobal.person.service.PersonService;
import org.openelisglobal.person.valueholder.Person;
import org.openelisglobal.sample.valueholder.OrderPriority;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.systemuser.service.SystemUserService;
import org.openelisglobal.systemuser.valueholder.SystemUser;
import org.openelisglobal.userrole.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -75,6 +82,10 @@ public class DBOrderPersister implements IOrderPersister {
private PersonAddressService personAddressService;
@Autowired
private AddressPartService addressPartService;
@Autowired
private NotificationDAO notificationDAO;
@Autowired
private UserRoleService userRoleService;

private Patient patient;

Expand Down Expand Up @@ -359,6 +370,22 @@ public void persist(MessagePatient orderPatient, ElectronicOrder eOrder) {
persist(orderPatient);
eOrder.setPatient(patient);
eOrderService.insert(eOrder);
if (eOrder.getPriority().equals(OrderPriority.STAT)) {
String message = MessageUtil.getMessage("notification.eorder.stat", eOrder.getExternalId());
List<String> systemUserIds = userRoleService.getUserIdsForRole(Constants.ROLE_RECEPTION);
for (String userId : systemUserIds) {
try {
Notification notification = new Notification();
notification.setMessage(message);
notification.setUser(systemUserService.getUserById(userId));
notification.setCreatedDate(OffsetDateTime.now());
notification.setReadAt(null);
notificationDAO.save(notification);

} catch (Exception e) {
}
}
}
} catch (RuntimeException e) {
LogEvent.logError(e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand All @@ -25,6 +26,7 @@
import org.openelisglobal.common.formfields.FormFields;
import org.openelisglobal.common.formfields.FormFields.Field;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.provider.validation.AlphanumAccessionValidator;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.DisplayListService.ListType;
import org.openelisglobal.common.services.IStatusService;
Expand All @@ -50,6 +52,8 @@
import org.openelisglobal.note.service.NoteService;
import org.openelisglobal.note.service.NoteServiceImpl.NoteType;
import org.openelisglobal.note.valueholder.Note;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.entity.Notification;
import org.openelisglobal.organization.service.OrganizationService;
import org.openelisglobal.patient.valueholder.Patient;
import org.openelisglobal.referral.action.beanitems.ReferralItem;
Expand All @@ -76,14 +80,17 @@
import org.openelisglobal.resultlimits.valueholder.ResultLimit;
import org.openelisglobal.role.service.RoleService;
import org.openelisglobal.sample.service.SampleService;
import org.openelisglobal.sample.valueholder.OrderPriority;
import org.openelisglobal.sample.valueholder.Sample;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.statusofsample.util.StatusRules;
import org.openelisglobal.systemuser.service.SystemUserService;
import org.openelisglobal.systemuser.service.UserService;
import org.openelisglobal.test.beanItems.TestResultItem;
import org.openelisglobal.test.service.TestSectionService;
import org.openelisglobal.test.valueholder.TestSection;
import org.openelisglobal.typeoftestresult.service.TypeOfTestResultServiceImpl;
import org.openelisglobal.userrole.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
Expand Down Expand Up @@ -145,6 +152,12 @@ public class LogbookResultsController extends LogbookResultsBaseController {
private RoleService roleService;
@Autowired
private MethodService methodService;
@Autowired
private NotificationDAO notificationDAO;
@Autowired
private SystemUserService systemUserService;
@Autowired
private UserRoleService userRoleService;

private final String RESULT_SUBJECT = "Result Note";
private final String REFERRAL_CONFORMATION_ID;
Expand Down Expand Up @@ -410,6 +423,36 @@ public ModelAndView showLogbookResultsUpdate(HttpServletRequest request,
} catch (FhirTransformationException | FhirPersistanceException e) {
LogEvent.logError(e);
}
List<Analysis> newResultAnalyses = actionDataSet.getNewResults().stream().map(a -> a.result.getAnalysis())
.collect(Collectors.toList());
List<String> systemUserIds = userRoleService.getUserIdsForRole(Constants.ROLE_VALIDATION);
String message = MessageUtil.getMessage("notification.result.stat");
StringBuffer sb = new StringBuffer(message);
for (String userId : systemUserIds) {
List<Analysis> userAnalyses = userService
.filterAnalysesByLabUnitRoles(userId, newResultAnalyses, Constants.ROLE_VALIDATION).stream()
.filter(a -> a.getSampleItem().getSample().getPriority().equals(OrderPriority.STAT))
.collect(Collectors.toList());

if (userAnalyses != null && !userAnalyses.isEmpty()) {
List<String> userTests = userAnalyses.stream()
.map(a -> AlphanumAccessionValidator
.convertAlphaNumLabNumForDisplay(a.getSampleItem().getSample().getAccessionNumber())
+ " - " + a.getTest().getLocalizedName())
.collect(Collectors.toList());
String testString = String.join(", ", userTests);
sb.append(testString);
try {
Notification notification = new Notification();
notification.setMessage(sb.toString());
notification.setUser(systemUserService.getUserById(userId));
notification.setCreatedDate(OffsetDateTime.now());
notification.setReadAt(null);
notificationDAO.save(notification);
} catch (Exception e) {
}
}
}
} catch (LIMSRuntimeException e) {
String errorMsg;
if (e.getCause() instanceof StaleObjectStateException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand All @@ -26,6 +27,7 @@
import org.openelisglobal.common.formfields.FormFields;
import org.openelisglobal.common.formfields.FormFields.Field;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.provider.validation.AlphanumAccessionValidator;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.DisplayListService.ListType;
import org.openelisglobal.common.services.IStatusService;
Expand All @@ -51,6 +53,8 @@
import org.openelisglobal.note.service.NoteService;
import org.openelisglobal.note.service.NoteServiceImpl.NoteType;
import org.openelisglobal.note.valueholder.Note;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.entity.Notification;
import org.openelisglobal.organization.service.OrganizationService;
import org.openelisglobal.patient.service.PatientService;
import org.openelisglobal.patient.valueholder.Patient;
Expand Down Expand Up @@ -80,12 +84,14 @@
import org.openelisglobal.resultlimits.valueholder.ResultLimit;
import org.openelisglobal.role.service.RoleService;
import org.openelisglobal.sample.service.SampleService;
import org.openelisglobal.sample.valueholder.OrderPriority;
import org.openelisglobal.sample.valueholder.Sample;
import org.openelisglobal.samplehuman.service.SampleHumanService;
import org.openelisglobal.sampleitem.service.SampleItemService;
import org.openelisglobal.search.service.SearchResultsService;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.statusofsample.util.StatusRules;
import org.openelisglobal.systemuser.service.SystemUserService;
import org.openelisglobal.systemuser.service.UserService;
import org.openelisglobal.test.beanItems.TestResultItem;
import org.openelisglobal.test.service.TestSectionService;
Expand Down Expand Up @@ -171,6 +177,10 @@ public class LogbookResultsRestController extends LogbookResultsBaseController {
private SampleHumanService sampleHumanService;
@Autowired
private MethodService methodService;
@Autowired
private NotificationDAO notificationDAO;
@Autowired
private SystemUserService systemUserService;

private final String RESULT_SUBJECT = "Result Note";
private final String REFERRAL_CONFORMATION_ID;
Expand Down Expand Up @@ -475,6 +485,36 @@ public Map<String, List<String>> showReactLogbookResultsUpdate(HttpServletReques
} catch (FhirTransformationException | FhirPersistanceException e) {
LogEvent.logError(e);
}
List<Analysis> newResultAnalyses = actionDataSet.getNewResults().stream().map(a -> a.result.getAnalysis())
.collect(Collectors.toList());
List<String> systemUserIds = userRoleService.getUserIdsForRole(Constants.ROLE_VALIDATION);
String message = MessageUtil.getMessage("notification.result.stat");
StringBuffer sb = new StringBuffer(message);
for (String userId : systemUserIds) {
List<Analysis> userAnalyses = userService
.filterAnalysesByLabUnitRoles(userId, newResultAnalyses, Constants.ROLE_VALIDATION).stream()
.filter(a -> a.getSampleItem().getSample().getPriority().equals(OrderPriority.STAT))
.collect(Collectors.toList());

if (userAnalyses != null && !userAnalyses.isEmpty()) {
List<String> userTests = userAnalyses.stream()
.map(a -> AlphanumAccessionValidator
.convertAlphaNumLabNumForDisplay(a.getSampleItem().getSample().getAccessionNumber())
+ " - " + a.getTest().getLocalizedName())
.collect(Collectors.toList());
String testString = String.join(", ", userTests);
sb.append(testString);
try {
Notification notification = new Notification();
notification.setMessage(sb.toString());
notification.setUser(systemUserService.getUserById(userId));
notification.setCreatedDate(OffsetDateTime.now());
notification.setReadAt(null);
notificationDAO.save(notification);
} catch (Exception e) {
}
}
}
} catch (LIMSRuntimeException e) {
String errorMsg;
if (e.getCause() instanceof StaleObjectStateException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.openelisglobal.sample.controller;

import java.lang.reflect.InvocationTargetException;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Pattern;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -11,10 +14,12 @@
import org.hl7.fhir.r4.model.Enumerations.ResourceType;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Task;
import org.openelisglobal.analysis.valueholder.Analysis;
import org.openelisglobal.common.constants.Constants;
import org.openelisglobal.common.exception.LIMSRuntimeException;
import org.openelisglobal.common.formfields.FormFields;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.provider.validation.AlphanumAccessionValidator;
import org.openelisglobal.common.services.DisplayListService;
import org.openelisglobal.common.services.DisplayListService.ListType;
import org.openelisglobal.common.services.SampleOrderService;
Expand All @@ -28,6 +33,9 @@
import org.openelisglobal.dataexchange.fhir.service.FhirTransformService;
import org.openelisglobal.dataexchange.order.valueholder.ElectronicOrder;
import org.openelisglobal.dataexchange.service.order.ElectronicOrderService;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.notifications.dao.NotificationDAO;
import org.openelisglobal.notifications.entity.Notification;
import org.openelisglobal.organization.service.OrganizationService;
import org.openelisglobal.organization.valueholder.Organization;
import org.openelisglobal.patient.action.IPatientUpdate;
Expand All @@ -41,11 +49,15 @@
import org.openelisglobal.sample.form.SamplePatientEntryForm;
import org.openelisglobal.sample.service.PatientManagementUpdate;
import org.openelisglobal.sample.service.SamplePatientEntryService;
import org.openelisglobal.sample.service.SampleService;
import org.openelisglobal.sample.validator.SamplePatientEntryFormValidator;
import org.openelisglobal.sample.valueholder.OrderPriority;
import org.openelisglobal.sample.valueholder.SampleAdditionalField;
import org.openelisglobal.sample.valueholder.SampleAdditionalField.AdditionalFieldName;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.systemuser.service.SystemUserService;
import org.openelisglobal.systemuser.service.UserService;
import org.openelisglobal.userrole.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -144,6 +156,14 @@ public class SamplePatientEntryController extends BaseSampleEntryController {
private ElectronicOrderService electronicOrderService;
@Autowired
private OrganizationService organizationService;
@Autowired
private NotificationDAO notificationDAO;
@Autowired
private UserRoleService userRoleService;
@Autowired
private SystemUserService systemUserService;
@Autowired
private SampleService sampleService;

@Autowired
private FhirUtil fhirUtil;
Expand Down Expand Up @@ -260,6 +280,34 @@ private void setupReferralOption(SamplePatientEntryForm form) {
LogEvent.logError(e);
}

if (sampleOrder.getPriority().equals(OrderPriority.STAT)) {
List<String> systemUserIds = userRoleService.getUserIdsForRole(Constants.ROLE_RESULTS);
List<Analysis> analyses = sampleService
.getAnalysis(sampleService.getSampleByAccessionNumber(sampleOrder.getLabNo()));
String message = MessageUtil.getMessage("notification.order.stat",
AlphanumAccessionValidator.convertAlphaNumLabNumForDisplay(sampleOrder.getLabNo()));
StringBuffer sb = new StringBuffer(message);
for (String userId : systemUserIds) {
List<Analysis> userAnalyses = userService.filterAnalysesByLabUnitRoles(userId, analyses,
Constants.ROLE_RESULTS);
if (userAnalyses != null && !userAnalyses.isEmpty()) {
List<String> tests = userAnalyses.stream().map(a -> a.getTest().getLocalizedName())
.collect(Collectors.toList());
String testString = String.join(", ", tests);
sb.append(testString);
try {
Notification notification = new Notification();
notification.setMessage(sb.toString());
notification.setUser(systemUserService.getUserById(userId));
notification.setCreatedDate(OffsetDateTime.now());
notification.setReadAt(null);
notificationDAO.save(notification);
} catch (Exception e) {
}
}
}
}

// String fhir_json = fhirTransformService.CreateFhirFromOESample(updateData,
// patientUpdate, patientInfo, form, request);
} catch (LIMSRuntimeException e) {
Expand Down
Loading
Loading