@extends('layouts.app') @section('title', 'Edit Pasien - MCU Klinik Mustika') @push('styles') @endpush @section('breadcrumb')

Edit Pasien

@endsection @section('content') @canRoute ('patients.update')
@csrf @method ('PUT') {{-- Hidden inputs untuk field yang tidak ditampilkan di form agar nilai lama tetap terkirim --}}
Data Pasien
@error ('name')
{{ $message }}
@enderror
@error ('nickname')
{{ $message }}
@enderror
@error ('nik')
{{ $message }}
@enderror
@error ('religion')
{{ $message }}
@enderror
@error ('gender')
{{ $message }}
@enderror
@error ('birth_date')
{{ $message }}
@enderror
@error ('birth_place')
{{ $message }}
@enderror
@error ('ethnicity')
{{ $message }}
@enderror
@error ('marital_status')
{{ $message }}
@enderror
@error ('number_of_children')
{{ $message }}
@enderror
@error ('blood_type')
{{ $message }}
@enderror
@error ('address')
{{ $message }}
@enderror
{{--
Informasi Kontak
@error('phone_number')
{{ $message }}
@enderror
@error('email')
{{ $message }}
@enderror
@error('emergency_contact_name')
{{ $message }}
@enderror
@error('emergency_contact_phone')
{{ $message }}
@enderror
--}} {{--
Informasi Pekerjaan
@error('company_id')
{{ $message }}
@enderror
@error('job_position')
{{ $message }}
@enderror
@error('occupation')
{{ $message }}
@enderror
@error('mcu_type')
{{ $message }}
@enderror
@error('referral_source')
{{ $message }}
@enderror
--}}
Foto & Dokumen
@if ($patient->photo) {{ $patient->name }} @else

Aktifkan kamera untuk mengambil foto pasien

@endif
Foto pasien menggunakan kamera. Format: JPG, JPEG, PNG @error ('photo')
{{ $message }}
@enderror
Foto pasien berhasil diambil
@if ($patient->ktp_photo) KTP {{ $patient->name }} @else

Aktifkan kamera untuk scan KTP (opsional)

