Skip to content
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

(feat) Restore recently searched patients functionality in compact search #1345

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

denniskigen
Copy link
Member

@denniskigen denniskigen commented Oct 14, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR restores the recently searched patients functionality in the compact patient search. It also introduces some refactoring of the code to make it more modular and easier to maintain. These changes include:

  • Tweaking the configuration schema to improve the names and descriptions of the config properties. This also includes renaming the patientResultUrl config property to patientChartUrl, which is more descriptive of what it is used for. Implementers will need to update their configurations to use the new key.
  • Cleaning up the logic in the useInfinitePatientSearch, useRecentlyViewedPatients and useRestPatients hooks to make them more modular and easier to maintain. This includes removing rendering logic from the hooks. We can now drop the .tsx extension for the patient search resource file as it no longer contains any JSX.
  • Annotating invocations of the useConfig hook with the PatientSearchConfig type for better type inference.
  • Adding some error handling logic to the addViewedPatientAndCloseSearchResults function.
  • Preloading user properties from the REST API when the user hovers over the search icon in the navbar using the SWR preload API.
  • Preserving recently searched patients when revalidating the recently viewed patients list by enabling the keepPreviousData option in the useInfinitePatientSearch hook for better UX. Without this, the UI would show a loading state when revalidating the recently viewed patients list which could be potentially jarring for the user.

Screenshots

recently-viewed-charts.mp4

Related Issue

Other

This implementation is a slight departure from what was envisioned in the original design. It's also a departure from a similar feature in O2:

CleanShot 2024-10-14 at 9  09 08@2x

The key difference is that both of those implementations would add any recently opened charts to the top of the list (regardless of whether they were recently searched or not). This implementation does not do that. Instead, it adds recently searched patients to the top of the list, but it does not add recently viewed charts. So, for example, if you clicked on patient in the Active Visits list and launched their chart, they would not show up at the top of the recently searched list. They would show up in the list if you went back and searched for them, but that's it. The reason for this is that in O2, every "chart" page calls EMR API's ApplicationEvent#patientViewed() service, which pushes the patient's ID into the list of recently viewed patients. The challenge is that none of this logic is exposed via the REST API. To get around this, we'd have to expose this mechanism by extending the REST API. In lieu of this, we'll have to make do with this approach for now.

…tient search

This restores the recently searched patients functionality in the compact patient search. It also introduces some refactoring of the code to make it more modular and easier to maintain. These changes include:

- Tweaking the configuration schema to improve the names and descriptions of the config properties. This also includes renaming the `patientResultUrl` config property to `patientChartUrl`, which is more descriptive of what it is used for. Implementers will need to update their configurations to use the new key.
- Cleaning up the logic in the `useInfinitePatientSearch`, `useRecentlyViewedPatients` and `useRestPatients` hooks to make them more modular and easier to maintain. This includes removing rendering logic from the hooks. We can now drop the `.tsx` extension for the patient search resource file as it no longer contains any JSX.
- Annotating invocations of the `useConfig` hook with the `PatientSearchConfig` type for better type inference.
- Adding some error handling logic to the `addViewedPatientAndCloseSearchResults` function.
- Preloading user properties from the REST API when the user hovers over the search icon in the navbar using the SWR preload API.
- Preserving recently searched patients when revalidating the recently viewed patients list
by enabling the `keepPreviousData` option in the `useInfinitePatientSearch` hook for better UX. Without this, the UI would show a loading state when revalidating the recently viewed patients list which could be potentially jarring for the user.
Copy link
Contributor

github-actions bot commented Oct 14, 2024

Size Change: -21.8 kB (-0.34%)

Total Size: 6.47 MB

