From 9b9fe77eb655b2f94507beb8f83f349d716ee078 Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Thu, 27 Jun 2024 05:20:08 +0530 Subject: [PATCH 1/9] restController init --- .../BatchTestReassignmentRestController.java | 311 ++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java diff --git a/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java new file mode 100644 index 000000000..b50c77e96 --- /dev/null +++ b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java @@ -0,0 +1,311 @@ +package org.openelisglobal.test.controller.rest; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.openelisglobal.analysis.service.AnalysisService; +import org.openelisglobal.analysis.valueholder.Analysis; +import org.openelisglobal.common.controller.BaseController; +import org.openelisglobal.common.exception.LIMSRuntimeException; +import org.openelisglobal.common.log.LogEvent; +import org.openelisglobal.common.services.DisplayListService; +import org.openelisglobal.common.services.IStatusService; +import org.openelisglobal.common.services.StatusService; +import org.openelisglobal.internationalization.MessageUtil; +import org.openelisglobal.spring.util.SpringContext; +import org.openelisglobal.test.action.BatchTestStatusChangeBean; +import org.openelisglobal.test.form.BatchTestReassignmentForm; +import org.openelisglobal.test.service.TestService; +import org.openelisglobal.test.service.TestServiceImpl; +import org.openelisglobal.test.validator.BatchTestReassignmentFormValidator; +import org.openelisglobal.test.valueholder.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/rest") +public class BatchTestReassignmentRestController extends BaseController { + + private static final String[] ALLOWED_FIELDS = new String[] { "jsonWad" }; + + @Autowired + BatchTestReassignmentFormValidator formValidator; + + @Autowired + private AnalysisService analysisService; + + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.setAllowedFields(ALLOWED_FIELDS); + } + + @GetMapping(value = "/BatchTestReassignment") + public BatchTestReassignmentForm showBatchTestReassignment(HttpServletRequest request) + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + BatchTestReassignmentForm form = new BatchTestReassignmentForm(); + + form.setSampleList(DisplayListService.getInstance().getList(DisplayListService.ListType.SAMPLE_TYPE_ACTIVE)); + + addFlashMsgsToRequest(request); + // return findForward(FWD_SUCCESS, form); + return form; + } + + @PostMapping(value = "/BatchTestReassignment") + public BatchTestReassignmentForm showBatchTestReassignmentUpdate(HttpServletRequest request, + @RequestBody @Valid BatchTestReassignmentForm form, BindingResult result) + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + + formValidator.validate(form, result); + if (result.hasErrors()) { + saveErrors(result); + // return findForward(FWD_FAIL_INSERT, form); + return form; + } + String jsonString = form.getJsonWad(); + // LogEvent.logInfo(this.getClass().getSimpleName(), "method unkown", + // jsonString); + + List newAnalysis = new ArrayList<>(); + List cancelAnalysis = new ArrayList<>(); + List changeBeans = new ArrayList<>(); + StatusChangedMetaInfo changedMetaInfo = new StatusChangedMetaInfo(); + manageAnalysis(jsonString, cancelAnalysis, newAnalysis, changeBeans, changedMetaInfo); + + try { + analysisService.updateAnalysises(cancelAnalysis, newAnalysis, getSysUserId(request)); + + } catch (LIMSRuntimeException e) { + LogEvent.logError(e); + } + + if (changeBeans.isEmpty()) { + // redirectAttributes.addFlashAttribute(FWD_SUCCESS, true); + // return findForward(FWD_SUCCESS_INSERT, form); + return form; + } else { + form.setSampleList( + DisplayListService.getInstance().getList(DisplayListService.ListType.SAMPLE_TYPE_ACTIVE)); + form.setStatusChangedList(changeBeans); + form.setStatusChangedSampleType(changedMetaInfo.sampleTypeName); + form.setStatusChangedCurrentTest(changedMetaInfo.currentTest); + form.setStatusChangedNextTest(changedMetaInfo.nextTest); + // return findForward("resubmit", form); + return form; + } + } + + private void manageAnalysis(String jsonString, List cancelAnalysis, List newAnalysis, + List changeBeans, StatusChangedMetaInfo changedMetaInfo) { + JSONParser parser = new JSONParser(); + + try { + JSONObject obj = (JSONObject) parser.parse(jsonString); + List newTests = getNewTestsFromJson(obj, parser); + List changedNotStarted = getAnalysisFromJson((String) obj.get("changeNotStarted"), parser); + List noChangedNotStarted = getAnalysisFromJson((String) obj.get("noChangeNotStarted"), parser); + List changeTechReject = getAnalysisFromJson((String) obj.get("changeTechReject"), parser); + List noChangeTechReject = getAnalysisFromJson((String) obj.get("noChangeTechReject"), parser); + List changeBioReject = getAnalysisFromJson((String) obj.get("changeBioReject"), parser); + List noChangeBioReject = getAnalysisFromJson((String) obj.get("noChangeBioReject"), parser); + List changeNotValidated = getAnalysisFromJson((String) obj.get("changeNotValidated"), parser); + List noChangeNotValidated = getAnalysisFromJson((String) obj.get("noChangeNotValidated"), parser); + + verifyStatusNotChanged(changedNotStarted, noChangedNotStarted, StatusService.AnalysisStatus.NotStarted, + changeBeans); + verifyStatusNotChanged(changeNotValidated, noChangeNotValidated, + StatusService.AnalysisStatus.TechnicalAcceptance, changeBeans); + verifyStatusNotChanged(changeTechReject, noChangeTechReject, StatusService.AnalysisStatus.TechnicalRejected, + changeBeans); + verifyStatusNotChanged(changeBioReject, noChangeBioReject, StatusService.AnalysisStatus.BiologistRejected, + changeBeans); + + cancelAnalysis.addAll(changedNotStarted); + cancelAnalysis.addAll(changeBioReject); + cancelAnalysis.addAll(changeNotValidated); + cancelAnalysis.addAll(changeTechReject); + + if (!newTests.isEmpty()) { + newAnalysis.addAll(createNewAnalysis(newTests, changedNotStarted)); + newAnalysis.addAll(createNewAnalysis(newTests, changeBioReject)); + newAnalysis.addAll(createNewAnalysis(newTests, changeNotValidated)); + newAnalysis.addAll(createNewAnalysis(newTests, changeTechReject)); + } + + if (!changeBeans.isEmpty()) { + String newTestsString; + if (newTests.isEmpty()) { + newTestsString = MessageUtil.getMessage("status.test.canceled"); + } else { + newTestsString = MessageUtil.getMessage("label.test.batch.reassignment") + ": " + + TestServiceImpl.getUserLocalizedTestName(newTests.get(0)); + for (int i = 1; i < newTests.size(); i++) { + newTestsString += ", " + TestServiceImpl.getUserLocalizedTestName(newTests.get(i)); + } + } + changedMetaInfo.nextTest = newTestsString; + changedMetaInfo.currentTest = (String) obj.get("current"); + changedMetaInfo.sampleTypeName = (String) obj.get("sampleType"); + } + } catch (ParseException e) { + LogEvent.logDebug(e); + } + } + + private List createNewAnalysis(List newTests, List changeAnalysis) { + List newAnalysis = new ArrayList<>(); + for (Test test : newTests) { + for (Analysis analysis : changeAnalysis) { + newAnalysis.add(analysisService.buildAnalysis(test, analysis.getSampleItem())); + } + } + + return newAnalysis; + } + + private void verifyStatusNotChanged(List changed, List noChanged, + StatusService.AnalysisStatus status, List changeBeans) { + String statusId = SpringContext.getBean(IStatusService.class).getStatusID(status); + + List changedAnalysis = new ArrayList<>(); + + for (Analysis analysis : changed) { + if (!statusId.equals(analysis.getStatusId())) { + changedAnalysis.add(analysis); + } + } + + if (!changedAnalysis.isEmpty()) { + changed.removeAll(changedAnalysis); + } + + for (Analysis analysis : noChanged) { + if (!statusId.equals(analysis.getStatusId())) { + changedAnalysis.add(analysis); + } + } + + if (!changedAnalysis.isEmpty()) { + String oldStatus = getStatusName(status); + + for (Analysis analysis : changedAnalysis) { + BatchTestStatusChangeBean bean = new BatchTestStatusChangeBean(); + bean.setLabNo(analysis.getSampleItem().getSample().getAccessionNumber()); + bean.setOldStatus(oldStatus); + bean.setNewStatus(getStatusName(analysis.getStatusId())); + changeBeans.add(bean); + } + } + } + + private String getStatusName(String statusId) { + StatusService.AnalysisStatus status = SpringContext.getBean(IStatusService.class) + .getAnalysisStatusForID(statusId); + String name = getStatusName(status); + return name == null ? SpringContext.getBean(IStatusService.class).getStatusName(status) : name; + } + + private String getStatusName(StatusService.AnalysisStatus status) { + switch (status) { + case NotStarted: + return MessageUtil.getMessage("label.analysisNotStarted"); + case TechnicalRejected: + return MessageUtil.getMessage("label.rejectedByTechnician"); + case TechnicalAcceptance: + return MessageUtil.getMessage("label.notValidated"); + case BiologistRejected: + return MessageUtil.getMessage("label.rejectedByBiologist"); + default: + return null; + } + } + + private List getNewTestsFromJson(JSONObject obj, JSONParser parser) { + List replacementTestList = new ArrayList<>(); + + String replacementTests = (String) obj.get("replace"); + if (replacementTests == null) { + return replacementTestList; + } + + JSONArray replacementTestArray; + try { + replacementTestArray = (JSONArray) parser.parse(replacementTests); + } catch (ParseException e) { + LogEvent.logDebug(e); + return replacementTestList; + } + + for (Object testIdObject : replacementTestArray) { + replacementTestList.add(SpringContext.getBean(TestService.class).get((String) testIdObject)); + } + + return replacementTestList; + } + + private List getAnalysisFromJson(String sampleIdList, JSONParser parser) { + List analysisList = new ArrayList<>(); + + if (sampleIdList == null) { + return analysisList; + } + + JSONArray modifyAnalysisArray; + try { + modifyAnalysisArray = (JSONArray) parser.parse(sampleIdList); + } catch (ParseException e) { + LogEvent.logDebug(e); + return analysisList; + } + + for (Object analysisId : modifyAnalysisArray) { + analysisList.add(analysisService.get((String) analysisId)); + } + + return analysisList; + } + + @Override + protected String findLocalForward(String forward) { + if (FWD_SUCCESS.equals(forward)) { + return "BatchTestReassignmentDefinition"; + } else if (FWD_SUCCESS_INSERT.equals(forward)) { + return "redirect:/BatchTestReassignment"; + } else if (FWD_FAIL_INSERT.equals(forward)) { + return "BatchTestReassignmentDefinition"; + } else if ("resubmit".equals(forward)) { + return "BatchTestReassignmentDefinition"; + } else { + return "PageNotFound"; + } + } + + @Override + protected String getPageTitleKey() { + return "configuration.batch.test.reassignment"; + } + + @Override + protected String getPageSubtitleKey() { + return "configuration.batch.test.reassignment"; + } + + private class StatusChangedMetaInfo { + public String currentTest; + public String nextTest; + public String sampleTypeName; + } +} From aeef3242f7fcf98db2e1dbe56e2757742ff7d123 Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Mon, 8 Jul 2024 00:58:31 +0530 Subject: [PATCH 2/9] basePage BatchTestRC init --- frontend/src/components/admin/Admin.js | 8 + .../BatchTestReassignmentAndCancelation.js | 379 ++++++++++++++++++ frontend/src/languages/en.json | 13 +- frontend/src/languages/fr.json | 13 +- 4 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js diff --git a/frontend/src/components/admin/Admin.js b/frontend/src/components/admin/Admin.js index b9cdf9e35..179efad4f 100644 --- a/frontend/src/components/admin/Admin.js +++ b/frontend/src/components/admin/Admin.js @@ -28,6 +28,7 @@ import { Report, Bullhorn, User, + BatchJob, } from "@carbon/icons-react"; import PathRoute from "../utils/PathRoute"; import CalculatedValue from "./calculatedValue/CalculatedValueForm"; @@ -52,6 +53,7 @@ import OrganizationAddModify from "./OrganizationManagement/OrganizationAddModif import UserManagement from "./userManagement/UserManagement"; import UserAddModify from "./userManagement/UserAddModify"; import ManageMethod from "./testManagement/ManageMethod.js"; +import BatchTestReassignmentAndCancelation from "./BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js"; function Admin() { const intl = useIntl(); @@ -123,6 +125,9 @@ function Admin() { + + + + + + diff --git a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js new file mode 100644 index 000000000..ccd7e95de --- /dev/null +++ b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js @@ -0,0 +1,379 @@ +import React, { useContext, useState, useEffect, useRef } from "react"; +import { + Grid, + Column, + Section, + Heading, + Form, + TextInput, + UnorderedList, + ListItem, + RadioButton, + Button, + Loading, + Select, + SelectItem, + PasswordInput, + Checkbox, + FormGroup, +} from "@carbon/react"; +import { FormattedMessage, injectIntl, useIntl } from "react-intl"; +import PageBreadCrumb from "../../common/PageBreadCrumb.js"; +import { + AlertDialog, + NotificationKinds, +} from "../../common/CustomNotification.js"; +import { + ConfigurationContext, + NotificationContext, +} from "../../layout/Layout.js"; +import { + getFromOpenElisServer, + postToOpenElisServer, + postToOpenElisServerJsonResponse, +} from "../../utils/Utils.js"; +import AutoComplete from "../../common/AutoComplete.js"; + +const breadcrumbs = [ + { label: "home.label", link: "/" }, + { label: "breadcrums.admin.managment", link: "/MasterListsPage" }, + { + label: "unifiedSystemUser.browser.title", + link: "/MasterListsPage#userManagement", + }, +]; + +function BatchTestReassignmentAndCancelation() { + const { notificationVisible, setNotificationVisible, addNotification } = + useContext(NotificationContext); + const { configurationProperties } = useContext(ConfigurationContext); + + const componentMounted = useRef(false); + const intl = useIntl(); + + const [saveButton, setSaveButton] = useState(true); + const [isLoading, setIsLoading] = useState(true); + const [sampleTypeList, setSampleTypeList] = useState(null); + const [sampleTypeListShow, setSampleTypeListShow] = useState([]); + const [sampleTypeListPost, setSampleTypeListPost] = useState(null); + + useEffect(() => { + componentMounted.current = true; + setIsLoading(true); + getFromOpenElisServer( + `/rest/BatchTestReassignment`, + handleBatchTestReassignment, + ); + return () => { + componentMounted.current = false; + setIsLoading(false); + }; + }, []); + + const handleBatchTestReassignment = (res) => { + if (!res) { + setIsLoading(true); + } else { + setSampleTypeList(res); + } + }; + + useEffect(() => { + if (sampleTypeList) { + const BatchTestReassignmentInfoToPost = { + formName: sampleTypeList.formName, + formMethod: sampleTypeList.formMethod, + cancelAction: sampleTypeList.cancelAction, + submitOnCancel: sampleTypeList.submitOnCancel, + cancelMethod: sampleTypeList.cancelMethod, + sampleList: sampleTypeList.sampleList, + statusChangedSampleType: sampleTypeList.statusChangedSampleType, + statusChangedCurrentTest: sampleTypeList.statusChangedCurrentTest, + statusChangedNextTest: sampleTypeList.statusChangedNextTest, + jsonWad: sampleTypeList.jsonWad, + }; + setSampleTypeListShow(sampleTypeList.sampleList); + setSampleTypeListPost(BatchTestReassignmentInfoToPost); + } + }, [sampleTypeList]); + + function batchTestReassignmentPostCall() { + setIsLoading(true); + postToOpenElisServerJsonResponse( + `/rest/BatchTestReassignment`, + JSON.stringify(sampleTypeListPost), + (res) => { + sampleTypeListPostCallback(res); + }, + ); + } + + function sampleTypeListPostCallback(res) { + if (res) { + setIsLoading(false); + addNotification({ + title: intl.formatMessage({ + id: "notification.title", + }), + message: intl.formatMessage({ + id: "notification.user.post.save.success", + }), + kind: NotificationKinds.success, + }); + setNotificationVisible(true); + setTimeout(() => { + window.location.reload(); + }, 200); + } else { + addNotification({ + kind: NotificationKinds.error, + title: intl.formatMessage({ id: "notification.title" }), + message: intl.formatMessage({ id: "server.error.msg" }), + }); + setNotificationVisible(true); + setTimeout(() => { + window.location.reload(); + }, 200); + } + } + + function handleStatusChange(e) { + setSaveButton(false); + setSampleTypeListPost((prevUserDataPost) => ({ + ...prevUserDataPost, + statusChangedSampleType: e.target.value, + statusChangedCurrentTest: e.target.value, + statusChangedNextTest: e.target.value, + jsonWad: e.target.value, + })); + } + + if (!isLoading) { + return ( + <> + + + ); + } + + return ( + <> + {notificationVisible === true ? : ""} +
+ + + +
+
+ + + +
+
+
+
+
+ + +
+
+
+ + + +
+
+
+
+
+
+
+ + + + + +
+ + + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+ +
+ + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+ +
+
+
+ + + + + +
+ + + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+
+ + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+
+ + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+
+ + +
+ { + // handleCheckboxChange(section.roleId); + // }} + /> +
+
+
+
+
+
+ + + {" "} + + + +
+
+ + ); +} + +export default injectIntl(BatchTestReassignmentAndCancelation); + +// labNumbers rendering according to there type +// SelectAll function fix +// post call checkup +// AJAX call handeling diff --git a/frontend/src/languages/en.json b/frontend/src/languages/en.json index 440e3a6a4..d467e528a 100644 --- a/frontend/src/languages/en.json +++ b/frontend/src/languages/en.json @@ -1219,5 +1219,16 @@ "notification.invalid.loginName": "Please enter AlphaNumeric values without spaces only.", "notification.invalid.password": "Please enter password according to instructions.", "notification.invalid.confirm.password": "Your entered password is not same as above password.", - "notification.invalid.name": "Please enter Alphanumeric values only." + "notification.invalid.name": "Please enter Alphanumeric values only.", + "configuration.batch.test.reassignment": "Batch test reassignment and cancelation", + "label.button.ok": "Ok", + "label.currentTest": "Current test", + "label.replaceWith": "Replace with", + "label.includeInactiveTests": "Include inactive tests", + "label.cancel.test.no.replace": "Cancel test for lab numbers selected, do not assign a new test", + "label.checkedWillBeModified": "Checked lab no. will be modified", + "label.analysisNotStarted": "Analysis not started", + "label.rejectedByBiologist": "Rejected by biologist", + "label.rejectedByTechnician": "Rejected by technician", + "label.notValidated": "Not validated" } diff --git a/frontend/src/languages/fr.json b/frontend/src/languages/fr.json index 617567048..59097b872 100644 --- a/frontend/src/languages/fr.json +++ b/frontend/src/languages/fr.json @@ -1123,5 +1123,16 @@ "notification.invalid.loginName": "Veuillez saisir des valeurs alphanumériques sans espaces uniquement.", "notification.invalid.password": "Veuillez entrer le mot de passe selon les instructions.", "notification.invalid.confirm.password": "Votre mot de passe saisi n'est pas identique au mot de passe ci-dessus.", - "notification.invalid.name": "Veuillez saisir des valeurs alphanumériques uniquement." + "notification.invalid.name": "Veuillez saisir des valeurs alphanumériques uniquement.", + "configuration.batch.test.reassignment": "Réaffectation et annulation des tests par lot", + "label.button.ok": "D'accord", + "label.currentTest": "Test actuel", + "label.replaceWith": "Remplacer par", + "label.includeInactiveTests": "Inclure les tests inactifs", + "label.cancel.test.no.replace": "Annuler le test pour les numéros de laboratoire sélectionnés, ne pas assigner un nouveau test", + "label.checkedWillBeModified": "Les numéros de laboratoire cochés seront modifiés", + "label.analysisNotStarted": "Analyse non commencée", + "label.rejectedByBiologist": "Rejeté par le biologiste", + "label.rejectedByTechnician": "Rejeté par le technicien", + "label.notValidated": "Non validé" } From b37449f1a554d0f304763f8c070107fcda33e3ca Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Fri, 12 Jul 2024 02:11:24 +0530 Subject: [PATCH 3/9] batchTestReassignment controller init + labNo rendering fixed --- .../BatchTestReassignmentAndCancelation.js | 259 ++++++++++++++++-- ...tsForSampleTypeProviderRestController.java | 74 +++++ ...AnalysisForTestProviderRestController.java | 106 +++++++ 3 files changed, 410 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java create mode 100644 src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java diff --git a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js index ccd7e95de..9c8b08ab5 100644 --- a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js +++ b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js @@ -38,8 +38,8 @@ const breadcrumbs = [ { label: "home.label", link: "/" }, { label: "breadcrums.admin.managment", link: "/MasterListsPage" }, { - label: "unifiedSystemUser.browser.title", - link: "/MasterListsPage#userManagement", + label: "configuration.batch.test.reassignment", + link: "/MasterListsPage#batchTestReassignment", }, ]; @@ -56,6 +56,14 @@ function BatchTestReassignmentAndCancelation() { const [sampleTypeList, setSampleTypeList] = useState(null); const [sampleTypeListShow, setSampleTypeListShow] = useState([]); const [sampleTypeListPost, setSampleTypeListPost] = useState(null); + const [sampleTypeToGetId, setSampleTypeToGetId] = useState(null); + const [sampleTypeToGetIdData, setSampleTypeToGetIdData] = useState([]); + const [sampleTypeTestIdToGetIdPending, setSampleTestTypeToGetPending] = + useState(null); + const [ + sampleTypeTestIdToGetIdPendingData, + setSampleTestTypeToGetPendingData, + ] = useState({}); useEffect(() => { componentMounted.current = true; @@ -78,6 +86,36 @@ function BatchTestReassignmentAndCancelation() { } }; + useEffect(() => { + const handleBatchTestReassignmentSampleTypeHandle = (res) => { + if (!res) { + setIsLoading(true); + } else { + setSampleTypeToGetIdData(res); + } + }; + + getFromOpenElisServer( + `/rest/AllTestsForSampleTypeProvider?sampleTypeId=${sampleTypeToGetId}`, + handleBatchTestReassignmentSampleTypeHandle, + ); + }, [sampleTypeToGetId]); + + useEffect(() => { + const handleBatchTestReassignmentSampleTypeTestHandle = (res) => { + if (!res) { + setIsLoading(true); + } else { + setSampleTestTypeToGetPendingData(res); + } + }; + + getFromOpenElisServer( + `/rest/getPendingAnalysisForTestProvider?testId=${sampleTypeTestIdToGetIdPending}`, + handleBatchTestReassignmentSampleTypeTestHandle, + ); + }, [sampleTypeTestIdToGetIdPending]); + useEffect(() => { if (sampleTypeList) { const BatchTestReassignmentInfoToPost = { @@ -92,7 +130,11 @@ function BatchTestReassignmentAndCancelation() { statusChangedNextTest: sampleTypeList.statusChangedNextTest, jsonWad: sampleTypeList.jsonWad, }; - setSampleTypeListShow(sampleTypeList.sampleList); + setSampleTypeListShow((prevSampleTypeListShow) => [ + ...prevSampleTypeListShow, + { id: "0", value: "Select SampleType" }, + ...sampleTypeList.sampleList, + ]); setSampleTypeListPost(BatchTestReassignmentInfoToPost); } }, [sampleTypeList]); @@ -148,6 +190,21 @@ function BatchTestReassignmentAndCancelation() { })); } + function handleCheckboxChange(id) { + setSaveButton(false); + setSampleTypeListPost(); + } + + function handleSampleTypeListSelectId(e) { + setSaveButton(false); + setSampleTypeToGetId(e.target.value); + } + + function handleSampleTypeListSelectIdTest(e) { + setSaveButton(false); + setSampleTestTypeToGetPending(e.target.value); + } + if (!isLoading) { return ( <> @@ -193,15 +250,19 @@ function BatchTestReassignmentAndCancelation() { @@ -224,17 +285,30 @@ function BatchTestReassignmentAndCancelation() { />
@@ -254,17 +328,32 @@ function BatchTestReassignmentAndCancelation() { />
@@ -291,13 +380,32 @@ function BatchTestReassignmentAndCancelation() { // handleCheckboxChange(section.roleId); // }} /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.notStarted && + sampleTypeTestIdToGetIdPendingData.notStarted.map( + (item, index) => ( +
+ { + handleCheckboxChange(item.id); + }} + /> +
+ ), + )}
- +
+ {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.technicianRejection && + sampleTypeTestIdToGetIdPendingData.technicianRejection.map( + (item, index) => ( +
+ { + handleCheckboxChange(item.id); + }} + /> +
+ ), + )}
- +
+ {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.biologistRejection && + sampleTypeTestIdToGetIdPendingData.biologistRejection.map( + (item, index) => ( +
+ { + handleCheckboxChange(item.id); + }} + /> +
+ ), + )}
@@ -339,6 +485,25 @@ function BatchTestReassignmentAndCancelation() { // handleCheckboxChange(section.roleId); // }} /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.notValidated && + sampleTypeTestIdToGetIdPendingData.notValidated.map( + (item, index) => ( +
+ { + handleCheckboxChange(item.id); + }} + /> +
+ ), + )}
@@ -366,6 +531,41 @@ function BatchTestReassignmentAndCancelation() { + + + + + ); @@ -373,7 +573,8 @@ function BatchTestReassignmentAndCancelation() { export default injectIntl(BatchTestReassignmentAndCancelation); -// labNumbers rendering according to there type +// selectAll CheckBox fix needed +// single labNo selection fix needed // SelectAll function fix // post call checkup -// AJAX call handeling +// defaultValues CONSOLE.error fix values fix diff --git a/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java new file mode 100644 index 000000000..72050cb2e --- /dev/null +++ b/src/main/java/org/openelisglobal/common/rest/provider/AllTestsForSampleTypeProviderRestController.java @@ -0,0 +1,74 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations under + * the License. + * + * The Original Code is OpenELIS code. + * + * Copyright (C) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ + +package org.openelisglobal.common.rest.provider; + +import java.util.List; +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.spring.util.SpringContext; +import org.openelisglobal.test.valueholder.Test; +import org.openelisglobal.typeofsample.service.TypeOfSampleService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/rest") +public class AllTestsForSampleTypeProviderRestController extends BaseRestController { + + private TypeOfSampleService typeOfSampleService = SpringContext.getBean(TypeOfSampleService.class); + + @GetMapping("/AllTestsForSampleTypeProvider") + public ResponseEntity processRequest(@RequestParam String sampleTypeId) { + if (sampleTypeId == null || sampleTypeId.isEmpty()) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body("Internal error, please contact Admin and file bug report"); + } + + try { + JSONObject jsonResult = createJsonGroupedTestNames(sampleTypeId); + return ResponseEntity.ok(jsonResult); + } catch (Exception e) { + LogEvent.logDebug(e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Internal error, please contact Admin and file bug report"); + } + } + + @SuppressWarnings("unchecked") + private JSONObject createJsonGroupedTestNames(String sampleTypeId) throws IllegalStateException { + List tests = typeOfSampleService.getAllTestsBySampleTypeId(sampleTypeId); + + JSONArray testArray = new JSONArray(); + + for (Test test : tests) { + JSONObject testObject = new JSONObject(); + testObject.put("name", test.getLocalizedTestName().getLocalizedValue()); + testObject.put("id", test.getId()); + testObject.put("isActive", test.getIsActive()); + testArray.add(testObject); + } + JSONObject jsonResult = new JSONObject(); + jsonResult.put("tests", testArray); + return jsonResult; + } +} diff --git a/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java new file mode 100644 index 000000000..3e795ec95 --- /dev/null +++ b/src/main/java/org/openelisglobal/common/rest/provider/PendingAnalysisForTestProviderRestController.java @@ -0,0 +1,106 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations under + * the License. + * + * The Original Code is OpenELIS code. + * + * Copyright (C) ITECH, University of Washington, Seattle WA. All Rights Reserved. + */ +package org.openelisglobal.common.rest.provider; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.validator.GenericValidator; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +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.spring.util.SpringContext; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/rest") +public class PendingAnalysisForTestProviderRestController extends BaseRestController { + + private static final List NOT_STARTED; + private static final List TECH_REJECT; + private static final List BIO_REJECT; + private static final List NOT_VALIDATED; + + protected AjaxServlet ajaxServlet = null; + private AnalysisService analysisService = SpringContext.getBean(AnalysisService.class); + + static { + IStatusService statusService = SpringContext.getBean(IStatusService.class); + NOT_STARTED = new ArrayList<>(); + NOT_STARTED.add(Integer.parseInt(statusService.getStatusID(StatusService.AnalysisStatus.NotStarted))); + + TECH_REJECT = new ArrayList<>(); + TECH_REJECT.add(Integer.parseInt(statusService.getStatusID(StatusService.AnalysisStatus.TechnicalRejected))); + + BIO_REJECT = new ArrayList<>(); + BIO_REJECT.add(Integer.parseInt(statusService.getStatusID(StatusService.AnalysisStatus.BiologistRejected))); + + NOT_VALIDATED = new ArrayList<>(); + NOT_VALIDATED + .add(Integer.parseInt(statusService.getStatusID(StatusService.AnalysisStatus.TechnicalAcceptance))); + } + + @GetMapping("/getPendingAnalysisForTestProvider") + public ResponseEntity processRequest(@RequestParam String testId) { + if (GenericValidator.isBlankOrNull(testId)) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body("Internal error, please contact Admin and file bug report"); + } + + try { + JSONObject jsonResult = createJsonGroupedAnalysis(testId); + return ResponseEntity.ok(jsonResult); + } catch (Exception e) { + LogEvent.logDebug(e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Internal error, please contact Admin and file bug report"); + } + } + + private JSONObject createJsonGroupedAnalysis(String testId) throws IllegalStateException { + JSONObject jsonResult = new JSONObject(); + createPendingList(testId, jsonResult, "notStarted", NOT_STARTED); + createPendingList(testId, jsonResult, "technicianRejection", TECH_REJECT); + createPendingList(testId, jsonResult, "biologistRejection", BIO_REJECT); + createPendingList(testId, jsonResult, "notValidated", NOT_VALIDATED); + return jsonResult; + } + + @SuppressWarnings("unchecked") + private void createPendingList(String testId, JSONObject jsonResult, String tag, List statusList) { + List notStartedAnalysis = analysisService.getAllAnalysisByTestAndStatus(testId, statusList); + + JSONArray analysisArray = new JSONArray(); + + for (Analysis analysis : notStartedAnalysis) { + JSONObject analysisObject = new JSONObject(); + analysisObject.put("labNo", analysis.getSampleItem().getSample().getAccessionNumber()); + analysisObject.put("id", analysis.getId()); + analysisArray.add(analysisObject); + } + jsonResult.put(tag, analysisArray); + } +} From 5eb06239cb21234e2cc9abc6196728712440cbd7 Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Sun, 14 Jul 2024 02:36:10 +0530 Subject: [PATCH 4/9] selection edge case + tag fixed --- .../BatchTestReassignmentAndCancelation.js | 165 ++++++++++++------ 1 file changed, 116 insertions(+), 49 deletions(-) diff --git a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js index 9c8b08ab5..1c2340b95 100644 --- a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js +++ b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js @@ -16,6 +16,7 @@ import { PasswordInput, Checkbox, FormGroup, + Tag, } from "@carbon/react"; import { FormattedMessage, injectIntl, useIntl } from "react-intl"; import PageBreadCrumb from "../../common/PageBreadCrumb.js"; @@ -53,9 +54,11 @@ function BatchTestReassignmentAndCancelation() { const [saveButton, setSaveButton] = useState(true); const [isLoading, setIsLoading] = useState(true); - const [sampleTypeList, setSampleTypeList] = useState(null); + const [currentTest, setCurrentTest] = useState(true); + const [replaceWith, setReplaceWith] = useState(false); + const [batchTestGet, setBatchTestGet] = useState(null); + const [batchTestPost, setBatchTestPost] = useState(null); const [sampleTypeListShow, setSampleTypeListShow] = useState([]); - const [sampleTypeListPost, setSampleTypeListPost] = useState(null); const [sampleTypeToGetId, setSampleTypeToGetId] = useState(null); const [sampleTypeToGetIdData, setSampleTypeToGetIdData] = useState([]); const [sampleTypeTestIdToGetIdPending, setSampleTestTypeToGetPending] = @@ -64,6 +67,10 @@ function BatchTestReassignmentAndCancelation() { sampleTypeTestIdToGetIdPendingData, setSampleTestTypeToGetPendingData, ] = useState({}); + const [sampleTestTypeToGetTagList, setSampleTestTypeToGetTagList] = useState( + [], + ); + const [jsonWad, setJsonWad] = useState({}); useEffect(() => { componentMounted.current = true; @@ -82,7 +89,7 @@ function BatchTestReassignmentAndCancelation() { if (!res) { setIsLoading(true); } else { - setSampleTypeList(res); + setBatchTestGet(res); } }; @@ -117,33 +124,33 @@ function BatchTestReassignmentAndCancelation() { }, [sampleTypeTestIdToGetIdPending]); useEffect(() => { - if (sampleTypeList) { + if (batchTestGet) { const BatchTestReassignmentInfoToPost = { - formName: sampleTypeList.formName, - formMethod: sampleTypeList.formMethod, - cancelAction: sampleTypeList.cancelAction, - submitOnCancel: sampleTypeList.submitOnCancel, - cancelMethod: sampleTypeList.cancelMethod, - sampleList: sampleTypeList.sampleList, - statusChangedSampleType: sampleTypeList.statusChangedSampleType, - statusChangedCurrentTest: sampleTypeList.statusChangedCurrentTest, - statusChangedNextTest: sampleTypeList.statusChangedNextTest, - jsonWad: sampleTypeList.jsonWad, + formName: batchTestGet.formName, + formMethod: batchTestGet.formMethod, + cancelAction: batchTestGet.cancelAction, + submitOnCancel: batchTestGet.submitOnCancel, + cancelMethod: batchTestGet.cancelMethod, + sampleList: batchTestGet.sampleList, + statusChangedSampleType: batchTestGet.statusChangedSampleType, + statusChangedCurrentTest: batchTestGet.statusChangedCurrentTest, + statusChangedNextTest: batchTestGet.statusChangedNextTest, + jsonWad: batchTestGet.jsonWad, }; + setBatchTestPost(BatchTestReassignmentInfoToPost); setSampleTypeListShow((prevSampleTypeListShow) => [ ...prevSampleTypeListShow, { id: "0", value: "Select SampleType" }, - ...sampleTypeList.sampleList, + ...batchTestGet.sampleList, ]); - setSampleTypeListPost(BatchTestReassignmentInfoToPost); } - }, [sampleTypeList]); + }, [batchTestGet]); function batchTestReassignmentPostCall() { setIsLoading(true); postToOpenElisServerJsonResponse( `/rest/BatchTestReassignment`, - JSON.stringify(sampleTypeListPost), + JSON.stringify(batchTestPost), (res) => { sampleTypeListPostCallback(res); }, @@ -179,30 +186,57 @@ function BatchTestReassignmentAndCancelation() { } } - function handleStatusChange(e) { + function handleCheckboxChange(id, index) { setSaveButton(false); - setSampleTypeListPost((prevUserDataPost) => ({ - ...prevUserDataPost, - statusChangedSampleType: e.target.value, - statusChangedCurrentTest: e.target.value, - statusChangedNextTest: e.target.value, - jsonWad: e.target.value, - })); - } - - function handleCheckboxChange(id) { - setSaveButton(false); - setSampleTypeListPost(); + setJsonWad({}); } function handleSampleTypeListSelectId(e) { setSaveButton(false); setSampleTypeToGetId(e.target.value); + setBatchTestPost((prevUserDataPost) => ({ + ...prevUserDataPost, + statusChangedSampleType: e.target.value, + })); } function handleSampleTypeListSelectIdTest(e) { setSaveButton(false); setSampleTestTypeToGetPending(e.target.value); + setBatchTestPost((prevUserDataPost) => ({ + ...prevUserDataPost, + statusChangedCurrentTest: e.target.value, + })); + } + + const handleSampleTypeListSelectIdTestTag = (e) => { + const selectedTestId = e.target.value; + const testName = e.target.options[e.target.selectedIndex].text; + + const existingIndex = sampleTestTypeToGetTagList.findIndex( + (item) => item.id === selectedTestId, + ); + + if (existingIndex !== -1) { + const updatedList = [...sampleTestTypeToGetTagList]; + updatedList.splice(existingIndex, 1); + setSampleTestTypeToGetTagList(updatedList); + } else { + const selectedTest = { + id: selectedTestId, + name: testName, + }; + setSampleTestTypeToGetTagList([ + ...sampleTestTypeToGetTagList, + selectedTest, + ]); + } + }; + + function handleRemoveSampleTypeListSelectIdTestTag(indexToRemove) { + setSampleTestTypeToGetTagList((prevTags) => + prevTags.filter((_, index) => index !== indexToRemove), + ); } if (!isLoading) { @@ -278,10 +312,10 @@ function BatchTestReassignmentAndCancelation() { labelText={intl.formatMessage({ id: "label.includeInactiveTests", })} - checked={true} - // onChange={() => { - // handleCheckboxChange(section.roleId); - // }} + checked={currentTest} + onChange={() => { + setCurrentTest(!currentTest); + }} />
handleSampleTypeListSelectIdTest(e)} + disabled={replaceWith} + onChange={(e) => handleSampleTypeListSelectIdTestTag(e)} > {sampleTypeToGetIdData && sampleTypeToGetIdData.tests && @@ -356,6 +391,31 @@ function BatchTestReassignmentAndCancelation() { /> )} +
+ {sampleTestTypeToGetTagList && + sampleTestTypeToGetTagList.length ? ( + <> + {sampleTestTypeToGetTagList.map((section, index) => ( + + handleRemoveSampleTypeListSelectIdTestTag(index) + } + style={{ marginRight: "0.5rem" }} + type={"red"} + > + {section.name} + + ))} + + ) : ( + <> + )} +

@@ -393,7 +453,7 @@ function BatchTestReassignmentAndCancelation() { })} checked={false} onChange={() => { - handleCheckboxChange(item.id); + handleCheckboxChange(item.id, index); }} /> @@ -428,7 +488,7 @@ function BatchTestReassignmentAndCancelation() { })} checked={false} onChange={() => { - handleCheckboxChange(item.id); + handleCheckboxChange(item.id, index); }} /> @@ -463,7 +523,7 @@ function BatchTestReassignmentAndCancelation() { })} checked={false} onChange={() => { - handleCheckboxChange(item.id); + handleCheckboxChange(item.id, index); }} /> @@ -498,7 +558,7 @@ function BatchTestReassignmentAndCancelation() { })} checked={false} onChange={() => { - handleCheckboxChange(item.id); + handleCheckboxChange(item.id, index); }} /> @@ -533,17 +593,17 @@ function BatchTestReassignmentAndCancelation() { + ); @@ -577,4 +644,4 @@ export default injectIntl(BatchTestReassignmentAndCancelation); // single labNo selection fix needed // SelectAll function fix // post call checkup -// defaultValues CONSOLE.error fix values fix +// multi-select need to implement From e19f93ac2f7fb76dc5c742042e879e9103768352 Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Mon, 15 Jul 2024 05:32:14 +0530 Subject: [PATCH 5/9] checkboxs edge case & its function fix --- .../BatchTestReassignmentAndCancelation.js | 289 +++++++++++++----- 1 file changed, 215 insertions(+), 74 deletions(-) diff --git a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js index 1c2340b95..82d45805a 100644 --- a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js +++ b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js @@ -61,16 +61,30 @@ function BatchTestReassignmentAndCancelation() { const [sampleTypeListShow, setSampleTypeListShow] = useState([]); const [sampleTypeToGetId, setSampleTypeToGetId] = useState(null); const [sampleTypeToGetIdData, setSampleTypeToGetIdData] = useState([]); + const [sampleTypeToGetIdDataTag, setSampleTypeToGetIdDataTag] = useState([]); const [sampleTypeTestIdToGetIdPending, setSampleTestTypeToGetPending] = useState(null); const [ sampleTypeTestIdToGetIdPendingData, - setSampleTestTypeToGetPendingData, + setSampleTypeTestIdToGetIdPendingData, ] = useState({}); const [sampleTestTypeToGetTagList, setSampleTestTypeToGetTagList] = useState( [], ); - const [jsonWad, setJsonWad] = useState({}); + const [jsonWad, setJsonWad] = useState({ + // current: "HIV+rapid+test+HIV", + // sampleType: "Plasma", + current: "", + sampleType: "", + changeNotStarted: [], + noChangeNotStarted: [], + changeTechReject: [], + noChangeTechReject: [], + changeBioReject: [], + noChangeBioReject: [], + changeNotValidated: [], + noChangeNotValidated: [], + }); useEffect(() => { componentMounted.current = true; @@ -99,6 +113,15 @@ function BatchTestReassignmentAndCancelation() { setIsLoading(true); } else { setSampleTypeToGetIdData(res); + const extraObject = { + name: "Select Multi Tests", + id: "", + isActive: "", + }; + setSampleTypeToGetIdDataTag((sampleTypeToGetIdDataTag) => ({ + ...sampleTypeToGetIdDataTag, + tests: [extraObject, ...(res.tests || [])], + })); } }; @@ -113,7 +136,7 @@ function BatchTestReassignmentAndCancelation() { if (!res) { setIsLoading(true); } else { - setSampleTestTypeToGetPendingData(res); + setSampleTypeTestIdToGetIdPendingData(res); } }; @@ -123,6 +146,51 @@ function BatchTestReassignmentAndCancelation() { ); }, [sampleTypeTestIdToGetIdPending]); + useEffect(() => { + if (sampleTypeTestIdToGetIdPendingData) { + const { + notStarted, + technicianRejection, + biologistRejection, + notValidated, + } = sampleTypeTestIdToGetIdPendingData; + + setJsonWad((prevJsonWad) => ({ + ...prevJsonWad, + changeNotStarted: notStarted ? notStarted.map((item) => item.id) : [], + noChangeNotStarted: notStarted + ? sampleTypeTestIdToGetIdPendingData.notStarted + .filter((item) => !item.checked) + .map((item) => item.id) + : [], + changeTechReject: technicianRejection + ? technicianRejection.map((item) => item.id) + : [], + noChangeTechReject: technicianRejection + ? sampleTypeTestIdToGetIdPendingData.technicianRejection + .filter((item) => !item.checked) + .map((item) => item.id) + : [], + changeBioReject: biologistRejection + ? biologistRejection.map((item) => item.id) + : [], + noChangeBioReject: biologistRejection + ? sampleTypeTestIdToGetIdPendingData.biologistRejection + .filter((item) => !item.checked) + .map((item) => item.id) + : [], + changeNotValidated: notValidated + ? notValidated.map((item) => item.id) + : [], + noChangeNotValidated: notValidated + ? sampleTypeTestIdToGetIdPendingData.notValidated + .filter((item) => !item.checked) + .map((item) => item.id) + : [], + })); + } + }, [sampleTypeTestIdToGetIdPendingData]); + useEffect(() => { if (batchTestGet) { const BatchTestReassignmentInfoToPost = { @@ -185,11 +253,47 @@ function BatchTestReassignmentAndCancelation() { }, 200); } } + const capitalizeFirstLetter = (string) => { + return string.charAt(0).toUpperCase() + string.slice(1); + }; - function handleCheckboxChange(id, index) { + const handleSelectAll = (sectionKey) => { + let allIds = sampleTypeTestIdToGetIdPendingData[sectionKey].map( + (item) => item.id, + ); + if ( + jsonWad[`change${capitalizeFirstLetter(sectionKey)}`].length === + allIds.length + ) { + setJsonWad((prevJsonWad) => ({ + ...prevJsonWad, + [`change${capitalizeFirstLetter(sectionKey)}`]: [], + })); + } else { + setJsonWad((prevJsonWad) => ({ + ...prevJsonWad, + [`change${capitalizeFirstLetter(sectionKey)}`]: allIds, + })); + } setSaveButton(false); - setJsonWad({}); - } + }; + + const handleCheckboxChange = (id, sectionKey) => { + setJsonWad((prevJsonWad) => { + let updatedArray = + prevJsonWad[`change${capitalizeFirstLetter(sectionKey)}`].slice(); + const index = updatedArray.indexOf(id); + if (index === -1) { + updatedArray.push(id); + } else { + updatedArray.splice(index, 1); + } + return { + ...prevJsonWad, + [`change${capitalizeFirstLetter(sectionKey)}`]: updatedArray, + }; + }); + }; function handleSampleTypeListSelectId(e) { setSaveButton(false); @@ -308,7 +412,6 @@ function BatchTestReassignmentAndCancelation() {
handleSampleTypeListSelectIdTestTag(e)} > - {sampleTypeToGetIdData && - sampleTypeToGetIdData.tests && - sampleTypeToGetIdData.tests.length > 0 ? ( - sampleTypeToGetIdData.tests.map((section) => ( + {sampleTypeToGetIdDataTag && + sampleTypeToGetIdDataTag.tests && + sampleTypeToGetIdDataTag.tests.length > 0 ? ( + sampleTypeToGetIdDataTag.tests.map((section) => ( - -
- { - // handleCheckboxChange(section.roleId); - // }} - /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.notStarted ? ( + <> + +
+ jsonWad.changeNotStarted.includes(item.id), + )} + onChange={() => { + handleSelectAll("notStarted"); + }} + /> + + ) : ( + <> + )} {sampleTypeTestIdToGetIdPendingData && sampleTypeTestIdToGetIdPendingData.notStarted && sampleTypeTestIdToGetIdPendingData.notStarted.map( @@ -451,9 +561,9 @@ function BatchTestReassignmentAndCancelation() { labelText={intl.formatMessage({ id: item.labNo, })} - checked={false} + checked={jsonWad.changeNotStarted.includes(item.id)} onChange={() => { - handleCheckboxChange(item.id, index); + handleCheckboxChange(item.id, "notStarted"); }} /> @@ -462,19 +572,27 @@ function BatchTestReassignmentAndCancelation() {
- -
- { - // handleCheckboxChange(section.roleId); - // }} - /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.technicianRejection ? ( + <> + +
+ jsonWad.changeTechReject.includes(item.id), + )} + onChange={() => { + handleSelectAll("techReject"); + }} + /> + + ) : ( + <> + )} {sampleTypeTestIdToGetIdPendingData && sampleTypeTestIdToGetIdPendingData.technicianRejection && sampleTypeTestIdToGetIdPendingData.technicianRejection.map( @@ -486,9 +604,9 @@ function BatchTestReassignmentAndCancelation() { labelText={intl.formatMessage({ id: item.labNo, })} - checked={false} + checked={jsonWad.changeTechReject.includes(item.id)} onChange={() => { - handleCheckboxChange(item.id, index); + handleCheckboxChange(item.id, "techReject"); }} /> @@ -497,19 +615,27 @@ function BatchTestReassignmentAndCancelation() {
- -
- { - // handleCheckboxChange(section.roleId); - // }} - /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.biologistRejection ? ( + <> + +
+ jsonWad.changeBioReject.includes(item.id), + )} + onChange={() => { + handleSelectAll("bioReject"); + }} + /> + + ) : ( + <> + )} {sampleTypeTestIdToGetIdPendingData && sampleTypeTestIdToGetIdPendingData.biologistRejection && sampleTypeTestIdToGetIdPendingData.biologistRejection.map( @@ -521,9 +647,9 @@ function BatchTestReassignmentAndCancelation() { labelText={intl.formatMessage({ id: item.labNo, })} - checked={false} + checked={jsonWad.changeBioReject.includes(item.id)} onChange={() => { - handleCheckboxChange(item.id, index); + handleCheckboxChange(item.id, "bioReject"); }} /> @@ -532,19 +658,27 @@ function BatchTestReassignmentAndCancelation() {
- -
- { - // handleCheckboxChange(section.roleId); - // }} - /> + {sampleTypeTestIdToGetIdPendingData && + sampleTypeTestIdToGetIdPendingData.notValidated ? ( + <> + +
+ jsonWad.changeNotValidated.includes(item.id), + )} + onChange={() => { + handleSelectAll("notValidated"); + }} + /> + + ) : ( + <> + )} {sampleTypeTestIdToGetIdPendingData && sampleTypeTestIdToGetIdPendingData.notValidated && sampleTypeTestIdToGetIdPendingData.notValidated.map( @@ -556,9 +690,9 @@ function BatchTestReassignmentAndCancelation() { labelText={intl.formatMessage({ id: item.labNo, })} - checked={false} + checked={jsonWad.changeNotValidated.includes(item.id)} onChange={() => { - handleCheckboxChange(item.id, index); + handleCheckboxChange(item.id, "notValidated"); }} /> @@ -619,6 +753,13 @@ function BatchTestReassignmentAndCancelation() { > sampleTypeToGetIdData + {" "}
+ {changesToShow ? ( + <> +
+
+
+ + + :{" "} + {jsonWad.sampleType} +
+
+ {" "} + {jsonWad.current}{" "} + +
+
+
+
+ + + {jsonWad.changeNotStarted.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.notStarted.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.changeTechReject.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.technicianRejection.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.changeBioReject.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.biologistRejection.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.changeNotValidated.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.notValidated.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ +
+
+ {" "} + {jsonWad.current}{" "} + +
+
+
+ + + {jsonWad.noChangeNotStarted.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.notStarted.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.noChangeTechReject.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.technicianRejection.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.noChangeBioReject.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.biologistRejection.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ + + {jsonWad.noChangeNotValidated.map((id) => { + const item = + sampleTypeTestIdToGetIdPendingData.notValidated.find( + (data) => data.id === id, + ); + return ( + item && ( +
+
+ +
+
+ ) + ); + })} +
+ +
+
+
+ {" "} + +
+
+ + ) : ( + <> + )} + ); } export default injectIntl(BatchTestReassignmentAndCancelation); - -// post call checkup -// batchTestReassignmentPostCall final call pending diff --git a/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java index b50c77e96..77e0f2cc5 100644 --- a/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java +++ b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java @@ -71,7 +71,7 @@ public BatchTestReassignmentForm showBatchTestReassignmentUpdate(HttpServletRequ formValidator.validate(form, result); if (result.hasErrors()) { - saveErrors(result); + // saveErrors(result); // return findForward(FWD_FAIL_INSERT, form); return form; } From a30107056f9fa06b0c7a37c9e7ec9ef2c55aeeb7 Mon Sep 17 00:00:00 2001 From: "Aditya @ArchLinux" <132184385+adityadeshlahre@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:36:49 +0530 Subject: [PATCH 9/9] fix(batchTestReAssignemnt/Cancelation): POST(updates-on-backend) request working --- .../BatchTestReassignmentAndCancelation.js | 65 ++----------------- .../BatchTestReassignmentRestController.java | 47 +++++++------- 2 files changed, 27 insertions(+), 85 deletions(-) diff --git a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js index 78ec58294..1fd1783d9 100644 --- a/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js +++ b/frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js @@ -54,7 +54,7 @@ function BatchTestReassignmentAndCancelation() { const [saveButton, setSaveButton] = useState(true); const [isLoading, setIsLoading] = useState(true); const [currentTest, setCurrentTest] = useState(true); - const [replaceWith, setReplaceWith] = useState(false); + const [replaceWith, setReplaceWith] = useState(true); const [batchTestGet, setBatchTestGet] = useState(null); const [batchTestPost, setBatchTestPost] = useState(null); const [sampleTypeListShow, setSampleTypeListShow] = useState([]); @@ -81,7 +81,6 @@ function BatchTestReassignmentAndCancelation() { noChangeTechReject: [], noChangeBioReject: [], noChangeNotValidated: [], - replace: "", }); const [changesToShow, setChangesToShow] = useState(false); @@ -346,7 +345,7 @@ function BatchTestReassignmentAndCancelation() { setSampleTestTypeToGetTagList(updatedList); } - const updatedReplace = updatedList.map((item) => item.id).join(","); + const updatedReplace = updatedList.map((item) => item.id); setJsonWad((prevJsonWad) => ({ ...prevJsonWad, replace: updatedReplace, @@ -359,7 +358,7 @@ function BatchTestReassignmentAndCancelation() { (_, index) => index !== indexToRemove, ); - const updatedReplace = updatedTags.map((item) => item.id).join(","); + const updatedReplace = updatedTags.map((item) => item.id); setJsonWad((prevJsonWad) => ({ ...prevJsonWad, replace: updatedReplace, @@ -517,7 +516,7 @@ function BatchTestReassignmentAndCancelation() { if (replaceWith) { setJsonWad((prevJsonWad) => ({ ...prevJsonWad, - replace: "", + replace: [], })); } else { const selectedTestIds = sampleTestTypeToGetTagList @@ -1006,62 +1005,6 @@ function BatchTestReassignmentAndCancelation() { <> )} - - - - - - - - ); diff --git a/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java index 77e0f2cc5..a8944ce74 100644 --- a/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java +++ b/src/main/java/org/openelisglobal/test/controller/rest/BatchTestReassignmentRestController.java @@ -115,14 +115,14 @@ private void manageAnalysis(String jsonString, List cancelAnalysis, Li try { JSONObject obj = (JSONObject) parser.parse(jsonString); List newTests = getNewTestsFromJson(obj, parser); - List changedNotStarted = getAnalysisFromJson((String) obj.get("changeNotStarted"), parser); - List noChangedNotStarted = getAnalysisFromJson((String) obj.get("noChangeNotStarted"), parser); - List changeTechReject = getAnalysisFromJson((String) obj.get("changeTechReject"), parser); - List noChangeTechReject = getAnalysisFromJson((String) obj.get("noChangeTechReject"), parser); - List changeBioReject = getAnalysisFromJson((String) obj.get("changeBioReject"), parser); - List noChangeBioReject = getAnalysisFromJson((String) obj.get("noChangeBioReject"), parser); - List changeNotValidated = getAnalysisFromJson((String) obj.get("changeNotValidated"), parser); - List noChangeNotValidated = getAnalysisFromJson((String) obj.get("noChangeNotValidated"), parser); + List changedNotStarted = getAnalysisFromJson(obj.get("changeNotStarted"), parser); + List noChangedNotStarted = getAnalysisFromJson(obj.get("noChangeNotStarted"), parser); + List changeTechReject = getAnalysisFromJson(obj.get("changeTechReject"), parser); + List noChangeTechReject = getAnalysisFromJson(obj.get("noChangeTechReject"), parser); + List changeBioReject = getAnalysisFromJson(obj.get("changeBioReject"), parser); + List noChangeBioReject = getAnalysisFromJson(obj.get("noChangeBioReject"), parser); + List changeNotValidated = getAnalysisFromJson(obj.get("changeNotValidated"), parser); + List noChangeNotValidated = getAnalysisFromJson(obj.get("noChangeNotValidated"), parser); verifyStatusNotChanged(changedNotStarted, noChangedNotStarted, StatusService.AnalysisStatus.NotStarted, changeBeans); @@ -236,27 +236,20 @@ private String getStatusName(StatusService.AnalysisStatus status) { private List getNewTestsFromJson(JSONObject obj, JSONParser parser) { List replacementTestList = new ArrayList<>(); - String replacementTests = (String) obj.get("replace"); - if (replacementTests == null) { - return replacementTestList; - } - - JSONArray replacementTestArray; - try { - replacementTestArray = (JSONArray) parser.parse(replacementTests); - } catch (ParseException e) { - LogEvent.logDebug(e); + JSONArray replacementTestArray = (JSONArray) obj.get("replace"); + if (replacementTestArray == null) { return replacementTestList; } for (Object testIdObject : replacementTestArray) { - replacementTestList.add(SpringContext.getBean(TestService.class).get((String) testIdObject)); + String testId = (String) testIdObject; + replacementTestList.add(SpringContext.getBean(TestService.class).get((String) testId)); } return replacementTestList; } - private List getAnalysisFromJson(String sampleIdList, JSONParser parser) { + private List getAnalysisFromJson(Object sampleIdList, JSONParser parser) { List analysisList = new ArrayList<>(); if (sampleIdList == null) { @@ -264,10 +257,16 @@ private List getAnalysisFromJson(String sampleIdList, JSONParser parse } JSONArray modifyAnalysisArray; - try { - modifyAnalysisArray = (JSONArray) parser.parse(sampleIdList); - } catch (ParseException e) { - LogEvent.logDebug(e); + if (sampleIdList instanceof String) { + try { + modifyAnalysisArray = (JSONArray) parser.parse((String) sampleIdList); + } catch (ParseException e) { + LogEvent.logDebug(e); + return analysisList; + } + } else if (sampleIdList instanceof JSONArray) { + modifyAnalysisArray = (JSONArray) sampleIdList; + } else { return analysisList; }