This commit is contained in:
Your Name
2026-05-06 11:17:31 +08:00
parent 71180d4fd8
commit dddc4d202a
3 changed files with 170 additions and 7 deletions
@@ -19,6 +19,7 @@ use app\adminapi\logic\dept\DeptLogic;
use app\common\model\tcm\Diagnosis;
use app\common\model\tcm\BloodRecord;
use app\common\model\DiagnosisViewRecord;
use app\common\model\Order;
use app\common\model\doctor\Appointment;
use app\common\model\tcm\Prescription;
use app\common\model\tcm\CallRecord;
@@ -130,6 +131,8 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
}
$this->applyPendingAssignBusinessOrderMonthFilter($query);
// 仅已开方(有处方)的诊单:随访列表传 only_has_prescription=1;问诊等页面不传则不过滤
if (isset($this->params['only_has_prescription']) && (string) $this->params['only_has_prescription'] === '1') {
$rxTbl = (new Prescription())->getTable();
@@ -541,7 +544,49 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
$diagTbl = (new Diagnosis())->getTable();
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
}
$this->applyPendingAssignBusinessOrderMonthFilter($query);
return $query->count();
}
/**
* 「待分配医助」Tab:按月份筛选——诊单在指定自然月内需存在业务订单(order.patient_id = 诊单 id
* create_time 兼容整型时间戳与 datetime 字符串
*/
private function applyPendingAssignBusinessOrderMonthFilter($query): void
{
$pendingAssign = isset($this->params['pending_assign']) && (string) $this->params['pending_assign'] === '1';
if (!$pendingAssign || empty($this->params['pending_assign_order_month'])) {
return;
}
$month = trim((string) $this->params['pending_assign_order_month']);
if (!preg_match('/^(\d{4})-(\d{2})$/', $month, $m)) {
return;
}
$y = (int) $m[1];
$mo = (int) $m[2];
if ($y < 1970 || $y > 2100 || $mo < 1 || $mo > 12) {
return;
}
$tStart = strtotime(sprintf('%04d-%02d-01 00:00:00', $y, $mo));
if ($tStart === false) {
return;
}
$tEnd = strtotime(date('Y-m-t 23:59:59', $tStart));
if ($tEnd === false) {
return;
}
$dsStart = date('Y-m-d H:i:s', $tStart);
$dsEnd = date('Y-m-d H:i:s', $tEnd);
$orderTbl = (new Order())->getTable();
$diagTbl = (new Diagnosis())->getTable();
$sql = "SELECT 1 FROM `{$orderTbl}` o WHERE o.patient_id = {$diagTbl}.id "
. 'AND o.delete_time IS NULL AND ('
. "(o.create_time >= {$tStart} AND o.create_time <= {$tEnd}) OR "
. "(o.create_time >= '{$dsStart}' AND o.create_time <= '{$dsEnd}')"
. ')';
$query->whereExists($sql);
}
}