user()?->name;
$data['issue_datetime'] = now();
$data['medication_ids'] = $data['medication_order'] ?? $data['medication_ids'] ?? [];
$content = $data['content'] ?? '';
if (empty($content) && ! empty($data['medication_ids'])) {
$medications = Medication::whereIn('id', $data['medication_ids'])->get()->keyBy('id');
$data['content'] = '
' . collect($data['medication_ids'])->map(fn ($id) => isset($medications[$id])
? '- ' . implode(' ', array_filter([
$medications[$id]->dosage_form,
$medications[$id]->name,
$medications[$id]->strength,
$medications[$id]->quantity ? '#' . $medications[$id]->quantity : null,
$medications[$id]->timing,
])) . '
'
: ''
)->filter()->implode('') . '
';
}
$labTestIds = $data['lab_test_ids'] ?? [];
$labContent = $data['lab_content'] ?? '';
if (empty($labContent) && ! empty($labTestIds)) {
$tests = LabTest::whereIn('id', $labTestIds)->orderBy('name')->get();
$data['lab_content'] = '' . $tests->map(fn ($t) => '- ' . $t->name . '
')->implode('') . '
';
}
return $data;
}
protected function getFormActions(): array
{
return [];
}
protected function getRedirectUrl(): string
{
$record = $this->getRecord();
if ($this->printType === 'prescription') {
return route('prescription.print', $record);
}
if ($this->printType === 'lab') {
return route('prescription.print', ['prescription' => $record, 'type' => 'lab']);
}
if ($this->printType === 'both') {
return route('prescription.print', ['prescription' => $record, 'type' => 'both']);
}
if ($this->printType === 'admission') {
return route('prescription.print.admission', $record);
}
return static::getResource()::getUrl('index');
}
}