287 lines
13 KiB
PHP
287 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Enums\Gender;
|
|
use App\Admin\Components;
|
|
use App\Admin\Services\PatientService;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
use App\Models\{Keyword, Patient};
|
|
use Illuminate\Http\Request;
|
|
use Slowlyo\OwlAdmin\Services\AdminUserService;
|
|
use Slowlyo\OwlAdmin\Support\Excel\AdminExport;
|
|
|
|
/**
|
|
* 病人管理
|
|
*/
|
|
class PatientController extends AdminController
|
|
{
|
|
protected string $serviceName = PatientService::class;
|
|
|
|
protected $typeOptions;
|
|
|
|
protected $adminUserOptions;
|
|
|
|
public function list(): Page
|
|
{
|
|
$crud = $this->baseCRUD()
|
|
->filterTogglable(false)
|
|
->columnsTogglable(false)
|
|
->headerToolbar([
|
|
$this->createButton(true, 'lg'),
|
|
amis('reload')->align('right'),
|
|
$this->exportAction(),
|
|
])
|
|
->filter($this->baseFilter()->actions()->body([
|
|
amisMake()->SelectControl()->options($this->getTypeOptions())->name('type_id')->label(__('patient.type_id'))->size('md')->clearable(),
|
|
amisMake()->TextControl()->name('keyword')->label(__('patient.keyword'))->placeholder(__('patient.name') . '/' . __('patient.phone'))->size('md')->clearable(),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('doctor_id')->label(__('patient.doctor_id'))->size('md')->clearable(),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('inviter_id')->label(__('patient.inviter_id'))->size('md')->clearable(),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('saler_id')->label(__('patient.saler_id'))->size('md')->clearable(),
|
|
// amisMake()->Button()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
|
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
|
]))
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('patient.id')),
|
|
amisMake()->TableColumn()->name('type.name')->label(__('patient.type_id')),
|
|
amisMake()->TableColumn()->name('name')->label(__('patient.name')),
|
|
amisMake()->TableColumn()->name('sex_text')->label(__('patient.sex')),
|
|
amisMake()->TableColumn()->name('phone')->label(__('patient.phone')),
|
|
amisMake()->TableColumn()->name('age')->label(__('patient.age')),
|
|
amisMake()->TableColumn()->name('treat_format')->label(__('patient.treat_at')),
|
|
amisMake()->TableColumn()->name('doctor.name')->label(__('patient.doctor_id')),
|
|
amisMake()->TableColumn()->name('inviter.name')->label(__('patient.inviter_id')),
|
|
amisMake()->TableColumn()->name('saler.name')->label(__('patient.saler_id')),
|
|
$this->rowActions(),
|
|
])
|
|
->alwaysShowPagination();
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form(): Form
|
|
{
|
|
return $this->baseForm()->body([
|
|
amisMake()->SelectControl()->options($this->getTypeOptions())->name('type_id')->label(__('patient.type_id'))->required(),
|
|
amisMake()->TextControl()->name('name')->label(__('patient.name'))->required(true),
|
|
amisMake()->SelectControl()->options(Gender::options())->name('sex')->label(__('patient.sex')),
|
|
amisMake()->TextControl()->name('phone')->label(__('patient.phone')),
|
|
amisMake()->TextControl()->name('address')->label(__('patient.address')),
|
|
amisMake()->DateControl()->name('birthday')->label(__('patient.birthday')),
|
|
amisMake()->DateControl()->name('treat_at')->label(__('patient.treat_at')),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('doctor_id')->label(__('patient.doctor_id')),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('inviter_id')->label(__('patient.inviter_id')),
|
|
amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('saler_id')->label(__('patient.saler_id')),
|
|
amisMake()->ImageControl()->multiple()->receiver(admin_url('upload_image') . '?full-url=1')->name('images')->label(__('patient.images')),
|
|
// Components::make()->fuEditorControl()->name('illness')->label(__('patient.illness')),
|
|
amisMake()->TextareaControl()->name('illness')->label(__('patient.illness')),
|
|
]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
if ($this->actionOfGetData()) {
|
|
return $this->response()->success($this->service->getDetail($id));
|
|
}
|
|
|
|
$record = new PatientRecordController();
|
|
$detail = amisMake()
|
|
->Card()
|
|
->className('base-form')
|
|
->header(['title' => __('admin.detail')])
|
|
->body($this->detail($id))
|
|
->toolbar([
|
|
amisMake()->Button()->label('修改基础信息')
|
|
->level('primary')
|
|
->className('mr-1')
|
|
->actionType('dialog')
|
|
->dialog(amisMake()->Dialog()->size('lg')->title('修改基础信息')->body(
|
|
$this->form(true)->api($this->getUpdatePath())->initApi($this->getEditGetDataPath())->onEvent([
|
|
'submitSucc' => [
|
|
'actions' => [
|
|
['actionType' => 'custom', 'script' => 'window.$owl.refreshAmisPage()',]
|
|
]
|
|
]
|
|
])
|
|
)),
|
|
amisMake()->Button()->label('添加病历记录')
|
|
->level('warning')
|
|
->className('mr-1')
|
|
->actionType('dialog')
|
|
->dialog(amisMake()->Dialog()->size('lg')->title('添加病历记录')->body(
|
|
$record->form(false, $id)->api('post:' . admin_url('/record'))->onEvent([
|
|
'submitSucc' => [
|
|
'actions' => [
|
|
['actionType' => 'custom', 'script' => 'window.$owl.refreshAmisPage()',]
|
|
]
|
|
]
|
|
])
|
|
)),
|
|
$this->backButton()
|
|
]);
|
|
|
|
$page = $this->basePage()->body($detail);
|
|
|
|
return $this->response()->success($page);
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
return $this->baseDetail()->body(amisMake()->Tabs()->tabs([
|
|
amisMake()->Tab()->title('基础信息')->body([
|
|
amisMake()->TextControl()->name('name')->label(__('patient.name'))->static(),
|
|
amisMake()->SelectControl()->options(Gender::options())->name('sex')->label(__('patient.sex'))->static(),
|
|
amisMake()->TextControl()->name('phone')->label(__('patient.phone'))->static(),
|
|
amisMake()->TextControl()->name('address')->label(__('patient.address'))->static(),
|
|
amisMake()->DateControl()->name('birthday')->label(__('patient.birthday'))->static(),
|
|
amisMake()->DateControl()->name('treat_format')->label(__('patient.treat_at'))->static(),
|
|
amisMake()->TextControl()->name('images')->label(__('patient.images'))->static()->staticSchema(amisMake()->Images()),
|
|
amisMake()->TextControl()->name('doctor.name')->label(__('patient.doctor_id'))->static(),
|
|
amisMake()->TextControl()->name('inviter.name')->label(__('patient.inviter_id'))->static(),
|
|
amisMake()->TextControl()->name('saler.name')->label(__('patient.saler_id'))->static(),
|
|
// Components::make()->fuEditorControl()->name('illness')->label(__('patient.illness'))->static(),
|
|
amisMake()->TextareaControl()->name('illness')->label(__('patient.illness'))->static(),
|
|
amisMake()->TextControl()->name('created_at')->label(__('patient.created_at'))->static(),
|
|
]),
|
|
amisMake()->Tab()->title('病历记录')->body(amisMake()->Service()
|
|
->api(admin_url('/record?_action=getData&page=1&patient_id='.$id.'&perPage=20'))
|
|
->body(amisMake()->Table()->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('patient-record.id')),
|
|
amisMake()->Mapping()->map($this->getTypeOptions()->pluck('label', 'value'))->name('type_id')->label(__('patient-record.type_id')),
|
|
amisMake()->TableColumn()->name('treat_at')->label(__('patient-record.treat_at')),
|
|
amisMake()->TableColumn()->name('next_treat_at')->label(__('patient-record.next_treat_at')),
|
|
amisMake()->TableColumn()->name('doctor.name')->label(__('patient-record.doctor_id')),
|
|
])->affixRow([
|
|
amisMake()->Button()->level('link')->label('查看更多')->colSpan(5)->actionType('link')->link(admin_url('/record?patient_id=' . $id)),
|
|
])
|
|
)
|
|
)
|
|
]));
|
|
}
|
|
|
|
public function getTypeOptions()
|
|
{
|
|
if (!$this->typeOptions) {
|
|
$this->typeOptions = Keyword::where('type_key', 'treat_type')->select(['id as value', 'name as label'])->get();
|
|
}
|
|
|
|
return $this->typeOptions;
|
|
}
|
|
|
|
public function getSelectOptions(Request $request)
|
|
{
|
|
$list = Patient::filter($request->all())->select(['id as value', 'name as label'])->sort()->get();
|
|
|
|
return $this->response()->success([
|
|
'items' => $list->items()
|
|
]);
|
|
}
|
|
public function getAdminUserOptions()
|
|
{
|
|
if (!$this->adminUserOptions) {
|
|
$this->adminUserOptions = AdminUserService::make()->query()->select(['id as value', 'name as label'])->get();
|
|
}
|
|
|
|
return $this->adminUserOptions;
|
|
}
|
|
|
|
protected function exportAction($disableSelectedItem = false)
|
|
{
|
|
$event = fn($script) => ['click' => ['actions' => [['actionType' => 'custom', 'script' => $script]]]];
|
|
$downloadPath = '/' . admin_url('_download_export', true);
|
|
$exportPath = $this->getExportPath();
|
|
$doAction = <<<JS
|
|
doAction([
|
|
{ actionType: "ajax", args: { api: { url: url.toString(), method: "get" } } },
|
|
{
|
|
actionType: "custom",
|
|
expression: "\${event.data.responseResult.responseStatus === 0}",
|
|
script: "window.open('{$downloadPath}?path='+event.data.responseResult.responseData.path)"
|
|
}
|
|
])
|
|
JS;
|
|
$buttons = [
|
|
amisMake()->VanillaAction()->label(__('admin.export.all'))->onEvent(
|
|
$event(<<<JS
|
|
let url = new URL("{$exportPath}", window.location.origin)
|
|
let param = window.location.href.split('?')[1]
|
|
if (param) {
|
|
url = url + '&' + param
|
|
}
|
|
{$doAction}
|
|
JS
|
|
|
|
)
|
|
),
|
|
];
|
|
return amisMake()
|
|
->DropdownButton()
|
|
->label(__('admin.export.title'))
|
|
->set('icon', 'fa-solid fa-download')
|
|
->buttons($buttons)
|
|
->align('right')
|
|
->closeOnClick();
|
|
}
|
|
|
|
protected function export()
|
|
{
|
|
// 默认在 storage/app/ 下
|
|
$path = sprintf('%s-%s.xlsx', $this->exportFileName(), date('YmdHis'));
|
|
|
|
// 导出本页和导出选中项都是通过 _ids 查询
|
|
$ids = request()->input('_ids');
|
|
|
|
// listQuery() 为列表查询条件,与获取列表数据一致
|
|
$query = $this->service->listQuery()
|
|
->when($ids, fn($query) => $query->whereIn($this->service->primaryKey(), explode(',', $ids)));
|
|
|
|
// 此处使用 laravel-excel 导出,可自行修改
|
|
AdminExport::make($query)
|
|
->setHeadings($this->exportHeadings())
|
|
->setMap(fn($row) => $this->exportColumns($row))
|
|
->store($path);
|
|
|
|
return $this->response()->success(compact('path'));
|
|
}
|
|
|
|
protected function exportHeadings()
|
|
{
|
|
return [
|
|
__('patient.id'),
|
|
__('patient.type_id'),
|
|
__('patient.name'),
|
|
__('patient.sex'),
|
|
__('patient.phone'),
|
|
__('patient.address'),
|
|
__('patient.birthday'),
|
|
__('patient.age'),
|
|
__('patient.treat_at'),
|
|
__('patient.doctor_id'),
|
|
__('patient.inviter_id'),
|
|
__('patient.saler_id'),
|
|
__('patient.created_at'),
|
|
];
|
|
}
|
|
|
|
protected function exportColumns($row)
|
|
{
|
|
return [
|
|
$row->id,
|
|
$row->type?->name,
|
|
$row->name,
|
|
$row->sex->text(),
|
|
$row->phone,
|
|
$row->address,
|
|
$row->birthday_format,
|
|
$row->age,
|
|
$row->treat_format,
|
|
$row->doctor?->name,
|
|
$row->inviter?->name,
|
|
$row->saler?->name,
|
|
$row->created_at,
|
|
];
|
|
}
|
|
}
|