@@ -19,6 +19,11 @@ import { DoctorAutoComplete } from '../doctor/DoctorAutoComplete'
1919import toast from 'react-hot-toast'
2020import { SurgeryModel } from '../../../../shared/models/SurgeryModel'
2121import { unwrapResult } from '@renderer/lib/utils'
22+
23+ const toValidDate = ( date ?: Date | null ) : Date | null => {
24+ if ( ! date ) return null
25+ return ! isNaN ( date . getTime ( ) ) ? date : null
26+ }
2227const KBD = ( { children } : { children : React . ReactNode } ) => (
2328 < kbd className = "pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100" >
2429 { children }
@@ -30,6 +35,8 @@ const surgerySchema = z.object({
3035 bht : z . string ( ) . min ( 1 , { message : 'BHT is required' } ) ,
3136 ward : z . string ( ) . min ( 1 , { message : 'Ward is required' } ) ,
3237 date : z . date ( ) . nullable ( ) ,
38+ doa : z . date ( ) . nullable ( ) ,
39+ dod : z . date ( ) . nullable ( ) ,
3340 doneBy : z . array ( z . number ( ) ) ,
3441 assistedBy : z . array ( z . number ( ) ) ,
3542 notes : z . string ( ) . optional ( ) ,
@@ -56,7 +63,9 @@ export const AddOrEditSurgery = forwardRef<AddOrEditSurgeryRef, AddOrEditSurgery
5663 bht : surgery ?. bht || '' ,
5764 title : surgery ?. title || '' ,
5865 ward : surgery ?. ward || '' ,
59- date : surgery ?. date || null ,
66+ date : toValidDate ( surgery ?. date ) ,
67+ doa : toValidDate ( surgery ?. doa ) ,
68+ dod : toValidDate ( surgery ?. dod ) ,
6069 assistedBy : surgery ?. assistedBy ?. map ( ( ab ) => ab . id ) || [ ] ,
6170 doneBy : surgery ?. doneBy ?. map ( ( db ) => db . id ) || [ ] ,
6271 notes : surgery ?. notes || '' ,
@@ -70,12 +79,14 @@ export const AddOrEditSurgery = forwardRef<AddOrEditSurgeryRef, AddOrEditSurgery
7079 try {
7180 console . log ( data )
7281 if ( ! patientId ) throw new Error ( 'Patient ID is required' )
73- const { doneBy, assistedBy, date, ...rest } = data
82+ const { doneBy, assistedBy, date, doa , dod , ...rest } = data
7483
7584 const { result, error } = await window . api . invoke ( 'createNewSurgery' , {
7685 ...rest ,
7786 patient_id : patientId ,
78- date : date ? + date : null
87+ date : date ? + date : null ,
88+ doa : doa ? + doa : null ,
89+ dod : dod ? + dod : null
7990 } )
8091
8192 if ( error ) throw error
@@ -104,11 +115,13 @@ export const AddOrEditSurgery = forwardRef<AddOrEditSurgeryRef, AddOrEditSurgery
104115 try {
105116 if ( ! surgery ) throw new Error ( 'Surgery is required' )
106117
107- const { doneBy, assistedBy, date, ...rest } = data
118+ const { doneBy, assistedBy, date, doa , dod , ...rest } = data
108119
109120 const { result, error } = await window . api . invoke ( 'updateSurgery' , surgery . id , {
110121 ...rest ,
111- date : date ? + date : null
122+ date : date ? + date : null ,
123+ doa : doa ? + doa : null ,
124+ dod : dod ? + dod : null
112125 } )
113126
114127 if ( error ) throw error
@@ -202,7 +215,7 @@ export const AddOrEditSurgery = forwardRef<AddOrEditSurgeryRef, AddOrEditSurgery
202215 ) }
203216 />
204217
205- < div className = "flex flex-col md:flex-row md:items-end md:space-x -2 w-full mt-1" >
218+ < div className = "flex flex-col md:flex-row md:items-end gap -2 w-full mt-1" >
206219 < div className = "flex flex-col w-full md:w-1/2" >
207220 < FormField
208221 name = "bht"
@@ -234,22 +247,48 @@ export const AddOrEditSurgery = forwardRef<AddOrEditSurgeryRef, AddOrEditSurgery
234247 ) }
235248 />
236249 </ div >
250+ </ div >
237251
238- < div className = "flex flex-col" >
239- < FormField
240- name = "date"
241- control = { form . control }
242- render = { ( { field } ) => (
243- < FormItem >
244- < FormLabel > Surgery Date</ FormLabel >
245- < FormControl >
246- < DatePicker onSelect = { field . onChange } selected = { field . value || undefined } />
247- </ FormControl >
248- < FormMessage />
249- </ FormItem >
250- ) }
251- />
252- </ div >
252+ < div className = "grid grid-cols-1 sm:grid-cols-3 gap-4 w-full mt-2" >
253+ < FormField
254+ name = "date"
255+ control = { form . control }
256+ render = { ( { field } ) => (
257+ < FormItem className = "flex flex-col" >
258+ < FormLabel > Surgery Date</ FormLabel >
259+ < FormControl >
260+ < DatePicker onSelect = { field . onChange } selected = { field . value || undefined } />
261+ </ FormControl >
262+ < FormMessage />
263+ </ FormItem >
264+ ) }
265+ />
266+ < FormField
267+ name = "doa"
268+ control = { form . control }
269+ render = { ( { field } ) => (
270+ < FormItem className = "flex flex-col" >
271+ < FormLabel > Date of Admission</ FormLabel >
272+ < FormControl >
273+ < DatePicker onSelect = { field . onChange } selected = { field . value || undefined } />
274+ </ FormControl >
275+ < FormMessage />
276+ </ FormItem >
277+ ) }
278+ />
279+ < FormField
280+ name = "dod"
281+ control = { form . control }
282+ render = { ( { field } ) => (
283+ < FormItem className = "flex flex-col" >
284+ < FormLabel > Date of Discharge</ FormLabel >
285+ < FormControl >
286+ < DatePicker onSelect = { field . onChange } selected = { field . value || undefined } />
287+ </ FormControl >
288+ < FormMessage />
289+ </ FormItem >
290+ ) }
291+ />
253292 </ div >
254293
255294 < div className = "flex flex-col mt-4" >
0 commit comments