-
Notifications
You must be signed in to change notification settings - Fork 195
LUI-198: Optimize patient dashboard loading by implementing pagination for observations #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
b03e0de
a06309a
ba7a0fc
fa01899
e1c2f60
9456377
98301a5
639a616
3426cb9
1bf5bea
6bcaeda
d7e5866
a6b840c
b763c92
568c1f9
9bf378f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
@@ -41,6 +42,8 @@ | |
| import org.openmrs.api.ConceptService; | ||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.module.legacyui.GeneralUtils; | ||
| import org.openmrs.parameter.EncounterSearchCriteria; | ||
| import org.openmrs.parameter.EncounterSearchCriteriaBuilder; | ||
| import org.openmrs.util.OpenmrsConstants.PERSON_TYPE; | ||
| import org.openmrs.util.PrivilegeConstants; | ||
| import org.openmrs.web.WebConstants; | ||
|
|
@@ -190,7 +193,10 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons | |
|
|
||
| // add encounters if this user can view them | ||
| if (Context.hasPrivilege(PrivilegeConstants.GET_ENCOUNTERS)) { | ||
| model.put("patientEncounters", Context.getEncounterService().getEncountersByPatient(p)); | ||
| model.put( | ||
| "patientEncounters", | ||
| Context.getEncounterService().getEncounters(p.getPatientIdentifier().getIdentifier(), 0, 100, | ||
| false)); | ||
| } | ||
|
|
||
| // add visits if this user can view them | ||
|
|
@@ -202,36 +208,16 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons | |
| } | ||
|
|
||
| if (Context.hasPrivilege(PrivilegeConstants.GET_OBS)) { | ||
| // Get pagination parameters | ||
| Integer page = getPageParameter(request); | ||
| Integer pageSize = getPageSizeParameter(request, as); | ||
|
|
||
| Person person = (Person) p; | ||
| List<Person> persons = Collections.singletonList(person); | ||
|
|
||
| // Setup parameters for database-level pagination | ||
| List<Encounter> encounters = null; | ||
| List<Concept> questions = null; | ||
| List<Concept> answers = null; | ||
| List<PERSON_TYPE> personTypes = null; | ||
| List<Location> locations = null; | ||
| List<String> sort = Collections.singletonList("obsDatetime desc"); | ||
| Integer obsGroupId = null; | ||
| Date fromDate = null; | ||
| Date toDate = null; | ||
| boolean includeVoided = false; | ||
|
|
||
| // Get observations for the current page | ||
| List<Obs> paginatedObs = Context.getObsService().getObservations(persons, encounters, questions, | ||
| answers, personTypes, locations, sort, null, obsGroupId, fromDate, toDate, includeVoided); | ||
|
|
||
| // Get total count for pagination | ||
| Integer totalCount = Context.getObsService().getObservationCount(persons, encounters, questions, | ||
| answers, personTypes, locations, obsGroupId, fromDate, toDate, includeVoided); | ||
| List<Obs> paginatedObs = Context.getObsService().getObservations(persons, null, null, null, null, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the user interface you shared, what do you do with the startIndex?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Select the page size
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the page size the same as startIndex?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, based on the link you shared I renamed pageSize to that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are you passing the two parameters in the getObservations api call?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are only passing the limit and not startIndex directly in that method call
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which means that if you are on the last page, you still load all obs from the database to memory.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dkayiwa Yes that's right, added that |
||
| null, Collections.singletonList("obsDatetime desc"), pageSize, | ||
|
||
| null, null, null, false); | ||
|
|
||
| model.put("currentPage", page); | ||
| model.put("pageSize", pageSize); | ||
| model.put("totalObsCount", totalCount); | ||
| model.put("patientObs", paginatedObs); | ||
|
|
||
| Obs latestWeight = null; | ||
|
|
@@ -473,23 +459,14 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons | |
| protected void populateModel(HttpServletRequest request, Map<String, Object> model) { | ||
| } | ||
|
|
||
| private Integer getPageParameter(HttpServletRequest request) { | ||
| try { | ||
| return Integer.parseInt(request.getParameter("page")); | ||
| } | ||
| catch (NumberFormatException e) { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| private Integer getPageSizeParameter(HttpServletRequest request, AdministrationService as) { | ||
| try { | ||
| String pageSizeParam = request.getParameter("pageSize"); | ||
| if (pageSizeParam != null) { | ||
| return Integer.parseInt(pageSizeParam); | ||
| } | ||
|
|
||
| String globalPageSize = as.getGlobalProperty("dashboard.defaultPageSize"); | ||
| String globalPageSize = as.getGlobalProperty("dashboard.encounters.maximumNumberToShow"); | ||
|
||
| if (globalPageSize != null) { | ||
| return Integer.parseInt(globalPageSize); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ODORA0 why are you hardcoding the start(0) and length(100) ? My understanding of these two variables is that they can help paginate the results, the
startbeing the page and thelengththe number of records per page.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad here, I might have forgotten to make the change but changed so that we using the proper pagination parameters using the configured page size in the
maximumNumberToShowGP or default to only 50 when empty and allow users to paginate through encounters.