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
/
CarePlanForm.tsx
167 lines (160 loc) · 5.58 KB
/
CarePlanForm.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { Alert, Column, Row } from '@hospitalrun/components'
import React from 'react'
import { useTranslation } from 'react-i18next'
import DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'
import SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'
import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'
import TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'
import CarePlan, { CarePlanIntent, CarePlanStatus } from '../../model/CarePlan'
import Patient from '../../model/Patient'
interface Error {
message?: string
title?: string
description?: string
status?: string
intent?: string
startDate?: string
endDate?: string
note?: string
condition?: string
}
interface Props {
patient: Patient
carePlan: Partial<CarePlan>
carePlanError?: Error
onChange?: (newCarePlan: Partial<CarePlan>) => void
disabled: boolean
}
const CarePlanForm = (props: Props) => {
const { t } = useTranslation()
const { patient, carePlan, carePlanError, disabled, onChange } = props
const onFieldChange = (name: string, value: string | CarePlanStatus | CarePlanIntent) => {
if (onChange) {
const newCarePlan = {
...carePlan,
[name]: value,
}
onChange(newCarePlan)
}
}
return (
<form>
{carePlanError?.message && <Alert color="danger" message={t(carePlanError.message)} />}
<Row>
<Column sm={12}>
<TextInputWithLabelFormGroup
isRequired
value={carePlan.title}
label={t('patient.carePlan.title')}
name="title"
feedback={t(carePlanError?.title || '')}
isInvalid={!!carePlanError?.title}
isEditable={!disabled}
onChange={(event) => onFieldChange('title', event.currentTarget.value)}
/>
</Column>
</Row>
<Row>
<Column sm={12}>
<TextFieldWithLabelFormGroup
isRequired
value={carePlan.description}
label={t('patient.carePlan.description')}
name="description"
feedback={t(carePlanError?.description || '')}
isInvalid={!!carePlanError?.description}
isEditable={!disabled}
onChange={(event) => onFieldChange('description', event.currentTarget.value)}
/>
</Column>
</Row>
<Row>
<Column sm={12}>
<SelectWithLabelFormGroup
isRequired
value={carePlan.diagnosisId}
label={t('patient.carePlan.condition')}
name="condition"
feedback={t(carePlanError?.condition || '')}
isInvalid={!!carePlanError?.condition}
isEditable={!disabled}
onChange={(event) => onFieldChange('diagnosisId', event.currentTarget.value)}
options={patient.diagnoses?.map((d) => ({ label: d.name, value: d.id })) || []}
/>
</Column>
</Row>
<Row>
<Column sm={6}>
<SelectWithLabelFormGroup
isRequired
value={carePlan.status}
label={t('patient.carePlan.status')}
name="status"
feedback={t(carePlanError?.status || '')}
isInvalid={!!carePlanError?.status}
isEditable={!disabled}
options={Object.values(CarePlanStatus).map((v) => ({ label: v, value: v }))}
onChange={(event) => onFieldChange('status', event.currentTarget.value)}
/>
</Column>
<Column sm={6}>
<SelectWithLabelFormGroup
isRequired
value={carePlan.intent}
label={t('patient.carePlan.intent')}
name="intent"
feedback={t(carePlanError?.intent || '')}
isInvalid={!!carePlanError?.intent}
isEditable={!disabled}
options={Object.values(CarePlanIntent).map((v) => ({ label: v, value: v }))}
onChange={(event) => onFieldChange('intent', event.currentTarget.value)}
/>
</Column>
</Row>
<Row>
<Column sm={6}>
<DatePickerWithLabelFormGroup
isRequired
value={carePlan.startDate ? new Date(carePlan.startDate) : new Date()}
label={t('patient.carePlan.startDate')}
name="startDate"
feedback={t(carePlanError?.startDate || '')}
isInvalid={!!carePlanError?.startDate}
isEditable={!disabled}
onChange={(date) => onFieldChange('startDate', date.toISOString())}
/>
</Column>
<Column sm={6}>
<DatePickerWithLabelFormGroup
isRequired
value={carePlan.endDate ? new Date(carePlan.endDate) : new Date()}
label={t('patient.carePlan.endDate')}
name="endDate"
feedback={t(carePlanError?.endDate || '')}
isInvalid={!!carePlanError?.endDate}
isEditable={!disabled}
onChange={(date) => onFieldChange('endDate', date.toISOString())}
/>
</Column>
</Row>
<Row>
<Column sm={12}>
<TextFieldWithLabelFormGroup
isRequired
value={carePlan.note}
label={t('patient.carePlan.note')}
name="note"
feedback={carePlanError?.note}
isInvalid={!!carePlanError?.note}
isEditable={!disabled}
onChange={(event) => onFieldChange('note', event.currentTarget.value)}
/>
</Column>
</Row>
</form>
)
}
CarePlanForm.defaultProps = {
disabled: false,
}
export default CarePlanForm