Skip to content

Commit

Permalink
fix non alpha labnumbers rejected when configured in alphanum mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebSLane committed Nov 17, 2023
1 parent 226d434 commit ac146b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 6 additions & 2 deletions frontend/src/components/common/CustomLabNumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/resultPage/SearchResultForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../Style.css";
import {
getFromOpenElisServer,
postToOpenElisServerJsonResponse,
convertAlphaNumLabNumForDisplay,
} from "../utils/Utils";
import {
Heading,
Expand All @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/components/workplan/Workplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -249,7 +255,14 @@ export default function Workplan(props) {
<TableCell>
{showAccessionNumber && (
<Link style={{ color: "blue" }} href="#">
<u>{row.accessionNumber}</u>
<u>
{configurationProperties.AccessionFormat ===
"ALPHANUM"
? convertAlphaNumLabNumForDisplay(
row.accessionNumber,
)
: row.accessionNumber}
</u>
</Link>
)}
</TableCell>
Expand Down

0 comments on commit ac146b6

Please sign in to comment.