(
+const InfoItem = ({ icon: Icon, label, iconBg, iconColor, children }: InfoItemProps) => (
{label}
-
{value || 'N/A'}
+ {children}
)
-// ============================================================
-// Doctor List Component
-// ============================================================
-interface DoctorListProps {
- doctors: DoctorModel[] | undefined
- emptyMessage: string
-}
-
-const DoctorList = ({ doctors, emptyMessage }: DoctorListProps) => {
- if (!doctors || doctors.length === 0) {
- return
{emptyMessage}
- }
-
- return (
-
- {doctors.map((doctor) => (
- -
-
-
-
- Dr. {doctor.name}
-
- {doctor.designation && (
- ({doctor.designation})
- )}
-
-
- ))}
-
- )
-}
-
// ============================================================
// Followup Card Component
// ============================================================
@@ -245,6 +217,7 @@ export const ViewSurgery = () => {
const { patientId, surgeryId } = useParams()
const { setBreadcrumbs } = useBreadcrumbs()
const { settings } = useSettings()
+ const queryClient = useQueryClient()
const { data: patient } = useQuery({
...getPatientByIdQuery(parseInt(patientId!)),
@@ -279,6 +252,86 @@ export const ViewSurgery = () => {
const noFollowups = !isFollowupLoading && followups && followups.length === 0
+ // ============================================================
+ // Field Update Mutations
+ // ============================================================
+ const updateSurgeryMutation = useMutation({
+ mutationFn: async (data: { field: string; value: unknown }) => {
+ if (!surgery) throw new Error('Surgery not found')
+ const { result, error } = await window.api.invoke('updateSurgery', surgery.id, {
+ [data.field]: data.value
+ })
+ if (error) throw new Error(error.message)
+ return result
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: queries.surgeries.get(parseInt(surgeryId!)).queryKey })
+ toast.success('Updated successfully')
+ },
+ onError: (error) => {
+ toast.error(`Failed to update: ${error.message}`)
+ }
+ })
+
+ const updateDoctorsDoneByMutation = useMutation({
+ mutationFn: async (doctorIds: number[]) => {
+ if (!surgery) throw new Error('Surgery not found')
+ return unwrapResult(window.api.invoke('updateSurgeryDoctorsDoneBy', surgery.id, doctorIds))
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: queries.surgeries.get(parseInt(surgeryId!)).queryKey })
+ toast.success('Surgeons updated')
+ },
+ onError: (error) => {
+ toast.error(`Failed to update surgeons: ${error.message}`)
+ }
+ })
+
+ const updateDoctorsAssistedByMutation = useMutation({
+ mutationFn: async (doctorIds: number[]) => {
+ if (!surgery) throw new Error('Surgery not found')
+ return unwrapResult(window.api.invoke('updateSurgeryDoctorsAssistedBy', surgery.id, doctorIds))
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: queries.surgeries.get(parseInt(surgeryId!)).queryKey })
+ toast.success('Assistants updated')
+ },
+ onError: (error) => {
+ toast.error(`Failed to update assistants: ${error.message}`)
+ }
+ })
+
+ // ============================================================
+ // Field Update Handlers
+ // ============================================================
+ const handleUpdateTextField = useCallback(
+ (field: string) => async (value: string) => {
+ await updateSurgeryMutation.mutateAsync({ field, value })
+ },
+ [updateSurgeryMutation]
+ )
+
+ const handleUpdateDateField = useCallback(
+ (field: string) => async (value: Date | null) => {
+ await updateSurgeryMutation.mutateAsync({ field, value: value ? +value : null })
+ },
+ [updateSurgeryMutation]
+ )
+
+ const handleUpdateDoneBy = useCallback(
+ async (doctorIds: number[]) => {
+ await updateDoctorsDoneByMutation.mutateAsync(doctorIds)
+ },
+ [updateDoctorsDoneByMutation]
+ )
+
+ const handleUpdateAssistedBy = useCallback(
+ async (doctorIds: number[]) => {
+ await updateDoctorsAssistedByMutation.mutateAsync(doctorIds)
+ },
+ [updateDoctorsAssistedByMutation]
+ )
+
return (
{
onClick={() => navigate(`/patients/${patientId}/surgeries/${surgeryId}/edit`)}
>
- Edit
+ Edit All
>
}
@@ -341,39 +394,66 @@ export const ViewSurgery = () => {
+ >
+
+
+ >
+
+
+ >
+
+
+ >
+
+
+ >
+
+
@@ -395,131 +475,97 @@ export const ViewSurgery = () => {
- {/* Operative Notes Card */}
-
-
-
-
-
-
-
- Operative Notes
-
-
-
-
- {!isEmptyHtml(surgery.notes) ? (
-
-
-
- ) : (
-
- )}
-
-
-
- {/* Post-Op Notes Card */}
-
-
-
-
-
-
-
- Post-Operative Care
-
+
-
-
- {!isEmptyHtml(surgery.post_op_notes) ? (
-
-
-
- ) : (
-
- )}
-
-
-
- {/* Inward Management Card */}
-
-
-
-
-
- Inward Management
-
-
-
-
- {!isEmptyHtml(surgery.inward_management) ? (
-
-
-
- ) : (
-
- )}
- {/* Discharge Plan Card - only show if content exists */}
- {!isEmptyHtml(surgery.discharge_plan) && (
-