-
Notifications
You must be signed in to change notification settings - Fork 203
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
(fix) Improve performance of patient chart #1083
Conversation
@@ -31,32 +31,40 @@ const PatientChart: React.FC = () => { | |||
changeWorkspaceContext(patientUuid); | |||
}, [patientUuid]); | |||
|
|||
const leftNavBasePath = useMemo(() => spaBasePath.replace(':patientUuid', patientUuid), [patientUuid]); |
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.
Pushed this down to the PatientChart from the Root component. Basically, this is how we pass the patient UUID into the left nav slot. Since we only need the UUID, and we can get that from the URL (rather than from usePatient()
, it made sense to put it here where we already extract the UUID from the URL (via useParams()
)
return ( | ||
<main className={`omrs-main-content ${styles.chartContainer}`}> | ||
{isLoadingPatient ? ( |
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 was the big content paint delay... In essence, this holds the whole patient chart hostage until the usePatientOrOfflineRegisteredPatient()
hook returns a value.
const { isLoading: isLoadingPatient, patient } = usePatientOrOfflineRegisteredPatient(patientUuid); | ||
const { isLoading: isLoadingPatient, patient } = usePatient(patientUuid); |
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.
IMO, we don't need a patient-chart specific hook for this. usePatientOrOfflineRegisteredPatient()
returns either the online patient or a patient who was registered offline if that patient exists. We pretty much want the same object everywhere, so I'm going to refactor things in the framework so that the usePatient()
hook has a better version of that logic. We rely on the fact that patients registered offline will have a UUID assigned and that this UUID is properly generated (which holds true). However, there's lots of stuff in core that will need to be updated for this, primarily because we replicated this logic a lot.
}`} | ||
> | ||
<ExtensionSlot extensionSlotName="breadcrumbs-slot" /> | ||
{isLoadingPatient ? ( |
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.
Realistically, I want to get rid of this <Loader />
component here at all. There's not really any state that we're passing to child objects aside from "usePatient()
resolved". Currently whatever renders in the patient-header-slot
and the conditions app on the chart seem to be broken without waiting for that, but that should be fixable at the level of those components.
) : ( | ||
<> | ||
<aside> | ||
<ExtensionSlot extensionSlotName="patient-header-slot" state={state} /> |
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.
Generally, we want to ensure components that render ExtensionSlot
s only re-render the extension slot if state relevant to that slot changes. Once option is to memoise the ExtensionSlot
itself... Just a thought. Not implementing that yet.
Size Change: -1.89 MB (-23%) 🎉 Total Size: 6.18 MB
ℹ️ View Unchanged
|
packages/esm-patient-chart-app/src/workspace/workspace-window.component.tsx
Show resolved
Hide resolved
import { usePatient, getSynchronizationItems } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
|
||
export const patientRegistrationSyncType = 'patient-registration'; |
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.
Deleting this constant may have been a mistake, but we don't need the rest of this file...
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, Ian.
ab8b1b2
to
6c212e5
Compare
835b812
to
5f639b2
Compare
@denniskigen Are you happy for me to merge this in? @donaldkibet You raised a good point about multiple requests for patients that I do want to address in the future. However, currently on dev3, before this change, when I load the patient on the chart, I see 8 requests to the |
I guess I put Descartes before the proverbial horse, @ibacher, but yes, very happy to merge this in, and the corollary of this is quite palpable for me on dev3. Thanks for the great work! The other incredible thing I hadn't noticed about this is this size diff: 😮 |
Requirements
Summary
This is a draft for the changes I'm trying to implement for the patient chart, mostly to discuss what's happening here. Commentary to follow.
Screenshots
Related Issue
Other