From ac146b610c8fff04d071703832b671d5f0a97877 Mon Sep 17 00:00:00 2001 From: CalebSLane Date: Fri, 17 Nov 2023 11:31:48 -0800 Subject: [PATCH] fix non alpha labnumbers rejected when configured in alphanum mode --- .../components/common/CustomLabNumberInput.js | 8 ++++++-- .../components/resultPage/SearchResultForm.js | 2 +- frontend/src/components/utils/Utils.js | 4 ++++ frontend/src/components/workplan/Workplan.js | 19 ++++++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/common/CustomLabNumberInput.js b/frontend/src/components/common/CustomLabNumberInput.js index 0c6c087f59..a1b914a4d2 100644 --- a/frontend/src/components/common/CustomLabNumberInput.js +++ b/frontend/src/components/common/CustomLabNumberInput.js @@ -13,9 +13,14 @@ const CustomLabNumberInput = (props) => { useEffect(() => { setRawInput(props.value); - if (configurationProperties.AccessionFormat === "ALPHANUM") { + if ( + configurationProperties.AccessionFormat === "ALPHANUM" && + props.value.length < 13 + ) { const formatted = convertAlphaNumLabNumForDisplay(props.value); // use your own format function here setFormattedInput(formatted); + } else { + setFormattedInput(props.value); } }, [props.value]); @@ -33,7 +38,6 @@ const CustomLabNumberInput = (props) => { {...props} onChange={(e) => { const val = e.target.value.replace(/-/g, ""); - if (val.length > 2 + 5 + 6) return; setRawInput(val); if (typeof props.onChange === "function") { props.onChange(e, val); diff --git a/frontend/src/components/resultPage/SearchResultForm.js b/frontend/src/components/resultPage/SearchResultForm.js index 608864878e..bea2689814 100644 --- a/frontend/src/components/resultPage/SearchResultForm.js +++ b/frontend/src/components/resultPage/SearchResultForm.js @@ -4,6 +4,7 @@ import "../Style.css"; import { getFromOpenElisServer, postToOpenElisServerJsonResponse, + convertAlphaNumLabNumForDisplay, } from "../utils/Utils"; import { Heading, @@ -24,7 +25,6 @@ import { SelectItem, Loading, } from "@carbon/react"; -import { convertAlphaNumLabNumForDisplay } from "../utils/Utils"; import CustomLabNumberInput from "../common/CustomLabNumberInput"; import DataTable from "react-data-table-component"; import { Formik, Field } from "formik"; diff --git a/frontend/src/components/utils/Utils.js b/frontend/src/components/utils/Utils.js index 826d4541ec..6948eb7e9b 100644 --- a/frontend/src/components/utils/Utils.js +++ b/frontend/src/components/utils/Utils.js @@ -163,6 +163,10 @@ export const convertAlphaNumLabNumForDisplay = (labNumber) => { if (!labNumber) { return labNumber; } + if (labNumber.length > 13) { + console.log("labNumber is not alphanumeric (too long), ignoring format"); + return labNumber; + } let labNumberForDisplay = labNumber; //incomplete lab number if (labNumber.length < 8) { diff --git a/frontend/src/components/workplan/Workplan.js b/frontend/src/components/workplan/Workplan.js index a58a3bd291..1bb13b0bdc 100644 --- a/frontend/src/components/workplan/Workplan.js +++ b/frontend/src/components/workplan/Workplan.js @@ -12,14 +12,20 @@ import { TableHeader, TableRow, } from "@carbon/react"; -import React, { useState } from "react"; +import React, { useState, useContext } from "react"; import "../Style.css"; import "./wpStyle.css"; import { FormattedMessage } from "react-intl"; import WorkplanSearchForm from "./WorkplanSearchForm"; -import { postToOpenElisServerForPDF } from "../utils/Utils"; +import { + postToOpenElisServerForPDF, + convertAlphaNumLabNumForDisplay, +} from "../utils/Utils"; +import { ConfigurationContext } from "../layout/Layout"; export default function Workplan(props) { + const { configurationProperties } = useContext(ConfigurationContext); + const [testsList, setTestsList] = useState([]); const [subjectOnWorkplan, setSubjectOnWorkplan] = useState(false); const [nextVisitOnWorkplan, setNextVisitOnWorkplan] = useState(false); @@ -249,7 +255,14 @@ export default function Workplan(props) { {showAccessionNumber && ( - {row.accessionNumber} + + {configurationProperties.AccessionFormat === + "ALPHANUM" + ? convertAlphaNumLabNumForDisplay( + row.accessionNumber, + ) + : row.accessionNumber} + )}