This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
NewPatient.tsx
79 lines (69 loc) · 2.1 KB
/
NewPatient.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useState } from 'react'
import { useHistory } from 'react-router'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import { Button } from '@hospitalrun/components'
import GeneralInformation from '../GeneralInformation'
import useTitle from '../../page-header/useTitle'
import Patient from '../../model/Patient'
import { createPatient } from '../patient-slice'
import { getPatientName } from '../util/patient-name-util'
import useAddBreadcrumbs from '../../breadcrumbs/useAddBreadcrumbs'
const breadcrumbs = [
{ i18nKey: 'patients.label', location: '/patients' },
{ i18nKey: 'patients.newPatient', location: '/patients/new' },
]
const NewPatient = () => {
const { t } = useTranslation()
const history = useHistory()
const dispatch = useDispatch()
const [patient, setPatient] = useState({} as Patient)
const [errorMessage, setErrorMessage] = useState('')
useTitle(t('patients.newPatient'))
useAddBreadcrumbs(breadcrumbs, true)
const onCancel = () => {
history.push('/patients')
}
const onSave = () => {
if (!patient.givenName) {
setErrorMessage(t('patient.errors.patientGivenNameRequired'))
} else {
dispatch(
createPatient(
{
...patient,
fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
},
history,
),
)
}
}
const onFieldChange = (key: string, value: string | boolean) => {
setPatient({
...patient,
[key]: value,
})
}
return (
<div>
<GeneralInformation
isEditable
patient={patient}
onFieldChange={onFieldChange}
errorMessage={errorMessage}
/>
<div className="row float-right">
<div className="btn-group btn-group-lg">
<Button className="mr-2" color="success" onClick={() => onSave()}>
{t('actions.save')}
</Button>
<Button color="danger" onClick={() => onCancel()}>
{t('actions.cancel')}
</Button>
</div>
</div>
</div>
)
}
export default NewPatient