Commit 750f1f3c by luoqi

fix(web): 病历快读同日多医生排序错乱 — 用关联事实真实时分做 tiebreak

emr_record 的 occurredAt 只到日期(00:00:00),同日多医生(典型:转诊,吴仲恺先诊断+转诊、
刘柳后做正畸评估)在 localeCompare 下打平 → 排序不稳定、先后乱。
修:emr 排序前预计算排序键 = 同次接诊关联事实(diagnosis/treatment,经
source_encounter_external_id  emr_external_id 关联,带真实时分)的最晚时间,fallback emr.occurredAt。
例 王思涵 2021-07-23:吴仲恺 emr(关联08:05)< 刘柳 emr(关联08:58)→ 刘柳正确排为第2次(最近)。
纯前端、渲染期推导,无需重摄。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 707325e2
......@@ -23,9 +23,26 @@ import type { AdaptedFact } from './adapt-data';
* - 当前卡淡入展示;默认最新一次接诊(idx=0)
*/
export function EmrSoapView({ facts }: { facts: AdaptedFact[] }) {
const emrs = facts
.filter((f) => f.type === 'emr_record')
.sort((a, b) => (b.occurredAt ?? '').localeCompare(a.occurredAt ?? ''));
// emr_record 的 occurredAt 只到日期(00:00:00)→ 同日多医生(如转诊:吴仲恺先、刘柳后)会打平,
// 排序不稳定。用同次接诊的诊断/治疗事实(带真实时分,经 source_encounter_external_id ↔ emr_external_id
// 关联)补出真实时序做 tiebreak。预计算每条 emr 的排序键,避免比较器里重复扫 facts。
const encId = (f: AdaptedFact) =>
String((f.content as Record<string, unknown> | null)?.source_encounter_external_id ?? '');
const emrList = facts.filter((f) => f.type === 'emr_record');
const sortKey = new Map<string, string>();
for (const emr of emrList) {
const emrId = String((emr.content as Record<string, unknown> | null)?.emr_external_id ?? '');
let best = emr.occurredAt ?? '';
if (emrId) {
for (const f of facts) {
if (f.occurredAt && f.occurredAt > best && encId(f) === emrId) best = f.occurredAt;
}
}
sortKey.set(emr.id, best);
}
const emrs = emrList.sort((a, b) =>
(sortKey.get(b.id) ?? '').localeCompare(sortKey.get(a.id) ?? ''),
);
const [idx, setIdx] = useState(0);
const total = emrs.length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment