-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
…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.
Size Change: -21.8 kB (-0.34%) Total Size: 6.47 MB
ℹ️ View Unchanged
|
if (selectPatientAction) { | ||
selectPatientAction(patients[index].uuid); | ||
} else { | ||
navigate({ | ||
to: `${interpolateString(config.search.patientResultUrl, { |
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.
interpolateString
returns a string, so there's no need for the additional interpolation.
const handleClear = useCallback(() => { | ||
setSearchTerm(''); | ||
}, [setSearchTerm]); | ||
const handleChange = useCallback((val) => setSearchTerm(val), [setSearchTerm]); | ||
|
||
const handleReset = useCallback(() => { | ||
setSearchTerm(''); | ||
}, [setSearchTerm]); |
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.
handleReset
and handleClear
do the same thing.
@@ -95,6 +118,24 @@ const CompactPatientSearchComponent: React.FC<CompactPatientSearchProps> = ({ | |||
} | |||
}, [focusedResult, bannerContainerRef, handleFocusToInput]); | |||
|
|||
useEffect(() => { | |||
if (fetchError) { |
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.
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
.
{isValidating && ( | ||
<span className={styles.validationIcon}> | ||
<InlineLoading className={styles.spinner} /> | ||
</span> | ||
)} |
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.
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: { |
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.
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, |
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.
FYI @ciaranduffy @paulsonder see the explanation in the |
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.
Thanks @denniskigen LGTM
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.
Impressive! Just one small thing that should be fixed up.
packages/esm-patient-search-app/src/compact-patient-search-extension/index.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Ian <[email protected]>
Requirements
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:
patientResultUrl
config property topatientChartUrl
, which is more descriptive of what it is used for. Implementers will need to update their configurations to use the new key.useInfinitePatientSearch
,useRecentlyViewedPatients
anduseRestPatients
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.useConfig
hook with thePatientSearchConfig
type for better type inference.addViewedPatientAndCloseSearchResults
function.keepPreviousData
option in theuseInfinitePatientSearch
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:
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.