Filename Size Change
packages/esm-patient-search-app/dist/335.js 0 B -25.1 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
packages/esm-active-visits-app/dist/106.js 8.63 kB 0 B
packages/esm-active-visits-app/dist/130.js 393 kB 0 B
packages/esm-active-visits-app/dist/233.js 3.37 kB 0 B
packages/esm-active-visits-app/dist/271.js 800 B 0 B
packages/esm-active-visits-app/dist/316.js 42.9 kB 0 B
packages/esm-active-visits-app/dist/319.js 712 B 0 B
packages/esm-active-visits-app/dist/325.js 3.09 kB 0 B
packages/esm-active-visits-app/dist/443.js 6.98 kB 0 B
packages/esm-active-visits-app/dist/460.js 824 B 0 B
packages/esm-active-visits-app/dist/574.js 615 B 0 B
packages/esm-active-visits-app/dist/586.js 53.5 kB 0 B
packages/esm-active-visits-app/dist/6.js 26.2 kB 0 B
packages/esm-active-visits-app/dist/644.js 800 B 0 B
packages/esm-active-visits-app/dist/725.js 643 B 0 B
packages/esm-active-visits-app/dist/757.js 731 B 0 B
packages/esm-active-visits-app/dist/784.js 2.63 kB 0 B
packages/esm-active-visits-app/dist/788.js 628 B 0 B
packages/esm-active-visits-app/dist/807.js 959 B 0 B
packages/esm-active-visits-app/dist/814.js 3.04 kB 0 B
packages/esm-active-visits-app/dist/833.js 765 B 0 B
packages/esm-active-visits-app/dist/879.js 3.02 kB 0 B
packages/esm-active-visits-app/dist/967.js 611 B 0 B
packages/esm-active-visits-app/dist/main.js 81.9 kB 0 B
packages/esm-active-visits-app/dist/openmrs-esm-active-visits-app.js 3.32 kB 0 B
packages/esm-appointments-app/dist/130.js 393 kB 0 B
packages/esm-appointments-app/dist/171.js 223 B 0 B
packages/esm-appointments-app/dist/198.js 250 kB 0 B
packages/esm-appointments-app/dist/2.js 2.23 kB 0 B
packages/esm-appointments-app/dist/265.js 1.79 kB 0 B
packages/esm-appointments-app/dist/269.js 7.38 kB 0 B
packages/esm-appointments-app/dist/271.js 2.41 kB 0 B
packages/esm-appointments-app/dist/319.js 2.27 kB 0 B
packages/esm-appointments-app/dist/325.js 3.08 kB 0 B
packages/esm-appointments-app/dist/372.js 2.57 kB 0 B
packages/esm-appointments-app/dist/385.js 31.3 kB 0 B
packages/esm-appointments-app/dist/440.js 16.6 kB 0 B
packages/esm-appointments-app/dist/460.js 2.46 kB 0 B
packages/esm-appointments-app/dist/501.js 7.02 kB 0 B
packages/esm-appointments-app/dist/574.js 2.02 kB 0 B
packages/esm-appointments-app/dist/581.js 9.03 kB 0 B
packages/esm-appointments-app/dist/591.js 16.8 kB 0 B
packages/esm-appointments-app/dist/644.js 2.41 kB 0 B
packages/esm-appointments-app/dist/711.js 129 kB 0 B
packages/esm-appointments-app/dist/757.js 2.39 kB 0 B
packages/esm-appointments-app/dist/784.js 2.62 kB 0 B
packages/esm-appointments-app/dist/788.js 2.02 kB 0 B
packages/esm-appointments-app/dist/807.js 2.65 kB 0 B
packages/esm-appointments-app/dist/833.js 2.37 kB 0 B
packages/esm-appointments-app/dist/903.js 879 B 0 B
packages/esm-appointments-app/dist/main.js 396 kB 0 B
packages/esm-appointments-app/dist/openmrs-esm-appointments-app.js 3.56 kB 0 B
packages/esm-bed-management-app/dist/130.js 393 kB 0 B
packages/esm-bed-management-app/dist/148.js 1.22 kB 0 B
packages/esm-bed-management-app/dist/169.js 6.98 kB 0 B
packages/esm-bed-management-app/dist/271.js 671 B 0 B
packages/esm-bed-management-app/dist/319.js 786 B 0 B
packages/esm-bed-management-app/dist/325.js 3.09 kB 0 B
packages/esm-bed-management-app/dist/339.js 50.2 kB 0 B
packages/esm-bed-management-app/dist/455.js 26.5 kB 0 B
packages/esm-bed-management-app/dist/460.js 671 B 0 B
packages/esm-bed-management-app/dist/501.js 7.03 kB 0 B
packages/esm-bed-management-app/dist/542.js 395 B 0 B
packages/esm-bed-management-app/dist/574.js 672 B 0 B
packages/esm-bed-management-app/dist/591.js 16.8 kB 0 B
packages/esm-bed-management-app/dist/644.js 671 B 0 B
packages/esm-bed-management-app/dist/757.js 814 B 0 B
packages/esm-bed-management-app/dist/766.js 113 kB 0 B
packages/esm-bed-management-app/dist/784.js 2.63 kB 0 B
packages/esm-bed-management-app/dist/788.js 671 B 0 B
packages/esm-bed-management-app/dist/807.js 671 B 0 B
packages/esm-bed-management-app/dist/833.js 671 B 0 B
packages/esm-bed-management-app/dist/main.js 3.87 kB 0 B
packages/esm-bed-management-app/dist/openmrs-esm-bed-management-app.js 3.25 kB 0 B
packages/esm-patient-list-management-app/dist/130.js 393 kB 0 B
packages/esm-patient-list-management-app/dist/233.js 3.38 kB 0 B
packages/esm-patient-list-management-app/dist/271.js 1.57 kB 0 B
packages/esm-patient-list-management-app/dist/319.js 1.51 kB 0 B
packages/esm-patient-list-management-app/dist/325.js 3.09 kB 0 B
packages/esm-patient-list-management-app/dist/37.js 12.5 kB 0 B
packages/esm-patient-list-management-app/dist/443.js 6.98 kB 0 B
packages/esm-patient-list-management-app/dist/455.js 58.1 kB 0 B
packages/esm-patient-list-management-app/dist/460.js 1.71 kB 0 B
packages/esm-patient-list-management-app/dist/574.js 1.34 kB 0 B
packages/esm-patient-list-management-app/dist/591.js 16.9 kB 0 B
packages/esm-patient-list-management-app/dist/644.js 1.57 kB 0 B
packages/esm-patient-list-management-app/dist/658.js 102 kB 0 B
packages/esm-patient-list-management-app/dist/757.js 1.62 kB 0 B
packages/esm-patient-list-management-app/dist/784.js 2.63 kB 0 B
packages/esm-patient-list-management-app/dist/788.js 1.33 kB 0 B
packages/esm-patient-list-management-app/dist/807.js 1.84 kB 0 B
packages/esm-patient-list-management-app/dist/814.js 3.05 kB 0 B
packages/esm-patient-list-management-app/dist/833.js 1.59 kB 0 B
packages/esm-patient-list-management-app/dist/main.js 162 kB 0 B
packages/esm-patient-list-management-app/dist/openmrs-esm-patient-list-management-app.js 3.3 kB 0 B
packages/esm-patient-registration-app/dist/130.js 393 kB 0 B
packages/esm-patient-registration-app/dist/169.js 6.71 kB 0 B
packages/esm-patient-registration-app/dist/2.js 2.24 kB 0 B
packages/esm-patient-registration-app/dist/250.js 526 B 0 B
packages/esm-patient-registration-app/dist/271.js 2.48 kB 0 B
packages/esm-patient-registration-app/dist/319.js 2.38 kB 0 B
packages/esm-patient-registration-app/dist/325.js 3.09 kB 0 B
packages/esm-patient-registration-app/dist/371.js 547 B 0 B
packages/esm-patient-registration-app/dist/372.js 2.57 kB 0 B
packages/esm-patient-registration-app/dist/460.js 2.46 kB 0 B
packages/esm-patient-registration-app/dist/501.js 7.03 kB 0 B
packages/esm-patient-registration-app/dist/574.js 2.09 kB 0 B
packages/esm-patient-registration-app/dist/591.js 16.8 kB 0 B
packages/esm-patient-registration-app/dist/644.js 2.48 kB 0 B
packages/esm-patient-registration-app/dist/662.js 453 B 0 B
packages/esm-patient-registration-app/dist/700.js 69.8 kB 0 B
packages/esm-patient-registration-app/dist/757.js 2.51 kB 0 B
packages/esm-patient-registration-app/dist/784.js 2.63 kB 0 B
packages/esm-patient-registration-app/dist/788.js 2.09 kB 0 B
packages/esm-patient-registration-app/dist/807.js 2.71 kB 0 B
packages/esm-patient-registration-app/dist/833.js 2.36 kB 0 B
packages/esm-patient-registration-app/dist/879.js 3.03 kB 0 B
packages/esm-patient-registration-app/dist/998.js 67.2 kB 0 B
packages/esm-patient-registration-app/dist/main.js 137 kB 0 B
packages/esm-patient-registration-app/dist/openmrs-esm-patient-registration-app.js 3.34 kB 0 B
packages/esm-patient-search-app/dist/130.js 393 kB 0 B
packages/esm-patient-search-app/dist/173.js 26 kB 0 B
packages/esm-patient-search-app/dist/233.js 3.37 kB 0 B
packages/esm-patient-search-app/dist/271.js 920 B 0 B
packages/esm-patient-search-app/dist/319.js 861 B 0 B
packages/esm-patient-search-app/dist/325.js 3.09 kB 0 B
packages/esm-patient-search-app/dist/443.js 6.98 kB 0 B
packages/esm-patient-search-app/dist/460.js 939 B 0 B
packages/esm-patient-search-app/dist/574.js 802 B +60 B (+8.09%) 🔍
packages/esm-patient-search-app/dist/591.js 16.8 kB 0 B
packages/esm-patient-search-app/dist/634.js 52.9 kB +913 B (+1.76%)
packages/esm-patient-search-app/dist/644.js 920 B 0 B
packages/esm-patient-search-app/dist/757.js 888 B 0 B
packages/esm-patient-search-app/dist/784.js 2.63 kB 0 B
packages/esm-patient-search-app/dist/788.js 736 B 0 B
packages/esm-patient-search-app/dist/807.js 1.04 kB 0 B
packages/esm-patient-search-app/dist/814.js 3.05 kB 0 B
packages/esm-patient-search-app/dist/833.js 877 B 0 B
packages/esm-patient-search-app/dist/main.js 80.2 kB +2.31 kB (+2.96%)
packages/esm-patient-search-app/dist/openmrs-esm-patient-search-app.js 3.29 kB -4 B (-0.12%)
packages/esm-service-queues-app/dist/130.js 393 kB 0 B
packages/esm-service-queues-app/dist/169.js 6.98 kB 0 B
packages/esm-service-queues-app/dist/199.js 1.36 kB 0 B
packages/esm-service-queues-app/dist/2.js 2.23 kB 0 B
packages/esm-service-queues-app/dist/236.js 5.84 kB 0 B
packages/esm-service-queues-app/dist/271.js 4.6 kB 0 B
packages/esm-service-queues-app/dist/282.js 8.97 kB 0 B
packages/esm-service-queues-app/dist/319.js 4.35 kB 0 B
packages/esm-service-queues-app/dist/325.js 3.09 kB 0 B
packages/esm-service-queues-app/dist/366.js 7.86 kB 0 B
packages/esm-service-queues-app/dist/372.js 2.57 kB 0 B
packages/esm-service-queues-app/dist/392.js 7.85 kB 0 B
packages/esm-service-queues-app/dist/460.js 4.82 kB 0 B
packages/esm-service-queues-app/dist/501.js 7.03 kB 0 B
packages/esm-service-queues-app/dist/574.js 3.88 kB 0 B
packages/esm-service-queues-app/dist/591.js 16.8 kB 0 B
packages/esm-service-queues-app/dist/6.js 1.75 kB 0 B
packages/esm-service-queues-app/dist/60.js 1.82 kB 0 B
packages/esm-service-queues-app/dist/604.js 6.96 kB 0 B
packages/esm-service-queues-app/dist/644.js 4.6 kB 0 B
packages/esm-service-queues-app/dist/665.js 160 kB 0 B
packages/esm-service-queues-app/dist/670.js 10.1 kB 0 B
packages/esm-service-queues-app/dist/727.js 8.1 kB 0 B
packages/esm-service-queues-app/dist/748.js 116 kB 0 B
packages/esm-service-queues-app/dist/752.js 1.62 kB 0 B
packages/esm-service-queues-app/dist/757.js 4.74 kB 0 B
packages/esm-service-queues-app/dist/760.js 7.13 kB 0 B
packages/esm-service-queues-app/dist/784.js 2.63 kB 0 B
packages/esm-service-queues-app/dist/788.js 3.89 kB 0 B
packages/esm-service-queues-app/dist/800.js 1.68 kB 0 B
packages/esm-service-queues-app/dist/807.js 5.17 kB 0 B
packages/esm-service-queues-app/dist/818.js 2.55 kB 0 B
packages/esm-service-queues-app/dist/828.js 1.39 kB 0 B
packages/esm-service-queues-app/dist/833.js 4.5 kB 0 B
packages/esm-service-queues-app/dist/911.js 7.76 kB 0 B
packages/esm-service-queues-app/dist/940.js 21.4 kB 0 B
packages/esm-service-queues-app/dist/main.js 276 kB 0 B
packages/esm-service-queues-app/dist/openmrs-esm-service-queues-app.js 3.31 kB 0 B
packages/esm-ward-app/dist/109.js 344 B 0 B
packages/esm-ward-app/dist/124.js 2.67 kB 0 B
packages/esm-ward-app/dist/125.js 5.5 kB 0 B
packages/esm-ward-app/dist/130.js 393 kB 0 B
packages/esm-ward-app/dist/146.js 709 B 0 B
packages/esm-ward-app/dist/15.js 482 B 0 B
packages/esm-ward-app/dist/153.js 33.2 kB 0 B
packages/esm-ward-app/dist/169.js 6.97 kB 0 B
packages/esm-ward-app/dist/304.js 5.69 kB 0 B
packages/esm-ward-app/dist/325.js 3.08 kB 0 B
packages/esm-ward-app/dist/348.js 349 B 0 B
packages/esm-ward-app/dist/372.js 2.56 kB 0 B
packages/esm-ward-app/dist/471.js 6.87 kB 0 B
packages/esm-ward-app/dist/481.js 1.43 kB 0 B
packages/esm-ward-app/dist/501.js 7.02 kB 0 B
packages/esm-ward-app/dist/53.js 11.4 kB 0 B
packages/esm-ward-app/dist/559.js 342 B 0 B
packages/esm-ward-app/dist/574.js 1.51 kB 0 B
packages/esm-ward-app/dist/576.js 5.08 kB 0 B
packages/esm-ward-app/dist/577.js 17.9 kB 0 B
packages/esm-ward-app/dist/591.js 16.8 kB 0 B
packages/esm-ward-app/dist/659.js 10 kB 0 B
packages/esm-ward-app/dist/67.js 33.2 kB 0 B
packages/esm-ward-app/dist/767.js 648 B 0 B
packages/esm-ward-app/dist/784.js 2.62 kB 0 B
packages/esm-ward-app/dist/850.js 3.01 kB 0 B
packages/esm-ward-app/dist/922.js 9.28 kB 0 B
packages/esm-ward-app/dist/940.js 21.4 kB 0 B
packages/esm-ward-app/dist/969.js 202 B 0 B
packages/esm-ward-app/dist/main.js 40.5 kB 0 B
packages/esm-ward-app/dist/openmrs-esm-ward-app.js 3.29 kB 0 B

