From 909f84b9e62ac4cbcd4694533781be88993d69d4 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Thu, 3 Dec 2026 10:58:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(production-reception):=20=E8=84=90?= =?UTF-8?q?=E5=B8=A6MSC=E5=A2=9E=E5=8A=A0=E9=80=89=E5=A1=AB=E8=84=90?= =?UTF-8?q?=E5=B8=A6=E9=95=BF=E5=BA=A6(cm)=20(#190)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生产接收 profile 挂载 cordLengthCm;前后端标为选填,避免被 既有「profile 全必填」逻辑拦截;只读/移动展示走共享字段解析。 Co-authored-by: Cursor --- .../app/api/sample_production_reception.py | 2 ++ .../app/crud/sample_production_reception.py | 14 ++++++-- backend/app/models/models.py | 1 + .../test_production_reception_cord_length.py | 35 +++++++++++++++++++ ...03-production-reception-cord-length-cm.sql | 17 +++++++++ ...-12-03-production-reception-cord-length.md | 9 +++++ ...production-reception-cord-length-design.md | 31 ++++++++++++++++ .../market/protocol-production-reception.js | 10 ++++-- .../protocol-production-reception.test.js | 7 ++-- .../src/api/sample-production-reception.ts | 1 + ...sample-production-reception-fields.test.ts | 16 +++++++++ .../sample-production-reception-fields.ts | 19 ++++++++-- .../SampleReceptionDialog.vue | 1 + 13 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 backend/tests/test_production_reception_cord_length.py create mode 100644 docs/sql/migrations/2026-12-03-production-reception-cord-length-cm.sql create mode 100644 docs/superpowers/plans/2026-12-03-production-reception-cord-length.md create mode 100644 docs/superpowers/specs/2026-12-03-production-reception-cord-length-design.md diff --git a/backend/app/api/sample_production_reception.py b/backend/app/api/sample_production_reception.py index e42c3701..37b30fb3 100644 --- a/backend/app/api/sample_production_reception.py +++ b/backend/app/api/sample_production_reception.py @@ -67,6 +67,7 @@ class ProductionReceptionBody(BaseModel): available_cell_count_1e7: Optional[float] = Field(None, alias="availableCellCount1e7") original_blood_volume_ml: Optional[float] = Field(None, alias="originalBloodVolumeMl") nucleated_cell_count_1e8: Optional[float] = Field(None, alias="nucleatedCellCount1e8") + cord_length_cm: Optional[float] = Field(None, alias="cordLengthCm") remark: Optional[str] = None @@ -92,6 +93,7 @@ def _body_to_payload(body: ProductionReceptionBody) -> dict: "availableCellCount1e7": body.available_cell_count_1e7, "originalBloodVolumeMl": body.original_blood_volume_ml, "nucleatedCellCount1e8": body.nucleated_cell_count_1e8, + "cordLengthCm": body.cord_length_cm, "remark": body.remark, } diff --git a/backend/app/crud/sample_production_reception.py b/backend/app/crud/sample_production_reception.py index be1e959f..1a4d8ffc 100644 --- a/backend/app/crud/sample_production_reception.py +++ b/backend/app/crud/sample_production_reception.py @@ -32,10 +32,12 @@ FIELD_PROFILES: Dict[Tuple[str, str], List[str]] = { "cryopreservationTime", "storageTotalTubes", "availableCellCount1e7", + "cordLengthCm", ], ("research_donation", SAMPLE_TYPE_UC_MSC): [ "inoculationAmount", "cryopreservationTime", + "cordLengthCm", ], ("research_donation", SAMPLE_TYPE_PERINATAL_HSC): [ "originalBloodVolumeMl", @@ -43,6 +45,11 @@ FIELD_PROFILES: Dict[Tuple[str, str], List[str]] = { ], } +# profile 内可选字段:出现在表单/落库,但不参与必填校验 +OPTIONAL_TYPE_FIELDS = { + "cordLengthCm", +} + ALL_TYPE_FIELDS = { "originalBloodWeightG", "hesVolumeMl", @@ -56,6 +63,7 @@ ALL_TYPE_FIELDS = { "availableCellCount1e7", "originalBloodVolumeMl", "nucleatedCellCount1e8", + "cordLengthCm", } @@ -105,6 +113,7 @@ def _row_to_dict(row: BizSampleProductionReception) -> Dict[str, Any]: "availableCellCount1e7": _dec(row.available_cell_count_1e7), "originalBloodVolumeMl": _dec(row.original_blood_volume_ml), "nucleatedCellCount1e8": _dec(row.nucleated_cell_count_1e8), + "cordLengthCm": _dec(getattr(row, "cord_length_cm", None)), "remark": row.remark or "", "createTime": _fmt_dt(row.create_time), "updateTime": _fmt_dt(row.update_time), @@ -148,8 +157,8 @@ def _validate_payload( source: str, sample_type_name: str, ) -> None: - required = {"handlerUserId", "processTime"} | set( - resolve_field_profile(source, sample_type_name) + required = {"handlerUserId", "processTime"} | ( + set(resolve_field_profile(source, sample_type_name)) - OPTIONAL_TYPE_FIELDS ) for key in required: val = data.get(key) @@ -219,6 +228,7 @@ def _apply_payload_to_row( row.nucleated_cell_count_1e8 = ( data.get("nucleatedCellCount1e8") if "nucleatedCellCount1e8" in allowed else None ) + row.cord_length_cm = data.get("cordLengthCm") if "cordLengthCm" in allowed else None def get_by_reception_id( diff --git a/backend/app/models/models.py b/backend/app/models/models.py index 6605f4c0..be5c2ffe 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -2062,6 +2062,7 @@ class BizSampleProductionReception(Base): available_cell_count_1e7 = Column(Numeric(18, 4), nullable=True, comment="可提供细胞数量/*10E7") original_blood_volume_ml = Column(Numeric(18, 4), nullable=True, comment="原血体积/ml") nucleated_cell_count_1e8 = Column(Numeric(18, 4), nullable=True, comment="有核细胞数/10E8") + cord_length_cm = Column(Numeric(18, 4), nullable=True, comment="脐带长度(cm)") tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号") order_num = Column(Integer, nullable=True, comment="排序号") remark = Column(String(512), nullable=True, comment="备注") diff --git a/backend/tests/test_production_reception_cord_length.py b/backend/tests/test_production_reception_cord_length.py new file mode 100644 index 00000000..682204ff --- /dev/null +++ b/backend/tests/test_production_reception_cord_length.py @@ -0,0 +1,35 @@ +"""生产接收 cordLengthCm:profile 挂载且选填。""" + +from unittest import TestCase + +from app.crud.sample_production_reception import ( + OPTIONAL_TYPE_FIELDS, + _validate_payload, + resolve_field_profile, +) + + +class ProductionReceptionCordLengthTest(TestCase): + def test_uc_msc_profiles_include_optional_cord_length(self): + for source in ("cell_storage", "research_donation"): + profile = resolve_field_profile(source, "脐带间充质干细胞") + self.assertIn("cordLengthCm", profile) + self.assertEqual(profile[-1], "cordLengthCm") + self.assertIn("cordLengthCm", OPTIONAL_TYPE_FIELDS) + + def test_perinatal_hsc_profile_excludes_cord_length(self): + profile = resolve_field_profile("cell_storage", "围产期造血干细胞") + self.assertNotIn("cordLengthCm", profile) + + def test_uc_msc_payload_allows_empty_cord_length(self): + # 其他必填齐全时,缺省 cordLengthCm 不应报错 + _validate_payload( + { + "handlerUserId": "u1", + "processTime": "2026-12-03", + "inoculationAmount": "1ml", + "cryopreservationTime": "2026-12-03", + }, + source="research_donation", + sample_type_name="脐带间充质干细胞", + ) diff --git a/docs/sql/migrations/2026-12-03-production-reception-cord-length-cm.sql b/docs/sql/migrations/2026-12-03-production-reception-cord-length-cm.sql new file mode 100644 index 00000000..5e73f13c --- /dev/null +++ b/docs/sql/migrations/2026-12-03-production-reception-cord-length-cm.sql @@ -0,0 +1,17 @@ +-- 生产接收:增加脐带长度(cm)。MySQL 5.7,可重复执行。 + +SET @col_exists := ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 'biz_sample_production_reception' + AND COLUMN_NAME = 'cord_length_cm' +); +SET @sql := IF( + @col_exists = 0, + 'ALTER TABLE biz_sample_production_reception + ADD COLUMN cord_length_cm DECIMAL(18,4) NULL COMMENT ''脐带长度(cm)'' AFTER nucleated_cell_count_1e8', + 'SELECT 1' +); +PREPARE stmt FROM @sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/docs/superpowers/plans/2026-12-03-production-reception-cord-length.md b/docs/superpowers/plans/2026-12-03-production-reception-cord-length.md new file mode 100644 index 00000000..28ab7ddd --- /dev/null +++ b/docs/superpowers/plans/2026-12-03-production-reception-cord-length.md @@ -0,0 +1,9 @@ +# 生产接收「脐带长度(cm)」Implementation Plan + +**Goal:** 脐带 MSC 生产接收增加选填脐带长度(cm)。 + +**Architecture:** `cord_length_cm` 落库;前后端 profile 挂载;字段 `required:false` 避免被现有“profile 全必填”逻辑卡住。 + +**修改端:** backend / web-admin / mobile-oa-h5 + +关联 #190 diff --git a/docs/superpowers/specs/2026-12-03-production-reception-cord-length-design.md b/docs/superpowers/specs/2026-12-03-production-reception-cord-length-design.md new file mode 100644 index 00000000..70208daf --- /dev/null +++ b/docs/superpowers/specs/2026-12-03-production-reception-cord-length-design.md @@ -0,0 +1,31 @@ +# 生产接收增加「脐带长度(cm)」 + +关联 Gitea #190。 + +## 目标 + +在生产接收登记中增加选填字段「脐带长度(cm)」,仅对脐带间充质干细胞(细胞存储 + 科研捐赠)展示与录入;凡展示生产接收信息处一并显示。 + +## 约束 + +- 选填;空值存 `NULL` +- 仅 profile:`cell_storage|脐带间充质干细胞`、`research_donation|脐带间充质干细胞` +- 表单位置:对应配置字段列表末尾、备注前 +- 不改质检接收字段 + +## 数据与 API + +- 表 `biz_sample_production_reception` 新增:`cord_length_cm DECIMAL(18,4) NULL COMMENT '脐带长度(cm)'` +- 迁移:`docs/sql/migrations/2026-12-03-production-reception-cord-length-cm.sql` +- ORM / CRUD / API:`cordLengthCm` + +## 前端 + +- `sample-production-reception-fields.ts`:字段定义 + 两处 profile 挂载 +- 生产填写弹窗、共享只读、详情、mobile-oa-h5 生产接收卡片走现有 `resolveProductionReceptionFields` + +## 验收 + +1. 脐带 MSC 生产接收可填脐带长度,空可提交 +2. 围产期造血干等其他配置不出现该字段 +3. 只读/详情/移动端生产接收可见该值(空为 —) diff --git a/mobile-oa-h5/src/market/protocol-production-reception.js b/mobile-oa-h5/src/market/protocol-production-reception.js index f3484eaa..1a733033 100644 --- a/mobile-oa-h5/src/market/protocol-production-reception.js +++ b/mobile-oa-h5/src/market/protocol-production-reception.js @@ -12,7 +12,8 @@ const FIELD_DEFS = Object.freeze({ storageTotalTubes: { key: 'storageTotalTubes', label: '储存总量(管)' }, availableCellCount1e7: { key: 'availableCellCount1e7', label: '可提供细胞数量/*10E7' }, originalBloodVolumeMl: { key: 'originalBloodVolumeMl', label: '原血体积/ml' }, - nucleatedCellCount1e8: { key: 'nucleatedCellCount1e8', label: '有核细胞数/10E8' } + nucleatedCellCount1e8: { key: 'nucleatedCellCount1e8', label: '有核细胞数/10E8' }, + cordLengthCm: { key: 'cordLengthCm', label: '脐带长度(cm)' } }) const PROFILE_KEYS = Object.freeze({ @@ -21,9 +22,12 @@ const PROFILE_KEYS = Object.freeze({ 'infectiousFourTestResult', 'enrichedBloodWeightG', 'cryopreservationVolumeMl' ], 'cell_storage|脐带间充质干细胞': [ - 'inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', 'availableCellCount1e7' + 'inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', 'availableCellCount1e7', + 'cordLengthCm' + ], + 'research_donation|脐带间充质干细胞': [ + 'inoculationAmount', 'cryopreservationTime', 'cordLengthCm' ], - 'research_donation|脐带间充质干细胞': ['inoculationAmount', 'cryopreservationTime'], 'research_donation|围产期造血干细胞': ['originalBloodVolumeMl', 'nucleatedCellCount1e8'] }) diff --git a/mobile-oa-h5/src/market/protocol-production-reception.test.js b/mobile-oa-h5/src/market/protocol-production-reception.test.js index 0a7c0f6d..0f4873f7 100644 --- a/mobile-oa-h5/src/market/protocol-production-reception.test.js +++ b/mobile-oa-h5/src/market/protocol-production-reception.test.js @@ -17,7 +17,7 @@ test('matches Web production reception profiles by source and sample type', () = ) assert.deepEqual( resolveProductionReceptionFields('research_donation', '脐带间充质干细胞').map((field) => field.key), - ['inoculationAmount', 'cryopreservationTime'] + ['inoculationAmount', 'cryopreservationTime', 'cordLengthCm'] ) assert.deepEqual( resolveProductionReceptionFields('research_donation', '围产期造血干细胞').map((field) => field.key), @@ -25,7 +25,10 @@ test('matches Web production reception profiles by source and sample type', () = ) assert.deepEqual( resolveProductionReceptionFields('cell_storage', '脐带间充质干细胞').map((field) => field.key), - ['inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', 'availableCellCount1e7'] + [ + 'inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', 'availableCellCount1e7', + 'cordLengthCm' + ] ) }) diff --git a/web-admin/src/api/sample-production-reception.ts b/web-admin/src/api/sample-production-reception.ts index 10f7382a..5aae5924 100644 --- a/web-admin/src/api/sample-production-reception.ts +++ b/web-admin/src/api/sample-production-reception.ts @@ -21,6 +21,7 @@ export type ProductionReceptionPayload = { availableCellCount1e7?: number originalBloodVolumeMl?: number nucleatedCellCount1e8?: number + cordLengthCm?: number | null remark?: string } diff --git a/web-admin/src/utils/sample-production-reception-fields.test.ts b/web-admin/src/utils/sample-production-reception-fields.test.ts index 57e486bd..7a430af3 100644 --- a/web-admin/src/utils/sample-production-reception-fields.test.ts +++ b/web-admin/src/utils/sample-production-reception-fields.test.ts @@ -31,4 +31,20 @@ describe('inoculationAmount / cryopreservationTime field kinds', () => { assert.equal(formatProductionFieldValue(inoc, record), '约 5×10⁶ cells,接种体积 2ml') assert.equal(formatProductionFieldValue(cryo, record), '2026-07-14') }) + + it('adds optional cordLengthCm at end of UC-MSC profiles only', () => { + for (const source of ['cell_storage', 'research_donation'] as const) { + const fields = resolveProductionReceptionFields(source, '脐带间充质干细胞') + const cord = fields.find((f) => f.key === 'cordLengthCm') + assert.ok(cord) + assert.equal(cord.label, '脐带长度(cm)') + assert.equal(cord.required, false) + assert.equal(fields[fields.length - 1].key, 'cordLengthCm') + } + const hsc = resolveProductionReceptionFields('cell_storage', '围产期造血干细胞') + assert.equal( + hsc.some((f) => f.key === 'cordLengthCm'), + false + ) + }) }) diff --git a/web-admin/src/utils/sample-production-reception-fields.ts b/web-admin/src/utils/sample-production-reception-fields.ts index 031fccdd..0d6d66f6 100644 --- a/web-admin/src/utils/sample-production-reception-fields.ts +++ b/web-admin/src/utils/sample-production-reception-fields.ts @@ -18,12 +18,15 @@ export type ProductionReceptionFieldKey = | 'availableCellCount1e7' | 'originalBloodVolumeMl' | 'nucleatedCellCount1e8' + | 'cordLengthCm' export type ProductionReceptionFieldDef = { key: ProductionReceptionFieldKey label: string kind: 'number' | 'text' | 'datetime' | 'date' | 'select' | 'integer' maxLength?: number + /** 默认 true;false 时表单不强制必填 */ + required?: boolean selectOptions?: Array<{ label: string; value: string }> } @@ -66,6 +69,12 @@ const FIELD_DEFS: Record = { 'inoculationAmount', 'cryopreservationTime', 'storageTotalTubes', - 'availableCellCount1e7' + 'availableCellCount1e7', + 'cordLengthCm' + ], + 'research_donation|脐带间充质干细胞': [ + 'inoculationAmount', + 'cryopreservationTime', + 'cordLengthCm' ], - 'research_donation|脐带间充质干细胞': ['inoculationAmount', 'cryopreservationTime'], 'research_donation|围产期造血干细胞': ['originalBloodVolumeMl', 'nucleatedCellCount1e8'] } @@ -125,6 +139,7 @@ export type ProductionReceptionRecord = { availableCellCount1e7?: number originalBloodVolumeMl?: number nucleatedCellCount1e8?: number + cordLengthCm?: number | null remark?: string } diff --git a/web-admin/src/views/production/production-work-order/SampleReceptionDialog.vue b/web-admin/src/views/production/production-work-order/SampleReceptionDialog.vue index a4307b54..0b65f83d 100644 --- a/web-admin/src/views/production/production-work-order/SampleReceptionDialog.vue +++ b/web-admin/src/views/production/production-work-order/SampleReceptionDialog.vue @@ -360,6 +360,7 @@ handlerUserId: [{ required: true, message: '请选择处理人', trigger: 'change' }] } for (const field of productionFieldDefs.value) { + if (field.required === false) continue rules[field.key] = [{ required: true, message: `请填写${field.label}`, trigger: 'blur' }] } return rules -- 2.54.0