@endif
Foto KTP menggunakan kamera. Format: JPG, JPEG, PNG @error ('ktp_photo')
{{ $message }}
@enderror
Foto KTP berhasil diambil
{{--
Catatan Tambahan
@error('notes')
{{ $message }}
@enderror
--}} @php $latestHealth = $patient->healthQuestionnaires()->latest()->first(); $latestWork = $patient->workActivities()->latest()->first(); $latestFamily = $patient->familyHealthHistories()->latest()->first(); // Ambil data gaya hidup yang terikat ke appointment terkini pasien ini saja, // agar tab Gaya Hidup di edit pasien mencerminkan kondisi MCU terbaru, // tidak tercampur dengan data dari MCU sebelumnya. $latestAppointmentForLifestyle = $patient->appointments()->where('status', '!=', 'cancelled')->latest()->first(); $latestLifestyle = $latestAppointmentForLifestyle ? $patient->lifestyleData()->where('appointment_id', $latestAppointmentForLifestyle->id)->latest()->first() : null; @endphp
Data Tambahan
@if ($latestHealth || $latestWork || $latestFamily || $latestLifestyle) Data tersedia @else Belum ada data @endif
Informasi Kerja Pasien
Data dapat diperbarui sesuai kebutuhan
Detail Pekerjaan
Informasi Perusahaan & Hobi
@php $previousCompanyHistories = collect(); // 1. Ambil dari riwayat appointment/MCU pasien $pastAppointments = $patient ->appointments() ->where('status', '!=', 'cancelled') ->with(['company', 'mcuResult.company', 'workActivity']) ->orderBy('appointment_date', 'desc') ->get(); foreach ($pastAppointments as $apt) { $comp = $apt->company ?? $apt->mcuResult?->company; if ($comp && (int) $comp->id !== (int) $patient->company_id) { $compKey = $comp->id; if (!$previousCompanyHistories->has($compKey)) { $aptWorkActivity = $apt->workActivity; if (!$aptWorkActivity) { $aptWorkActivity = \App\Models\WorkActivity::where('appointment_id', $apt->id)->first(); } if (!$aptWorkActivity) { $aptWorkActivity = \App\Models\WorkActivity::where('patient_id', $patient->id) ->where('created_at', '<=', $apt->created_at ?: now()) ->orderBy('created_at', 'desc') ->first(); } // Resolusi Jabatan di perusahaan sebelumnya $jobPos = null; if ($aptWorkActivity && !empty($aptWorkActivity->occupation) && $aptWorkActivity->occupation !== '-') { $jobPos = $aptWorkActivity->occupation; } if (!$jobPos || $jobPos === '-') { $corpEmp = $patient->corporateInvitationEmployees?->first( fn($emp) => $emp->invitation?->company_id == $comp->id || $emp->company_id == $comp->id, ); if ($corpEmp) { $jobPos = $corpEmp->resolvedPositionName(); } } if (!$jobPos || $jobPos === '-') { $anyCorpEmp = $patient->corporateInvitationEmployees?->first(); if ($anyCorpEmp) { $jobPos = $anyCorpEmp->resolvedPositionName(); } } if (!$jobPos || $jobPos === '-') { $jobPos = $patient->job_position ?? '-'; } // Resolusi Tahun Mulai Bekerja di perusahaan sebelumnya $workStart = null; if ( $aptWorkActivity && !empty($aptWorkActivity->work_start_year) && $aptWorkActivity->work_start_year !== '-' ) { $workStart = $aptWorkActivity->work_start_year; } if (!$workStart || $workStart === '-') { $aptLog = \App\Models\PatientChangeLog::where('appointment_id', $apt->id) ->where('field_name', 'work_start_year') ->whereNotNull('new_value') ->where('new_value', '!=', '-') ->where('new_value', '!=', '') ->orderBy('created_at', 'desc') ->first(); if ($aptLog) { $workStart = $aptLog->new_value; } } if (!$workStart || $workStart === '-') { $compWork = \App\Models\WorkActivity::where('patient_id', $patient->id) ->whereHas('appointment', function ($q) use ($comp) { $q->where('company_id', $comp->id); }) ->whereNotNull('work_start_year') ->where('work_start_year', '!=', '-') ->where('work_start_year', '!=', '') ->latest() ->first(); if ($compWork) { $workStart = $compWork->work_start_year; } } if (!$workStart || $workStart === '-') { $compLog = \App\Models\PatientChangeLog::where('patient_id', $patient->id) ->where('field_name', 'work_start_year') ->whereNotNull('new_value') ->where('new_value', '!=', '-') ->where('new_value', '!=', '') ->where(function ($q) use ($apt) { $q->where('appointment_id', $apt->id)->orWhere('created_at', '<=', $apt->created_at ?: now()); }) ->orderBy('created_at', 'desc') ->first(); if ($compLog) { $workStart = $compLog->new_value; } } if (!$workStart || $workStart === '-') { $prevWork = \App\Models\WorkActivity::where('patient_id', $patient->id) ->where('created_at', '<=', $apt->created_at ?: now()) ->whereNotNull('work_start_year') ->where('work_start_year', '!=', '-') ->where('work_start_year', '!=', '') ->orderBy('created_at', 'desc') ->first(); if ($prevWork) { $workStart = $prevWork->work_start_year; } } $previousCompanyHistories->put($compKey, [ 'company' => $comp, 'company_name' => $comp->name, 'job_position' => $jobPos ?: '-', 'work_start_year' => $workStart ?: '-', 'last_mcu_date' => $apt->appointment_date ? \App\Helpers\DateHelper::formatDate($apt->appointment_date) : null, ]); } } } // 2. Tambahkan previousCompany milik pasien jika belum ada di list (fallback) if ($patient->previousCompany && (int) $patient->previous_company_id !== (int) $patient->company_id) { if (!$previousCompanyHistories->has($patient->previous_company_id)) { $prevCompId = $patient->previous_company_id; $prevCompanyWork = \App\Models\WorkActivity::where('patient_id', $patient->id) ->whereHas('appointment', function ($q) use ($prevCompId) { $q->where('company_id', $prevCompId); }) ->first(); $jobPos = null; if ($prevCompanyWork && !empty($prevCompanyWork->occupation) && $prevCompanyWork->occupation !== '-') { $jobPos = $prevCompanyWork->occupation; } if (!$jobPos || $jobPos === '-') { $corpEmp = $patient->corporateInvitationEmployees?->first( fn($emp) => $emp->invitation?->company_id == $prevCompId || $emp->company_id == $prevCompId, ); if ($corpEmp) { $jobPos = $corpEmp->resolvedPositionName(); } } if (!$jobPos || $jobPos === '-') { $anyCorpEmp = $patient->corporateInvitationEmployees?->first(); if ($anyCorpEmp) { $jobPos = $anyCorpEmp->resolvedPositionName(); } } if (!$jobPos || $jobPos === '-') { $jobPos = $patient->job_position ?? '-'; } $workStart = null; if ( $prevCompanyWork && !empty($prevCompanyWork->work_start_year) && $prevCompanyWork->work_start_year !== '-' ) { $workStart = $prevCompanyWork->work_start_year; } if (!$workStart || $workStart === '-') { $prevCompLog = \App\Models\PatientChangeLog::where('patient_id', $patient->id) ->where('field_name', 'work_start_year') ->whereNotNull('new_value') ->where('new_value', '!=', '-') ->where('new_value', '!=', '') ->whereHas('appointment', function ($q) use ($prevCompId) { $q->where('company_id', $prevCompId); }) ->orderBy('created_at', 'desc') ->first(); if ($prevCompLog) { $workStart = $prevCompLog->new_value; } } $previousCompanyHistories->put($patient->previous_company_id, [ 'company' => $patient->previousCompany, 'company_name' => $patient->previousCompany->name, 'job_position' => $jobPos ?: '-', 'work_start_year' => $workStart ?: '-', 'last_mcu_date' => null, ]); } } // Resolve work_start_year khusus untuk perusahaan saat ini $latestAppt = $patient->appointments()->where('status', '!=', 'cancelled')->latest()->first(); $currentCompanyWorkActivity = null; if ($latestAppt && (int) $latestAppt->company_id === (int) $patient->company_id) { $currentCompanyWorkActivity = \App\Models\WorkActivity::where('appointment_id', $latestAppt->id)->latest()->first(); } if ((!$currentCompanyWorkActivity || !$currentCompanyWorkActivity->work_start_year) && $patient->company_id) { $currentCompanyWorkActivity = \App\Models\WorkActivity::where('patient_id', $patient->id) ->whereHas('appointment', function ($q) use ($patient) { $q->where('company_id', $patient->company_id); }) ->latest() ->first(); } if (!$currentCompanyWorkActivity || !$currentCompanyWorkActivity->work_start_year) { $currentCompanyWorkActivity = \App\Models\WorkActivity::where('patient_id', $patient->id)->latest()->first(); } $currentWorkStartYear = $currentCompanyWorkActivity?->work_start_year; if (!$currentWorkStartYear) { $anyWorkStart = \App\Models\WorkActivity::where('patient_id', $patient->id) ->whereNotNull('work_start_year') ->where('work_start_year', '!=', '') ->latest() ->first(); if ($anyWorkStart) { $currentWorkStartYear = $anyWorkStart->work_start_year; } } @endphp @if ($previousCompanyHistories->isNotEmpty())
Riwayat Perusahaan Sebelumnya ({{ $previousCompanyHistories->count() }}):
@foreach ($previousCompanyHistories as $prevHist) @endforeach
Perusahaan Jabatan Tahun Mulai Bekerja MCU Terakhir
{{ $prevHist['company_name'] }} {{ $prevHist['job_position'] }} {{ $prevHist['work_start_year'] }} {{ $prevHist['last_mcu_date'] ?? '-' }}
@endif
Pilih perusahaan terdaftar @error ('company_id')
{{ $message }}
@enderror {{ $patient->company->address ?? 'Alamat tidak tersedia' }}
@php $selectedJobPosition = trim((string) old('job_position', $patient->job_position ?? '')); $selectedCompanyId = old('company_id', $patient->company_id); $companyJobPositions = collect(); if ($selectedCompanyId) { $jobPositionIds = \App\Models\MatrixRule::where('company_id', $selectedCompanyId) ->distinct('client_job_position_id') ->pluck('client_job_position_id') ->toArray(); $companyJobPositions = \App\Models\ClientJobPosition::whereIn('id', $jobPositionIds)->get(); } $hasSelectedJobInOptions = $companyJobPositions->contains(function ($jobPosition) use ($selectedJobPosition) { return mb_strtolower(trim((string) $jobPosition->name)) === mb_strtolower($selectedJobPosition); }); @endphp @if ($selectedCompanyId && $companyJobPositions->count() > 0) Pilih jabatan dari daftar yang tersedia untuk perusahaan ini @else Masukkan jabatan/posisi di perusahaan @endif @error ('job_position')
{{ $message }}
@enderror
Isi tahun (4 digit) atau tanda "-" jika tidak diketahui @error ('work_start_year')
{{ $message }}
@enderror
Kegiatan yang Anda sukai di waktu luang @error ('hobby')
{{ $message }}
@enderror
Deskripsi singkat aktivitas harian Anda @error ('activities')
{{ $message }}
@enderror

