feat(qc): 质检工单卡片展示协议母血采集时间 #123
No files matched your search
@@ -49,6 +49,7 @@ from app.models.models import (
|
||||
BizPilotInfusionSchedule,
|
||||
BizPilotInfusionScheduleProduct,
|
||||
BizPilotPatient,
|
||||
BizProtocolCollectionInfo,
|
||||
BizProtocolPartyCustomer,
|
||||
BizProtocolSample,
|
||||
BizProductionTask,
|
||||
@@ -69,6 +70,7 @@ from app.models.models import (
|
||||
from app.models.qc_param import BizQcTaskResult
|
||||
from app.models.research_donation import (
|
||||
BizResearchDonation,
|
||||
BizResearchDonationCollection,
|
||||
BizResearchDonationParty,
|
||||
BizResearchDonationSample,
|
||||
)
|
||||
@@ -808,12 +810,39 @@ def _enrich_work_order_list_items(
|
||||
party.mother_name or "",
|
||||
party.newborn_name or "",
|
||||
)
|
||||
cell_maternal_map: Dict[str, str] = {}
|
||||
if cell_proto_ids:
|
||||
for coll in (
|
||||
db.query(BizProtocolCollectionInfo)
|
||||
.filter(
|
||||
BizProtocolCollectionInfo.collection_protocol_id.in_(cell_proto_ids),
|
||||
BizProtocolCollectionInfo.del_flag == 0,
|
||||
)
|
||||
.all()
|
||||
):
|
||||
cell_maternal_map[coll.collection_protocol_id] = _fmt_dt(
|
||||
coll.maternal_blood_collect_time
|
||||
)
|
||||
donation_maternal_map: Dict[str, str] = {}
|
||||
if donation_ids:
|
||||
for coll in (
|
||||
db.query(BizResearchDonationCollection)
|
||||
.filter(
|
||||
BizResearchDonationCollection.research_donation_id.in_(donation_ids),
|
||||
BizResearchDonationCollection.del_flag == 0,
|
||||
)
|
||||
.all()
|
||||
):
|
||||
donation_maternal_map[coll.research_donation_id] = _fmt_dt(
|
||||
coll.maternal_blood_collect_time
|
||||
)
|
||||
for item in items:
|
||||
if item.get("workOrderType") == "temporary":
|
||||
item["receptionSource"] = ""
|
||||
item["receptionSourceLabel"] = ""
|
||||
item["motherName"] = ""
|
||||
item["newbornName"] = ""
|
||||
item["maternalBloodCollectTime"] = ""
|
||||
continue
|
||||
rec = _resolve_reception(item)
|
||||
source = _effective_reception_source(item, rec)
|
||||
@@ -826,6 +855,7 @@ def _enrich_work_order_list_items(
|
||||
_mother, _newborn = donation_party_map.get(_did or "", ("", ""))
|
||||
item["motherName"] = _mother
|
||||
item["newbornName"] = _newborn
|
||||
item["maternalBloodCollectTime"] = donation_maternal_map.get(_did or "", "") or ""
|
||||
else:
|
||||
_pid = (
|
||||
(getattr(rec, "collection_protocol_id", None) if rec else None) or ""
|
||||
@@ -833,6 +863,7 @@ def _enrich_work_order_list_items(
|
||||
_mother, _newborn = cell_party_map.get(_pid or "", ("", ""))
|
||||
item["motherName"] = _mother
|
||||
item["newbornName"] = _newborn
|
||||
item["maternalBloodCollectTime"] = cell_maternal_map.get(_pid or "", "") or ""
|
||||
if not rec:
|
||||
item.setdefault("receptionTime", "")
|
||||
item.setdefault("handlerName", "")
|
||||
@@ -1140,6 +1171,7 @@ def _wo_to_dict(
|
||||
"receptionTime": "",
|
||||
"handlerName": "",
|
||||
"sampleTypeName": "",
|
||||
"maternalBloodCollectTime": "",
|
||||
"workOrderStatus": wo.work_order_status,
|
||||
"workOrderStatusLabel": _WORK_ORDER_STATUS_LABELS.get(
|
||||
wo.work_order_status or "", wo.work_order_status or ""
|
||||
@@ -2601,6 +2633,7 @@ def get_work_order_detail(
|
||||
"receptionSourceLabel": enriched.get("receptionSourceLabel", ""),
|
||||
"motherName": enriched.get("motherName", ""),
|
||||
"newbornName": enriched.get("newbornName", ""),
|
||||
"maternalBloodCollectTime": enriched.get("maternalBloodCollectTime", ""),
|
||||
"protocolStatus": enriched.get("protocolStatus", ""),
|
||||
"protocolStatusLabel": enriched.get("protocolStatusLabel", ""),
|
||||
"cellProductCode": enriched.get("cellProductCode", ""),
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
"""入库质检工单列表:从协议/捐赠采集信息补齐母血采集时间。"""
|
||||
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from unittest import mock
|
||||
|
||||
import app.crud.qc_task # noqa: F401 先加载任务模块,避免与工单模块循环导入
|
||||
from app.crud import qc_work_order as qc_wo
|
||||
from app.crud.qc_work_order import _enrich_work_order_list_items
|
||||
from app.models.models import (
|
||||
BizCollectionProtocol,
|
||||
BizProtocolCollectionInfo,
|
||||
BizProtocolPartyCustomer,
|
||||
BizSampleReception,
|
||||
)
|
||||
from app.models.research_donation import (
|
||||
BizResearchDonation,
|
||||
BizResearchDonationCollection,
|
||||
BizResearchDonationParty,
|
||||
)
|
||||
|
||||
|
||||
def _item(**kwargs):
|
||||
data = {
|
||||
"id": "wo-1",
|
||||
"workOrderType": "inbound",
|
||||
"receptionId": "rec-1",
|
||||
"sampleCode": "S001",
|
||||
"collectionProtocolId": "proto-1",
|
||||
"receptionSource": "cell_storage",
|
||||
"protocolSampleId": "",
|
||||
"maternalBloodCollectTime": "",
|
||||
}
|
||||
data.update(kwargs)
|
||||
return data
|
||||
|
||||
|
||||
def _query_router(mapping):
|
||||
def _query(*entities):
|
||||
q = mock.Mock()
|
||||
q.filter.return_value = q
|
||||
q.order_by.return_value = q
|
||||
model = entities[0]
|
||||
# db.query(Model.col, ...) → first entity is InstrumentedAttribute
|
||||
cls = getattr(model, "class_", model)
|
||||
key = getattr(cls, "__name__", str(cls))
|
||||
rows = mapping.get(key, [])
|
||||
q.all.return_value = rows
|
||||
return q
|
||||
|
||||
return _query
|
||||
|
||||
|
||||
class TestEnrichWorkOrderMaternalBlood(unittest.TestCase):
|
||||
def test_cell_storage_fills_maternal_blood_collect_time(self):
|
||||
rec = mock.Mock(
|
||||
id="rec-1",
|
||||
sample_code="S001",
|
||||
reception_source="cell_storage",
|
||||
collection_protocol_id="proto-1",
|
||||
research_donation_id="",
|
||||
protocol_sample_id="",
|
||||
donation_sample_id="",
|
||||
reception_time=datetime(2026, 11, 8, 13, 30, 41),
|
||||
handler_name="质检员",
|
||||
lab_storage_code="",
|
||||
)
|
||||
coll = mock.Mock(
|
||||
collection_protocol_id="proto-1",
|
||||
maternal_blood_collect_time=datetime(2026, 11, 7, 9, 15, 0),
|
||||
del_flag=0,
|
||||
)
|
||||
db = mock.Mock()
|
||||
db.query.side_effect = _query_router(
|
||||
{
|
||||
BizSampleReception.__name__: [rec],
|
||||
BizProtocolCollectionInfo.__name__: [coll],
|
||||
BizProtocolPartyCustomer.__name__: [],
|
||||
BizCollectionProtocol.__name__: [],
|
||||
}
|
||||
)
|
||||
|
||||
with mock.patch.object(
|
||||
qc_wo, "_enrich_protocol_sibling_samples", side_effect=lambda _db, items: items
|
||||
), mock.patch.object(
|
||||
qc_wo, "apply_special_to_item_from_samples", side_effect=lambda item, **_k: item
|
||||
):
|
||||
items = _enrich_work_order_list_items(db, [_item()])
|
||||
|
||||
self.assertEqual(items[0]["maternalBloodCollectTime"], "2026-11-07 09:15:00")
|
||||
|
||||
def test_missing_maternal_blood_stays_empty(self):
|
||||
rec = mock.Mock(
|
||||
id="rec-1",
|
||||
sample_code="S001",
|
||||
reception_source="cell_storage",
|
||||
collection_protocol_id="proto-1",
|
||||
research_donation_id="",
|
||||
protocol_sample_id="",
|
||||
donation_sample_id="",
|
||||
reception_time=datetime(2026, 11, 8, 13, 30, 41),
|
||||
handler_name="质检员",
|
||||
lab_storage_code="",
|
||||
)
|
||||
db = mock.Mock()
|
||||
db.query.side_effect = _query_router(
|
||||
{
|
||||
BizSampleReception.__name__: [rec],
|
||||
BizProtocolCollectionInfo.__name__: [],
|
||||
BizProtocolPartyCustomer.__name__: [],
|
||||
BizCollectionProtocol.__name__: [],
|
||||
}
|
||||
)
|
||||
|
||||
with mock.patch.object(
|
||||
qc_wo, "_enrich_protocol_sibling_samples", side_effect=lambda _db, items: items
|
||||
), mock.patch.object(
|
||||
qc_wo, "apply_special_to_item_from_samples", side_effect=lambda item, **_k: item
|
||||
):
|
||||
items = _enrich_work_order_list_items(db, [_item()])
|
||||
|
||||
self.assertEqual(items[0]["maternalBloodCollectTime"], "")
|
||||
|
||||
def test_research_donation_fills_maternal_blood_collect_time(self):
|
||||
rec = mock.Mock(
|
||||
id="rec-2",
|
||||
sample_code="D001",
|
||||
reception_source="research_donation",
|
||||
collection_protocol_id="",
|
||||
research_donation_id="don-1",
|
||||
protocol_sample_id="",
|
||||
donation_sample_id="",
|
||||
reception_time=datetime(2026, 11, 8, 10, 0, 0),
|
||||
handler_name="质检员",
|
||||
lab_storage_code="",
|
||||
)
|
||||
coll = mock.Mock(
|
||||
research_donation_id="don-1",
|
||||
maternal_blood_collect_time=datetime(2026, 11, 6, 8, 0, 0),
|
||||
del_flag=0,
|
||||
)
|
||||
db = mock.Mock()
|
||||
db.query.side_effect = _query_router(
|
||||
{
|
||||
BizSampleReception.__name__: [rec],
|
||||
BizResearchDonationCollection.__name__: [coll],
|
||||
BizResearchDonationParty.__name__: [],
|
||||
BizResearchDonation.__name__: [],
|
||||
}
|
||||
)
|
||||
|
||||
with mock.patch.object(
|
||||
qc_wo, "_enrich_protocol_sibling_samples", side_effect=lambda _db, items: items
|
||||
), mock.patch.object(
|
||||
qc_wo, "apply_special_to_item_from_samples", side_effect=lambda item, **_k: item
|
||||
):
|
||||
items = _enrich_work_order_list_items(
|
||||
db,
|
||||
[
|
||||
_item(
|
||||
id="wo-2",
|
||||
receptionId="rec-2",
|
||||
sampleCode="D001",
|
||||
collectionProtocolId="don-1",
|
||||
receptionSource="research_donation",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
self.assertEqual(items[0]["maternalBloodCollectTime"], "2026-11-06 08:00:00")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -141,6 +141,8 @@ export type QcWorkOrder = {
|
||||
patientName?: string
|
||||
/** 入库工单(细胞存储/科研捐赠):母亲姓名 */
|
||||
motherName?: string
|
||||
/** 协议单母血采集时间;未录入时为空,前端展示为 — */
|
||||
maternalBloodCollectTime?: string
|
||||
/** 入库工单(细胞存储/科研捐赠):新生儿姓名 */
|
||||
newbornName?: string
|
||||
/** 出库工单:当前为第几次输注计划 */
|
||||
|
||||
@@ -139,6 +139,11 @@ const inboundGroupedFields: CardMetaField[] = [
|
||||
getValue: (row) => row.sampleTypeName || '—',
|
||||
visible: isInboundUserInfoRow
|
||||
},
|
||||
{
|
||||
label: '母血采集时间',
|
||||
getValue: (row) => formatDisplayOrDash(row.maternalBloodCollectTime),
|
||||
visible: isInboundUserInfoRow
|
||||
},
|
||||
...commonTailFields
|
||||
]
|
||||
|
||||
@@ -197,6 +202,7 @@ function buildCellStorageGroupContext(row: QcWorkOrder): string[] {
|
||||
if (row.newbornName) parts.push(`新生儿 ${row.newbornName}`)
|
||||
if (row.sampleTypeName) parts.push(row.sampleTypeName)
|
||||
if (row.receptionTime) parts.push(`接收 ${row.receptionTime}`)
|
||||
parts.push(`母血采集 ${formatDisplayOrDash(row.maternalBloodCollectTime)}`)
|
||||
if (row.handlerName) parts.push(row.handlerName)
|
||||
return parts
|
||||
}
|
||||
@@ -207,6 +213,7 @@ function buildDonationGroupContext(row: QcWorkOrder): string[] {
|
||||
if (row.newbornName) parts.push(`新生儿 ${row.newbornName}`)
|
||||
if (row.sampleTypeName) parts.push(row.sampleTypeName)
|
||||
if (row.receptionTime) parts.push(`接收 ${row.receptionTime}`)
|
||||
parts.push(`母血采集 ${formatDisplayOrDash(row.maternalBloodCollectTime)}`)
|
||||
if (row.handlerName) parts.push(row.handlerName)
|
||||
return parts
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user