更新
This commit is contained in:
@@ -160,7 +160,7 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
->whereNull('delete_time')
|
||||
->where('void_status', 0)
|
||||
->order('id', 'desc')
|
||||
->field(['id', 'appointment_id', 'audit_status', 'void_status'])
|
||||
->field(['id', 'appointment_id', 'audit_status', 'void_status', 'is_system_auto'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($rxRows as $rx) {
|
||||
@@ -193,6 +193,7 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
$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;
|
||||
$item['prescription_is_system_auto'] = $apptRx !== null ? (int) ($apptRx['is_system_auto'] ?? 0) : 0;
|
||||
|
||||
// 格式化时间戳为日期时间
|
||||
if (isset($item['create_time']) && is_numeric($item['create_time'])) {
|
||||
|
||||
@@ -86,7 +86,18 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
// 按诊单医助筛选(订单 patient_id 存诊单 id)
|
||||
$assistantId = (int) ($this->params['assistant_id'] ?? 0);
|
||||
if ($assistantId > 0) {
|
||||
$where[] = ['patient_id', 'in', function ($query) use ($assistantId) {
|
||||
$query->table('zyt_tcm_diagnosis')
|
||||
->whereNull('delete_time')
|
||||
->where('assistant_id', '=', $assistantId)
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
|
||||
// 处理创建时间范围
|
||||
if (!empty($this->params['create_time_start'])) {
|
||||
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
|
||||
@@ -132,7 +143,17 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
$assistantIdCount = (int) ($this->params['assistant_id'] ?? 0);
|
||||
if ($assistantIdCount > 0) {
|
||||
$where[] = ['patient_id', 'in', function ($query) use ($assistantIdCount) {
|
||||
$query->table('zyt_tcm_diagnosis')
|
||||
->whereNull('delete_time')
|
||||
->where('assistant_id', '=', $assistantIdCount)
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
|
||||
// 处理创建时间范围
|
||||
if (!empty($this->params['create_time_start'])) {
|
||||
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
|
||||
|
||||
@@ -42,8 +42,12 @@ class CustomerLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
// 按首次添加时间倒序:库字段 external_first_add_time;未回填(0)时回退 create_time(与列表「添加时间」展示一致)
|
||||
$lists = $this->baseQuery()
|
||||
->order('id', 'desc')
|
||||
->orderRaw(
|
||||
'(COALESCE(NULLIF(external_first_add_time, 0), create_time) = 0) ASC, '
|
||||
. 'COALESCE(NULLIF(external_first_add_time, 0), create_time) DESC, id DESC'
|
||||
)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@@ -115,6 +115,13 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
// 至少有一条挂号为「已完成」(status=3),用于列表顶部「已完成」Tab
|
||||
if (isset($this->params['completed_appointment']) && (string) $this->params['completed_appointment'] === '1') {
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
|
||||
}
|
||||
|
||||
// 仅已开方(有处方)的诊单:随访列表传 only_has_prescription=1;问诊等页面不传则不过滤
|
||||
if (isset($this->params['only_has_prescription']) && (string) $this->params['only_has_prescription'] === '1') {
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
@@ -474,6 +481,13 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereNotExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status IN (1,3,4)");
|
||||
}
|
||||
}
|
||||
|
||||
// 至少有一条挂号为「已完成」(status=3)
|
||||
if (isset($this->params['completed_appointment']) && (string) $this->params['completed_appointment'] === '1') {
|
||||
$aptTbl = (new Appointment())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ 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['is_system_auto'] = (int) ($item['is_system_auto'] ?? 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'] ?? ''));
|
||||
|
||||
@@ -10,6 +10,7 @@ use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
use app\common\service\gancao\GancaoScmRecipelService;
|
||||
@@ -27,6 +28,8 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
public function lists(): array
|
||||
{
|
||||
$query = PrescriptionOrder::where($this->searchWhere)->whereNull('delete_time');
|
||||
$this->applyDoctorAssistantFilters($query);
|
||||
$this->applyPatientKeywordFilter($query);
|
||||
if (!PrescriptionOrderLogic::canSeeAllPrescriptionOrders($this->adminInfo)) {
|
||||
$diagIds = Diagnosis::where('assistant_id', $this->adminId)->whereNull('delete_time')->column('id');
|
||||
$query->where(function ($q) use ($diagIds) {
|
||||
@@ -165,6 +168,8 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
public function count(): int
|
||||
{
|
||||
$query = PrescriptionOrder::where($this->searchWhere)->whereNull('delete_time');
|
||||
$this->applyDoctorAssistantFilters($query);
|
||||
$this->applyPatientKeywordFilter($query);
|
||||
if (!PrescriptionOrderLogic::canSeeAllPrescriptionOrders($this->adminInfo)) {
|
||||
$diagIds = Diagnosis::where('assistant_id', $this->adminId)->whereNull('delete_time')->column('id');
|
||||
$query->where(function ($q) use ($diagIds) {
|
||||
@@ -177,4 +182,46 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
|
||||
return (int) $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按开方医生(关联处方 creator_id)/ 诊单医助(关联诊单 assistant_id)筛选
|
||||
*/
|
||||
private function applyDoctorAssistantFilters($query): void
|
||||
{
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
|
||||
if (isset($this->params['doctor_id']) && (int) $this->params['doctor_id'] > 0) {
|
||||
$doctorId = (int) $this->params['doctor_id'];
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$rxTbl} rx WHERE rx.id = {$poTbl}.prescription_id AND rx.delete_time IS NULL AND rx.creator_id = {$doctorId}");
|
||||
}
|
||||
|
||||
if (isset($this->params['assistant_id']) && (int) $this->params['assistant_id'] > 0) {
|
||||
$assistantId = (int) $this->params['assistant_id'];
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$diagTbl} dg WHERE dg.id = {$poTbl}.diagnosis_id AND dg.delete_time IS NULL AND dg.assistant_id = {$assistantId}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按诊单患者姓名 / 手机号模糊检索(关联 diagnosis_id)
|
||||
*/
|
||||
private function applyPatientKeywordFilter($query): void
|
||||
{
|
||||
$kw = trim((string) ($this->params['patient_keyword'] ?? ''));
|
||||
if ($kw === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$likeInner = str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $kw);
|
||||
$like = '%' . $likeInner . '%';
|
||||
$likeSql = str_replace("'", "''", $like);
|
||||
|
||||
$query->whereExists(
|
||||
"SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$poTbl}`.`diagnosis_id` AND dg.`delete_time` IS NULL "
|
||||
. "AND (dg.`patient_name` LIKE '{$likeSql}' OR dg.`phone` LIKE '{$likeSql}')"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user