From 2408e3286cc841a5bd05930441f66944e3a198ee Mon Sep 17 00:00:00 2001 From: Connor McCandless Date: Tue, 19 Oct 2021 23:15:45 -0400 Subject: [PATCH 1/2] fix(patients): allow the duplicate patient modal to show properly on possible duplicate patient fix #2546 --- src/patients/new/DuplicateNewPatientModal.tsx | 8 ++++---- src/patients/new/NewPatient.tsx | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/patients/new/DuplicateNewPatientModal.tsx b/src/patients/new/DuplicateNewPatientModal.tsx index 6d78d76c38..fed60567e5 100644 --- a/src/patients/new/DuplicateNewPatientModal.tsx +++ b/src/patients/new/DuplicateNewPatientModal.tsx @@ -6,7 +6,7 @@ import useTranslator from '../../shared/hooks/useTranslator' import Patient from '../../shared/model/Patient' interface Props { - duplicatePatient?: Patient + duplicatePatientList?: Patient[] show: boolean toggle: () => void onCloseButtonClick: () => void @@ -15,7 +15,7 @@ interface Props { const DuplicateNewPatientModal = (props: Props) => { const { t } = useTranslator() - const { duplicatePatient, show, toggle, onCloseButtonClick, onContinueButtonClick } = props + const { duplicatePatientList, show, toggle, onCloseButtonClick, onContinueButtonClick } = props const body = ( <> @@ -27,8 +27,8 @@ const DuplicateNewPatientModal = (props: Props) => {
{t('patients.possibleDuplicatePatient')} - {duplicatePatient !== undefined && - Object.entries(duplicatePatient).map(([key, patient]) => ( + {duplicatePatientList !== undefined && + Object.entries(duplicatePatientList).map(([key, patient]) => (
  • {patient.fullName}
  • diff --git a/src/patients/new/NewPatient.tsx b/src/patients/new/NewPatient.tsx index 5fb7e223f7..2730ab5105 100644 --- a/src/patients/new/NewPatient.tsx +++ b/src/patients/new/NewPatient.tsx @@ -6,7 +6,9 @@ import { useHistory } from 'react-router-dom' import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs' import { useUpdateTitle } from '../../page-header/title/TitleContext' import useTranslator from '../../shared/hooks/useTranslator' +import usePatients from '../hooks/usePatients' import Patient from '../../shared/model/Patient' +import PatientSearchRequest from '../models/PatientSearchRequest' import { RootState } from '../../shared/store' import GeneralInformation from '../GeneralInformation' import { createPatient } from '../patient-slice' @@ -23,10 +25,11 @@ const NewPatient = () => { const history = useHistory() const dispatch = useDispatch() const { createError } = useSelector((state: RootState) => state.patient) - const { patients } = Object(useSelector((state: RootState) => state.patients)) + const [searchRequest] = useState({ queryString: '' }) + const { data } = usePatients(searchRequest) const [patient, setPatient] = useState({} as Patient) - const [duplicatePatient, setDuplicatePatient] = useState(undefined) + const [duplicatePatientList, setDuplicatePatientList] = useState(undefined) const [showDuplicateNewPatientModal, setShowDuplicateNewPatientModal] = useState(false) const testPatient = { @@ -56,16 +59,16 @@ const NewPatient = () => { } const onSave = () => { - let duplicatePatients = [] - if (patients !== undefined) { - duplicatePatients = patients.filter((existingPatient: any) => + let duplicatePatients: Patient[] = []; + if (data !== undefined && data.patients !== undefined) { + duplicatePatients = data.patients.filter((existingPatient: any) => isPossibleDuplicatePatient(patient, existingPatient), ) } if (duplicatePatients.length > 0) { setShowDuplicateNewPatientModal(true) - setDuplicatePatient(duplicatePatients as Patient) + setDuplicatePatientList(duplicatePatients) } else { dispatch(createPatient(patient, onSuccessfulSave)) } @@ -109,7 +112,7 @@ const NewPatient = () => {
    Date: Thu, 21 Oct 2021 18:19:02 -0400 Subject: [PATCH 2/2] style(newpatients.tsx): fixed linting issues with NewPatients.tsx fix #2785 --- src/patients/new/NewPatient.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/patients/new/NewPatient.tsx b/src/patients/new/NewPatient.tsx index 2730ab5105..70ac719b03 100644 --- a/src/patients/new/NewPatient.tsx +++ b/src/patients/new/NewPatient.tsx @@ -6,11 +6,11 @@ import { useHistory } from 'react-router-dom' import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs' import { useUpdateTitle } from '../../page-header/title/TitleContext' import useTranslator from '../../shared/hooks/useTranslator' -import usePatients from '../hooks/usePatients' import Patient from '../../shared/model/Patient' -import PatientSearchRequest from '../models/PatientSearchRequest' import { RootState } from '../../shared/store' import GeneralInformation from '../GeneralInformation' +import usePatients from '../hooks/usePatients' +import PatientSearchRequest from '../models/PatientSearchRequest' import { createPatient } from '../patient-slice' import { isPossibleDuplicatePatient } from '../util/is-possible-duplicate-patient' import DuplicateNewPatientModal from './DuplicateNewPatientModal' @@ -59,7 +59,7 @@ const NewPatient = () => { } const onSave = () => { - let duplicatePatients: Patient[] = []; + let duplicatePatients: Patient[] = [] if (data !== undefined && data.patients !== undefined) { duplicatePatients = data.patients.filter((existingPatient: any) => isPossibleDuplicatePatient(patient, existingPatient),