compressed-size-action

@denniskigen denniskigen marked this pull request as ready for review October 15, 2024 08:15
if (selectPatientAction) {
selectPatientAction(patients[index].uuid);
} else {
navigate({
to: `${interpolateString(config.search.patientResultUrl, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interpolateString returns a string, so there's no need for the additional interpolation.

Comment on lines -35 to -41
const handleClear = useCallback(() => {
setSearchTerm('');
}, [setSearchTerm]);
const handleChange = useCallback((val) => setSearchTerm(val), [setSearchTerm]);

const handleReset = useCallback(() => {
setSearchTerm('');
}, [setSearchTerm]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleReset and handleClear do the same thing.

@@ -95,6 +118,24 @@ const CompactPatientSearchComponent: React.FC<CompactPatientSearchProps> = ({
}
}, [focusedResult, bannerContainerRef, handleFocusToInput]);

useEffect(() => {
if (fetchError) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved these here so that the resource file doesn't have to deal with any rendering concerns. A post-merge commit should change the resource file extension from .tsx to .ts.

Comment on lines +82 to +86
{isValidating && (
<span className={styles.validationIcon}>
<InlineLoading className={styles.spinner} />
</span>
)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will render a loading spinner when we're revalidating recently searched patients. Additionally, because we've specified the keepPreviousData option in the useInfinitePatientSearch hook, the previous data will be returned while the new data is being fetched.

@@ -2,17 +2,18 @@ import { Type, validators } from '@openmrs/esm-framework';

export const configSchema = {
search: {
// TODO: Rename this config property
patientResultUrl: {
patientChartUrl: {
Copy link
Member Author

@denniskigen denniskigen Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config property key change is a BREAKING change for implementers' config schemas. It will be communicated appropriately in the release notes when the next release gets cut.

shouldFetch ? getPatientUrl : null,
openmrsFetch,
{
keepPreviousData: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denniskigen
Copy link
Member Author

denniskigen commented Oct 15, 2024

FYI @ciaranduffy @paulsonder see the explanation in the Other section of the PR description for why the implementation has had to differ slightly from what you envisioned.

Copy link
Member

@donaldkibet donaldkibet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @denniskigen LGTM

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive! Just one small thing that should be fixed up.

Co-authored-by: Ian <[email protected]>
@denniskigen denniskigen merged commit fcc0125 into main Oct 17, 2024
6 checks passed
@denniskigen denniskigen deleted the feat/recent-patient-search branch October 17, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants