From d34ebe1b44455f1951209a6fe4ca72973a6ad5ae Mon Sep 17 00:00:00 2001 From: arihoSeth Date: Fri, 8 Nov 2024 18:17:44 +0300 Subject: [PATCH 01/10] Refactored the getSysUserId Method into a Single Class --- .../common/controller/BaseController.java | 15 ++------------- .../common/rest/DisplayListController.java | 3 ++- ...estsForSampleTypeProviderRestController.java | 4 ++-- .../provider/PatientSearchRestController.java | 4 ++-- ...ngAnalysisForTestProviderRestController.java | 4 ++-- ...EntryTestsForTypeProviderRestController.java | 4 ++-- .../ControllerUtills.java} | 10 +++++----- .../rest/NotificationRestController.java | 16 ++-------------- .../rest/PatientManagementRestController.java | 4 ++-- .../program/controller/ProgramController.java | 4 ++-- .../controller/cytology/CytologyController.java | 4 ++-- .../ImmunohistochemistryController.java | 4 ++-- .../pathology/PathologyController.java | 4 ++-- ...ingEventsCorrectionActionRestController.java | 17 ++--------------- .../ReportNonConformEventsRestController.java | 17 ++--------------- .../ViewNonConformEventsRestController.java | 17 ++--------------- .../controller/rest/ReportRestController.java | 4 ++-- .../sample/service/PatientManagementUpdate.java | 8 ++------ .../rest/PrintWorkplanReportRestController.java | 4 ++-- .../controller/rest/WorkplanRestController.java | 4 ++-- 20 files changed, 43 insertions(+), 108 deletions(-) rename src/main/java/org/openelisglobal/common/{rest/BaseRestController.java => util/ControllerUtills.java} (78%) diff --git a/src/main/java/org/openelisglobal/common/controller/BaseController.java b/src/main/java/org/openelisglobal/common/controller/BaseController.java index 5c36541ba9..3086331f96 100644 --- a/src/main/java/org/openelisglobal/common/controller/BaseController.java +++ b/src/main/java/org/openelisglobal/common/controller/BaseController.java @@ -13,10 +13,10 @@ import org.openelisglobal.common.form.BaseForm; import org.openelisglobal.common.log.LogEvent; import org.openelisglobal.common.util.ConfigurationProperties; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.StringUtil; import org.openelisglobal.internationalization.MessageUtil; import org.openelisglobal.login.dao.UserModuleService; -import org.openelisglobal.login.valueholder.UserSessionData; import org.openelisglobal.view.PageBuilderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ import org.springframework.web.servlet.support.RequestContextUtils; @Component -public abstract class BaseController implements IActionConstants { +public abstract class BaseController extends ControllerUtills { // Request being autowired appears to be threadsafe because of how Spring // handles autowiring, despite all controllers being singletons @@ -183,17 +183,6 @@ protected void setPageTitles(HttpServletRequest request, BaseForm form) { } } - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); - if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); - if (usd == null) { - return null; - } - } - return String.valueOf(usd.getSystemUserId()); - } - protected void setSuccessFlag(HttpServletRequest request, boolean success) { request.setAttribute(FWD_SUCCESS, success); } diff --git a/src/main/java/org/openelisglobal/common/rest/DisplayListController.java b/src/main/java/org/openelisglobal/common/rest/DisplayListController.java index 6451199863..a54264415e 100644 --- a/src/main/java/org/openelisglobal/common/rest/DisplayListController.java +++ b/src/main/java/org/openelisglobal/common/rest/DisplayListController.java @@ -28,6 +28,7 @@ import org.openelisglobal.common.services.StatusService.AnalysisStatus; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.LabelValuePair; @@ -73,7 +74,7 @@ @Controller @RequestMapping(value = "/rest/") -public class DisplayListController extends BaseRestController { +public class DisplayListController extends ControllerUtills { @Value("${org.itech.login.saml:false}") private Boolean useSAML; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java index 72050cb2e6..dd4dbbff4a 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java @@ -20,7 +20,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.spring.util.SpringContext; import org.openelisglobal.test.valueholder.Test; import org.openelisglobal.typeofsample.service.TypeOfSampleService; @@ -33,7 +33,7 @@ @RestController @RequestMapping("/rest") -public class AllTestsForSampleTypeProviderRestController extends BaseRestController { +public class AllTestsForSampleTypeProviderRestController extends ControllerUtills { private TypeOfSampleService typeOfSampleService = SpringContext.getBean(TypeOfSampleService.class); diff --git a/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java index 52d02541dc..df7b265474 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java @@ -19,10 +19,10 @@ import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalAndExternalWorker; import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalWorker; import org.openelisglobal.common.provider.query.workerObjects.PatientSearchWorker; -import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.rest.util.PatientSearchResultsPaging; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.dataexchange.fhir.FhirConfig; import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; @@ -49,7 +49,7 @@ @Controller @RequestMapping(value = "/rest/") -public class PatientSearchRestController extends BaseRestController { +public class PatientSearchRestController extends ControllerUtills { @Autowired private FhirConfig fhirConfig; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java index 3e795ec955..f300f75f26 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java @@ -23,10 +23,10 @@ import org.openelisglobal.analysis.service.AnalysisService; import org.openelisglobal.analysis.valueholder.Analysis; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.services.StatusService; import org.openelisglobal.common.servlet.validation.AjaxServlet; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.spring.util.SpringContext; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +37,7 @@ @RestController @RequestMapping("/rest") -public class PendingAnalysisForTestProviderRestController extends BaseRestController { +public class PendingAnalysisForTestProviderRestController extends ControllerUtills { private static final List NOT_STARTED; private static final List TECH_REJECT; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java index 49603df506..5d8dcf7638 100755 --- a/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java @@ -13,7 +13,7 @@ import org.apache.commons.validator.GenericValidator; import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.common.constants.Constants; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.StringUtil; import org.openelisglobal.login.valueholder.UserSessionData; @@ -38,7 +38,7 @@ @Controller @RequestMapping(value = "/rest/") -public class SampleEntryTestsForTypeProviderRestController extends BaseRestController { +public class SampleEntryTestsForTypeProviderRestController extends ControllerUtills { private static String USER_TEST_SECTION_ID; diff --git a/src/main/java/org/openelisglobal/common/rest/BaseRestController.java b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java similarity index 78% rename from src/main/java/org/openelisglobal/common/rest/BaseRestController.java rename to src/main/java/org/openelisglobal/common/util/ControllerUtills.java index 1309d9a5f1..de59a5d9e4 100644 --- a/src/main/java/org/openelisglobal/common/rest/BaseRestController.java +++ b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java @@ -1,13 +1,12 @@ -package org.openelisglobal.common.rest; +package org.openelisglobal.common.util; import javax.servlet.http.HttpServletRequest; import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.login.valueholder.UserSessionData; -import org.springframework.stereotype.Component; - -@Component -public class BaseRestController implements IActionConstants { +import org.springframework.stereotype.Controller; +@Controller +public class ControllerUtills implements IActionConstants { protected String getSysUserId(HttpServletRequest request) { UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); if (usd == null) { @@ -18,4 +17,5 @@ protected String getSysUserId(HttpServletRequest request) { } return String.valueOf(usd.getSystemUserId()); } + } diff --git a/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java b/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java index 2c8da886ef..52329fe6b7 100644 --- a/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java +++ b/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java @@ -10,7 +10,7 @@ import nl.martijndwars.webpush.PushService; import org.apache.http.HttpResponse; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.openelisglobal.login.valueholder.UserSessionData; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.notifications.dao.NotificationDAO; import org.openelisglobal.notifications.dao.NotificationSubscriptionDAO; import org.openelisglobal.notifications.entity.Notification; @@ -31,12 +31,11 @@ @RequestMapping("/rest") @RestController -public class NotificationRestController { +public class NotificationRestController extends ControllerUtills { private final NotificationDAO notificationDAO; private final SystemUserService systemUserService; private final NotificationSubscriptionDAO notificationSubscriptionDAO; - private static final String USER_SESSION_DATA = "userSessionData"; @Autowired private ConfigurableEnvironment env; @@ -210,15 +209,4 @@ public ResponseEntity unsubscribe(HttpServletRequest request) { return ResponseEntity.ok().body("Unsubscribed successfully"); } - - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); - if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); - if (usd == null) { - return null; - } - } - return String.valueOf(usd.getSystemUserId()); - } } diff --git a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java index d7f966b646..1b594b554f 100644 --- a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java +++ b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java @@ -9,7 +9,7 @@ import org.hibernate.StaleObjectStateException; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.dataexchange.fhir.exception.FhirPersistanceException; import org.openelisglobal.dataexchange.fhir.exception.FhirTransformationException; import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; @@ -37,7 +37,7 @@ @Controller @RequestMapping(value = "/rest/") -public class PatientManagementRestController extends BaseRestController { +public class PatientManagementRestController extends ControllerUtills { @Autowired SearchResultsService searchService; @Autowired diff --git a/src/main/java/org/openelisglobal/program/controller/ProgramController.java b/src/main/java/org/openelisglobal/program/controller/ProgramController.java index 7d6974dd0b..b41271f4fb 100644 --- a/src/main/java/org/openelisglobal/program/controller/ProgramController.java +++ b/src/main/java/org/openelisglobal/program/controller/ProgramController.java @@ -6,9 +6,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.validator.GenericValidator; import org.hl7.fhir.r4.model.Questionnaire; -import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.DisplayListService; import org.openelisglobal.common.services.DisplayListService.ListType; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.exception.FhirLocalPersistingException; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; @@ -28,7 +28,7 @@ @RestController @RequestMapping(value = "/rest") -public class ProgramController extends BaseRestController { +public class ProgramController extends ControllerUtills { @Autowired private FhirPersistanceService fhirPersistanceService; diff --git a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java index 16f2ddc7d4..5a70ad888e 100644 --- a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.program.bean.CytologyDashBoardCount; import org.openelisglobal.program.service.cytology.CytologyDisplayService; import org.openelisglobal.program.service.cytology.CytologySampleService; @@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class CytologyController extends BaseRestController { +public class CytologyController extends ControllerUtills { @Autowired private CytologySampleService cytologySampleService; diff --git a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java index c136d04bc6..e4fb385240 100644 --- a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java +++ b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.program.bean.ImmunohistochemistryDashBoardCount; import org.openelisglobal.program.service.ImmunohistochemistryDisplayService; import org.openelisglobal.program.service.ImmunohistochemistrySampleService; @@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ImmunohistochemistryController extends BaseRestController { +public class ImmunohistochemistryController extends ControllerUtills { @Autowired private ImmunohistochemistrySampleService immunohistochemistrySampleService; diff --git a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java index d0772bb688..ec05a7ae73 100644 --- a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.program.bean.PathologyDashBoardCount; import org.openelisglobal.program.service.PathologyDisplayService; import org.openelisglobal.program.service.PathologySampleService; @@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class PathologyController extends BaseRestController { +public class PathologyController extends ControllerUtills { @Autowired private PathologySampleService pathologySampleService; diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java index b511a058e7..dc9b2d4cb7 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java @@ -8,7 +8,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.GenericValidator; import org.openelisglobal.common.services.DisplayListService; -import org.openelisglobal.login.valueholder.UserSessionData; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.patient.action.bean.PatientSearch; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NCEventService; @@ -26,12 +26,10 @@ @RestController @RequestMapping(value = "/rest") -public class NonConformingEventsCorrectionActionRestController { +public class NonConformingEventsCorrectionActionRestController extends ControllerUtills { private NCEventService ncEventService = SpringContext.getBean(NCEventService.class); - private static final String USER_SESSION_DATA = "userSessionData"; - @Autowired private NonConformingEventWorker nonConformingEventWorker; @@ -90,15 +88,4 @@ public ResponseEntity updateNCECorretiveActionForm(@RequestBody NonConforming return ResponseEntity.ok().body(Map.of("success", false)); } } - - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); - if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); - if (usd == null) { - return null; - } - } - return String.valueOf(usd.getSystemUserId()); - } } diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java index 15152f6697..c5f3cb6274 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java @@ -9,8 +9,8 @@ import org.openelisglobal.common.rest.bean.NceSampleItemInfo; import org.openelisglobal.common.services.DisplayListService; import org.openelisglobal.common.services.RequesterService; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; -import org.openelisglobal.login.valueholder.UserSessionData; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NceCategoryService; import org.openelisglobal.qaevent.valueholder.NcEvent; @@ -33,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ReportNonConformEventsRestController { +public class ReportNonConformEventsRestController extends ControllerUtills { private final SampleService sampleService; private final SampleItemService sampleItemService; @@ -42,8 +42,6 @@ public class ReportNonConformEventsRestController { private final NceCategoryService nceCategoryService; private final RequesterService requesterService; - private static final String USER_SESSION_DATA = "userSessionData"; - @Autowired private SystemUserService systemUserService; @@ -175,17 +173,6 @@ private NceSampleInfo addSample(Sample sample) { return sampleInfo; } - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); - if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); - if (usd == null) { - return null; - } - } - return String.valueOf(usd.getSystemUserId()); - } - private Sample getSampleForLabNumber(String labNumber) throws LIMSInvalidConfigurationException { return sampleService.getSampleByAccessionNumber(labNumber); } diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java index abfd7bcb32..e6047efc73 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java @@ -6,8 +6,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.openelisglobal.common.services.DisplayListService; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; -import org.openelisglobal.login.valueholder.UserSessionData; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NCEventService; import org.openelisglobal.qaevent.service.NceCategoryService; @@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ViewNonConformEventsRestController { +public class ViewNonConformEventsRestController extends ControllerUtills { @Autowired private NCEventService ncEventService; @@ -46,8 +46,6 @@ public class ViewNonConformEventsRestController { @Autowired private SampleItemService sampleItemService; - private static final String USER_SESSION_DATA = "userSessionData"; - private final NonConformingEventWorker nonConformingEventWorker; public ViewNonConformEventsRestController(NonConformingEventWorker nonConformingEventWorker) { @@ -120,15 +118,4 @@ public ResponseEntity postReportNonConformingEvent(@RequestBody NonConforming .body("An error occurred while processing the request." + e); } } - - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); - if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); - if (usd == null) { - return null; - } - } - return String.valueOf(usd.getSystemUserId()); - } } diff --git a/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java b/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java index 9893169b35..c409f83db8 100644 --- a/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java +++ b/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java @@ -16,7 +16,7 @@ import net.sf.jasperreports.engine.JRException; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.validator.GenericValidator; import org.openelisglobal.reports.action.implementation.IReportCreator; import org.openelisglobal.reports.action.implementation.ReportImplementationFactory; @@ -30,7 +30,7 @@ @Controller @RequestMapping(value = "/rest/") -public class ReportRestController extends BaseRestController { +public class ReportRestController extends ControllerUtills { @Autowired private ServletContext context; diff --git a/src/main/java/org/openelisglobal/sample/service/PatientManagementUpdate.java b/src/main/java/org/openelisglobal/sample/service/PatientManagementUpdate.java index ec39ca9e27..860cc34c8f 100644 --- a/src/main/java/org/openelisglobal/sample/service/PatientManagementUpdate.java +++ b/src/main/java/org/openelisglobal/sample/service/PatientManagementUpdate.java @@ -16,6 +16,7 @@ import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.validator.BaseErrors; import org.openelisglobal.login.valueholder.UserSessionData; import org.openelisglobal.patient.action.IPatientUpdate; @@ -39,7 +40,7 @@ @Service @Scope("prototype") -public class PatientManagementUpdate implements IPatientUpdate { +public class PatientManagementUpdate extends ControllerUtills implements IPatientUpdate { private String currentUserId; protected Patient patient; @@ -78,11 +79,6 @@ public void initializeGlobalVariables() { } } - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA); - return String.valueOf(usd.getSystemUserId()); - } - public void setSysUserIdFromRequest(HttpServletRequest request) { UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA); currentUserId = String.valueOf(usd.getSystemUserId()); diff --git a/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java b/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java index 11a8d7f212..2f6e11829a 100644 --- a/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java +++ b/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java @@ -15,7 +15,7 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.rest.BaseRestController; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.test.service.TestServiceImpl; import org.openelisglobal.workplan.form.WorkplanForm; import org.openelisglobal.workplan.form.WorkplanForm.PrintWorkplan; @@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController("PrintWorkplanReportRestController") -public class PrintWorkplanReportRestController extends BaseRestController { +public class PrintWorkplanReportRestController extends ControllerUtills { private String reportPath = null; diff --git a/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java b/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java index a6e78e95d9..ca09bbe304 100644 --- a/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java +++ b/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java @@ -7,11 +7,11 @@ import org.openelisglobal.analysis.valueholder.Analysis; import org.openelisglobal.common.formfields.FormFields; import org.openelisglobal.common.formfields.FormFields.Field; -import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.services.StatusService.AnalysisStatus; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; +import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.StringUtil; import org.openelisglobal.observationhistory.service.ObservationHistoryService; @@ -27,7 +27,7 @@ import org.springframework.stereotype.Controller; @Controller -public class WorkplanRestController extends BaseRestController { +public class WorkplanRestController extends ControllerUtills { @Autowired protected TestService testService; From d10b3e2770c0a74b2818ab6f61dd6b788d3649ed Mon Sep 17 00:00:00 2001 From: arihoSeth Date: Tue, 19 Nov 2024 12:50:22 +0300 Subject: [PATCH 02/10] Refactored the getSysUserId Method into a Single Class --- .../common/controller/BaseController.java | 2 +- .../common/rest/BaseRestController.java | 11 +++++++++++ .../common/rest/DisplayListController.java | 3 +-- .../AllTestsForSampleTypeProviderRestController.java | 4 ++-- .../rest/provider/PatientSearchRestController.java | 4 ++-- .../PendingAnalysisForTestProviderRestController.java | 4 ++-- ...SampleEntryTestsForTypeProviderRestController.java | 4 ++-- .../openelisglobal/common/util/ControllerUtills.java | 8 +++----- .../rest/PatientManagementRestController.java | 4 ++-- .../program/controller/ProgramController.java | 4 ++-- .../controller/cytology/CytologyController.java | 5 +++-- .../ImmunohistochemistryController.java | 5 +++-- .../controller/pathology/PathologyController.java | 5 +++-- .../reports/controller/rest/ReportRestController.java | 4 ++-- .../rest/PrintWorkplanReportRestController.java | 4 ++-- .../controller/rest/WorkplanRestController.java | 4 ++-- 16 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 src/main/java/org/openelisglobal/common/rest/BaseRestController.java diff --git a/src/main/java/org/openelisglobal/common/controller/BaseController.java b/src/main/java/org/openelisglobal/common/controller/BaseController.java index 3086331f96..cb39939bb8 100644 --- a/src/main/java/org/openelisglobal/common/controller/BaseController.java +++ b/src/main/java/org/openelisglobal/common/controller/BaseController.java @@ -28,7 +28,7 @@ import org.springframework.web.servlet.support.RequestContextUtils; @Component -public abstract class BaseController extends ControllerUtills { +public abstract class BaseController extends ControllerUtills implements IActionConstants{ // Request being autowired appears to be threadsafe because of how Spring // handles autowiring, despite all controllers being singletons diff --git a/src/main/java/org/openelisglobal/common/rest/BaseRestController.java b/src/main/java/org/openelisglobal/common/rest/BaseRestController.java new file mode 100644 index 0000000000..0ded2188ff --- /dev/null +++ b/src/main/java/org/openelisglobal/common/rest/BaseRestController.java @@ -0,0 +1,11 @@ +package org.openelisglobal.common.rest; + +import org.openelisglobal.common.action.IActionConstants; +import org.openelisglobal.common.util.ControllerUtills; +import org.springframework.stereotype.Component; + +@Component +public class BaseRestController extends ControllerUtills implements IActionConstants{ + + +} \ No newline at end of file diff --git a/src/main/java/org/openelisglobal/common/rest/DisplayListController.java b/src/main/java/org/openelisglobal/common/rest/DisplayListController.java index a54264415e..6451199863 100644 --- a/src/main/java/org/openelisglobal/common/rest/DisplayListController.java +++ b/src/main/java/org/openelisglobal/common/rest/DisplayListController.java @@ -28,7 +28,6 @@ import org.openelisglobal.common.services.StatusService.AnalysisStatus; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.LabelValuePair; @@ -74,7 +73,7 @@ @Controller @RequestMapping(value = "/rest/") -public class DisplayListController extends ControllerUtills { +public class DisplayListController extends BaseRestController { @Value("${org.itech.login.saml:false}") private Boolean useSAML; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java index dd4dbbff4a..72050cb2e6 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java @@ -20,7 +20,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.spring.util.SpringContext; import org.openelisglobal.test.valueholder.Test; import org.openelisglobal.typeofsample.service.TypeOfSampleService; @@ -33,7 +33,7 @@ @RestController @RequestMapping("/rest") -public class AllTestsForSampleTypeProviderRestController extends ControllerUtills { +public class AllTestsForSampleTypeProviderRestController extends BaseRestController { private TypeOfSampleService typeOfSampleService = SpringContext.getBean(TypeOfSampleService.class); diff --git a/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java index df7b265474..52d02541dc 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/PatientSearchRestController.java @@ -19,10 +19,10 @@ import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalAndExternalWorker; import org.openelisglobal.common.provider.query.workerObjects.PatientSearchLocalWorker; import org.openelisglobal.common.provider.query.workerObjects.PatientSearchWorker; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.rest.util.PatientSearchResultsPaging; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.dataexchange.fhir.FhirConfig; import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; @@ -49,7 +49,7 @@ @Controller @RequestMapping(value = "/rest/") -public class PatientSearchRestController extends ControllerUtills { +public class PatientSearchRestController extends BaseRestController { @Autowired private FhirConfig fhirConfig; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java index f300f75f26..3e795ec955 100644 --- a/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java @@ -23,10 +23,10 @@ import org.openelisglobal.analysis.service.AnalysisService; import org.openelisglobal.analysis.valueholder.Analysis; import org.openelisglobal.common.log.LogEvent; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.services.StatusService; import org.openelisglobal.common.servlet.validation.AjaxServlet; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.spring.util.SpringContext; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +37,7 @@ @RestController @RequestMapping("/rest") -public class PendingAnalysisForTestProviderRestController extends ControllerUtills { +public class PendingAnalysisForTestProviderRestController extends BaseRestController { private static final List NOT_STARTED; private static final List TECH_REJECT; diff --git a/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java index 5d8dcf7638..49603df506 100755 --- a/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/provider/SampleEntryTestsForTypeProviderRestController.java @@ -13,7 +13,7 @@ import org.apache.commons.validator.GenericValidator; import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.common.constants.Constants; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.StringUtil; import org.openelisglobal.login.valueholder.UserSessionData; @@ -38,7 +38,7 @@ @Controller @RequestMapping(value = "/rest/") -public class SampleEntryTestsForTypeProviderRestController extends ControllerUtills { +public class SampleEntryTestsForTypeProviderRestController extends BaseRestController { private static String USER_TEST_SECTION_ID; diff --git a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java index de59a5d9e4..3e5ced8d6a 100644 --- a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java +++ b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java @@ -1,12 +1,11 @@ package org.openelisglobal.common.util; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.login.valueholder.UserSessionData; -import org.springframework.stereotype.Controller; +public class ControllerUtills { + + private static final String USER_SESSION_DATA = "userSessionData"; -@Controller -public class ControllerUtills implements IActionConstants { protected String getSysUserId(HttpServletRequest request) { UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); if (usd == null) { @@ -17,5 +16,4 @@ protected String getSysUserId(HttpServletRequest request) { } return String.valueOf(usd.getSystemUserId()); } - } diff --git a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java index 1b594b554f..d7f966b646 100644 --- a/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java +++ b/src/main/java/org/openelisglobal/patient/controller/rest/PatientManagementRestController.java @@ -9,7 +9,7 @@ import org.hibernate.StaleObjectStateException; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.dataexchange.fhir.exception.FhirPersistanceException; import org.openelisglobal.dataexchange.fhir.exception.FhirTransformationException; import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; @@ -37,7 +37,7 @@ @Controller @RequestMapping(value = "/rest/") -public class PatientManagementRestController extends ControllerUtills { +public class PatientManagementRestController extends BaseRestController { @Autowired SearchResultsService searchService; @Autowired diff --git a/src/main/java/org/openelisglobal/program/controller/ProgramController.java b/src/main/java/org/openelisglobal/program/controller/ProgramController.java index b41271f4fb..7d6974dd0b 100644 --- a/src/main/java/org/openelisglobal/program/controller/ProgramController.java +++ b/src/main/java/org/openelisglobal/program/controller/ProgramController.java @@ -6,9 +6,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.validator.GenericValidator; import org.hl7.fhir.r4.model.Questionnaire; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.DisplayListService; import org.openelisglobal.common.services.DisplayListService.ListType; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.exception.FhirLocalPersistingException; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; @@ -28,7 +28,7 @@ @RestController @RequestMapping(value = "/rest") -public class ProgramController extends ControllerUtills { +public class ProgramController extends BaseRestController { @Autowired private FhirPersistanceService fhirPersistanceService; diff --git a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java index 5a70ad888e..e03b07012d 100644 --- a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java @@ -7,7 +7,8 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.util.ControllerUtills; + +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.CytologyDashBoardCount; import org.openelisglobal.program.service.cytology.CytologyDisplayService; import org.openelisglobal.program.service.cytology.CytologySampleService; @@ -27,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class CytologyController extends ControllerUtills { +public class CytologyController extends BaseRestController { @Autowired private CytologySampleService cytologySampleService; diff --git a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java index e4fb385240..4c1821c80d 100644 --- a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java +++ b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java @@ -7,7 +7,8 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.util.ControllerUtills; + +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.ImmunohistochemistryDashBoardCount; import org.openelisglobal.program.service.ImmunohistochemistryDisplayService; import org.openelisglobal.program.service.ImmunohistochemistrySampleService; @@ -27,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ImmunohistochemistryController extends ControllerUtills { +public class ImmunohistochemistryController extends BaseRestController { @Autowired private ImmunohistochemistrySampleService immunohistochemistrySampleService; diff --git a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java index ec05a7ae73..60c1bdde98 100644 --- a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java @@ -7,7 +7,8 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.openelisglobal.common.util.ControllerUtills; + +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.PathologyDashBoardCount; import org.openelisglobal.program.service.PathologyDisplayService; import org.openelisglobal.program.service.PathologySampleService; @@ -27,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class PathologyController extends ControllerUtills { +public class PathologyController extends BaseRestController { @Autowired private PathologySampleService pathologySampleService; diff --git a/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java b/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java index c409f83db8..9893169b35 100644 --- a/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java +++ b/src/main/java/org/openelisglobal/reports/controller/rest/ReportRestController.java @@ -16,7 +16,7 @@ import net.sf.jasperreports.engine.JRException; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.util.validator.GenericValidator; import org.openelisglobal.reports.action.implementation.IReportCreator; import org.openelisglobal.reports.action.implementation.ReportImplementationFactory; @@ -30,7 +30,7 @@ @Controller @RequestMapping(value = "/rest/") -public class ReportRestController extends ControllerUtills { +public class ReportRestController extends BaseRestController { @Autowired private ServletContext context; diff --git a/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java b/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java index 2f6e11829a..11a8d7f212 100644 --- a/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java +++ b/src/main/java/org/openelisglobal/workplan/controller/rest/PrintWorkplanReportRestController.java @@ -15,7 +15,7 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import org.openelisglobal.common.exception.LIMSRuntimeException; import org.openelisglobal.common.log.LogEvent; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.test.service.TestServiceImpl; import org.openelisglobal.workplan.form.WorkplanForm; import org.openelisglobal.workplan.form.WorkplanForm.PrintWorkplan; @@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController("PrintWorkplanReportRestController") -public class PrintWorkplanReportRestController extends ControllerUtills { +public class PrintWorkplanReportRestController extends BaseRestController { private String reportPath = null; diff --git a/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java b/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java index ca09bbe304..a6e78e95d9 100644 --- a/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java +++ b/src/main/java/org/openelisglobal/workplan/controller/rest/WorkplanRestController.java @@ -7,11 +7,11 @@ import org.openelisglobal.analysis.valueholder.Analysis; import org.openelisglobal.common.formfields.FormFields; import org.openelisglobal.common.formfields.FormFields.Field; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.services.StatusService.AnalysisStatus; import org.openelisglobal.common.util.ConfigurationProperties; import org.openelisglobal.common.util.ConfigurationProperties.Property; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.IdValuePair; import org.openelisglobal.common.util.StringUtil; import org.openelisglobal.observationhistory.service.ObservationHistoryService; @@ -27,7 +27,7 @@ import org.springframework.stereotype.Controller; @Controller -public class WorkplanRestController extends ControllerUtills { +public class WorkplanRestController extends BaseRestController { @Autowired protected TestService testService; From ac5fb5df030188b7276355237beef54e8e2fa933 Mon Sep 17 00:00:00 2001 From: arihoSeth Date: Tue, 19 Nov 2024 13:19:50 +0300 Subject: [PATCH 03/10] Refactored code using the spotless command --- .../org/openelisglobal/common/controller/BaseController.java | 2 +- .../org/openelisglobal/common/rest/BaseRestController.java | 3 +-- .../java/org/openelisglobal/common/util/ControllerUtills.java | 1 + .../program/controller/cytology/CytologyController.java | 1 - .../immunohistochemistry/ImmunohistochemistryController.java | 1 - .../program/controller/pathology/PathologyController.java | 1 - 6 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openelisglobal/common/controller/BaseController.java b/src/main/java/org/openelisglobal/common/controller/BaseController.java index cb39939bb8..dfd7fc469f 100644 --- a/src/main/java/org/openelisglobal/common/controller/BaseController.java +++ b/src/main/java/org/openelisglobal/common/controller/BaseController.java @@ -28,7 +28,7 @@ import org.springframework.web.servlet.support.RequestContextUtils; @Component -public abstract class BaseController extends ControllerUtills implements IActionConstants{ +public abstract class BaseController extends ControllerUtills implements IActionConstants { // Request being autowired appears to be threadsafe because of how Spring // handles autowiring, despite all controllers being singletons diff --git a/src/main/java/org/openelisglobal/common/rest/BaseRestController.java b/src/main/java/org/openelisglobal/common/rest/BaseRestController.java index 0ded2188ff..2067d42e8e 100644 --- a/src/main/java/org/openelisglobal/common/rest/BaseRestController.java +++ b/src/main/java/org/openelisglobal/common/rest/BaseRestController.java @@ -5,7 +5,6 @@ import org.springframework.stereotype.Component; @Component -public class BaseRestController extends ControllerUtills implements IActionConstants{ +public class BaseRestController extends ControllerUtills implements IActionConstants { - } \ No newline at end of file diff --git a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java index 3e5ced8d6a..31783d3a30 100644 --- a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java +++ b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java @@ -2,6 +2,7 @@ import javax.servlet.http.HttpServletRequest; import org.openelisglobal.login.valueholder.UserSessionData; + public class ControllerUtills { private static final String USER_SESSION_DATA = "userSessionData"; diff --git a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java index e03b07012d..16f2ddc7d4 100644 --- a/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/cytology/CytologyController.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; - import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.CytologyDashBoardCount; import org.openelisglobal.program.service.cytology.CytologyDisplayService; diff --git a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java index 4c1821c80d..c136d04bc6 100644 --- a/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java +++ b/src/main/java/org/openelisglobal/program/controller/immunohistochemistry/ImmunohistochemistryController.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; - import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.ImmunohistochemistryDashBoardCount; import org.openelisglobal.program.service.ImmunohistochemistryDisplayService; diff --git a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java index 60c1bdde98..d0772bb688 100644 --- a/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java +++ b/src/main/java/org/openelisglobal/program/controller/pathology/PathologyController.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; - import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.program.bean.PathologyDashBoardCount; import org.openelisglobal.program.service.PathologyDisplayService; From cda9d07653fcf223170c17008a659f15392aec7e Mon Sep 17 00:00:00 2001 From: arihoSeth Date: Wed, 20 Nov 2024 01:22:22 +0300 Subject: [PATCH 04/10] Requested changes added --- .../org/openelisglobal/common/util/ControllerUtills.java | 7 +++---- .../notifications/rest/NotificationRestController.java | 4 ++-- .../NonConformingEventsCorrectionActionRestController.java | 4 ++-- .../rest/ReportNonConformEventsRestController.java | 4 ++-- .../rest/ViewNonConformEventsRestController.java | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java index 31783d3a30..1d10cb279a 100644 --- a/src/main/java/org/openelisglobal/common/util/ControllerUtills.java +++ b/src/main/java/org/openelisglobal/common/util/ControllerUtills.java @@ -1,16 +1,15 @@ package org.openelisglobal.common.util; import javax.servlet.http.HttpServletRequest; +import org.openelisglobal.common.action.IActionConstants; import org.openelisglobal.login.valueholder.UserSessionData; public class ControllerUtills { - private static final String USER_SESSION_DATA = "userSessionData"; - protected String getSysUserId(HttpServletRequest request) { - UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); + UserSessionData usd = (UserSessionData) request.getSession().getAttribute(IActionConstants.USER_SESSION_DATA); if (usd == null) { - usd = (UserSessionData) request.getAttribute(USER_SESSION_DATA); + usd = (UserSessionData) request.getAttribute(IActionConstants.USER_SESSION_DATA); if (usd == null) { return null; } diff --git a/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java b/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java index 52329fe6b7..01c1fef210 100644 --- a/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java +++ b/src/main/java/org/openelisglobal/notifications/rest/NotificationRestController.java @@ -10,7 +10,7 @@ import nl.martijndwars.webpush.PushService; import org.apache.http.HttpResponse; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.openelisglobal.common.util.ControllerUtills; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.notifications.dao.NotificationDAO; import org.openelisglobal.notifications.dao.NotificationSubscriptionDAO; import org.openelisglobal.notifications.entity.Notification; @@ -31,7 +31,7 @@ @RequestMapping("/rest") @RestController -public class NotificationRestController extends ControllerUtills { +public class NotificationRestController extends BaseRestController { private final NotificationDAO notificationDAO; private final SystemUserService systemUserService; diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java index dc9b2d4cb7..3767316fc9 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/NonConformingEventsCorrectionActionRestController.java @@ -7,8 +7,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.GenericValidator; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.DisplayListService; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.patient.action.bean.PatientSearch; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NCEventService; @@ -26,7 +26,7 @@ @RestController @RequestMapping(value = "/rest") -public class NonConformingEventsCorrectionActionRestController extends ControllerUtills { +public class NonConformingEventsCorrectionActionRestController extends BaseRestController { private NCEventService ncEventService = SpringContext.getBean(NCEventService.class); diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java index c5f3cb6274..6fd6e4e798 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/ReportNonConformEventsRestController.java @@ -5,11 +5,11 @@ import javax.servlet.http.HttpServletRequest; import org.openelisglobal.common.exception.LIMSInvalidConfigurationException; import org.openelisglobal.common.provider.query.PatientSearchResults; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.rest.bean.NceSampleInfo; import org.openelisglobal.common.rest.bean.NceSampleItemInfo; import org.openelisglobal.common.services.DisplayListService; import org.openelisglobal.common.services.RequesterService; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NceCategoryService; @@ -33,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ReportNonConformEventsRestController extends ControllerUtills { +public class ReportNonConformEventsRestController extends BaseRestController { private final SampleService sampleService; private final SampleItemService sampleItemService; diff --git a/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java b/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java index e6047efc73..4f8f1ef3c2 100644 --- a/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java +++ b/src/main/java/org/openelisglobal/qaevent/controller/rest/ViewNonConformEventsRestController.java @@ -5,8 +5,8 @@ import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; +import org.openelisglobal.common.rest.BaseRestController; import org.openelisglobal.common.services.DisplayListService; -import org.openelisglobal.common.util.ControllerUtills; import org.openelisglobal.common.util.DateUtil; import org.openelisglobal.qaevent.form.NonConformingEventForm; import org.openelisglobal.qaevent.service.NCEventService; @@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class ViewNonConformEventsRestController extends ControllerUtills { +public class ViewNonConformEventsRestController extends BaseRestController { @Autowired private NCEventService ncEventService; From 7c5f28b71953d3732ddb6827c27a1efae94d2eec Mon Sep 17 00:00:00 2001 From: harshitg927 Date: Thu, 9 Jan 2025 01:00:27 +0530 Subject: [PATCH 05/10] Fix: Prevent negative age input values in New Patient form, along with some formatting of frontend code --- frontend/cypress/pages/ModifyOrderPage.js | 6 +++--- .../src/components/patient/CreatePatientForm.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/cypress/pages/ModifyOrderPage.js b/frontend/cypress/pages/ModifyOrderPage.js index efddfb1e1f..7595866790 100644 --- a/frontend/cypress/pages/ModifyOrderPage.js +++ b/frontend/cypress/pages/ModifyOrderPage.js @@ -41,9 +41,9 @@ class ModifyOrderPage { clickRespectivePatient() { return cy - .get('tbody tr') - .first() - .find('.cds--radio-button__appearance') + .get("tbody tr") + .first() + .find(".cds--radio-button__appearance") .click(); } } diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js index 1f16d7efe0..2ae4e31039 100644 --- a/frontend/src/components/patient/CreatePatientForm.js +++ b/frontend/src/components/patient/CreatePatientForm.js @@ -143,8 +143,16 @@ function CreatePatientForm(props) { }; function handleYearsChange(e, values) { - setPatientDetails(values); - let years = e.target.value; + // Ensure years is not negative + const years = Math.max(0, Number(e.target.value)); + + // Update form values with the validated years + setPatientDetails({ + ...values, + // Update the specific field that contains years to ensure the form shows the corrected value + [e.target.name]: years, + }); + let dobFormatter = { ...dateOfBirthFormatter, years: years, @@ -625,6 +633,7 @@ function CreatePatientForm(props) { })} id="years" type="number" + min="0" onChange={(e) => handleYearsChange(e, values)} placeholder={intl.formatMessage({ id: "patient.information.age", From 6e8ec488f7949d383d8e0a0d6125cf97cff7acce Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jan 2025 18:18:31 +0400 Subject: [PATCH 06/10] additional labs column in csv routine expoert --- .../reportBeans/CIRoutineColumnBuilder.java | 1 + .../reportBeans/CSVRoutineColumnBuilder.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CIRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CIRoutineColumnBuilder.java index 2368849832..1867938a4b 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CIRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CIRoutineColumnBuilder.java @@ -120,6 +120,7 @@ protected void appendOtherDiseaseCrosstab(Date lowDate, Date highDate, SQLConsta protected void defineBasicColumns() { add("accession_number", "LABNO", NONE); + add("lab_unit", "LAB_UNIT", NONE); add("national_id", "IDENTIFIER", NONE); add("gender", "SEX", NONE); add("birth_date", "BIRTHDATE", DATE); diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java index fa26b99612..3b64b16e9e 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java @@ -539,6 +539,7 @@ protected void appendResultCrosstab(java.sql.Date lowDate, java.sql.Date highDat + " join clinlims.sample AS s on s.id = si.samp_id \n" + " join clinlims.test_result AS tr on r.test_result_id = tr.id \n" + " join clinlims.test AS t on tr.test_id = t.id \n" + + " join clinlims.test_section ts on t.test_section_id = ts.id \n" // lab units column + " left join sample_projects sp on si.samp_id = sp.samp_id \n" + "\n" + " WHERE sp.id IS NULL AND s.entered_date >= date(''" + formatDateForDatabaseSql(lowDate) + "'') AND s.entered_date <= date(''" + formatDateForDatabaseSql(highDate) + " '') " + "\n " @@ -631,7 +632,15 @@ protected void appendObservationHistoryCrosstab(java.sql.Date lowDate, java.sql. } protected void appendCrosstabPreamble(SQLConstant listName) { - query.append(", \n\n ( SELECT s.id AS samp_id, " + listName + ".* " + " FROM sample AS s LEFT JOIN \n "); + query.append(", \n\n ( SELECT s.id AS samp_id, " + + " (SELECT ts.name FROM clinlims.test_section ts " // Modify subquery to get test section name + + " JOIN clinlims.test t ON t.test_section_id = ts.id " + + " JOIN clinlims.analysis a ON a.test_id = t.id " + + " WHERE a.sampitem_id = si.id LIMIT 1) as lab_unit, " // Link back to sample item + + listName + ".* " + + " FROM sample AS s " + + " LEFT JOIN sample_item si ON s.id = si.samp_id " // Add sample_item join + + " LEFT JOIN \n "); } protected void appendCrosstabPostfix(java.sql.Date lowDate, java.sql.Date highDate, SQLConstant listName) { From fc0f57a6c0df1d67fa810f9df5e33ad34785a3fc Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jan 2025 18:39:42 +0400 Subject: [PATCH 07/10] code formatting --- .../reportBeans/CSVRoutineColumnBuilder.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java index 3b64b16e9e..bc642e9442 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java @@ -632,14 +632,18 @@ protected void appendObservationHistoryCrosstab(java.sql.Date lowDate, java.sql. } protected void appendCrosstabPreamble(SQLConstant listName) { - query.append(", \n\n ( SELECT s.id AS samp_id, " - + " (SELECT ts.name FROM clinlims.test_section ts " // Modify subquery to get test section name + query.append(", \n\n ( SELECT s.id AS samp_id, " + " (SELECT ts.name FROM clinlims.test_section ts " // Modify + // subquery + // to get + // test + // section + // name + " JOIN clinlims.test t ON t.test_section_id = ts.id " + " JOIN clinlims.analysis a ON a.test_id = t.id " + " WHERE a.sampitem_id = si.id LIMIT 1) as lab_unit, " // Link back to sample item - + listName + ".* " - + " FROM sample AS s " - + " LEFT JOIN sample_item si ON s.id = si.samp_id " // Add sample_item join + + listName + ".* " + " FROM sample AS s " + " LEFT JOIN sample_item si ON s.id = si.samp_id " // Add + // sample_item + // join + " LEFT JOIN \n "); } From 207f025cfbf4e2af38b1f9fafde49660492ab377 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jan 2025 19:00:12 +0400 Subject: [PATCH 08/10] additional formatting and removing unnecessary comments --- .../reportBeans/CSVRoutineColumnBuilder.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java index bc642e9442..a4884985ea 100644 --- a/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java +++ b/src/main/java/org/openelisglobal/reports/action/implementation/reportBeans/CSVRoutineColumnBuilder.java @@ -539,7 +539,7 @@ protected void appendResultCrosstab(java.sql.Date lowDate, java.sql.Date highDat + " join clinlims.sample AS s on s.id = si.samp_id \n" + " join clinlims.test_result AS tr on r.test_result_id = tr.id \n" + " join clinlims.test AS t on tr.test_id = t.id \n" - + " join clinlims.test_section ts on t.test_section_id = ts.id \n" // lab units column + + " join clinlims.test_section ts on t.test_section_id = ts.id \n" + " left join sample_projects sp on si.samp_id = sp.samp_id \n" + "\n" + " WHERE sp.id IS NULL AND s.entered_date >= date(''" + formatDateForDatabaseSql(lowDate) + "'') AND s.entered_date <= date(''" + formatDateForDatabaseSql(highDate) + " '') " + "\n " @@ -632,19 +632,11 @@ protected void appendObservationHistoryCrosstab(java.sql.Date lowDate, java.sql. } protected void appendCrosstabPreamble(SQLConstant listName) { - query.append(", \n\n ( SELECT s.id AS samp_id, " + " (SELECT ts.name FROM clinlims.test_section ts " // Modify - // subquery - // to get - // test - // section - // name + query.append(", \n\n ( SELECT s.id AS samp_id, " + " (SELECT ts.name FROM clinlims.test_section ts " + " JOIN clinlims.test t ON t.test_section_id = ts.id " + " JOIN clinlims.analysis a ON a.test_id = t.id " - + " WHERE a.sampitem_id = si.id LIMIT 1) as lab_unit, " // Link back to sample item - + listName + ".* " + " FROM sample AS s " + " LEFT JOIN sample_item si ON s.id = si.samp_id " // Add - // sample_item - // join - + " LEFT JOIN \n "); + + " WHERE a.sampitem_id = si.id LIMIT 1) as lab_unit, " + listName + ".* " + " FROM sample AS s " + + " LEFT JOIN sample_item si ON s.id = si.samp_id " + " LEFT JOIN \n "); } protected void appendCrosstabPostfix(java.sql.Date lowDate, java.sql.Date highDate, SQLConstant listName) { From 5317a1d8aa836228fdf8c56fa8ac34f4ec230c5c Mon Sep 17 00:00:00 2001 From: mozzy11 Date: Thu, 9 Jan 2025 18:28:04 +0300 Subject: [PATCH 09/10] bump fix version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 03ab4c4f92..9f1628c75e 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 1 0 - 0 + 1 UTF-8 ${project.basedir}/liquibase/liquibase.properties 1.4.1 From 6b52f5f9bda67ea1a6259e37907238d0b7f8f5a3 Mon Sep 17 00:00:00 2001 From: harshitg927 Date: Thu, 9 Jan 2025 01:00:27 +0530 Subject: [PATCH 10/10] Fix: Prevent negative age input values in New Patient form, along with some formatting of frontend code --- .../components/patient/CreatePatientForm.js | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js index 2ae4e31039..f9de1bd7ca 100644 --- a/frontend/src/components/patient/CreatePatientForm.js +++ b/frontend/src/components/patient/CreatePatientForm.js @@ -161,8 +161,16 @@ function CreatePatientForm(props) { } function handleMonthsChange(e, values) { - setPatientDetails(values); - let months = e.target.value; + // Ensure months is not negative + const months = Math.max(0, Number(e.target.value)); + + // Update form values with the validated months + setPatientDetails({ + ...values, + // Update the specific field that contains months to ensure the form shows the corrected value + [e.target.name]: months, + }); + let dobFormatter = { ...dateOfBirthFormatter, months: months, @@ -171,8 +179,16 @@ function CreatePatientForm(props) { } function handleDaysChange(e, values) { - setPatientDetails(values); - let days = e.target.value; + // Ensure days is not negative + const days = Math.max(0, Number(e.target.value)); + + // Update form values with the validated days + setPatientDetails({ + ...values, + // Update the specific field that contains days to ensure the form shows the corrected value + [e.target.name]: days, + }); + let dobFormatter = { ...dateOfBirthFormatter, days: days, @@ -646,6 +662,7 @@ function CreatePatientForm(props) { name="months" labelText={intl.formatMessage({ id: "patient.age.months" })} type="number" + min="0" onChange={(e) => handleMonthsChange(e, values)} id="months" placeholder={intl.formatMessage({ @@ -658,6 +675,7 @@ function CreatePatientForm(props) { value={dateOfBirthFormatter.days} name="days" type="number" + min="0" onChange={(e) => handleDaysChange(e, values)} labelText={intl.formatMessage({ id: "patient.age.days" })} id="days"