fix(application-form-fill): 清理填表说明并收窄按钮话术
This commit is contained in:
@@ -28,6 +28,15 @@ FIELD_ALIASES = {
|
||||
"storage_condition_and_validity": ["产品储存条件及有效期", "储存条件及有效期", "储存条件", "有效期"],
|
||||
}
|
||||
|
||||
STATIC_STOP_LABELS = [
|
||||
"申请人",
|
||||
"国家药品监督管理局",
|
||||
"填表说明",
|
||||
"注",
|
||||
"保证书",
|
||||
"应附资料",
|
||||
]
|
||||
|
||||
|
||||
def collect_document_texts(summary_batch: FileSummaryBatch) -> dict[str, str]:
|
||||
texts: dict[str, str] = {}
|
||||
@@ -180,7 +189,7 @@ def _field_aliases(field: dict[str, str]) -> list[str]:
|
||||
|
||||
|
||||
def _all_field_labels(fields: list[dict[str, str]]) -> list[str]:
|
||||
labels: list[str] = []
|
||||
labels: list[str] = list(STATIC_STOP_LABELS)
|
||||
for field in fields:
|
||||
for label in _field_aliases(field):
|
||||
if label not in labels:
|
||||
@@ -194,7 +203,7 @@ def _extract_label_value(text: str, label: str, labels: list[str]) -> tuple[str,
|
||||
|
||||
def _extract_colon_label_value(text: str, label: str, labels: list[str]) -> tuple[str, str]:
|
||||
escaped_labels = "|".join(re.escape(item) for item in labels if item != label)
|
||||
stop_pattern = rf"(?=\n\s*(?:{escaped_labels})\s*[::])" if escaped_labels else r"(?=\Z)"
|
||||
stop_pattern = rf"(?=\n\s*(?:{escaped_labels})(?:\s*[::]|\s*$))" if escaped_labels else r"(?=\Z)"
|
||||
pattern = re.compile(rf"{re.escape(label)}\s*[::]\s*(.+?)(?:{stop_pattern}|\Z)", re.S)
|
||||
match = pattern.search(text or "")
|
||||
if not match:
|
||||
|
||||
@@ -22,6 +22,7 @@ def fill_template(
|
||||
conflicts: list[dict] | None = None,
|
||||
) -> Path:
|
||||
document = Document(str(template_path))
|
||||
remove_fill_instructions(document)
|
||||
conflict_keys = {item.get("field_key") for item in conflicts or []}
|
||||
for field_config in spec.fields:
|
||||
target = field_config.get("target") or {}
|
||||
@@ -43,6 +44,25 @@ def fill_template(
|
||||
return output
|
||||
|
||||
|
||||
def remove_fill_instructions(document: Document) -> None:
|
||||
removing = False
|
||||
for paragraph in list(document.paragraphs):
|
||||
text = _normalize_label(paragraph.text)
|
||||
if text == "填表说明":
|
||||
removing = True
|
||||
if removing:
|
||||
_remove_paragraph(paragraph)
|
||||
continue
|
||||
if text.startswith("注填表前") and "填表说明" in text:
|
||||
_remove_paragraph(paragraph)
|
||||
|
||||
for table in document.tables:
|
||||
for row in list(table.rows):
|
||||
row_text = _normalize_label("".join(cell.text for cell in row.cells))
|
||||
if row_text == "填表说明" or row_text.startswith("注填表前"):
|
||||
_remove_row(row)
|
||||
|
||||
|
||||
def fill_table_row(document: Document, row_label: str, value: str, *, conflict: bool = False) -> bool:
|
||||
normalized_label = _normalize_label(row_label)
|
||||
for table in document.tables:
|
||||
@@ -71,6 +91,15 @@ def apply_cell_shading(cell, fill: str) -> None:
|
||||
shading.set(qn("w:fill"), fill)
|
||||
|
||||
|
||||
def _remove_paragraph(paragraph) -> None:
|
||||
element = paragraph._element
|
||||
element.getparent().remove(element)
|
||||
|
||||
|
||||
def _remove_row(row) -> None:
|
||||
row._tr.getparent().remove(row._tr)
|
||||
|
||||
|
||||
def create_word_export(
|
||||
batch: ApplicationFormFillBatch,
|
||||
spec: TemplateSpec,
|
||||
|
||||
Reference in New Issue
Block a user