feat(sample-reception): 增加选填血量克重(g)并全量展示 (#188) #189

Merged
cykj merged 2 commits from feat/sample-reception-blood-weight into V2.0 2026-12-03 02:40:54 +00:00
18 changed files with 267 additions and 1 deletions

No files matched your search

+4
View File
@@ -325,6 +325,7 @@ class SampleReceptionUpdateBody(BaseModel):
receive_attachments: Optional[str] = Field(None, alias="receiveAttachments")
remark: Optional[str] = None
lab_storage_code: Optional[str] = Field(None, alias="labStorageCode")
blood_weight_g: Optional[float] = Field(None, alias="bloodWeightG")
class SampleReceptionCreateBody(BaseModel):
@@ -342,6 +343,7 @@ class SampleReceptionCreateBody(BaseModel):
source_type: Optional[str] = Field("cell_storage", alias="sourceType")
donation_sample_id: Optional[str] = Field(None, alias="donationSampleId")
lab_storage_code: Optional[str] = Field(None, alias="labStorageCode")
blood_weight_g: Optional[float] = Field(None, alias="bloodWeightG")
class AllocateLabStorageCodesBody(BaseModel):
@@ -412,6 +414,7 @@ async def post_sample_reception(
receive_attachments=body.receive_attachments,
remark=body.remark,
lab_storage_code=body.lab_storage_code,
blood_weight_g=body.blood_weight_g,
)
detail = sr_svc.get_reception_by_id(db, obj.id, tenant_no)
return success_response(detail or {"id": obj.id})
@@ -453,6 +456,7 @@ async def put_sample_reception(
receive_attachments=body.receive_attachments,
remark=body.remark,
lab_storage_code=body.lab_storage_code,
blood_weight_g=body.blood_weight_g,
)
detail = sr_svc.get_reception_by_id(db, obj.id, tenant_no)
return success_response(detail or {"id": obj.id})
+14
View File
@@ -73,6 +73,15 @@ def _dec(v: Any) -> Optional[float]:
return float(v)
def _fmt_optional_decimal(value: Any) -> Optional[float]:
if value is None or value == "":
return None
try:
return float(value)
except (TypeError, ValueError):
return None
def _reception_to_dict(
r: BizSampleReception,
*,
@@ -89,6 +98,7 @@ def _reception_to_dict(
"checkResults": check_results or [],
"acceptConclusion": r.accept_conclusion or "",
"labStorageCode": r.lab_storage_code or "",
"bloodWeightG": _fmt_optional_decimal(getattr(r, "blood_weight_g", None)),
"receiveAttachments": r.receive_attachments or "",
"remark": r.remark or "",
"createTime": _fmt_dt(r.create_time),
@@ -909,6 +919,7 @@ def create_sample_reception(
receive_temperature: Optional[str],
volume_ml: Optional[float] = None,
net_weight_g: Optional[float] = None,
blood_weight_g: Optional[float] = None,
checks: List[Dict[str, Any]],
accept_conclusion: str,
receive_attachments: Optional[str],
@@ -1022,6 +1033,7 @@ def create_sample_reception(
research_donation_id=_research_donation_id,
sample_code=_sample_code or None,
lab_storage_code=resolved_lab_code,
blood_weight_g=_fmt_optional_decimal(blood_weight_g),
reception_time=reception_time,
handler_user_id=handler_user_id,
handler_name=handler_display or None,
@@ -1186,6 +1198,7 @@ def update_sample_reception(
receive_temperature: Optional[str],
volume_ml: Optional[float] = None,
net_weight_g: Optional[float] = None,
blood_weight_g: Optional[float] = None,
checks: List[Dict[str, Any]],
accept_conclusion: str,
receive_attachments: Optional[str],
@@ -1259,6 +1272,7 @@ def update_sample_reception(
rec.handler_user_id = handler_user_id
rec.handler_name = handler_display or None
rec.receive_temperature = (receive_temperature or "").strip() or None
rec.blood_weight_g = _fmt_optional_decimal(blood_weight_g)
rec.accept_conclusion = conclusion
rec.receive_attachments = (receive_attachments or "").strip() or None
rec.remark = (remark or "").strip() or None
@@ -677,6 +677,7 @@ def get_review_detail(db: Session, review_id: str, tenant_no: str) -> Optional[D
"acceptConclusion": reception_detail.get("acceptConclusion") or "",
"acceptConclusionLabel": reception_detail.get("acceptConclusionLabel") or "",
"labStorageCode": reception_detail.get("labStorageCode") or "",
"bloodWeightG": reception_detail.get("bloodWeightG"),
"remark": reception_detail.get("remark") or "",
"checkResults": reception_detail.get("checkResults") or [],
"receiveAttachments": reception_detail.get("receiveAttachments") or "",
@@ -902,6 +903,9 @@ def _build_reception_info(db: Session, rev: BizStorageReleaseReview) -> Dict[str
"netWeightG": float(rec.net_weight_g) if rec.net_weight_g else None,
"acceptConclusion": rec.accept_conclusion or "",
"labStorageCode": rec.lab_storage_code or "",
"bloodWeightG": float(rec.blood_weight_g)
if getattr(rec, "blood_weight_g", None) not in (None, "")
else None,
}
+1
View File
@@ -2003,6 +2003,7 @@ class BizSampleReception(Base):
research_donation_id = Column(String(64), nullable=True, comment="科研捐赠单ID(仅科研捐赠)")
sample_code = Column(String(32), nullable=True, comment="样本编码快照")
lab_storage_code = Column(String(32), nullable=True, comment="实验室入库编码")
blood_weight_g = Column(Numeric(18, 4), nullable=True, comment="血量克重(g)")
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
order_num = Column(Integer, nullable=True, comment="排序号")
remark = Column(String(512), nullable=True, comment="备注信息")
@@ -0,0 +1,36 @@
"""样本接收 bloodWeightG 序列化与可选写回。"""
from datetime import datetime
from decimal import Decimal
from unittest import TestCase
from app.crud.sample_reception import _reception_to_dict
from app.models.models import BizSampleReception
def _make_reception(**kwargs) -> BizSampleReception:
defaults = dict(
id="rec-1",
protocol_sample_id="ps-1",
collection_protocol_id="cp-1",
reception_time=datetime(2026, 12, 3, 10, 0, 0),
accept_conclusion="js",
tenant_no="zkxw",
create_dept_id="",
del_flag=0,
)
defaults.update(kwargs)
return BizSampleReception(**defaults)
class SampleReceptionBloodWeightTest(TestCase):
def test_reception_to_dict_includes_blood_weight(self):
row = _make_reception(blood_weight_g=Decimal("12.5000"), lab_storage_code="LAB001")
data = _reception_to_dict(row)
self.assertEqual(data["labStorageCode"], "LAB001")
self.assertEqual(data["bloodWeightG"], 12.5)
def test_reception_to_dict_blood_weight_null(self):
row = _make_reception(blood_weight_g=None)
data = _reception_to_dict(row)
self.assertIsNone(data["bloodWeightG"])
@@ -0,0 +1,17 @@
-- 样本接收:增加血量克重(g)。MySQL 5.7,可重复执行。
SET @col_exists := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'biz_sample_reception'
AND COLUMN_NAME = 'blood_weight_g'
);
SET @sql := IF(
@col_exists = 0,
'ALTER TABLE biz_sample_reception
ADD COLUMN blood_weight_g DECIMAL(18,4) NULL COMMENT ''血量克重(g)'' AFTER lab_storage_code',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@@ -0,0 +1,64 @@
# 样本接收「血量克重(g)」Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 样本接收增加选填字段血量克重(g),落库并在所有质检接收信息展示点(含市场/生产)显示。
**Architecture:** `biz_sample_reception.blood_weight_g` 新列;API camelCase `bloodWeightG`;Web 录入页与共享只读组件/`buildQcReceptionViewFields` 贯通;移动 OA 协议生命周期卡片补字段。
**Tech Stack:** FastAPI / SQLAlchemy / Vue 3 / mobile-oa-h5 / MySQL 迁移
**Spec:** `docs/superpowers/specs/2026-12-03-sample-reception-blood-weight-design.md`
**修改端:** `backend`、`web-admin`、`mobile-oa-h5`
---
## File map
| 文件 | 职责 |
| --- | --- |
| `docs/sql/migrations/2026-12-03-sample-reception-blood-weight-g.sql` | 幂等加列 |
| `backend/app/models/models.py` | ORM 字段 |
| `backend/app/crud/sample_reception.py` | 序列化/创建/更新 |
| `backend/app/api/sample_reception.py` | Create/Update Body + 传参 |
| `backend/app/crud/storage_release_review.py` | 放行详情里的接收摘要补字段 |
| `backend/tests/test_sample_reception_blood_weight.py` | 序列化与写回单测 |
| `web-admin/src/api/sample-reception.ts` | 请求类型 |
| `web-admin/src/utils/sample-production-reception-fields.ts` | `QcReceptionRecord` |
| `web-admin/src/utils/sample-reception-view-sections.ts` | 共享只读字段 |
| `web-admin/src/utils/sample-reception-view-sections.test.ts` | 字段顺序断言 |
| `web-admin/src/components/business/sample-reception-dual-readonly-panel/index.vue` | 双只读面板 |
| `web-admin/src/views/quality-inspection/sample-reception/index.vue` | 录入/批量/详情 |
| `mobile-oa-h5/src/market/modules/protocol.js` | 质检接收卡片字段 |
| `mobile-oa-h5/src/market/protocol-mobile-parity.test.js` | 补测数据与断言 |
---
### Task 1: 后端序列化单测(红)+ 模型/CRUD/API/SQL
- [ ] **Step 1:** 新增 `backend/tests/test_sample_reception_blood_weight.py`,断言 `_reception_to_dict` 输出 `bloodWeightG`,空为 `None`/`""` 约定与实现对齐
- [ ] **Step 2:** 跑测确认失败
- [ ] **Step 3:** SQL 迁移 + ORM + `_reception_to_dict` + create/update 赋值 + API Body 传参;`storage_release_review` 接收摘要补字段
- [ ] **Step 4:** 跑测通过;`python backend/scripts/check_field_consistency.py` 核对相关实体(区分既有失败)
### Task 2: Web 共享展示 + 类型
- [ ] **Step 1:** 为 `buildQcReceptionViewFields` 写失败测试:入库编码后紧跟「血量克重(g)」
- [ ] **Step 2:** 实现 view-sections、`QcReceptionRecord`、dual-readonly-panel
- [ ] **Step 3:** 跑前端相关 test 通过
### Task 3: Web 样本接收录入页
- [ ] **Step 1:** `sample-reception.ts` 提交/更新类型加 `bloodWeightG?`
- [ ] **Step 2:** `index.vue` 单条/批量/详情:入库编码后增加字段;submit payload 带上;空串不传或传 null
### Task 4: 移动 OA
- [ ] **Step 1:** `protocol.js` 质检接收卡片入库编码后加「血量克重(g)」
- [ ] **Step 2:** 更新 `protocol-mobile-parity.test.js` 并跑通
### Task 5: 收尾
- [ ] 字段一致性 / 定向测试 / 代码审查
- [ ] 合入 `V2.0`、推送、关 Gitea 工单;不启停服务、不打 tag、不部署
@@ -0,0 +1,58 @@
# 样本接收增加「血量克重(g)」
关联 Gitea #188。
## 目标
在质量检测「样本接收」登记/编辑中增加选填字段「血量克重(g)」,放在「实验室入库编码」之后;凡展示质检样本接收信息的界面(含市场、生产大菜单下)一并展示。
## 约束
- 选填:空值可提交,库中存 `NULL`
- 所有样本类型均显示、均可填
- 不改生产接收字段(如 `originalBloodWeightG`)
- 不复用未启用的 `net_weight_g`(净重),避免语义冲突
- 列表/卡片摘要、仅作标题或检索键的入库编码展示处不追加该字段
## 数据与 API
- 表 `biz_sample_reception` 新增:`blood_weight_g DECIMAL(18,4) NULL COMMENT '血量克重(g)'`,位于 `lab_storage_code` 之后
- 迁移:`docs/sql/migrations/2026-12-03-sample-reception-blood-weight-g.sql`(幂等)
- ORM、`_reception_to_dict`、创建/更新 CRUD、Create/Update Body 增加可选 `bloodWeightG`
- 前端契约字段名:`bloodWeightG`;文案:`血量克重(g)`
## 录入(Web)
页面:`web-admin/src/views/quality-inspection/sample-reception/index.vue`
- 单条接收/编辑弹窗:实验室入库编码后增加输入项
- 批量接收:每条同样位置增加输入项
- 接收详情:只读展示于入库编码后;空显示 `—`
- 已接收列表卡片不展示该字段(避免卡片过密)
## 展示覆盖
### 共享层(优先改,覆盖市场/生产/质检)
| 共享点 | 覆盖场景 |
| --- | --- |
| `buildQcReceptionViewFields` | 生产工单详情「质检接收」、质检入库视图、入库放行查看、质检任务详情等 |
| `SampleReceptionDualReadonlyPanel` | 市场协议/捐赠详情;生产「样本接收信息填写」中的质检接收只读区;入库放行审核;样本接收编辑只读区等 |
| `QcReceptionRecord` 等类型 | 补 `bloodWeightG` |
共享展示中,字段顺序:实验室入库编码 → 血量克重(g)。
### 单独改
| 位置 | 说明 |
| --- | --- |
| 样本接收「接收详情」弹窗 | 手写只读网格 |
| `mobile-oa-h5` 协议生命周期「质检接收」卡片 | `protocol.js` 字段列表 |
## 验收
1. 样本接收单条/批量/编辑可填血量克重,空值可提交并保存为 `NULL`
2. 接收详情与共享只读组件在入库编码后展示该值(空为 `—`)
3. 市场协议/捐赠详情、生产样本接收弹窗与生产工单质检接收区块可见该字段
4. 移动 OA 质检接收卡片可见该字段
5. 字段一致性检查与相关单测通过
@@ -336,6 +336,7 @@ function sampleLifecycleCards(item, source) {
{ label: '接收温度(℃)', value: value(reception, 'receiveTemperature') },
{ label: '结论', value: value(reception, 'acceptConclusionLabel'), tag: true },
{ label: '实验室入库编码', value: value(reception, 'labStorageCode') },
{ label: '血量克重(g)', value: value(reception, 'bloodWeightG') },
{ label: '检查项', value: checkedItems(reception?.checkResults) },
{ label: '备注', value: value(reception, 'remark') },
{ label: '接收附件', value: reception?.receiveAttachmentFiles || reception?.receiveAttachments || '', type: 'attachments' }
@@ -36,6 +36,7 @@ test('protocol detail exposes reception and storage release without qc productio
receiveTemperature: '4.2',
acceptConclusionLabel: '接收',
labStorageCode: 'LAB-1',
bloodWeightG: 12.5,
checkResults: [{ itemName: '包装完整', checked: true }],
remark: '接收正常',
receiveAttachmentFiles: [{ fileUrl: 'receive.pdf', fileName: 'receive.pdf' }]
@@ -75,9 +76,11 @@ test('protocol detail exposes reception and storage release without qc productio
)
const labels = [...sample.fields.map((field) => field.label), ...sample.cards.flatMap(cardLabels)]
for (const expected of [
'质检接收', '接收时间', '接收附件', '生产接收', '处理时间',
'质检接收', '接收时间', '血量克重(g)', '接收附件', '生产接收', '处理时间',
'入库放行', '生产结论', '质检结论', '入库状态', '质检附件', '生产附件'
]) assert.ok(labels.includes(expected), `missing ${expected}`)
const reception = sample.cards.find((card) => card.title === '质检接收')
assert.equal(reception.fields.find((field) => field.label === '血量克重(g)').value, '12.5')
for (const hidden of ['门控质检', '过程质检 1', '生产信息', '生产任务 1']) {
assert.ok(!labels.includes(hidden), `must not show ${hidden}`)
}
+1
View File
@@ -72,6 +72,7 @@ export type QcWorkOrderReceptionDetail = {
acceptConclusion?: string
acceptConclusionLabel?: string
labStorageCode?: string
bloodWeightG?: number | null
remark?: string
etaTime?: string
transportType?: string
+2
View File
@@ -73,6 +73,7 @@ export function fetchSampleReceptionUpdate(
receiveAttachments?: string
remark?: string
labStorageCode?: string
bloodWeightG?: number | null
}
) {
return request.put({
@@ -94,6 +95,7 @@ export function fetchSampleReceptionSubmit(data: {
receiveAttachments?: string
remark?: string
labStorageCode?: string
bloodWeightG?: number | null
}) {
return request.post({
url: '/web/admin/sample-receptions',
@@ -92,6 +92,7 @@ export type ReceptionInfo = {
netWeightG?: number | null
acceptConclusion?: string
labStorageCode?: string
bloodWeightG?: number | null
}
export type QcInfoTask = {
@@ -32,6 +32,16 @@
>
<span class="label">实验室入库编码</span>{{ qcReception.labStorageCode || '—' }}
</div>
<div class="readonly-item">
<span class="label">血量克重(g)</span
>{{
qcReception.bloodWeightG === null ||
qcReception.bloodWeightG === undefined ||
qcReception.bloodWeightG === ''
? '—'
: qcReception.bloodWeightG
}}
</div>
<div class="readonly-item form-col-span-2 check-items-readonly">
<span class="label">检查项</span>
<div v-if="qcReception.checkResults?.length" class="check-list check-list-view">
@@ -135,6 +135,7 @@ export type QcReceptionRecord = {
acceptConclusion?: string
acceptConclusionLabel?: string
labStorageCode?: string
bloodWeightG?: number | string | null
checkResults?: Array<{ itemName?: string; checked?: boolean }>
remark?: string
receiveAttachmentFiles?: Array<Record<string, unknown>>
@@ -8,6 +8,11 @@ import {
type ProductionReceptionRecord
} from '@/utils/sample-production-reception-fields'
function formatBloodWeightG(value: unknown): string {
if (value === null || value === undefined || value === '') return '—'
return String(value)
}
export function buildQcReceptionViewFields(
r: Record<string, unknown>,
d?: Record<string, unknown>
@@ -20,6 +25,10 @@ export function buildQcReceptionViewFields(
label: '实验室入库编码',
value: String(r.labStorageCode || d?.labStorageCode || '—')
},
{
label: '血量克重(g)',
value: formatBloodWeightG(r.bloodWeightG ?? d?.bloodWeightG)
},
{
label: '接收温度(℃)',
value: r.receiveTemperature ? `${r.receiveTemperature}℃` : '—'
@@ -344,6 +344,13 @@
@input="onLabStorageCodeManualInput"
/>
</el-form-item>
<el-form-item label="血量克重(g)">
<el-input
v-model="receiveForm.bloodWeightG"
placeholder="选填"
clearable
/>
</el-form-item>
<el-form-item label="检查项确认" class="form-col-span-2">
<div v-if="activeCheckItems.length" class="check-list">
<el-checkbox
@@ -504,6 +511,16 @@
<div class="readonly-item">
<span class="label">实验室入库编码</span>{{ viewRow.labStorageCode || '-' }}
</div>
<div class="readonly-item">
<span class="label">血量克重(g)</span
>{{
viewRow.bloodWeightG === null ||
viewRow.bloodWeightG === undefined ||
viewRow.bloodWeightG === ''
? '-'
: viewRow.bloodWeightG
}}
</div>
<div class="readonly-item">
<span class="label">结论</span
><el-tag
@@ -700,6 +717,9 @@
@input="() => onBatchLabStorageCodeManualInput(entry)"
/>
</el-form-item>
<el-form-item label="血量克重(g)">
<el-input v-model="entry.bloodWeightG" placeholder="选填" clearable />
</el-form-item>
</div>
<el-form-item label="检查项确认" class="form-col-span-2">
<div v-if="activeCheckItems.length" class="check-list">
@@ -915,6 +935,7 @@
acceptConclusion: 'js' | 'bj'
remark: string
labStorageCode: string
bloodWeightG: string
labStorageCodeManuallyEdited: boolean
lastAllocatedReceptionDate: string
checkValues: Record<string, boolean>
@@ -930,9 +951,19 @@
receiveTemperature: '',
acceptConclusion: 'js' as 'js' | 'bj',
labStorageCode: '',
bloodWeightG: '',
remark: ''
})
/** 空串 → null(可清空);非法数字也按空处理 */
function parseOptionalBloodWeightG(raw: unknown): number | null {
const text = String(raw ?? '').trim()
if (!text) return null
const num = Number(text)
if (Number.isNaN(num)) return null
return num
}
const labStorageCodeManuallyEdited = ref(false)
const lastAllocatedReceptionDate = ref('')
@@ -1045,6 +1076,10 @@
receiveForm.receiveTemperature = String(detail.receiveTemperature || '')
receiveForm.acceptConclusion = String(detail.acceptConclusion || 'js') === 'bj' ? 'bj' : 'js'
receiveForm.labStorageCode = String(detail.labStorageCode || '')
receiveForm.bloodWeightG =
detail.bloodWeightG === null || detail.bloodWeightG === undefined
? ''
: String(detail.bloodWeightG)
receiveForm.remark = String(detail.remark || '')
labStorageCodeManuallyEdited.value = !!receiveForm.labStorageCode
lastAllocatedReceptionDate.value = extractReceptionDate(receiveForm.receptionTime)
@@ -1258,6 +1293,7 @@
receiveForm.receiveTemperature = ''
receiveForm.acceptConclusion = 'js'
receiveForm.labStorageCode = ''
receiveForm.bloodWeightG = ''
receiveForm.remark = ''
labStorageCodeManuallyEdited.value = false
lastAllocatedReceptionDate.value = ''
@@ -1288,6 +1324,7 @@
receiveTemperature: '',
acceptConclusion: 'js',
labStorageCode: '',
bloodWeightG: '',
labStorageCodeManuallyEdited: false,
lastAllocatedReceptionDate: '',
remark: '',
@@ -1395,6 +1432,7 @@
checks: buildChecksFromEntry(entry),
acceptConclusion: entry.acceptConclusion,
labStorageCode: String(entry.labStorageCode || '').trim() || undefined,
bloodWeightG: parseOptionalBloodWeightG(entry.bloodWeightG),
receiveAttachments: financeAttachmentsToUrlString(entry.attachments) || undefined,
remark: entry.remark || undefined
})
@@ -1635,6 +1673,7 @@
})),
acceptConclusion: receiveForm.acceptConclusion,
labStorageCode: String(receiveForm.labStorageCode || '').trim() || undefined,
bloodWeightG: parseOptionalBloodWeightG(receiveForm.bloodWeightG),
receiveAttachments: financeAttachmentsToUrlString(attachments.value) || undefined,
remark: receiveForm.remark || undefined
}
@@ -185,6 +185,7 @@
receiveTemperature: ri.receiveTemperature,
acceptConclusion: ri.acceptConclusion,
labStorageCode: ri.labStorageCode,
bloodWeightG: ri.bloodWeightG,
transportType: d.transportInfo?.transportType,
waybillNo: d.transportInfo?.waybillNo,
carrierName: d.transportInfo?.carrierName,