diff --git a/frontend/src/components/resultPage/SearchResultForm.js b/frontend/src/components/resultPage/SearchResultForm.js deleted file mode 100644 index 7e1e0b733d..0000000000 --- a/frontend/src/components/resultPage/SearchResultForm.js +++ /dev/null @@ -1,1109 +0,0 @@ -import React, { useContext, useEffect, useState, useRef } from "react"; -import { FormattedMessage, injectIntl } from "react-intl"; -import "../Style.css"; -import { - getFromOpenElisServer, - postToOpenElisServerJsonResponse, - convertAlphaNumLabNumForDisplay, -} from "../utils/Utils"; -import { - Heading, - Form, - FormLabel, - TextInput, - TextArea, - Checkbox, - Button, - Grid, - Column, - DatePicker, - DatePickerInput, - Stack, - Section, - Pagination, - Select, - SelectItem, - Loading, -} from "@carbon/react"; -import CustomLabNumberInput from "../common/CustomLabNumberInput"; -import DataTable from "react-data-table-component"; -import { Formik, Field } from "formik"; -import SearchResultFormValues from "../formModel/innitialValues/SearchResultFormValues"; -import { AlertDialog, NotificationKinds } from "../common/CustomNotification"; -import { NotificationContext } from "../layout/Layout"; -import SearchPatientForm from "../patient/SearchPatientForm"; -import { ConfigurationContext } from "../layout/Layout"; -import config from "../../config.json"; - -function ResultSearchPage() { - const [resultForm, setResultForm] = useState({ testResult: [] }); - return ( - <> - - - - ); -} - -export function SearchResultForm(props) { - const { notificationVisible, setNotificationVisible, setNotificationBody } = - useContext(NotificationContext); - - const [tests, setTests] = useState([]); - const [analysisStatusTypes, setAnalysisStatusTypes] = useState([]); - const [sampleStatusTypes, setSampleStatusTypes] = useState([]); - const [loading, setLoading] = useState(false); - const [searchBy, setSearchBy] = useState({ type: "", doRange: false }); - const [patient, setPatient] = useState({ patientPK: "" }); - const [testSections, setTestSections] = useState([]); - const [searchFormValues, setSearchFormValues] = useState( - SearchResultFormValues, - ); - - const componentMounted = useRef(false); - - const setResultsWithId = (results) => { - if (results.testResult) { - var i = 0; - if (results.testResult) { - results.testResult.forEach((item) => (item.id = "" + i++)); - } - props.setResults?.(results); - setLoading(false); - } else { - props.setResults?.({ testResult: [] }); - setNotificationBody({ - title: , - message: "No results found!", - kind: NotificationKinds.warning, - }); - setNotificationVisible(true); - setLoading(false); - } - }; - - const handleAdvancedSearch = () => {}; - - const getSelectedPatient = (patient) => { - setPatient(patient); - }; - useEffect(() => { - querySearch(searchFormValues); - }, [patient]); - - const querySearch = (values) => { - setLoading(true); - props.setResults({ testResult: [] }); - - let accessionNumber = - values.accessionNumber !== "" - ? values.accessionNumber - : values.startLabNo; - let labNo = accessionNumber !== undefined ? accessionNumber : ""; - const endLabNo = values.endLabNo !== undefined ? values.endLabNo : ""; - values.unitType = values.unitType ? values.unitType : ""; - - let searchEndPoint = - "/rest/ReactLogbookResultsByRange?" + - "labNumber=" + - labNo + - "&upperRangeAccessionNumber=" + - endLabNo + - "&patientPK=" + - patient.patientPK + - "&testSectionId=" + - values.unitType + - "&collectionDate=" + - values.collectionDate + - "&recievedDate=" + - values.recievedDate + - "&selectedTest=" + - values.testName + - "&selectedSampleStatus=" + - values.sampleStatusType + - "&selectedAnalysisStatus=" + - values.analysisStatus + - "&doRange=" + - searchBy.doRange + - "&finished=" + - true; - getFromOpenElisServer(searchEndPoint, setResultsWithId); - }; - - const handleSubmit = (values) => { - querySearch(values); - }; - - const getTests = (tests) => { - if (componentMounted.current) { - setTests(tests); - } - }; - - const getAnalysisStatusTypes = (analysisStatusTypes) => { - if (componentMounted.current) { - setAnalysisStatusTypes(analysisStatusTypes); - } - }; - - const getSampleStatusTypes = (sampleStatusTypes) => { - if (componentMounted.current) { - setSampleStatusTypes(sampleStatusTypes); - } - }; - - const fetchTestSections = (response) => { - setTestSections(response); - }; - - const submitOnSelect = (e) => { - var values = { unitType: e.target.value }; - handleSubmit(values); - }; - - useEffect(() => { - componentMounted.current = true; - getFromOpenElisServer("/rest/test-list", getTests); - getFromOpenElisServer( - "/rest/analysis-status-types", - getAnalysisStatusTypes, - ); - getFromOpenElisServer("/rest/sample-status-types", getSampleStatusTypes); - getFromOpenElisServer("/rest/user-test-sections", fetchTestSections); - let displayFormType = new URLSearchParams(window.location.search).get( - "type", - ); - let doRange = new URLSearchParams(window.location.search).get("doRange"); - setSearchBy({ - type: displayFormType, - doRange: doRange, - }); - }, []); - - useEffect(() => { - let accessionNumber = new URLSearchParams(window.location.search).get( - "accessionNumber", - ); - if (accessionNumber) { - let searchValues = { - ...searchFormValues, - accessionNumber: accessionNumber, - }; - setSearchFormValues(searchValues); - querySearch(searchValues); - } - }, [searchBy]); - - return ( - <> - {notificationVisible === true ? : ""} - {loading && } - - {({ - values, - // errors, - // touched, - handleChange, - setFieldValue, - // handleBlur, - handleSubmit, - }) => ( -
- - - -

- -

-
- {searchBy.type === "order" && ( - <> - - - {({ field }) => ( - - } - onChange={(e, rawValue) => { - setFieldValue(field.name, rawValue); - }} - /> - )} - - - - - )} - - {searchBy.type === "range" && ( - <> - - - {({ field }) => ( - - } - /> - )} - - - - - {({ field }) => ( - - } - /> - )} - - - - - )} - - {searchBy.type === "date" && ( - <> - - - {({ field }) => ( - - } - /> - )} - - - - - {({ field }) => ( - - } - /> - )} - - - - - {({ field }) => ( - - )} - - - - - {({ field }) => ( - - )} - - - - - {({ field }) => ( - - )} - - - - - )} - - {searchBy.type !== "patient" && searchBy.type !== "unit" && ( - - - - )} -
-
-
- )} -
- {searchBy.type === "patient" && ( - - )} - - {searchBy.type === "unit" && ( - <> - - - - - - - - )} - - ); -} - -export function SearchResults(props) { - const { notificationVisible, setNotificationBody, setNotificationVisible } = - useContext(NotificationContext); - const { configurationProperties } = useContext(ConfigurationContext); - - const [page, setPage] = useState(1); - const [pageSize, setPageSize] = useState(20); - const [acceptAsIs, setAcceptAsIs] = useState([]); - const [referalOrganizations, setReferalOrganizations] = useState([]); - const [methods, setMethods] = useState([]); - const [referralReasons, setReferralReasons] = useState([]); - const [rejectReasons, setRejectReasons] = useState([]); - const [rejectedItems, setRejectedItems] = useState({}); - const saveStatus = ""; - - const componentMounted = useRef(true); - - useEffect(() => { - componentMounted.current = true; - - getFromOpenElisServer( - "/rest/displayList/REFERRAL_ORGANIZATIONS", - loadReferalOrganizations, - ); - getFromOpenElisServer("/rest/displayList/METHODS", loadMethods); - getFromOpenElisServer( - "/rest/displayList/REFERRAL_REASONS", - loadReferalReasons, - ); - getFromOpenElisServer( - "/rest/displayList/REJECTION_REASONS", - loadRejectReasons, - ); - if (props.results.testResult.length > 0) { - var defaultRejectedItems = {}; - props.results.testResult.forEach((result) => { - defaultRejectedItems[result.id] = false; - }); - setRejectedItems(defaultRejectedItems); - } - return () => { - componentMounted.current = false; - }; - }, []); - - const loadReferalOrganizations = (values) => { - if (componentMounted.current) { - setReferalOrganizations(values); - } - }; - - const loadMethods = (values) => { - if (componentMounted.current) { - setMethods(values); - } - }; - - const loadReferalReasons = (values) => { - if (componentMounted.current) { - setReferralReasons(values); - } - }; - - const loadRejectReasons = (values) => { - if (componentMounted.current) { - setRejectReasons(values); - } - }; - - const addRejectResult = () => { - const resultColumn = { - name: "Reject", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - width: "12rem", - }; - - if (configurationProperties.allowResultRejection == "true") { - if (columns) { - const updatedList = [ - ...columns.slice(0, 8), - resultColumn, - ...columns.slice(8), - ]; - columns = updatedList; - } - } - }; - - var columns = [ - { - name: "Sample Info", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - sortable: true, - width: "15rem", - }, - { - name: "Test Date", - selector: (row) => row.testDate, - sortable: true, - width: "7rem", - }, - - { - name: "Analyzer Result", - selector: (row) => row.analysisMethod, - sortable: true, - width: "7rem", - }, - { - name: "Test Name", - selector: (row) => row.testName, - sortable: true, - width: "8rem", - }, - { - name: "Normal Range", - selector: (row) => row.normalRange, - sortable: true, - width: "8rem", - }, - { - name: "Accept", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - width: "5rem", - }, - { - name: "Result", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - width: "8rem", - }, - { - name: "Current Result", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - width: "8rem", - }, - { - name: "Notes", - cell: (row, index, column, id) => { - return renderCell(row, index, column, id); - }, - width: "7rem", - }, - ]; - - const renderCell = (row, index, column, id) => { - let formatLabNum = configurationProperties.AccessionFormat === "ALPHANUM"; - - console.log("renderCell: index: " + index + ", id: " + id); - switch (column.name) { - case "Sample Info": - // return - return ( - <> -
- -
- {row.nonconforming && ( - - nonconforming - - )} - - ); - - case "Accept": - return ( - <> - - {() => ( - handleAcceptAsIsChange(e, row.id)} - /> - )} - - - ); - - case "Reject": - return ( - <> - - - - {() => ( - handleRejectCheckBoxChange(e, row.id)} - /> - )} - - - {rejectedItems[row.id] == true && ( - - - - )} - - - ); - - case "Notes": - return ( - <> -
- -
- - ); - - case "Result": - switch (row.resultType) { - case "M": - case "C": - case "D": - return ( - - ); - - case "N": - return ( - handleChange(e, row.id)} - /> - ); - - case "R": - return ( -