新增功能
This commit is contained in:
@@ -59,12 +59,18 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
$this->searchWhere[] = ['a.appointment_date', '<=', $this->params['end_date']];
|
||||
}
|
||||
|
||||
// 诊单维度患者(挂号表 patient_id 存诊单 id)
|
||||
if (!empty($this->params['patient_id'])) {
|
||||
$this->searchWhere[] = ['a.patient_id', '=', (int) $this->params['patient_id']];
|
||||
}
|
||||
|
||||
// 构建查询
|
||||
$query = Appointment::alias('a')
|
||||
->with('diagnosis')
|
||||
->leftJoin('tcm_diagnosis u', 'a.patient_id = u.id')
|
||||
->leftJoin('admin ad', 'a.doctor_id = ad.id')
|
||||
->field('a.*, u.patient_name as patient_name, u.phone as patient_phone, u.gender as gender, u.age as age, u.weight as weight, u.height as height, ad.name as doctor_name, u.id as diagnosis_id')
|
||||
->leftJoin('admin asst', 'a.assistant_id = asst.id')
|
||||
->field('a.*, u.patient_name as patient_name, u.phone as patient_phone, u.gender as gender, u.age as age, u.weight as weight, u.height as height, ad.name as doctor_name, asst.name as assistant_name, u.id as diagnosis_id')
|
||||
->where($this->searchWhere);
|
||||
|
||||
// 是否确认诊单:1=已确认 0=未确认
|
||||
@@ -88,6 +94,9 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
if (in_array(2, $roleIds)) {
|
||||
$query->where('u.assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
// 诊单软删除后不再展示对应挂号(leftJoin 时无诊单或诊单未删)
|
||||
$query->whereRaw('(u.id IS NULL OR u.delete_time IS NULL)');
|
||||
|
||||
$lists = $query
|
||||
->order('a.status', 'asc')
|
||||
@@ -116,6 +125,23 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
->column('diagnosis_id');
|
||||
$prescribedDiagnosisIds = array_flip($prescribedDiagnosisIds ?: []);
|
||||
}
|
||||
// 当前页预约关联的处方(按 appointment_id,取最新一条):用于「开方/查看」与审核状态
|
||||
$appointmentIds = array_filter(array_map('intval', array_column($lists, 'id')));
|
||||
$rxByAppointmentId = [];
|
||||
if (!empty($appointmentIds)) {
|
||||
$rxRows = Prescription::whereIn('appointment_id', $appointmentIds)
|
||||
->whereNull('delete_time')
|
||||
->order('id', 'desc')
|
||||
->field(['id', 'appointment_id', 'audit_status', 'void_status'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($rxRows as $rx) {
|
||||
$aid = (int) ($rx['appointment_id'] ?? 0);
|
||||
if ($aid > 0 && !isset($rxByAppointmentId[$aid])) {
|
||||
$rxByAppointmentId[$aid] = $rx;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($lists as &$item) {
|
||||
$statusMap = [
|
||||
1 => '已预约',
|
||||
@@ -135,6 +161,11 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
$item['diagnosis_confirmed'] = isset($confirmedMap[$item['diagnosis_id'] ?? 0]) ? 1 : 0;
|
||||
$item['has_prescription'] = isset($prescribedDiagnosisIds[$item['diagnosis_id'] ?? 0]) ? 1 : 0;
|
||||
|
||||
$apptId = (int) ($item['id'] ?? 0);
|
||||
$apptRx = $rxByAppointmentId[$apptId] ?? null;
|
||||
$item['prescription_audit_status'] = $apptRx !== null ? (int) ($apptRx['audit_status'] ?? -1) : -1;
|
||||
$item['prescription_void_status'] = $apptRx !== null ? (int) ($apptRx['void_status'] ?? 0) : 0;
|
||||
|
||||
// 格式化时间戳为日期时间
|
||||
if (isset($item['create_time']) && is_numeric($item['create_time'])) {
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
@@ -173,6 +204,10 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
$query->where('a.appointment_date', '<=', $this->params['end_date']);
|
||||
}
|
||||
|
||||
if (!empty($this->params['patient_id'])) {
|
||||
$query->where('a.patient_id', '=', (int) $this->params['patient_id']);
|
||||
}
|
||||
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
$tbl = (new DiagnosisViewRecord())->getTable();
|
||||
@@ -190,6 +225,8 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
if (in_array(2, $roleIds)) {
|
||||
$query->where('u.assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
$query->whereRaw('(u.id IS NULL OR u.delete_time IS NULL)');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user