1. 开方页面代煎选择交互
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled

This commit is contained in:
李琦
2026-07-10 15:11:18 +08:00
parent 026d0e0a48
commit e0cb5c660c
3 changed files with 402 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
/** 展示用优先顶层合并医嘱fallback content 纯医嘱 */
export function formatDoctorOrderText(
item?: {
doctor_order?: string | string[];
content?: { doctor_order?: string };
} | null,
): string {
const raw = item?.doctor_order ?? item?.content?.doctor_order ?? '';
if (Array.isArray(raw)) {
const list = raw.map((s) => String(s).trim()).filter(Boolean);
return list.length ? list.join('') : '-';
}
const parts = String(raw)
.split('|')
.map((s) => s.trim())
.filter(Boolean);
return parts.length ? parts.join('') : raw ? String(raw) : '-';
}
/** 复用开方输入框detail.doctor_order 为数组时转回字符串 */
export function detailDoctorOrderToText(
doctorOrder?: string | string[] | null,
): string {
if (Array.isArray(doctorOrder)) {
return doctorOrder.map((s) => String(s).trim()).filter(Boolean).join('|');
}
return doctorOrder ?? '';
}

View File

@@ -0,0 +1,90 @@
export type ProcessRuleListItem = { id?: number | string };
export type ProcessRuleLoadedLevel = 'root' | 'child' | 'note';
/**
* 列表仅一项且当前未选时,返回该项 id
* 用于委托调剂制剂/煎法/备注的默认选中
*/
export function getSingleProcessRuleId(
list: ProcessRuleListItem[] | null | undefined,
currentId?: number | string | null,
): number | null {
if (!Array.isArray(list) || list.length !== 1) {
return null;
}
const cur = currentId == null || currentId === '' ? null : Number(currentId);
if (cur != null && Number.isFinite(cur) && cur > 0) {
return null;
}
const id = Number(list[0]?.id);
return Number.isFinite(id) && id > 0 ? id : null;
}
/** 根据 loadProcessRuleData 参数判断刚加载的是哪一级 */
export function resolveProcessRuleLoadedLevel(
pid: number,
ruleId: number,
): ProcessRuleLoadedLevel {
if (ruleId !== 0) {
return 'note';
}
if (pid === 0) {
return 'root';
}
return 'child';
}
export type ProcessRuleAutoSelectContext = {
ruleType: number;
disabled?: boolean;
processRuleId?: number | string | null;
childProcessRuleId?: number | string | null;
processRuleNoteId?: number | string | null;
processRuleList: ProcessRuleListItem[];
childProcessRuleList: ProcessRuleListItem[];
processRuleNoteList: ProcessRuleListItem[];
load: (pid: number, ruleId: number) => Promise<void>;
setProcessRuleId: (id: number) => void;
setChildProcessRuleId: (id: number) => void;
setProcessRuleNoteId: (id: number) => void;
clearBelowProcessRule: () => void;
clearBelowChild: () => void;
};
/**
* 子级仅一项时自动选中,并级联 load 下一级
* 不覆盖已有选中值(草稿恢复、用户手选、历史导入)
*/
export async function applySingleChildProcessRuleAutoSelect(
loadedLevel: ProcessRuleLoadedLevel,
ctx: ProcessRuleAutoSelectContext,
): Promise<void> {
if (ctx.disabled || ctx.ruleType !== 2) {
return;
}
if (loadedLevel === 'root') {
const id = getSingleProcessRuleId(ctx.processRuleList, ctx.processRuleId);
if (id == null) {
return;
}
ctx.clearBelowProcessRule();
ctx.setProcessRuleId(id);
await ctx.load(id, 0);
return;
}
if (loadedLevel === 'child') {
const id = getSingleProcessRuleId(ctx.childProcessRuleList, ctx.childProcessRuleId);
if (id == null) {
return;
}
ctx.clearBelowChild();
ctx.setChildProcessRuleId(id);
await ctx.load(0, id);
return;
}
const noteId = getSingleProcessRuleId(ctx.processRuleNoteList, ctx.processRuleNoteId);
if (noteId != null) {
ctx.setProcessRuleNoteId(noteId);
}
}