feat(sign): 补齐医护端与患者端签署流程
This commit is contained in:
@@ -136,19 +136,37 @@ export function readVersionContentHtml(dto: TemplateVersionResponseDto | null):
|
||||
/**
|
||||
* 把正文 HTML 里的占位符编译成后端可留存的结构化字段定义。
|
||||
*
|
||||
* 后端版本 DTO 的 signatureFields 字段承载「这份模板有哪些填写项」,
|
||||
* 正文本身仍以 contentHtml 提交。不提交这个字段的话,后端拿不到字段口径,
|
||||
* 也就无法在签署侧做必填校验与证据固化。
|
||||
* 正文填写项和 PDF 签名几何是两个独立契约:formFields 负责字段语义,
|
||||
* signatureFields 只负责患者签名图在服务端生成 PDF 中的位置。
|
||||
*/
|
||||
export function buildSignatureFieldsPayload(contentHtml: string): unknown[] {
|
||||
const field = collectFieldDefs(contentHtml).find((item) => item.id === 'signature')
|
||||
if (!field || field.kind !== 'signature') {
|
||||
throw new Error('请在正文中插入“患者签名”占位符')
|
||||
}
|
||||
if (!field.pdfPosition) {
|
||||
throw new Error('请先为“患者签名”配置 PDF 页码和签名位置')
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: field.id,
|
||||
page: field.pdfPosition.page,
|
||||
x: field.pdfPosition.x,
|
||||
y: field.pdfPosition.y,
|
||||
width: field.pdfPosition.width,
|
||||
height: field.pdfPosition.height,
|
||||
coordinateSystem: field.pdfPosition.coordinateSystem,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export function buildFormFieldsPayload(contentHtml: string): unknown[] {
|
||||
return collectFieldDefs(contentHtml).map((field) => ({
|
||||
id: field.id,
|
||||
label: field.label,
|
||||
kind: field.kind,
|
||||
required: field.required,
|
||||
options: field.options,
|
||||
// 单/多选必须一起上报:后端靠它渲染签署控件与做取值校验,
|
||||
// 缺了这个字段就只能按 kind 猜,多选组会被当成单个勾选框
|
||||
...(field.multi === undefined ? {} : { multi: field.multi }),
|
||||
...(field.risk ? { risk: field.risk } : {}),
|
||||
}))
|
||||
@@ -519,6 +537,7 @@ export async function createTemplateWithContent(
|
||||
|
||||
await createTemplateVersion(template.id, {
|
||||
...version,
|
||||
formFields: buildFormFieldsPayload(version.contentHtml),
|
||||
signatureFields: buildSignatureFieldsPayload(version.contentHtml),
|
||||
})
|
||||
|
||||
@@ -539,6 +558,7 @@ export async function updateTemplateContent(
|
||||
): Promise<void> {
|
||||
await createTemplateVersion(templateId, {
|
||||
...version,
|
||||
formFields: buildFormFieldsPayload(version.contentHtml),
|
||||
signatureFields: buildSignatureFieldsPayload(version.contentHtml),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user