@if ($patient->company) Karyawan Perusahaan @else Pasien Individu @endif

Status berdasarkan data perusahaan
@if ($patient->company)
Informasi Tambahan Perusahaan

Email: {{ $patient->company->email ?? 'Tidak tersedia' }}

Telepon: {{ $patient->company->phone ?? 'Tidak tersedia' }}

Kontak Person: {{ $patient->company->contact_person ?? 'Tidak tersedia' }}

Status: @if ($patient->company->is_active) Aktif @else Tidak Aktif @endif

@else
Perhatian

Pasien ini tidak terdaftar dalam perusahaan manapun. Jika perlu menambahkan ke perusahaan, silakan edit data pasien dan pilih perusahaan yang sesuai.

@endif
@if ($latestWork)
Data aktivitas kerja sudah tersedia
Diperbarui: {{ \App\Helpers\DateHelper::formatShort($latestWork->updated_at) }} {{ $latestWork->updated_at->format('H:i') }}
@endif {{--
Kegiatan Waktu Kerja
--}} @php $workActivities = [ 'operates_moving_equipment' => 'Sopir / mengoperasikan peralatan bergerak (mobil, crane, alat lainnya)', 'works_at_height' => 'Bekerja di ketinggian (tangga, Lift, eskalator)', 'works_in_office' => 'Bekerja di perkantoran', 'works_in_noisy_place' => 'Bekerja di tempat bising', 'works_in_dusty_place' => 'Bekerja di tempat berdebu', 'needs_color_accuracy' => 'Perlu keakuratan warna, kode lampu warna', 'is_catering_staff' => 'Staff Catering (seluruh personal yang mengelola makanan)', 'handles_dangerous_materials' => 'Berhubungan dengan bahan yang berpotensi membahayakan', ]; $protectionMap = [ 'operates_moving_equipment' => 'moving_equipment', 'works_at_height' => 'height', 'works_in_office' => 'office', 'works_in_noisy_place' => 'noise', 'works_in_dusty_place' => 'dusty', 'needs_color_accuracy' => 'color', 'is_catering_staff' => 'catering', 'handles_dangerous_materials' => 'dangerous', ]; @endphp
@foreach ($workActivities as $field => $label) @php $protectionKey = $protectionMap[$field] ?? ''; $usesProtection = $protectionKey && $latestWork && $latestWork->{"uses_{$protectionKey}_protection"}; $protectionDetails = $protectionKey && $latestWork ? $latestWork->{"{$protectionKey}_protection_details"} : ''; @endphp @endforeach
Kegiatan Waktu Kerja Y/N Memakai Perlindungan Y/N
{{ $label }}
$field ? 'checked' : '' }} >
@if ($latestHealth)
Data riwayat kesehatan sudah tersedia
Diperbarui: {{ \App\Helpers\DateHelper::formatShort($latestHealth->updated_at) }} {{ $latestHealth->updated_at->format('H:i') }}
@endif {{--
Riwayat Kesehatan
--}} @php $healthConditions = [ 'column1' => [ 'has_head_injury' => 'Cedera Kepala', 'has_seizure' => 'Ayan', 'has_vision_disorder' => 'Gangguan Penglihatan', 'has_hearing_disorder' => 'Gangguan Pendengaran', 'has_ear_nose_throat_problem' => 'Masalah Pada Telinga, Hidung', 'has_ear_problem_4weeks' => 'Masalah Telinga > 4 Minggu', 'has_womens_health_issue' => 'Masalah Kewanitaan', 'has_chronic_skin_problem' => 'Penyakit Kulit Menahun', 'has_chronic_diarrhea_issue' => 'Diare Kronis', 'has_appetite_loss_4weeks' => 'Nafsu Makan Menurun > 4 mgg', 'has_gastritis_ulcer' => 'Gastritis / Radang Lambung', ], 'column2' => [ 'has_yellow_fever_hepatitis' => 'Sakit Kuning / Hepatitis', 'has_chronic_cough_issue' => 'Batuk Kronis', 'has_hemorrhoids_issue' => 'Ambeien / Hemoroid', 'has_chronic_abdominal_pain' => 'Nyeri Perut Kronis', 'has_sexual_transmitted_disease' => 'Penyakit Kelamin', 'has_diabetes_mellitus' => 'Kencing Manis / Diabetes', 'has_asthma_shortness' => 'Asma / Sesak Napas', 'has_allergy_issue' => 'Alergi', 'has_tuberculosis' => 'TB Paru', 'has_mental_health_problem' => 'Masalah Kejiwaan', 'has_hypertension_issue' => 'Tekanan Darah Tinggi', ], 'column3' => [ 'has_heart_chest_pain' => 'Nyeri Dada / Jantung', 'has_malaria_disease' => 'Malaria', 'has_surgical_operation' => 'Operasi Pembedahan', 'has_abnormal_weight_change' => 'Perubahan BB tdk normal', 'has_back_pain_4weeks' => 'Nyeri Pinggang > 4 mgg', 'has_typhoid_fever' => 'Demam Thyfoid', 'has_joint_swelling_pain' => 'Bengkak / Nyeri pd sendi', 'has_kidney_stone_disease' => 'Kencing Batu / Ginjal', ], ]; @endphp
@php // Pad arrays to ensure they have the same length $column1Items = array_keys($healthConditions['column1']); $column2Items = array_keys($healthConditions['column2']); $column3Items = array_keys($healthConditions['column3']); $maxRows = max(count($column1Items), count($column2Items), count($column3Items)); // Pad arrays with null values to make them same length $column1Items = array_pad($column1Items, $maxRows, null); $column2Items = array_pad($column2Items, $maxRows, null); $column3Items = array_pad($column3Items, $maxRows, null); @endphp @for ($i = 0; $i < $maxRows; $i++) @endfor
Apakah Anda Pernah Menderita Y/N Apakah Anda Pernah Menderita Y/N Apakah Anda Pernah Menderita Y/N
@if ($column1Items[$i]) {{ $healthConditions['column1'][$column1Items[$i]] }} @endif @if ($column1Items[$i])
{$column1Items[$i]} ? 'checked' : '' }} >
@endif
@if ($column2Items[$i]) {{ $healthConditions['column2'][$column2Items[$i]] }} @endif @if ($column2Items[$i])
{$column2Items[$i]} ? 'checked' : '' }} >
@endif
@if ($column3Items[$i]) {{ $healthConditions['column3'][$column3Items[$i]] }} @endif @if ($column3Items[$i])
{$column3Items[$i]} ? 'checked' : '' }} >
@endif
@if ($latestFamily)
Data riwayat keluarga sudah tersedia
Diperbarui: {{ \App\Helpers\DateHelper::formatShort($latestFamily->updated_at) }} {{ $latestFamily->updated_at->format('H:i') }}
@endif {{--
Riwayat Kesehatan Keluarga
--}} @php $familyMembers = [ 'father' => 'Bapak', 'mother' => 'Ibu', 'siblings' => 'Saudara', 'others' => 'Lain-lain', ]; $healthConditions = [ 'diabetes' => 'Diabetes', 'hypertension' => 'Hipertensi', ]; @endphp
@foreach ($familyMembers as $key => $label) @foreach ($healthConditions as $conditionKey => $conditionLabel) @php $familyDbVal = optional($latestFamily)->{$key . '_' . $conditionKey}; $familySelectedVal = old( 'family_' . $key . '_' . $conditionKey, match ($familyDbVal) { 'Ya' => 'yes', 'Tidak' => 'no', 'Tidak Tahu' => 'unknown', default => '', }, ); @endphp @endforeach @endforeach
Anggota Keluarga Diabetes Hipertensi Penyakit Lainnya
{{ $label }}
@if ($latestLifestyle)
Data gaya hidup sudah tersedia
Diperbarui: {{ \App\Helpers\DateHelper::formatShort($latestLifestyle->updated_at) }} {{ $latestLifestyle->updated_at->format('H:i') }}
@endif
Gaya Hidup
consumes_alcohol : '', ) === '1' ? 'checked' : '' }} >
consumes_alcohol : '', ) === '0' ? 'checked' : '' }} >
is_smoker : '', ) === '1' ? 'checked' : '' }} >
is_smoker : '', ) === '0' ? 'checked' : '' }} >
Tuliskan nama obat yang dikonsumsi rutin
medication_prescription) === 'DENGAN RESEP DOKTER' ? 'checked' : '' }} >
medication_prescription) === 'TANPA RESEP DOKTER' ? 'checked' : '' }} >
Pilih sesuai dengan status resep obat
@canRoute ('patients.show') Batal @endcanRoute
@endcanRoute @endsection @push('scripts') @include('pendaftaran.partials.js.camera-functions') @endpush