-
-
Notifications
You must be signed in to change notification settings - Fork 55
WEB-4677 - Improve Pop Health Add/Edit Patient Modal Performance #1995
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
Open
henry-tp
wants to merge
13
commits into
develop
Choose a base branch
from
WEB-4677-modal-perf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+244
−159
Open
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dd19b61
WEB-4677 abstract AddPatientDialog
henry-tp 9829870
WEB-4677 abstract editPatientDialog
henry-tp 4e1aaa9
WEB-4677 fix formContext noop issue
henry-tp 99783f4
WEB-4677 memoize validation schema
henry-tp 2c8194a
WEB-4677 fix imports
henry-tp 39b73d2
WEB-4677 memoize schema in patientform
henry-tp 651efa4
WEB-4677 fix stale imports
henry-tp dd70d46
WEB-4677 change file name
henry-tp bb0e996
WEB-4677 change file name
henry-tp 420f591
WEB-4677 improve table performance via memoization
henry-tp 8a83a08
WEB-4677 restory missing array-dep
henry-tp 3a292e7
WEb-4677 add missing dep to renderPeopleTable array
henry-tp 8c9d577
Revert "WEb-4677 add missing dep to renderPeopleTable array"
henry-tp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/pages/clinicworkspace/clinicPatientsDialogs/addPatientDialog.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import React, { useMemo, useState } from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { trackMetric } from '../../../core/metricUtils'; | ||
|
|
||
| import keys from 'lodash/keys'; | ||
| import noop from 'lodash/noop'; | ||
| import { fieldsAreValid } from '../../../core/forms'; | ||
| import { patientSchema as validationSchema } from '../../../core/clinicUtils'; | ||
|
|
||
| import Button from '../../../components/elements/Button'; | ||
| import { Dialog, DialogContent, DialogTitle, DialogActions } from '../../../components/elements/Dialog'; | ||
| import { MediumTitle } from '../../../components/elements/FontStyles'; | ||
| import PatientForm from '../../../components/clinic/PatientForm'; | ||
|
|
||
| const SEARCH_DEBOUNCE_MS = 1000; | ||
|
|
||
| const AddPatientDialog = ({ | ||
| api, | ||
| onClose = noop, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| const creatingClinicCustodialAccount = useSelector(state => state.blip.working.creatingClinicCustodialAccount); | ||
| const selectedClinicId = useSelector(state => state.blip.selectedClinicId); | ||
|
|
||
| const clinic = useSelector(state => state.blip.clinics?.[selectedClinicId]); | ||
| const mrnSettings = useMemo(() => clinic?.mrnSettings ?? {}, [clinic?.mrnSettings]); | ||
|
|
||
| const clinicMRNsForPatientFormValidation = useSelector(state => state.blip.clinicMRNsForPatientFormValidation); | ||
| const existingMRNs = useMemo(() => clinicMRNsForPatientFormValidation || [], [clinicMRNsForPatientFormValidation]); | ||
| const schema = useMemo(() => validationSchema({ mrnSettings, existingMRNs }), [mrnSettings, existingMRNs]); | ||
|
|
||
| const [formContext, setFormContext] = useState(null); | ||
|
|
||
| const handleFormChange = (formikContext) => setFormContext({ ...formikContext }); | ||
|
|
||
| const handleClose = () => onClose(); | ||
|
|
||
| const handleConfirm = () => { | ||
| trackMetric('Clinic - Add patient confirmed', { clinicId: selectedClinicId }); | ||
| formContext?.handleSubmit(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| id="addPatient" | ||
| aria-labelledby="dialog-title" | ||
| open={true} | ||
| onClose={handleClose} | ||
| > | ||
| <DialogTitle onClose={handleClose}> | ||
| <MediumTitle id="dialog-title">{t('Add New Patient Account')}</MediumTitle> | ||
| </DialogTitle> | ||
|
|
||
| <DialogContent> | ||
| <PatientForm | ||
| api={api} | ||
| trackMetric={trackMetric} | ||
| onFormChange={handleFormChange} | ||
| searchDebounceMs={SEARCH_DEBOUNCE_MS} | ||
| action="create" | ||
| /> | ||
| </DialogContent> | ||
|
|
||
| <DialogActions> | ||
| <Button id="addPatientCancel" variant="secondary" onClick={handleClose}> | ||
| {t('Cancel')} | ||
| </Button> | ||
| <Button | ||
| id="addPatientConfirm" | ||
| variant="primary" | ||
| onClick={handleConfirm} | ||
| processing={creatingClinicCustodialAccount.inProgress} | ||
| disabled={!fieldsAreValid(keys(formContext?.values), schema, formContext?.values)} | ||
| > | ||
| {t('Add Patient')} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
||
| export default AddPatientDialog; |
103 changes: 103 additions & 0 deletions
103
app/pages/clinicworkspace/clinicPatientsDialogs/editPatientDialog.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import React, { useMemo, useState } from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { trackMetric } from '../../../core/metricUtils'; | ||
|
|
||
| import keys from 'lodash/keys'; | ||
| import noop from 'lodash/noop'; | ||
| import isEqual from 'lodash/isEqual'; | ||
| import { fieldsAreValid } from '../../../core/forms'; | ||
| import { patientSchema as validationSchema } from '../../../core/clinicUtils'; | ||
|
|
||
| import Button from '../../../components/elements/Button'; | ||
| import { Dialog, DialogContent, DialogTitle, DialogActions } from '../../../components/elements/Dialog'; | ||
| import { MediumTitle } from '../../../components/elements/FontStyles'; | ||
| import PatientForm from '../../../components/clinic/PatientForm'; | ||
|
|
||
| const SEARCH_DEBOUNCE_MS = 1000; | ||
|
|
||
| const EditPatientDialog = ({ | ||
| api, | ||
| patient, | ||
| onClose = noop, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| const updatingClinicPatient = useSelector(state => state.blip.working.updatingClinicPatient); | ||
| const selectedClinicId = useSelector(state => state.blip.selectedClinicId); | ||
|
|
||
| const clinic = useSelector(state => state.blip.clinics?.[selectedClinicId]); | ||
| const mrnSettings = useMemo(() => clinic?.mrnSettings ?? {}, [clinic?.mrnSettings]); | ||
|
|
||
| const clinicMRNsForPatientFormValidation = useSelector(state => state.blip.clinicMRNsForPatientFormValidation); | ||
| // Patient's pre-existing MRN will already exist in clinic, so it needs to not trip the validator | ||
| const existingMRNs = useMemo(() => ( | ||
| clinicMRNsForPatientFormValidation?.filter(mrn => mrn !== patient?.mrn) || [] | ||
| ), [clinicMRNsForPatientFormValidation, patient?.mrn]); | ||
| const schema = useMemo(() => validationSchema({ mrnSettings, existingMRNs }), [mrnSettings, existingMRNs]); | ||
|
|
||
| const [formContext, setFormContext] = useState(null); | ||
|
|
||
| const handleFormChange = (formikContext) => setFormContext({ ...formikContext }); | ||
|
|
||
| const handleClose = () => onClose(); | ||
|
|
||
| const handleConfirm = () => { | ||
| trackMetric('Clinic - Edit patient confirmed', { clinicId: selectedClinicId }); | ||
| const updatedTags = [...(formContext?.values?.tags || [])]; | ||
| const existingTags = [...(patient?.tags || [])]; | ||
|
|
||
| if (!isEqual(updatedTags.sort(), existingTags.sort())) { | ||
| trackMetric('Clinic - Population Health - Edit patient tags confirm', { clinicId: selectedClinicId }); | ||
| } | ||
|
|
||
| formContext?.handleSubmit(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| id="editPatient" | ||
| aria-labelledby="dialog-title" | ||
| open={true} | ||
| onClose={handleClose} | ||
| > | ||
| <DialogTitle onClose={() => { | ||
| trackMetric('Clinic - Edit patient close', { clinicId: selectedClinicId }); | ||
| handleClose() | ||
| }}> | ||
| <MediumTitle id="dialog-title">{t('Edit Patient Details')}</MediumTitle> | ||
| </DialogTitle> | ||
|
|
||
| <DialogContent> | ||
| <PatientForm | ||
| api={api} | ||
| trackMetric={trackMetric} | ||
| onFormChange={handleFormChange} | ||
| patient={patient} | ||
| searchDebounceMs={SEARCH_DEBOUNCE_MS} | ||
| action="edit" | ||
| /> | ||
| </DialogContent> | ||
|
|
||
| <DialogActions> | ||
| <Button id="editPatientCancel" variant="secondary" onClick={() => { | ||
| trackMetric('Clinic - Edit patient cancel', { clinicId: selectedClinicId, source: 'Patients list' }); | ||
| handleClose() | ||
| }}> | ||
| {t('Cancel')} | ||
| </Button> | ||
|
|
||
| <Button | ||
| id="editPatientConfirm" | ||
| variant="primary" | ||
| onClick={handleConfirm} | ||
| processing={updatingClinicPatient.inProgress} | ||
| disabled={!fieldsAreValid(keys(formContext?.values), schema, formContext?.values)} | ||
| > | ||
| {t('Save Changes')} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
||
| export default EditPatientDialog; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Forward
searchDebounceMsthrough the extracted dialogs.The inline dialogs forwarded
searchDebounceMstoPatientForm, andPatientFormuses it to debounce MRN lookups. The extracted dialogs replace that input with fixed1000, so a caller-provided non-default value has no effect. (raw.githubusercontent.com)app/pages/clinicworkspace/ClinicPatients.js#L3036-L3049: PasssearchDebounceMsto both dialog components and add it to bothuseCallbackdependency arrays.app/pages/clinicworkspace/clinicPatientsDialogs/addPatientDialog.js#L18-L21: AcceptsearchDebounceMs, withSEARCH_DEBOUNCE_MSas its default.app/pages/clinicworkspace/clinicPatientsDialogs/addPatientDialog.js#L60-L60: Pass the received value toPatientForm.app/pages/clinicworkspace/clinicPatientsDialogs/editPatientDialog.js#L19-L23: AcceptsearchDebounceMs, withSEARCH_DEBOUNCE_MSas its default.app/pages/clinicworkspace/clinicPatientsDialogs/editPatientDialog.js#L76-L76: Pass the received value toPatientForm.Proposed fix
📍 Affects 3 files
app/pages/clinicworkspace/ClinicPatients.js#L3036-L3049(this comment)app/pages/clinicworkspace/clinicPatientsDialogs/addPatientDialog.js#L18-L21app/pages/clinicworkspace/clinicPatientsDialogs/addPatientDialog.js#L60-L60app/pages/clinicworkspace/clinicPatientsDialogs/editPatientDialog.js#L19-L23app/pages/clinicworkspace/clinicPatientsDialogs/editPatientDialog.js#L76-L76🤖 Prompt for AI Agents