first commit
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\controller\tcm;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\logic\tcm\PrescriptionLibraryAiLogic;
|
||||
use app\adminapi\logic\tcm\PrescriptionLibraryLogic;
|
||||
use app\adminapi\validate\tcm\PrescriptionLibraryValidate;
|
||||
|
||||
/**
|
||||
* 处方库控制器
|
||||
*/
|
||||
class PrescriptionLibraryController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @notes 处方库列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new \app\adminapi\lists\tcm\PrescriptionLibraryLists());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加处方库
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->post()->goCheck('add');
|
||||
$params['creator_id'] = $this->adminId;
|
||||
$params['creator_name'] = $this->adminInfo['name'] ?? '';
|
||||
$id = PrescriptionLibraryLogic::add($params);
|
||||
if ($id === null) {
|
||||
return $this->fail(PrescriptionLibraryLogic::getError());
|
||||
}
|
||||
return $this->success('保存成功', ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑处方库
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->post()->goCheck('edit');
|
||||
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
||||
$result = PrescriptionLibraryLogic::edit($params, $this->adminId, $canAll);
|
||||
if (!$result) {
|
||||
return $this->fail(PrescriptionLibraryLogic::getError());
|
||||
}
|
||||
return $this->success('编辑成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除处方库
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->post()->goCheck('delete');
|
||||
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
||||
$result = PrescriptionLibraryLogic::delete((int) $params['id'], $this->adminId, $canAll);
|
||||
if (!$result) {
|
||||
return $this->fail(PrescriptionLibraryLogic::getError());
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 处方库详情
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->get()->goCheck('detail');
|
||||
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
||||
$detail = PrescriptionLibraryLogic::detail((int) $params['id'], $this->adminId, $canAll);
|
||||
if (!$detail) {
|
||||
return $this->fail('处方不存在或无权限查看');
|
||||
}
|
||||
return $this->data($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 读取已保存的双模型 AI 解释,不触发上游调用
|
||||
*/
|
||||
public function aiReports()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->get()->goCheck('aiReports');
|
||||
$reports = PrescriptionLibraryAiLogic::getSavedReports(
|
||||
(int) $params['id'],
|
||||
$this->adminId,
|
||||
$this->adminInfo
|
||||
);
|
||||
if ($reports === null) {
|
||||
return $this->fail(PrescriptionLibraryAiLogic::getError());
|
||||
}
|
||||
return $this->data($reports);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查询当前数据范围内完全没有 AI 报告的处方,不触发上游调用
|
||||
*/
|
||||
public function missingAiReports()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->get()->goCheck('missingAiReports');
|
||||
$result = PrescriptionLibraryAiLogic::getMissingReports(
|
||||
(int) ($params['limit'] ?? 500),
|
||||
$this->adminId,
|
||||
$this->adminInfo
|
||||
);
|
||||
if ($result === null) {
|
||||
return $this->fail(PrescriptionLibraryAiLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 整份重新生成两个固定模型的 AI 解释并保存成功项
|
||||
*/
|
||||
public function generateAiReports()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->post()->goCheck('generateAiReports');
|
||||
$reports = PrescriptionLibraryAiLogic::generateAll(
|
||||
(int) $params['id'],
|
||||
$this->adminId,
|
||||
$this->adminInfo
|
||||
);
|
||||
if ($reports === null) {
|
||||
return $this->fail(PrescriptionLibraryAiLogic::getError());
|
||||
}
|
||||
return $this->data($reports);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑一份已保存的 AI 解释
|
||||
*/
|
||||
public function editAiReport()
|
||||
{
|
||||
$params = (new PrescriptionLibraryValidate())->post()->goCheck('editAiReport');
|
||||
$report = PrescriptionLibraryAiLogic::editReport(
|
||||
(int) $params['id'],
|
||||
(int) $params['report_id'],
|
||||
$params['content'] ?? null,
|
||||
$this->adminId,
|
||||
$this->adminInfo
|
||||
);
|
||||
if ($report === null) {
|
||||
return $this->fail(PrescriptionLibraryAiLogic::getError());
|
||||
}
|
||||
return $this->data($report);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user