import InputError from '@/components/input-error';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import AppLayout from '@/layouts/app-layout';
import { type BreadcrumbItem } from '@/types';
import { Head, useForm } from '@inertiajs/react';
interface RegistrationFormProps {
mode: 'create' | 'edit';
registration?: {
id?: string;
registration_number: string;
patient_id: string;
employee_id: string;
service_room_id: string;
insurance_id: string;
registration_type: string;
patient_type: string;
registration_datetime: string;
discharge_datetime?: string;
estimated_discharge?: string;
complaint: string;
medical_notes?: string;
diagnoses?: any[];
prescriptions?: any[];
status: string;
payment_status: string;
is_referral: boolean;
referral_from?: string;
need_icu: boolean;
is_active: boolean;
};
patients: { id: string; name: string }[];
employees: { id: string; name: string }[];
serviceRooms: { id: string; name: string }[];
insurances: { id: string; name: string }[];
registrationTypes: string[];
patientTypes: string[];
statusOptions?: string[];
paymentStatusOptions?: string[];
}
const breadcrumbs: BreadcrumbItem[] = [
{ title: 'Dashboard', href: '/dashboard' },
{ title: 'Registrasi Pasien', href: '/registrations' },
{ title: 'Form Registrasi', href: '#' },
];
export default function RegistrationForm({
mode,
registration,
patients = [],
employees = [],
serviceRooms = [],
insurances = [],
registrationTypes = ['Rawat Jalan', 'Rawat Inap', 'UGD'],
patientTypes = ['Umum', 'BPJS', 'Asuransi', 'Perusahaan', 'Gratis'],
statusOptions = ['registered', 'in_progress', 'completed', 'cancelled'],
paymentStatusOptions = ['unpaid', 'partial', 'paid', 'insurance_cover'],
}: RegistrationFormProps) {
const { data, setData, post, put, processing, errors, reset } = useForm({
registration_number: registration?.registration_number || '',
patient_id: registration?.patient_id || '',
employee_id: registration?.employee_id || '',
service_room_id: registration?.service_room_id || '',
insurance_id: registration?.insurance_id || '',
registration_type: registration?.registration_type || 'Rawat Jalan',
patient_type: registration?.patient_type || 'Umum',
registration_datetime: registration?.registration_datetime || new Date().toISOString(),
estimated_discharge: registration?.estimated_discharge || '',
complaint: registration?.complaint || '',
medical_notes: registration?.medical_notes || '',
diagnoses: registration?.diagnoses || [],
prescriptions: registration?.prescriptions || [],
status: registration?.status || 'registered',
payment_status: registration?.payment_status || 'unpaid',
is_referral: registration?.is_referral ?? false,
referral_from: registration?.referral_from || '',
need_icu: registration?.need_icu ?? false,
is_active: registration?.is_active ?? true,
});
const onSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (mode === 'create') {
post(route('registrations.store'), {
onSuccess: () => reset(),
});
} else {
put(route('registrations.update', registration?.id), {
preserveScroll: true,
});
}
};
return (