dataLists(new \app\adminapi\lists\tcm\PrescriptionLists()); } /** * @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 edit() { $params = (new PrescriptionValidate())->post()->goCheck('edit'); $result = PrescriptionLogic::edit($params, $this->adminId); if (!$result) { return $this->fail(PrescriptionLogic::getError()); } return $this->success('编辑成功'); } /** * @notes 删除处方 */ public function delete() { $params = (new PrescriptionValidate())->post()->goCheck('delete'); $result = PrescriptionLogic::delete($params['id']); if (!$result) { return $this->fail(PrescriptionLogic::getError()); } return $this->success('删除成功'); } /** * @notes 处方详情 */ public function detail() { $params = (new PrescriptionValidate())->get()->goCheck('detail'); $detail = PrescriptionLogic::detail((int) $params['id'], (int) $this->adminId, $this->adminInfo); if (!$detail) { $msg = PrescriptionLogic::getError(); return $this->fail($msg !== '' ? $msg : '处方不存在'); } return $this->data($detail); } /** * @notes 审核处方(通过 / 驳回,驳回即作废) */ public function audit() { $params = (new PrescriptionValidate())->post()->goCheck('audit'); $ok = PrescriptionLogic::audit( (int) $params['id'], (string) $params['action'], (string) ($params['remark'] ?? ''), (int) $this->adminId, $this->adminInfo ); if (!$ok) { return $this->fail(PrescriptionLogic::getError()); } $msg = $params['action'] === 'reject' ? '已驳回并作废处方' : '审核通过'; $wecom = PrescriptionLogic::consumeLastAuditWecomNotify(); $data = []; if (is_array($wecom)) { $data['wecom_notify_ok'] = !empty($wecom['ok']); if (empty($wecom['ok']) && !empty($wecom['message'])) { $data['wecom_notify_hint'] = (string) $wecom['message']; } } return $this->success($msg, $data); } /** * @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, (int)$this->adminId, $this->adminInfo); if ($prescription === null) { //$msg = PrescriptionLogic::getError(); return ''; } 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('作废成功'); } }