Files
zyt/server/app/adminapi/controller/tcm/PrescriptionController.php
T
2026-03-18 14:53:09 +08:00

86 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace app\adminapi\controller\tcm;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\logic\tcm\PrescriptionLogic;
use app\adminapi\validate\tcm\PrescriptionValidate;
/**
* 中医处方单控制器
*/
class PrescriptionController extends BaseAdminController
{
/**
* @notes 添加处方
*/
public function add()
{
$params = (new PrescriptionValidate())->post()->goCheck('add');
$params['creator_id'] = $this->adminId;
$id = PrescriptionLogic::add($params, $this->adminId);
if ($id === null) {
return $this->fail(PrescriptionLogic::getError());
}
return $this->success('保存成功', ['id' => $id]);
}
/**
* @notes 处方详情
*/
public function detail()
{
$params = (new PrescriptionValidate())->get()->goCheck('detail');
$detail = PrescriptionLogic::detail((int)$params['id']);
if (!$detail) {
return $this->fail('处方不存在');
}
return $this->data($detail);
}
/**
* @notes 根据诊单获取处方列表
*/
public function listByDiagnosis()
{
$diagnosisId = (int)($this->request->get('diagnosis_id') ?? 0);
if (!$diagnosisId) {
return $this->fail('诊单ID不能为空');
}
$list = PrescriptionLogic::listByDiagnosis($diagnosisId);
return $this->data($list);
}
/**
* @notes 根据预约获取处方
*/
public function getByAppointment()
{
$appointmentId = (int)($this->request->get('appointment_id') ?? 0);
if (!$appointmentId) {
return $this->fail('预约ID不能为空');
}
$prescription = PrescriptionLogic::getByAppointment($appointmentId);
return $this->data($prescription ?? []);
}
/**
* @notes 作废处方
*/
public function void()
{
$id = (int)($this->request->post('id') ?? 0);
if (!$id) {
return $this->fail('处方ID不能为空');
}
$admin = $this->adminInfo;
$ok = PrescriptionLogic::void($id, (int)$this->adminId, $admin['name'] ?? '');
if (!$ok) {
return $this->fail(PrescriptionLogic::getError());
}
return $this->success('作废成功');
}
}