新增功能
This commit is contained in:
@@ -77,47 +77,63 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
// 挂号日期筛选:当天/明天/后天
|
||||
// 挂号日期筛选:当天/明天/后天(1=已预约 3=已完成 4=已过号,需展示以便取消等操作)
|
||||
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)");
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.appointment_date = '{$aptDate}' AND apt.status IN (1,3,4)");
|
||||
}
|
||||
|
||||
// 挂号状态:1=已挂号 0=未挂号
|
||||
// 挂号状态: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)");
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status IN (1,3,4)");
|
||||
} else {
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status IN (1,3,4)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 按挂号日期+时间升序。若传了 appointment_date(当天/明天等筛选),只按「该日」的挂号排序与展示,避免仍按历史最早一天把昨天号顶到最前
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$minAptDateCond = '';
|
||||
if (!empty($this->params['appointment_date'])) {
|
||||
$sortAptDate = addslashes((string) $this->params['appointment_date']);
|
||||
$minAptDateCond = " AND apt.appointment_date = '{$sortAptDate}'";
|
||||
}
|
||||
$minAptExpr = '(SELECT MIN(CONCAT(apt.appointment_date, \' \', IFNULL(NULLIF(TRIM(apt.appointment_time), \'\'), \'00:00:00\'))) FROM ' . $aptTbl . ' apt WHERE apt.patient_id = ' . $diagTbl . '.id AND apt.status IN (1,3,4)' . $minAptDateCond . ')';
|
||||
|
||||
$lists = $query
|
||||
->with(['DiagnosisViewRecord'])
|
||||
->field(['id', 'patient_id', 'patient_name', 'id_card', 'phone', 'gender', 'age', 'diagnosis_date', 'diagnosis_type', 'syndrome_type', 'assistant_id', 'status', 'create_time', 'update_time'])
|
||||
->append(['gender_desc', 'status_desc', 'diagnosis_date_text'])
|
||||
->order(['id' => 'desc'])
|
||||
->orderRaw('IFNULL(' . $minAptExpr . ", '9999-12-31 23:59:59') ASC, {$diagTbl}.id DESC")
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 关联挂号信息:获取患者最新有效挂号(已预约或已完成)
|
||||
$patientIds = array_filter(array_unique(array_column($lists, 'patient_id')));
|
||||
if (!empty($patientIds)) {
|
||||
// 关联挂号:doctor_appointment.patient_id 存诊单主键 id(与 Appointment 列表 join 一致)
|
||||
$diagnosisIds = array_filter(array_unique(array_column($lists, 'id')));
|
||||
if (!empty($diagnosisIds)) {
|
||||
$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');
|
||||
$subQuery = Appointment::where('patient_id', 'in', $diagnosisIds)
|
||||
->where('status', 'in', [1, 3, 4]); // 1=已预约 3=已完成 4=已过号
|
||||
if (!empty($this->params['appointment_date'])) {
|
||||
$subQuery->where('appointment_date', (string) $this->params['appointment_date']);
|
||||
}
|
||||
$subQuery
|
||||
->field('id, patient_id, doctor_id, appointment_date, appointment_time, status, create_time')
|
||||
->order('appointment_date', 'asc')
|
||||
->order('appointment_time', 'asc')
|
||||
->order('id', 'asc');
|
||||
$appointments = $subQuery->select()->toArray();
|
||||
foreach ($appointments as $apt) {
|
||||
$pid = $apt['patient_id'];
|
||||
if (!isset($appointmentMap[$pid])) {
|
||||
$appointmentMap[$pid] = $apt;
|
||||
$did = $apt['patient_id'];
|
||||
if (!isset($appointmentMap[$did])) {
|
||||
$appointmentMap[$did] = $apt;
|
||||
}
|
||||
}
|
||||
// 获取医生名称
|
||||
@@ -129,10 +145,11 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
}
|
||||
// 合并到诊单列表
|
||||
foreach ($lists as &$item) {
|
||||
$apt = $appointmentMap[$item['patient_id']] ?? null;
|
||||
$apt = $appointmentMap[$item['id']] ?? null;
|
||||
if ($apt) {
|
||||
$item['has_appointment'] = 1;
|
||||
$item['appointment_id'] = $apt['id'];
|
||||
$item['appointment_status'] = (int) ($apt['status'] ?? 0);
|
||||
$item['appointment_doctor_id'] = $apt['doctor_id'];
|
||||
$item['appointment_doctor_name'] = $doctorNames[$apt['doctor_id']] ?? '-';
|
||||
$timePart = $apt['appointment_time'] ?? '';
|
||||
@@ -143,6 +160,7 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
} else {
|
||||
$item['has_appointment'] = 0;
|
||||
$item['appointment_id'] = null;
|
||||
$item['appointment_status'] = 0;
|
||||
$item['appointment_doctor_id'] = null;
|
||||
$item['appointment_doctor_name'] = '';
|
||||
$item['appointment_time_text'] = '';
|
||||
@@ -152,6 +170,7 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
foreach ($lists as &$item) {
|
||||
$item['has_appointment'] = 0;
|
||||
$item['appointment_id'] = null;
|
||||
$item['appointment_status'] = 0;
|
||||
$item['appointment_doctor_id'] = null;
|
||||
$item['appointment_doctor_name'] = '';
|
||||
$item['appointment_time_text'] = '';
|
||||
@@ -277,7 +296,7 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$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)");
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.appointment_date = '{$aptDate}' AND apt.status IN (1,3,4)");
|
||||
}
|
||||
|
||||
// 挂号状态
|
||||
@@ -285,9 +304,9 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$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)");
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status IN (1,3,4)");
|
||||
} else {
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.patient_id AND apt.status IN (1,3)");
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status IN (1,3,4)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\adminapi\logic\tcm\PrescriptionLogic;
|
||||
use app\common\model\tcm\Prescription;
|
||||
|
||||
/**
|
||||
@@ -19,24 +20,86 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['is_shared'],
|
||||
'%like%' => ['prescription_name', 'patient_name', 'sn']
|
||||
'%like%' => ['patient_name', 'sn'],
|
||||
'between_time' => 'create_time',
|
||||
];
|
||||
}
|
||||
|
||||
/** 创建人(医师账号)多选,参数 creator_ids:数组或逗号分隔 ID */
|
||||
private function applyCreatorIdsFilter($query): void
|
||||
{
|
||||
$raw = $this->params['creator_ids'] ?? null;
|
||||
if ($raw === null || $raw === '') {
|
||||
return;
|
||||
}
|
||||
$ids = \is_array($raw) ? $raw : explode(',', (string) $raw);
|
||||
$ids = array_values(array_filter(array_map('intval', $ids), static function (int $id): bool {
|
||||
return $id > 0;
|
||||
}));
|
||||
if ($ids === []) {
|
||||
return;
|
||||
}
|
||||
$query->whereIn('creator_id', $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* audit_filter:passed=已通过,not_passed=未通过(待审+驳回),pending,rejected
|
||||
*/
|
||||
private function applyAuditFilter($query): void
|
||||
{
|
||||
$af = (string) ($this->params['audit_filter'] ?? '');
|
||||
if ($af === '' || $af === 'all') {
|
||||
return;
|
||||
}
|
||||
switch ($af) {
|
||||
case 'passed':
|
||||
$query->where('audit_status', '=', 1);
|
||||
break;
|
||||
case 'not_passed':
|
||||
$query->whereIn('audit_status', [0, 2]);
|
||||
break;
|
||||
case 'pending':
|
||||
$query->where('audit_status', '=', 0);
|
||||
break;
|
||||
case 'rejected':
|
||||
$query->where('audit_status', '=', 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function applyVisibilityScope($query): void
|
||||
{
|
||||
$query->where(function ($query) {
|
||||
if (!empty($this->adminInfo['root']) && (int) $this->adminInfo['root'] === 1) {
|
||||
return;
|
||||
}
|
||||
$adminId = $this->adminId;
|
||||
$roleIds = array_values(array_unique(array_map('intval', $this->adminInfo['role_id'] ?? [])));
|
||||
$query->where(function ($q) use ($adminId, $roleIds) {
|
||||
$q->whereOr('is_shared', '=', 1);
|
||||
$q->whereOr('creator_id', '=', $adminId);
|
||||
foreach ($roleIds as $rid) {
|
||||
if ($rid > 0) {
|
||||
$q->whereOrRaw('FIND_IN_SET(?, `visible_role_ids`)', [(string) $rid]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$lists = Prescription::where($this->searchWhere)
|
||||
->where(function ($query) {
|
||||
// 如果不是共享的,只能看到自己创建的
|
||||
$query->whereOr([
|
||||
['is_shared', '=', 1],
|
||||
['creator_id', '=', $this->adminId]
|
||||
]);
|
||||
})
|
||||
$query = Prescription::where($this->searchWhere);
|
||||
$this->applyAuditFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
|
||||
$lists = $query
|
||||
->whereNull('delete_time')
|
||||
->order('id', 'desc')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
@@ -51,7 +114,10 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$item['usage_notes'] = $item['usage_notes'] ?? '';
|
||||
$item['usage_days'] = $item['usage_days'] ?? 7;
|
||||
$item['is_shared'] = $item['is_shared'] ?? 0;
|
||||
|
||||
$item['audit_status'] = (int) ($item['audit_status'] ?? 1);
|
||||
$item['void_status'] = (int) ($item['void_status'] ?? 0);
|
||||
$item['visible_role_ids'] = PrescriptionLogic::visibleRoleIdsToArray((string) ($item['visible_role_ids'] ?? ''));
|
||||
|
||||
// 将 dietary_taboo 从逗号分隔的字符串转换为数组(前端需要数组格式)
|
||||
if (!empty($item['dietary_taboo']) && is_string($item['dietary_taboo'])) {
|
||||
$item['dietary_taboo'] = array_filter(explode(',', $item['dietary_taboo']));
|
||||
@@ -68,15 +134,11 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Prescription::where($this->searchWhere)
|
||||
->where(function ($query) {
|
||||
// 如果不是共享的,只能看到自己创建的
|
||||
$query->whereOr([
|
||||
['is_shared', '=', 1],
|
||||
['creator_id', '=', $this->adminId]
|
||||
]);
|
||||
})
|
||||
->whereNull('delete_time')
|
||||
->count();
|
||||
$query = Prescription::where($this->searchWhere);
|
||||
$this->applyAuditFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
|
||||
return $query->whereNull('delete_time')->count();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user