更新
This commit is contained in:
@@ -4701,7 +4701,8 @@ class YejiStatsLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 业绩看板业务订单侧栏:按 channel_code 收窄(与 overview「{渠道}业绩」同患者判定;含 ap.channels 与 ap.channel_source)
|
||||
* 业绩看板业务订单侧栏:按 channel_code 收窄(与 overview「{渠道}业绩」同患者判定;含 ap.channels 与 ap.channel_source);
|
||||
* **二中心及其组织下级**展示部门与看板一致:选定渠道收窄时本条无渠道订单(表中渠道业绩已为 0)。
|
||||
*
|
||||
* @param Query $query PrescriptionOrder 主表查询
|
||||
* @param array<string, mixed> $params
|
||||
@@ -4715,6 +4716,16 @@ class YejiStatsLogic
|
||||
if ($channelCode === '') {
|
||||
return;
|
||||
}
|
||||
/** @see excludeErCenterSubtreeFromChannelMetrics 看板选定渠道时对二中心子树渠道列置 0,侧栏须同步 */
|
||||
$assistantDeptForDrawer = (int) ($params['assistant_dept_id'] ?? 0);
|
||||
if ($assistantDeptForDrawer > 0) {
|
||||
$erCenterSubtree = DeptLogic::getErCenterSubtreeDeptIdSet();
|
||||
if (isset($erCenterSubtree[$assistantDeptForDrawer])) {
|
||||
$query->whereRaw('0 = 1');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$startDate = '';
|
||||
$endDate = '';
|
||||
$st = trim((string) ($params['start_time'] ?? ''));
|
||||
@@ -4803,4 +4814,110 @@ class YejiStatsLogic
|
||||
$query->whereRaw('0 = 1');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 业绩看板业务订单侧栏:在「渠道筛选」模式下,为每个诊单挑一条用于「关联挂号」展示的预约行——
|
||||
* 须为已完成(status=3)、挂号助理为医助(role_id=2),且 channels/channel_source 与当前 channel_code 同源命中(与 {@see applyYejiDrawerChannelFilterToPrescriptionOrderQuery} 的 dict 收窄一致)。
|
||||
* 若为 tag 等未走 channels 表达式的情况则返回空图,交由列表沿用处方/最近挂号。
|
||||
*
|
||||
* @param int[] $diagnosisIds doctor_appointment.patient_id(与本系统诊单 id 一致)
|
||||
* @param array<string, mixed> $params 与列表同源:yeji_order_drawer、channel_code、start_time、end_time
|
||||
*
|
||||
* @return array<int, int> diagnosis_id => appointment_id
|
||||
*/
|
||||
public static function batchResolveYejiChannelDrawerHighlightAppointmentIds(array $diagnosisIds, array $params): array
|
||||
{
|
||||
$diagnosisIds = array_values(array_unique(array_filter(array_map('intval', $diagnosisIds), static fn (int $x): bool => $x > 0)));
|
||||
if ($diagnosisIds === []) {
|
||||
return [];
|
||||
}
|
||||
if ((int) ($params['yeji_order_drawer'] ?? 0) !== 1) {
|
||||
return [];
|
||||
}
|
||||
$channelCode = trim((string) ($params['channel_code'] ?? ''));
|
||||
if ($channelCode === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$startDate = '';
|
||||
$endDate = '';
|
||||
$st = trim((string) ($params['start_time'] ?? ''));
|
||||
if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $st, $m)) {
|
||||
$startDate = $m[1];
|
||||
}
|
||||
$et = trim((string) ($params['end_time'] ?? ''));
|
||||
if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $et, $m)) {
|
||||
$endDate = $m[1];
|
||||
}
|
||||
if ($startDate === '' || $endDate === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ctx = self::resolveYejiContext([
|
||||
'start_date' => $startDate,
|
||||
'end_date' => $endDate,
|
||||
'channel_code' => $channelCode,
|
||||
'dept_ids' => null,
|
||||
]);
|
||||
if (!$ctx['channelFilterActive'] || $ctx['channelInfo'] === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$norm = self::normalizeAppointmentChannelValues($ctx['appointmentChannelValues']);
|
||||
$srcStrings = self::appointmentChannelDictStringValuesForDrawer($ctx['channelInfo']);
|
||||
if ($norm === [] && $srcStrings === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$apTable = self::tableWithPrefix('doctor_appointment');
|
||||
$arTable = self::tableWithPrefix('admin_role');
|
||||
|
||||
$hasCh = self::doctorAppointmentHasChannelsColumn();
|
||||
$orParts = [];
|
||||
$channelBind = [];
|
||||
if ($norm !== [] && $hasCh) {
|
||||
$strVals = array_values(array_unique(array_map(static fn (int $v): string => (string) $v, $norm)));
|
||||
$ph = implode(',', array_fill(0, count($strVals), '?'));
|
||||
$orParts[] = "ap.`channels` IN ({$ph})";
|
||||
foreach ($strVals as $sv) {
|
||||
$channelBind[] = $sv;
|
||||
}
|
||||
}
|
||||
if ($srcStrings !== [] && self::doctorAppointmentHasChannelSourceColumn()) {
|
||||
$ph = implode(',', array_fill(0, count($srcStrings), '?'));
|
||||
$orParts[] = "ap.`channel_source` IN ({$ph})";
|
||||
foreach ($srcStrings as $s) {
|
||||
$channelBind[] = $s;
|
||||
}
|
||||
}
|
||||
if ($orParts === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$inPh = implode(',', array_fill(0, count($diagnosisIds), '?'));
|
||||
$bind = array_merge($diagnosisIds, $channelBind);
|
||||
|
||||
$orSql = '(' . implode(' OR ', $orParts) . ')';
|
||||
$sql = "SELECT ap.`patient_id` AS dg, MAX(ap.`id`) AS aid FROM `{$apTable}` ap "
|
||||
. "INNER JOIN `{$arTable}` ar ON ar.`admin_id` = ap.`assistant_id` AND ar.`role_id` = 2 "
|
||||
. "WHERE ap.`patient_id` IN ({$inPh}) AND ap.`status` = 3 AND {$orSql} "
|
||||
. 'GROUP BY ap.`patient_id`';
|
||||
|
||||
try {
|
||||
$rows = Db::query($sql, $bind);
|
||||
} catch (\Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($rows as $r) {
|
||||
$dg = (int) ($r['dg'] ?? $r['DG'] ?? 0);
|
||||
$aid = (int) ($r['aid'] ?? $r['AID'] ?? 0);
|
||||
if ($dg > 0 && $aid > 0) {
|
||||
$out[$dg] = $aid;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user