update
修改未服务天数判断条件
This commit is contained in:
@@ -257,7 +257,7 @@
|
|||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
v-if="row.last_blood_record_at"
|
v-if="row.last_blood_record_at"
|
||||||
:content="`最近一次血糖打卡:${row.last_blood_record_at}`"
|
:content="`最近一次健康打卡:${row.last_blood_record_at}`"
|
||||||
placement="top"
|
placement="top"
|
||||||
>
|
>
|
||||||
<span class="unserved-days" :class="unservedDaysClass(row.unserved_days)">
|
<span class="unserved-days" :class="unservedDaysClass(row.unserved_days)">
|
||||||
|
|||||||
@@ -17,14 +17,14 @@
|
|||||||
</span>
|
</span>
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
v-if="lastBloodAt"
|
v-if="lastBloodAt"
|
||||||
:content="`最近一次血糖打卡:${lastBloodAt}`"
|
:content="`最近一次健康打卡:${lastBloodAt}`"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
>
|
>
|
||||||
<span :class="['unserved-badge', unservedDaysClass(unservedDays)]">
|
<span :class="['unserved-badge', unservedDaysClass(unservedDays)]">
|
||||||
未服务 {{ unservedDays ?? '—' }} 天
|
未服务 {{ unservedDays ?? '—' }} 天
|
||||||
</span>
|
</span>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<span v-else class="unserved-badge unserved-muted">从未打卡血糖</span>
|
<span v-else class="unserved-badge unserved-muted">从未打卡</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ use app\adminapi\lists\BaseAdminDataLists;
|
|||||||
use app\adminapi\logic\dept\DeptLogic;
|
use app\adminapi\logic\dept\DeptLogic;
|
||||||
use app\common\model\tcm\Diagnosis;
|
use app\common\model\tcm\Diagnosis;
|
||||||
use app\common\model\tcm\BloodRecord;
|
use app\common\model\tcm\BloodRecord;
|
||||||
|
use app\common\model\tcm\DietRecord;
|
||||||
|
use app\common\model\tcm\ExerciseRecord;
|
||||||
use app\common\model\DiagnosisViewRecord;
|
use app\common\model\DiagnosisViewRecord;
|
||||||
use app\common\model\Order;
|
use app\common\model\Order;
|
||||||
use app\common\model\doctor\Appointment;
|
use app\common\model\doctor\Appointment;
|
||||||
@@ -387,19 +389,34 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
}
|
}
|
||||||
unset($item);
|
unset($item);
|
||||||
|
|
||||||
// 未服务天数:以血糖记录最近一条 record_date 为锚点(口径见 prd T3)
|
// 未服务天数:血糖 / 饮食 / 运动任一记录最近一条 record_date 为锚点
|
||||||
// 单次 GROUP BY 聚合,不会成 N+1;走 idx_diagnosis_id 索引。
|
|
||||||
$diagIdsForUnserved = array_values(array_filter(array_unique(array_column($lists, 'id'))));
|
$diagIdsForUnserved = array_values(array_filter(array_unique(array_column($lists, 'id'))));
|
||||||
$maxBloodByDiag = [];
|
$maxRecordByDiag = [];
|
||||||
if (!empty($diagIdsForUnserved)) {
|
if (!empty($diagIdsForUnserved)) {
|
||||||
$maxBloodByDiag = BloodRecord::whereIn('diagnosis_id', $diagIdsForUnserved)
|
$maxBlood = BloodRecord::whereIn('diagnosis_id', $diagIdsForUnserved)
|
||||||
->whereNull('delete_time')
|
->whereNull('delete_time')
|
||||||
->group('diagnosis_id')
|
->group('diagnosis_id')
|
||||||
->column('MAX(record_date)', 'diagnosis_id');
|
->column('MAX(record_date)', 'diagnosis_id');
|
||||||
|
$maxDiet = DietRecord::whereIn('diagnosis_id', $diagIdsForUnserved)
|
||||||
|
->whereNull('delete_time')
|
||||||
|
->group('diagnosis_id')
|
||||||
|
->column('MAX(record_date)', 'diagnosis_id');
|
||||||
|
$maxExercise = ExerciseRecord::whereIn('diagnosis_id', $diagIdsForUnserved)
|
||||||
|
->whereNull('delete_time')
|
||||||
|
->group('diagnosis_id')
|
||||||
|
->column('MAX(record_date)', 'diagnosis_id');
|
||||||
|
foreach ($diagIdsForUnserved as $did) {
|
||||||
|
$candidates = [
|
||||||
|
(int) ($maxBlood[$did] ?? 0),
|
||||||
|
(int) ($maxDiet[$did] ?? 0),
|
||||||
|
(int) ($maxExercise[$did] ?? 0),
|
||||||
|
];
|
||||||
|
$maxRecordByDiag[$did] = max($candidates);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$nowTs = time();
|
$nowTs = time();
|
||||||
foreach ($lists as &$item) {
|
foreach ($lists as &$item) {
|
||||||
$last = (int) ($maxBloodByDiag[(int) $item['id']] ?? 0);
|
$last = (int) ($maxRecordByDiag[(int) $item['id']] ?? 0);
|
||||||
$item['last_blood_record_at'] = $last > 0 ? date('Y-m-d', $last) : null;
|
$item['last_blood_record_at'] = $last > 0 ? date('Y-m-d', $last) : null;
|
||||||
$item['unserved_days'] = $last > 0 ? max(0, (int) floor(($nowTs - $last) / 86400)) : null;
|
$item['unserved_days'] = $last > 0 ? max(0, (int) floor(($nowTs - $last) / 86400)) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3728,12 +3728,13 @@ class DiagnosisLogic extends BaseLogic
|
|||||||
// 5.1) 跟踪备注(只读展示,按 note_date DESC)
|
// 5.1) 跟踪备注(只读展示,按 note_date DESC)
|
||||||
$trackingNotes = TrackingNoteLogic::getByDiagnosis($diagnosisId);
|
$trackingNotes = TrackingNoteLogic::getByDiagnosis($diagnosisId);
|
||||||
|
|
||||||
// 6) 未服务天数(与 T3 列同口径)
|
// 6) 未服务天数:血糖 / 饮食 / 运动任一记录最近一条 record_date 为锚点
|
||||||
$maxBloodTs = BloodRecord::where('diagnosis_id', $diagnosisId)
|
$maxBloodTs = (int) BloodRecord::where('diagnosis_id', $diagnosisId)->max('record_date');
|
||||||
->max('record_date');
|
$maxDietTs = (int) DietRecord::where('diagnosis_id', $diagnosisId)->max('record_date');
|
||||||
$maxBloodTs = (int) $maxBloodTs;
|
$maxExerciseTs = (int) ExerciseRecord::where('diagnosis_id', $diagnosisId)->max('record_date');
|
||||||
$unservedDays = $maxBloodTs > 0 ? max(0, (int) floor((time() - $maxBloodTs) / 86400)) : null;
|
$maxRecordTs = max($maxBloodTs, $maxDietTs, $maxExerciseTs);
|
||||||
$lastBloodRecordAt = $maxBloodTs > 0 ? date('Y-m-d', $maxBloodTs) : null;
|
$unservedDays = $maxRecordTs > 0 ? max(0, (int) floor((time() - $maxRecordTs) / 86400)) : null;
|
||||||
|
$lastBloodRecordAt = $maxRecordTs > 0 ? date('Y-m-d', $maxRecordTs) : null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'appointment' => $appointment,
|
'appointment' => $appointment,
|
||||||
|
|||||||
Reference in New Issue
Block a user