Skip to content

Commit

Permalink
Merge pull request #618 from mozzy11/2.8
Browse files Browse the repository at this point in the history
implement API pagination for results and validation pages
  • Loading branch information
mozzy11 authored Nov 30, 2023
2 parents 1a462f4 + d2746aa commit 8864ddd
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 38 deletions.
78 changes: 75 additions & 3 deletions frontend/src/components/resultPage/SearchResultForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export function SearchResultForm(props) {
const [searchFormValues, setSearchFormValues] = useState(
SearchResultFormValues,
);

const [nextPage, setNextPage] = useState(null);
const [previousPage, setPreviousPage] = useState(null);
const [pagination, setPagination] = useState(false);
const [url, setUrl] = useState("");
const componentMounted = useRef(false);

const setResultsWithId = (results) => {
Expand All @@ -70,6 +73,22 @@ export function SearchResultForm(props) {
}
props.setResults?.(results);
setLoading(false);
if (results.paging) {
var { totalPages, currentPage } = results.paging;
if (totalPages > 1) {
setPagination(true);
if (parseInt(currentPage) < parseInt(totalPages)) {
setNextPage(parseInt(currentPage) + 1);
} else {
setNextPage(null);
}
if (parseInt(currentPage) > 1) {
setPreviousPage(parseInt(currentPage) - 1);
} else {
setPreviousPage(null);
}
}
}
} else {
props.setResults?.({ testResult: [] });
setNotificationBody({
Expand All @@ -84,7 +103,20 @@ export function SearchResultForm(props) {

const handleAdvancedSearch = () => {};

const loadNextResultsPage = () => {
setLoading(true);
getFromOpenElisServer(url + "&page=" + nextPage, setResultsWithId);
};

const loadPreviousResultsPage = () => {
setLoading(true);
getFromOpenElisServer(url + "&page=" + previousPage, setResultsWithId);
};

const getSelectedPatient = (patient) => {
setNextPage(null);
setPreviousPage(null);
setPagination(false);
setPatient(patient);
};
useEffect(() => {
Expand Down Expand Up @@ -127,10 +159,15 @@ export function SearchResultForm(props) {
searchBy.doRange +
"&finished=" +
true;
setUrl(searchEndPoint);

getFromOpenElisServer(searchEndPoint, setResultsWithId);
};

const handleSubmit = (values) => {
setNextPage(null);
setPreviousPage(null);
setPagination(false);
querySearch(values);
};

Expand All @@ -157,6 +194,9 @@ export function SearchResultForm(props) {
};

const submitOnSelect = (e) => {
setNextPage(null);
setPreviousPage(null);
setPagination(false);
var values = { unitType: e.target.value };
handleSubmit(values);
};
Expand Down Expand Up @@ -192,6 +232,9 @@ export function SearchResultForm(props) {
setSearchFormValues(searchValues);
querySearch(searchValues);
}
setNextPage(null);
setPreviousPage(null);
setPagination(false);
}, [searchBy]);

return (
Expand Down Expand Up @@ -434,6 +477,35 @@ export function SearchResultForm(props) {
</Grid>
</>
)}

<>
{pagination && (
<Grid>
<Column lg={12} />
<Column lg={1}>
<Button
type=""
id="loadpreviousresults"
onClick={loadPreviousResultsPage}
disabled={previousPage != null ? false : true}
>
<FormattedMessage id="Load Previous" />
</Button>
</Column>
<Column lg={1} />
<Column lg={1}>
<Button
type=""
id="loadpreviousresults"
disabled={nextPage != null ? false : true}
onClick={loadNextResultsPage}
>
<FormattedMessage id="Load Next" />
</Button>
</Column>
</Grid>
)}
</>
</>
);
}
Expand Down Expand Up @@ -1046,8 +1118,8 @@ export function SearchResults(props) {
<img
src={config.serverBaseUrl + "/images/nonconforming.gif"}
alt="nonconforming"
width="25"
height="20"
width="25"
height="20"
/>
</picture>
<b>
Expand Down
71 changes: 70 additions & 1 deletion frontend/src/components/validation/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,31 @@ const SearchForm = (props) => {
const [testSections, setTestSections] = useState([]);
const [testDate, setTestDate] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [nextPage, setNextPage] = useState(null);
const [previousPage, setPreviousPage] = useState(null);
const [pagination, setPagination] = useState(false);
const [url, setUrl] = useState("");

const validationResults = (data) => {
if (data) {
setSearchResults(data);
setIsLoading(false);
if (data.paging) {
var { totalPages, currentPage } = data.paging;
if (totalPages > 1) {
setPagination(true);
if (parseInt(currentPage) < parseInt(totalPages)) {
setNextPage(parseInt(currentPage) + 1);
} else {
setNextPage(null);
}
if (parseInt(currentPage) > 1) {
setPreviousPage(parseInt(currentPage) - 1);
} else {
setPreviousPage(null);
}
}
}
if (data.resultList.length > 0) {
const newResultsList = data.resultList.map((data, id) => {
let tempData = { ...data };
Expand Down Expand Up @@ -70,6 +91,9 @@ const SearchForm = (props) => {
}, [searchResults]);

const handleSubmit = (values) => {
setNextPage(null);
setPreviousPage(null);
setPagination(false);
setIsLoading(true);
var accessionNumber = values.accessionNumber ? values.accessionNumber : "";
var unitType = values.unitType ? values.unitType : "";
Expand All @@ -84,16 +108,29 @@ const SearchForm = (props) => {
date +
"&doRange=" +
doRange;

setUrl(searchEndPoint);
getFromOpenElisServer(searchEndPoint, validationResults);
};

const handleChange = () => {};

const loadNextResultsPage = () => {
setIsLoading(true);
getFromOpenElisServer(url + "&page=" + nextPage, validationResults);
};

const loadPreviousResultsPage = () => {
setIsLoading(true);
getFromOpenElisServer(url + "&page=" + previousPage, validationResults);
};
const fetchTestSections = (response) => {
setTestSections(response);
};

const submitOnSelect = (e) => {
setNextPage(null);
setPreviousPage(null);
setPagination(false);
var values = { unitType: e.target.value };
handleSubmit(values);
};
Expand All @@ -111,6 +148,9 @@ const SearchForm = (props) => {
setDoRagnge(false);
}
getFromOpenElisServer("/rest/user-test-sections", fetchTestSections);
setNextPage(null);
setPreviousPage(null);
setPagination(false);
}, []);
return (
<>
Expand Down Expand Up @@ -236,6 +276,35 @@ const SearchForm = (props) => {
</Grid>
</>
)}

<>
{pagination && (
<Grid>
<Column lg={12} />
<Column lg={1}>
<Button
type=""
id="loadpreviousresults"
onClick={loadPreviousResultsPage}
disabled={previousPage != null ? false : true}
>
<FormattedMessage id="Load Previous" />
</Button>
</Column>
<Column lg={1} />
<Column lg={1}>
<Button
type=""
id="loadpreviousresults"
disabled={nextPage != null ? false : true}
onClick={loadNextResultsPage}
>
<FormattedMessage id="Load Next" />
</Button>
</Column>
</Grid>
)}
</>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.openelisglobal.common.daoimpl.BaseDAOImpl;
import org.openelisglobal.common.exception.LIMSRuntimeException;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.paging.PagingProperties;
//import org.openelisglobal.common.paging.PagingProperties;
import org.openelisglobal.common.services.IStatusService;
import org.openelisglobal.common.services.StatusService.AnalysisStatus;
import org.openelisglobal.common.util.StringUtil;
Expand Down Expand Up @@ -216,7 +216,7 @@ public List<Analysis> getPageAnalysisByTestSectionAndStatus(String testSectionId

query.setParameter("testSectionId", Integer.parseInt(testSectionId));
query.setParameterList("statusIdList", statusIdList);
query.setMaxResults(SpringContext.getBean(PagingProperties.class).getValidationPageSize());
// query.setMaxResults(SpringContext.getBean(PagingProperties.class).getValidationPageSize());

return query.list();
} catch (RuntimeException e) {
Expand All @@ -241,7 +241,7 @@ public List<Analysis> getPageAnalysisAtAccessionNumberAndStatus(String accession

query.setParameter("accessionNumber", accessionNumber);
query.setParameterList("statusIdList", statusIdList);
query.setMaxResults(SpringContext.getBean(PagingProperties.class).getValidationPageSize());
//query.setMaxResults(SpringContext.getBean(PagingProperties.class).getValidationPageSize());

return query.list();
} catch (RuntimeException e) {
Expand Down Expand Up @@ -1256,7 +1256,7 @@ public List<Analysis> getPageAnalysisByTestSectionAndStatus(String testSectionId
query.setParameter("testSectionId", Integer.parseInt(testSectionId));
query.setParameterList("analysisStatusList", analysisStatusList);
query.setParameterList("sampleStatusList", sampleStatusList);
query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());
// query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());

List<Analysis> analysisList = query.list();

Expand Down Expand Up @@ -1537,7 +1537,7 @@ public List<Analysis> getPageAnalysisByStatusFromAccession(List<Integer> analysi
query.setParameter("accessionNumber", accessionNumber);
query.setParameterList("analysisStatusList", analysisStatusList);
query.setParameterList("sampleStatusList", sampleStatusList);
query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());
//query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());

List<Analysis> analysisList = query.list();

Expand Down Expand Up @@ -1595,7 +1595,7 @@ public List<Analysis> getPageAnalysisByStatusFromAccession(List<Integer> analysi
}
query.setParameterList("analysisStatusList", analysisStatusList);
query.setParameterList("sampleStatusList", sampleStatusList);
query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());
//query.setMaxResults(SpringContext.getBean(PagingProperties.class).getResultsPageSize());

List<Analysis> analysisList = query.list();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setDatabaseResults(HttpSession session, E items, IPageDivider<E> div
public E getPage(int page, HttpSession session) {
if (page > 0) {
List<E> pagedResults = (List<E>) session.getAttribute(IActionConstants.RESULTS_SESSION_CACHE);

totalPages = pagedResults.size();
if (pagedResults != null && pagedResults.size() >= page) {
return pagedResults.get(page - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void page(HttpServletRequest request, ResultsPagingForm form, int newPage
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

request.getSession().setAttribute(IActionConstants.SAVE_DISABLED, IActionConstants.FALSE);
List<TestResultItem> clientTests = form.getTestResult();
PagingBean bean = form.getPaging();
paging.updatePagedResults(request.getSession(), clientTests, bean, pagingHelper);
//List<TestResultItem> clientTests = form.getTestResult();
//PagingBean bean = form.getPaging();
//paging.updatePagedResults(request.getSession(), clientTests, bean, pagingHelper);

if (newPage < 0) {
newPage = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,27 +222,6 @@ public LogbookResultsForm showReactLogbookResults(@RequestParam(required = false
}


@GetMapping(value = "ReactRangeResults", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public LogbookResultsForm showReactLogbookResultsByRange(@RequestParam String labNumber,
@RequestParam String upperRangeAccessionNumber,@RequestParam boolean doRange, @RequestParam boolean finished,
@Validated(LogbookResults.class) @ModelAttribute("form") LogbookResultsForm form, BindingResult result)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

LogbookResultsForm newForm = new LogbookResultsForm();
if (!(result.hasFieldErrors("type") || result.hasFieldErrors("accessionNumber"))) {
newForm.setType(form.getType());
newForm.setAccessionNumber(form.getAccessionNumber());

String currentDate = getCurrentDate();
newForm.setCurrentDate(currentDate);
}
newForm.setDisplayTestSections(false);
newForm.setSearchByRange(true);

return getLogbookResults(request, newForm,null, labNumber,"",upperRangeAccessionNumber, doRange, finished);
}

private LogbookResultsForm getLogbookResults(HttpServletRequest request, LogbookResultsForm form,StatusResultsForm statusResultsForm, String labNumber,String patientPK,String upperRangeAccessionNumber, boolean doRange,
boolean finished) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void page(HttpServletRequest request, ValidationPagingForm form, int newP
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

request.getSession().setAttribute(IActionConstants.SAVE_DISABLED, IActionConstants.FALSE);
List<AnalysisItem> clientAnalysis = form.getResultList();
PagingBean bean = form.getPaging();
// List<AnalysisItem> clientAnalysis = form.getResultList();
// PagingBean bean = form.getPaging();
String testSectionId = form.getTestSectionId();

paging.updatePagedResults(request.getSession(), clientAnalysis, bean, pagingHelper);
// paging.updatePagedResults(request.getSession(), clientAnalysis, bean, pagingHelper);

if (newPage < 0) {
newPage = 0;
Expand Down

0 comments on commit 8864ddd

Please sign in to comment.