更新
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
namespace app\adminapi\lists\doctor;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\DiagnosisViewRecord;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
@@ -55,14 +57,26 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
} elseif (!empty($this->params['end_date'])) {
|
||||
$this->searchWhere[] = ['a.appointment_date', '<=', $this->params['end_date']];
|
||||
}
|
||||
|
||||
|
||||
// 构建查询
|
||||
$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, ad.name as doctor_name, u.id as diagnosis_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')
|
||||
->where($this->searchWhere);
|
||||
|
||||
// 是否确认诊单:1=已确认 0=未确认
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
$tbl = (new DiagnosisViewRecord())->getTable();
|
||||
$subSql = "SELECT 1 FROM {$tbl} dvr WHERE dvr.diagnosis_id = u.id AND dvr.is_confirmed = 1 AND dvr.delete_time IS NULL";
|
||||
if ($confirmed === 1) {
|
||||
$query->whereExists($subSql);
|
||||
} else {
|
||||
$query->whereNotExists($subSql);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是医生角色(role_id=1),只显示挂自己号的预约
|
||||
if (in_array(1, $roleIds)) {
|
||||
@@ -82,7 +96,25 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 添加状态和类型描述
|
||||
// 添加状态、类型描述及确认诊单状态
|
||||
$diagnosisIds = array_filter(array_unique(array_column($lists, 'diagnosis_id')));
|
||||
$confirmedMap = [];
|
||||
if (!empty($diagnosisIds)) {
|
||||
$confirmedIds = \think\facade\Db::name('diagnosis_view_records')
|
||||
->whereIn('diagnosis_id', $diagnosisIds)
|
||||
->where('is_confirmed', 1)
|
||||
->whereNull('delete_time')
|
||||
->column('diagnosis_id');
|
||||
$confirmedMap = array_flip($confirmedIds ?: []);
|
||||
}
|
||||
// 开方状态:诊单是否有处方(按 diagnosis_id 查)
|
||||
$prescribedDiagnosisIds = [];
|
||||
if (!empty($diagnosisIds)) {
|
||||
$prescribedDiagnosisIds = Prescription::whereIn('diagnosis_id', $diagnosisIds)
|
||||
->whereNull('delete_time')
|
||||
->column('diagnosis_id');
|
||||
$prescribedDiagnosisIds = array_flip($prescribedDiagnosisIds ?: []);
|
||||
}
|
||||
foreach ($lists as &$item) {
|
||||
$statusMap = [
|
||||
1 => '已预约',
|
||||
@@ -99,6 +131,9 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
];
|
||||
$item['appointment_type_desc'] = $typeMap[$item['appointment_type']] ?? '未知';
|
||||
|
||||
$item['diagnosis_confirmed'] = isset($confirmedMap[$item['diagnosis_id'] ?? 0]) ? 1 : 0;
|
||||
$item['has_prescription'] = isset($prescribedDiagnosisIds[$item['diagnosis_id'] ?? 0]) ? 1 : 0;
|
||||
|
||||
// 格式化时间戳为日期时间
|
||||
if (isset($item['create_time']) && is_numeric($item['create_time'])) {
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
@@ -149,6 +184,18 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
->leftJoin('tcm_diagnosis u', 'a.patient_id = u.id')
|
||||
->leftJoin('admin ad', 'a.doctor_id = ad.id')
|
||||
->where($this->searchWhere);
|
||||
|
||||
// 是否确认诊单
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
$tbl = (new DiagnosisViewRecord())->getTable();
|
||||
$subSql = "SELECT 1 FROM {$tbl} dvr WHERE dvr.diagnosis_id = u.id AND dvr.is_confirmed = 1 AND dvr.delete_time IS NULL";
|
||||
if ($confirmed === 1) {
|
||||
$query->whereExists($subSql);
|
||||
} else {
|
||||
$query->whereNotExists($subSql);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是医生角色(role_id=1),只显示挂自己号的预约
|
||||
if (in_array(1, $roleIds)) {
|
||||
|
||||
@@ -16,6 +16,10 @@ namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\DiagnosisViewRecord;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
@@ -58,6 +62,38 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
if (in_array(2, $roleIds)) {
|
||||
$query->where('assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
// 是否确认诊单:1=已确认 0=未确认
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
$dvrTbl = (new DiagnosisViewRecord())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$subSql = "SELECT 1 FROM {$dvrTbl} dvr WHERE dvr.diagnosis_id = {$diagTbl}.id AND dvr.is_confirmed = 1 AND dvr.delete_time IS NULL";
|
||||
if ($confirmed === 1) {
|
||||
$query->whereExists($subSql);
|
||||
} else {
|
||||
$query->whereNotExists($subSql);
|
||||
}
|
||||
}
|
||||
|
||||
// 挂号日期筛选:当天/明天/后天
|
||||
if (!empty($this->params['appointment_date'])) {
|
||||
$aptDate = addslashes($this->params['appointment_date']);
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.appointment_date = '{$aptDate}' AND apt.status IN (1,3)");
|
||||
}
|
||||
|
||||
// 挂号状态:1=已挂号 0=未挂号
|
||||
if (isset($this->params['has_appointment']) && $this->params['has_appointment'] !== '') {
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
if ((int)$this->params['has_appointment'] === 1) {
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
} else {
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
}
|
||||
}
|
||||
|
||||
$lists = $query
|
||||
->with(['DiagnosisViewRecord'])
|
||||
@@ -68,6 +104,70 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 关联挂号信息:获取患者最新有效挂号(已预约或已完成)
|
||||
$patientIds = array_filter(array_unique(array_column($lists, 'patient_id')));
|
||||
if (!empty($patientIds)) {
|
||||
$appointmentMap = [];
|
||||
$subQuery = Appointment::where('patient_id', 'in', $patientIds)
|
||||
->where('status', 'in', [1, 3]) // 1=已预约 3=已完成
|
||||
->field('id, patient_id, doctor_id, appointment_date, appointment_time, create_time')
|
||||
->order('id', 'desc');
|
||||
$appointments = $subQuery->select()->toArray();
|
||||
foreach ($appointments as $apt) {
|
||||
$pid = $apt['patient_id'];
|
||||
if (!isset($appointmentMap[$pid])) {
|
||||
$appointmentMap[$pid] = $apt;
|
||||
}
|
||||
}
|
||||
// 获取医生名称
|
||||
$doctorIds = array_unique(array_column($appointmentMap, 'doctor_id'));
|
||||
$doctorNames = [];
|
||||
if (!empty($doctorIds)) {
|
||||
$doctors = Admin::whereIn('id', $doctorIds)->column('name', 'id');
|
||||
$doctorNames = $doctors ?: [];
|
||||
}
|
||||
// 合并到诊单列表
|
||||
foreach ($lists as &$item) {
|
||||
$apt = $appointmentMap[$item['patient_id']] ?? null;
|
||||
if ($apt) {
|
||||
$item['has_appointment'] = 1;
|
||||
$item['appointment_doctor_id'] = $apt['doctor_id'];
|
||||
$item['appointment_doctor_name'] = $doctorNames[$apt['doctor_id']] ?? '-';
|
||||
$timePart = $apt['appointment_time'] ?? '';
|
||||
if (strlen($timePart) > 5) {
|
||||
$timePart = substr($timePart, 0, 5); // 09:00:00 -> 09:00
|
||||
}
|
||||
$item['appointment_time_text'] = trim(($apt['appointment_date'] ?? '') . ' ' . $timePart);
|
||||
} else {
|
||||
$item['has_appointment'] = 0;
|
||||
$item['appointment_doctor_id'] = null;
|
||||
$item['appointment_doctor_name'] = '';
|
||||
$item['appointment_time_text'] = '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($lists as &$item) {
|
||||
$item['has_appointment'] = 0;
|
||||
$item['appointment_doctor_id'] = null;
|
||||
$item['appointment_doctor_name'] = '';
|
||||
$item['appointment_time_text'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// 关联是否开方:诊单是否有处方记录
|
||||
$diagnosisIds = array_column($lists, 'id');
|
||||
$prescriptionMap = [];
|
||||
if (!empty($diagnosisIds)) {
|
||||
$prescriptionTbl = (new Prescription())->getTable();
|
||||
$prescribedIds = Prescription::whereIn('diagnosis_id', $diagnosisIds)
|
||||
->whereNull('delete_time')
|
||||
->column('diagnosis_id');
|
||||
$prescriptionMap = array_fill_keys($prescribedIds, 1);
|
||||
}
|
||||
foreach ($lists as &$item) {
|
||||
$item['has_prescription'] = isset($prescriptionMap[$item['id']]) ? 1 : 0;
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
@@ -87,6 +187,38 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
if (in_array(2, $roleIds)) {
|
||||
$query->where('assistant_id', $this->adminId);
|
||||
}
|
||||
|
||||
// 是否确认诊单
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
$dvrTbl = (new DiagnosisViewRecord())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$subSql = "SELECT 1 FROM {$dvrTbl} dvr WHERE dvr.diagnosis_id = {$diagTbl}.id AND dvr.is_confirmed = 1 AND dvr.delete_time IS NULL";
|
||||
if ($confirmed === 1) {
|
||||
$query->whereExists($subSql);
|
||||
} else {
|
||||
$query->whereNotExists($subSql);
|
||||
}
|
||||
}
|
||||
|
||||
// 挂号日期筛选
|
||||
if (!empty($this->params['appointment_date'])) {
|
||||
$aptDate = addslashes($this->params['appointment_date']);
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.appointment_date = '{$aptDate}' AND apt.status IN (1,3)");
|
||||
}
|
||||
|
||||
// 挂号状态
|
||||
if (isset($this->params['has_appointment']) && $this->params['has_appointment'] !== '') {
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
if ((int)$this->params['has_appointment'] === 1) {
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
} else {
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
}
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user