get('view_type', 'mis'); $patientId = $request->get('patient_id'); if ($viewType == 'foxpro') $patient = SiSttMedicalHistory::where('keykarta', $id)->first(); else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first(); if($patient instanceof MisSttMedicalHistory) { if ($patient->archiveHistory->count() === 0) { $foxproCardId = $patient->archiveInfo->foxpro_history_id; $foxproPatient = SiSttMedicalHistory::where('keykarta', $foxproCardId)->first(); $journalHistory = $foxproPatient->archiveHistory; } else { $journalHistory = $patient->archiveHistory; } } else { $journalHistory = $patient->archiveHistory; } $archiveInfo = $patient->archiveInfo ? $patient->archiveInfo : null; $patientInfo = [ 'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class, 'info' => [ 'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class, ...PatientInfoResource::make($patient)->toArray(request()), 'can_be_issued' => $patient->canBeIssued() ], 'journal' => ArchiveHistoryResource::collection($journalHistory), 'archiveInfo' => $archiveInfo ? ArchiveInfoResource::make($archiveInfo) : null ]; return response()->json($patientInfo); } }