Skip to content

Commit

Permalink
fix url when crResult is toggled off
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Aug 31, 2024
1 parent 83088c7 commit 1539e4f
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions frontend/src/components/patient/SearchPatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function SearchPatientForm(props) {
const [pageSize, setPageSize] = useState(5);
const [loading, setLoading] = useState(false);
const [nextPage, setNextPage] = useState(null);
const [isToggled, setIsToggled] = useState(false);
const [previousPage, setPreviousPage] = useState(null);
const [pagination, setPagination] = useState(false);
const [url, setUrl] = useState("");
Expand All @@ -54,7 +55,7 @@ function SearchPatientForm(props) {
const handleSubmit = (values) => {
setLoading(true);
values.dateOfBirth = dob;
const searchEndPoint =
let searchEndPoint =
"/rest/patient-search-results?" +
"lastName=" +
values.lastName +
Expand All @@ -75,9 +76,12 @@ function SearchPatientForm(props) {
"&gender=" +
values.gender +
"&suppressExternalSearch=" +
values.suppressExternalSearch +
"&crResult=" +
values.crResult;
values.suppressExternalSearch;

if (values.crResult === true) {
searchEndPoint += "&crResult=true";
}

getFromOpenElisServer(searchEndPoint, fetchPatientResults);
setUrl(searchEndPoint);
};
Expand All @@ -91,6 +95,10 @@ function SearchPatientForm(props) {
getFromOpenElisServer(url + "&page=" + previousPage, fetchPatientResults);
};

const toggle = () => {
setIsToggled((prev) => !prev);
};

const fetchPatientResults = (res) => {
let patientsResults = res.patientSearchResults;
if (patientsResults.length > 0) {
Expand Down Expand Up @@ -307,7 +315,11 @@ function SearchPatientForm(props) {
labelA="false"
labelB="true"
id="toggle-cr"
onClick={() => setFieldValue("crResult", true)}
toggled={isToggled}
onClick={() => {
toggle();
setFieldValue("crResult", !isToggled);
}}
/>
</Column>
<Column lg={8} md={4} sm={4}>
Expand Down

0 comments on commit 1539e4f

Please sign in to comment.