This commit is contained in:
Your Name
2026-04-30 14:04:12 +08:00
parent eb782305e6
commit d3003ce0ac
19 changed files with 1560 additions and 313 deletions
@@ -16,6 +16,7 @@ namespace app\adminapi\logic\tcm;
use app\common\logic\BaseLogic;
use app\common\model\tcm\Diagnosis;
use app\common\model\tcm\DiagnosisGuahaoLog;
use app\common\model\tcm\DiagnosisAssignLog;
use app\common\model\tcm\ImChatMessage;
use app\common\model\DiagnosisViewRecord;
@@ -3296,4 +3297,36 @@ class DiagnosisLogic extends BaseLogic
],
];
}
/**
* @notes 诊单挂号 / 取消挂号 操作日志(后台)
*
* @return array<int, array<string, mixed>>
*/
public static function guahaoLogList(int $diagnosisId): array
{
self::$error = '';
$exists = Diagnosis::where('id', $diagnosisId)->whereNull('delete_time')->find();
if (!$exists) {
self::setError('诊单不存在');
return [];
}
$logs = DiagnosisGuahaoLog::where('diagnosis_id', $diagnosisId)
->order('id', 'desc')
->limit(200)
->select()
->toArray();
foreach ($logs as &$r) {
$t = (int) ($r['create_time'] ?? 0);
$r['create_time_text'] = $t > 0 ? date('Y-m-d H:i:s', $t) : '';
$act = (string) ($r['action'] ?? '');
$r['action_desc'] = $act === 'cancel' ? '取消挂号' : ($act === 'create' ? '挂号' : $act);
}
unset($r);
return $logs;
}
}
@@ -382,10 +382,13 @@ class PrescriptionLogic
'dietary_taboo' => is_array($params['dietary_taboo'] ?? null) ? implode(',', $params['dietary_taboo']) : ($params['dietary_taboo'] ?? $prescription->dietary_taboo),
'usage_notes' => $params['usage_notes'] ?? $prescription->usage_notes,
'doctor_name' => $params['doctor_name'] ?? $prescription->doctor_name,
'doctor_signature' => $params['doctor_signature'] ?? $prescription->doctor_signature,
'is_shared' => (int)($params['is_shared'] ?? $prescription->is_shared),
'visible_role_ids' => array_key_exists('visible_role_ids', $params)
? self::normalizeVisibleRoleIds($params['visible_role_ids'])
: (string) ($prescription->visible_role_ids ?? ''),
// 后台编辑保存后视为手工处方(原系统代开标记清除)
'is_system_auto' => 0,
// 开方医生修改后重新进入待审核
'audit_status' => 0,
'audit_time' => null,
@@ -13,6 +13,7 @@ use app\common\model\tcm\Prescription;
use app\common\model\tcm\PrescriptionOrder;
use app\common\model\tcm\PrescriptionOrderLog;
use app\common\model\tcm\PrescriptionOrderPayOrder;
use app\common\model\doctor\Appointment;
use app\common\model\auth\Admin;
use app\common\service\ExpressTrackService;
use app\common\service\gancao\GancaoScmRecipelService;
@@ -706,9 +707,176 @@ class PrescriptionOrderLogic
}
$arr['diagnosis_creator_dept_path'] = $deptPath;
// 挂号预约摘要:优先处方 appointment_id;否则按诊单 id 匹配预约表 patient_id(诊单)
$arr['linked_appointment'] = null;
$rxApptId = 0;
if (isset($arr['prescription']) && is_array($arr['prescription'])) {
$rxApptId = (int) ($arr['prescription']['appointment_id'] ?? 0);
}
$resolvedApptId = $rxApptId;
if ($resolvedApptId <= 0 && $diagIdForMeta > 0) {
$apFallback = Appointment::where('patient_id', $diagIdForMeta)->order('id', 'desc')->find();
if ($apFallback !== null) {
$resolvedApptId = (int) $apFallback->id;
}
}
if ($resolvedApptId > 0) {
$brief = self::buildAppointmentBrief($resolvedApptId);
if ($brief !== null) {
$brief['resolved_from'] = $rxApptId === $resolvedApptId ? 'prescription' : 'diagnosis';
$arr['linked_appointment'] = $brief;
}
}
return $arr;
}
/**
* 业务订单详情场景:仅更新关联处方的患者姓名与手机号(不重置消费者处方审核、不改变其它处方字段)
*/
public static function patchPrescriptionPatient(
int $prescriptionOrderId,
string $patientName,
string $phone,
int $adminId,
array $adminInfo
): bool {
self::$error = '';
$order = PrescriptionOrder::where('id', $prescriptionOrderId)->whereNull('delete_time')->find();
if (!$order) {
self::setError('订单不存在');
return false;
}
if (!self::canAccessOrder($order, $adminId, $adminInfo)) {
self::setError('无权限操作');
return false;
}
$rxId = (int) ($order->prescription_id ?? 0);
if ($rxId <= 0) {
self::setError('该订单未关联处方');
return false;
}
$rx = Prescription::where('id', $rxId)->whereNull('delete_time')->find();
if (!$rx) {
self::setError('处方不存在');
return false;
}
if (!PrescriptionLogic::canViewPrescription($rx, $adminId, $adminInfo)) {
self::setError('无权限修改此处方');
return false;
}
$patientName = trim($patientName);
$phone = trim($phone);
if ($patientName === '') {
self::setError('患者姓名不能为空');
return false;
}
if (mb_strlen($patientName) > 50) {
self::setError('患者姓名过长');
return false;
}
if ($phone === '') {
self::setError('手机号不能为空');
return false;
}
if (strlen($phone) > 20) {
self::setError('手机号过长');
return false;
}
$oldName = trim((string) ($rx->patient_name ?? ''));
$oldPhone = trim((string) ($rx->phone ?? ''));
try {
$rx->save([
'patient_name' => $patientName,
'phone' => $phone,
]);
$nameFrom = $oldName === '' ? '—' : $oldName;
$phoneFrom = $oldPhone === '' ? '—' : $oldPhone;
$summary = sprintf(
'关联处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」',
$rxId,
$nameFrom,
$patientName,
$phoneFrom,
$phone
);
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* 挂号预约简要信息(业务订单详情展示)
*
* @return array<string, mixed>|null
*/
private static function buildAppointmentBrief(int $appointmentId): ?array
{
if ($appointmentId <= 0) {
return null;
}
$ap = Appointment::find($appointmentId);
if ($ap === null) {
return null;
}
$row = $ap->toArray();
$doctorName = '';
$did = (int) ($row['doctor_id'] ?? 0);
if ($did > 0) {
$doctorName = (string) (Admin::where('id', $did)->value('name') ?? '');
}
$statusMap = [
1 => '已预约',
2 => '已取消',
3 => '已完成',
4 => '已过号',
];
$typeMap = [
'video' => '视频问诊',
'text' => '图文问诊',
'phone' => '电话问诊',
];
$periodRaw = (string) ($row['period'] ?? '');
$period = $periodRaw === 'afternoon' ? '下午' : ($periodRaw === 'morning' ? '上午' : $periodRaw);
$timePart = (string) ($row['appointment_time'] ?? '');
if (strlen($timePart) > 5) {
$timePart = substr($timePart, 0, 5);
}
$status = (int) ($row['status'] ?? 0);
$atype = (string) ($row['appointment_type'] ?? '');
return [
'id' => $appointmentId,
'appointment_date' => (string) ($row['appointment_date'] ?? ''),
'period' => $period,
'appointment_time' => $timePart,
'appointment_type' => $atype,
'appointment_type_desc' => $typeMap[$atype] ?? '未知',
'status' => $status,
'status_desc' => $statusMap[$status] ?? '未知',
'doctor_name' => $doctorName,
'channel_source' => (string) ($row['channel_source'] ?? ''),
'remark' => (string) ($row['remark'] ?? ''),
];
}
/**
* 物流轨迹(顺丰/京东等,优先快递100;未配置密钥时返回官网链接)
*