11/** @jsxImportSource @emotion /react */
22import React , { FC } from 'react' ;
33
4- import { Button , Select , TextField } from '@orfium/ictinus' ;
4+ import { Button , Select , TextArea , TextField } from '@orfium/ictinus' ;
55import { omit } from 'lodash' ;
66import { Field , Form } from 'react-final-form' ;
77import { useRouteMatch } from 'react-router-dom' ;
88
9+ import { CheckBoxWrapper } from '../../../../../common.style' ;
10+ import Checkbox from '../../../../../components/FormElements/Checkbox' ;
911import { useDischarge } from '../../../../../hooks/api/patientHooks' ;
10- import { DischargeAPI , DischargeForm } from '../../../../../models/apiTypes' ;
12+ import { DischargeAPI , SelectOption } from '../../../../../models/apiTypes' ;
1113import {
1214 FormHeadingContainer ,
1315 SelectWrapper ,
@@ -16,6 +18,15 @@ import { BOOLEAN_OPTIONS } from '../../../../RegisterEpisode/constants';
1618import { InternalContainer } from '../style' ;
1719import { FieldWrapper } from './style' ;
1820
21+ const POST_OPERATIVE_COMPLICATIONS = [
22+ { label : 'Bleeding' } ,
23+ { label : 'Haematoma' } ,
24+ { label : 'Urinary Retention' } ,
25+ { label : 'Return to theatre' } ,
26+ { label : 'Death' } ,
27+ { label : 'None' } ,
28+ ] ;
29+
1930const Discharge : FC < {
2031 isOpen : boolean ;
2132 discharge : DischargeAPI ;
@@ -24,16 +35,37 @@ const Discharge: FC<{
2435 const { episodeID } = match . params ;
2536 const { mutate, isLoading } = useDischarge ( episodeID ) ;
2637
27- const handleSubmit = ( form : DischargeForm ) => {
38+ const handleSubmit = ( form : {
39+ date : string ;
40+ aware_of_mesh : SelectOption ;
41+ infection : string ;
42+ episode_id : number ;
43+ comments ?: string ;
44+ discharge_duration ?: string ;
45+ } ) => {
2846 mutate ( form ) ;
2947 } ;
3048
31- const canSubmit = discharge ?. infection === undefined ;
49+ const canSubmit = discharge ?. infection == undefined ;
3250
3351 return (
3452 < InternalContainer isOpen = { isOpen } aria-expanded = { isOpen } >
35- < Form onSubmit = { handleSubmit } >
36- { ( { handleSubmit } ) => {
53+ < Form
54+ onSubmit = { ( values ) => {
55+ const newValues = {
56+ ...values ,
57+ infection : ( values . infection ? values . infection . join ( ',' ) : 'none' ) as string ,
58+ } ;
59+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
60+ // @ts -ignore
61+ handleSubmit ( newValues ) ;
62+ } }
63+ initialValues = { {
64+ ...discharge ,
65+ infection : discharge && discharge . infection ? discharge . infection ?. split ( ',' ) : undefined ,
66+ } }
67+ >
68+ { ( { handleSubmit, values } ) => {
3769 return (
3870 < form
3971 onSubmit = { handleSubmit }
@@ -89,17 +121,25 @@ const Discharge: FC<{
89121 < Select
90122 locked = { ! canSubmit }
91123 id = "aware_of_mesh"
92- label = "Mesh "
124+ label = "Antibiotics given on discharge "
93125 styleType = "outlined"
94126 size = "md"
95127 required = { canSubmit }
96128 status = { hasError ? 'error' : 'hint' }
97129 hintMsg = { hasError ? props . meta . error : undefined }
98130 options = { BOOLEAN_OPTIONS }
99131 { ...omit ( props . input , [ 'onFocus' ] ) }
100- selectedOption = { BOOLEAN_OPTIONS . find (
101- ( option ) => option . value === props . input . value . value
102- ) }
132+ selectedOption = {
133+ discharge ?. aware_of_mesh !== undefined
134+ ? BOOLEAN_OPTIONS . find ( ( option ) =>
135+ discharge ?. aware_of_mesh
136+ ? option . label === 'Yes'
137+ : option . label === 'No'
138+ )
139+ : BOOLEAN_OPTIONS . find (
140+ ( option ) => option . value === props . input . value . value
141+ )
142+ }
103143 handleSelectedOption = { props . input . onChange }
104144 />
105145 </ SelectWrapper >
@@ -108,40 +148,69 @@ const Discharge: FC<{
108148 </ Field >
109149 </ FieldWrapper >
110150
111- < FieldWrapper >
112- < Field
113- name = "infection"
114- initialValue = {
115- discharge ?. infection !== undefined
116- ? BOOLEAN_OPTIONS . find ( ( option ) =>
117- discharge ?. infection ? option . label === 'Yes' : option . label === 'No'
118- )
119- : undefined
120- }
121- >
122- { ( props ) => {
123- const hasError =
124- props . meta . touched && props . meta . invalid && ! props . meta . active ;
125-
126- return (
127- < SelectWrapper >
128- < Select
129- id = "infection"
130- label = "Infection"
131- styleType = "outlined"
132- size = "md"
151+ { values ?. aware_of_mesh ?. value === 0 && (
152+ < FieldWrapper >
153+ < Field
154+ name = "discharge_duration"
155+ initialValue = { discharge ?. discharge_duration }
156+ parse = { ( value ) => value }
157+ >
158+ { ( props ) => {
159+ const hasError =
160+ props . meta . touched && props . meta . invalid && ! props . meta . active ;
161+ return (
162+ < TextField
163+ id = "discharge_duration"
133164 locked = { ! canSubmit }
165+ label = { 'Duration (days)' }
134166 required = { canSubmit }
167+ styleType = "outlined"
168+ size = "md"
135169 status = { hasError ? 'error' : 'hint' }
136170 hintMsg = { hasError ? props . meta . error : undefined }
137- options = { BOOLEAN_OPTIONS }
138- { ...omit ( props . input , [ 'onFocus' ] ) }
139- selectedOption = { BOOLEAN_OPTIONS . find (
140- ( option ) => option . value === props . input . value . value
141- ) }
142- handleSelectedOption = { props . input . onChange }
171+ { ...props . input }
143172 />
144- </ SelectWrapper >
173+ ) ;
174+ } }
175+ </ Field >
176+ </ FieldWrapper >
177+ ) }
178+
179+ < FieldWrapper >
180+ < label > Post-operative complications</ label >
181+ < CheckBoxWrapper >
182+ { POST_OPERATIVE_COMPLICATIONS . map ( ( option ) => (
183+ < div key = { option . label } >
184+ < Field
185+ name = { `infection` }
186+ type = "checkbox"
187+ value = { option . label }
188+ label = { option . label }
189+ component = { Checkbox }
190+ required = { canSubmit }
191+ disabled = { ! canSubmit }
192+ />
193+ </ div >
194+ ) ) }
195+ </ CheckBoxWrapper >
196+ </ FieldWrapper >
197+
198+ < FieldWrapper >
199+ < label > Comments</ label >
200+ < Field name = "comments" initialValue = { discharge ?. comments } >
201+ { ( props ) => {
202+ const hasError =
203+ props . meta . touched && props . meta . invalid && ! props . meta . active ;
204+ return (
205+ < TextArea
206+ id = "comments"
207+ required = { canSubmit }
208+ styleType = "outlined"
209+ status = { hasError ? 'error' : 'hint' }
210+ hintMsg = { hasError ? props . meta . error : undefined }
211+ disabled = { ! canSubmit }
212+ { ...props . input }
213+ />
145214 ) ;
146215 } }
147216 </ Field >
@@ -151,7 +220,7 @@ const Discharge: FC<{
151220 color = { 'blue-200' }
152221 buttonType = "button"
153222 onClick = { handleSubmit }
154- disabled = { isLoading || ! canSubmit }
223+ disabled = { isLoading || ! canSubmit || ! values . infection }
155224 block
156225 size = "md"
157226 >
0 commit comments