{
- 0 ? new Date(patient.dateOfBirth) : undefined}
- onChange={(date: Date) => {
- onDateOfBirthChange(date)
- }}
- />
+ {patient.isApproximateDateOfBirth ? (
+
+ ) : (
+ 0
+ ? new Date(patient.dateOfBirth)
+ : undefined
+ }
+ onChange={(date: Date) => {
+ onDateOfBirthChange(date)
+ }}
+ />
+ )}
{
- setPatient({ ...patient, isApproximateDateOfBirth: event.target.checked })
- }}
+ disabled={!isEditable}
+ onChange={(event) => onCheckboxChange(event, 'isApproximateDateOfBirth')}
/>
- {patient.isApproximateDateOfBirth && (
-
-
-
- )}
@@ -239,8 +195,9 @@ const NewPatientForm = (props: Props) => {
/>
-
-
{t('patient.contactInformation')}
+
+
+
{
name="address"
value={patient.address}
isEditable={isEditable}
- onChange={(event: React.ChangeEvent) => {
- onFieldChange('address', event.currentTarget.value)
- }}
+ onChange={(event: React.ChangeEvent) =>
+ onFieldChange && onFieldChange('address', event.currentTarget.value)}
/>
- {isEditable && (
-
-
-
-
-
-
- )}
-
+
+ {isEditable ? (
+
+
+
+
+ ) : (
+
+
+
+ )}
)
}
-export default NewPatientForm
+export default GeneralInformation
diff --git a/src/patients/edit/EditPatient.tsx b/src/patients/edit/EditPatient.tsx
new file mode 100644
index 0000000000..0678cbdd44
--- /dev/null
+++ b/src/patients/edit/EditPatient.tsx
@@ -0,0 +1,86 @@
+import React, { useEffect, useState } from 'react'
+import { useHistory, useParams } from 'react-router'
+import { useTranslation } from 'react-i18next'
+import { useDispatch, useSelector } from 'react-redux'
+import { Spinner } from '@hospitalrun/components'
+
+import GeneralInformation from '../GeneralInformation'
+import useTitle from '../../page-header/useTitle'
+import Patient from '../../model/Patient'
+import { updatePatient, fetchPatient } from '../patient-slice'
+import { RootState } from '../../store'
+import { getPatientFullName, getPatientName } from '../util/patient-name-util'
+
+const getFriendlyId = (p: Patient): string => {
+ if (p) {
+ return p.friendlyId
+ }
+
+ return ''
+}
+
+const EditPatient = () => {
+ const { t } = useTranslation()
+ const history = useHistory()
+ const dispatch = useDispatch()
+
+ const [patient, setPatient] = useState({} as Patient)
+ const { patient: reduxPatient } = useSelector((state: RootState) => state.patient)
+
+ useTitle(
+ `${t('patients.editPatient')}: ${getPatientFullName(reduxPatient)} (${getFriendlyId(
+ reduxPatient,
+ )})`,
+ )
+
+ useEffect(() => {
+ setPatient(reduxPatient)
+ }, [reduxPatient])
+
+ const { id } = useParams()
+ useEffect(() => {
+ if (id) {
+ dispatch(fetchPatient(id))
+ }
+ }, [id, dispatch])
+
+ const onCancel = () => {
+ history.goBack()
+ }
+
+ const onSave = () => {
+ dispatch(
+ updatePatient(
+ {
+ ...patient,
+ fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
+ },
+ history,
+ ),
+ )
+ }
+
+ const onFieldChange = (key: string, value: string | boolean) => {
+ setPatient({
+ ...patient,
+ [key]: value,
+ })
+ }
+
+ // see comment in ViewPatient
+ if (!reduxPatient) {
+ return