diff --git a/backend/app/crud/collection_protocol.py b/backend/app/crud/collection_protocol.py index 3b56e567..6e6cc64d 100644 --- a/backend/app/crud/collection_protocol.py +++ b/backend/app/crud/collection_protocol.py @@ -1394,6 +1394,7 @@ def list_collection_protocols( "sampleTypeName": type_name, "sampleCode": code, "sampleStatus": (s.sample_status or "").strip(), + "voidDesc": (getattr(s, "void_desc", None) or "").strip(), "labStorageCode": lab_code_map.get(code, "") if code else "", "transport": transport_dict, "freight": freight_by_sample.get(s.id), diff --git a/backend/app/crud/protocol_sample_collection.py b/backend/app/crud/protocol_sample_collection.py index 1d74658a..a42bb2d6 100644 --- a/backend/app/crud/protocol_sample_collection.py +++ b/backend/app/crud/protocol_sample_collection.py @@ -410,7 +410,8 @@ def list_protocol_sample_collections( item["newbornDeliveryTime"] = _fmt_dt(party.newborn_delivery_time) if party else "" item["protocolRemark"] = (proto.remark or "") if proto else "" item["voidType"] = (proto.void_type or "") if proto else "" - item["voidDesc"] = (proto.void_desc or "") if proto else "" + # 样本状态问号展示样本作废原因,不用协议作废描述 + item["voidDesc"] = (getattr(psample, "void_desc", None) or "").strip() item["protocolAttachments"] = (proto.protocol_attachments or "") if proto else "" item["consentFormUrls"] = (proto.consent_form_urls or "") if proto else "" item["healthSurveyFormUrls"] = (proto.health_survey_form_urls or "") if proto else "" diff --git a/backend/app/crud/research_donation.py b/backend/app/crud/research_donation.py index a6826844..26f07f3c 100644 --- a/backend/app/crud/research_donation.py +++ b/backend/app/crud/research_donation.py @@ -976,6 +976,7 @@ def list_donations( "sampleTypeName": type_name, "sampleCode": code, "sampleStatus": (s.sample_status or "").strip(), + "voidDesc": (getattr(s, "void_desc", None) or "").strip(), "labStorageCode": lab_code_map.get(code, "") if code else "", "transport": transport_dict, "freight": freight_by_sample.get(s.id), diff --git a/backend/app/crud/sample_reception.py b/backend/app/crud/sample_reception.py index 0de74a29..c489e4bb 100644 --- a/backend/app/crud/sample_reception.py +++ b/backend/app/crud/sample_reception.py @@ -444,6 +444,7 @@ def _rows_to_sample_list_items( "sampleTypeName": type_map.get(sample.sample_type_id or "", ""), "collectAmount": _dec(sample.collect_amount), "sampleStatus": sample.sample_status or "", + "voidDesc": (getattr(sample, "void_desc", None) or "").strip(), "motherName": (party.mother_name if party else "") or "", "newbornName": (party.newborn_name if party else "") or "", "sampleCollectTime": ( diff --git a/backend/tests/test_protocol_list_sample_void_desc.py b/backend/tests/test_protocol_list_sample_void_desc.py new file mode 100644 index 00000000..3127fbee --- /dev/null +++ b/backend/tests/test_protocol_list_sample_void_desc.py @@ -0,0 +1,46 @@ +"""协议/捐赠列表 sampleItems 须返回样本 voidDesc,供审核列表问号展示。""" +from __future__ import annotations + +import inspect +import re +import unittest + + +_SAMPLE_ITEM_VOID_DESC = re.compile( + r'"sampleStatus"\s*:\s*\(s\.sample_status[^)]*\)\.strip\(\),\s*' + r'"voidDesc"\s*:\s*\(getattr\(s,\s*"void_desc"', + re.S, +) + + +class TestProtocolListSampleVoidDesc(unittest.TestCase): + def test_collection_protocol_list_includes_sample_void_desc(self): + from app.crud import collection_protocol as cp + + src = inspect.getsource(cp.list_collection_protocols) + self.assertRegex(src, _SAMPLE_ITEM_VOID_DESC) + + def test_research_donation_list_includes_sample_void_desc(self): + from app.crud import research_donation as rd + + # 捐赠列表函数名 + fn = None + for name, obj in inspect.getmembers(rd, inspect.isfunction): + if "list" in name and "donation" in name: + src = inspect.getsource(obj) + if "sample_items.append" in src and '"sampleStatus"' in src: + fn = obj + break + self.assertIsNotNone(fn, "未找到组装 sampleItems 的捐赠列表函数") + self.assertRegex(inspect.getsource(fn), _SAMPLE_ITEM_VOID_DESC) + + def test_sample_collection_list_uses_sample_void_desc(self): + from app.crud import protocol_sample_collection as psc + + src = inspect.getsource(psc) + self.assertIn('getattr(psample, "void_desc"', src) + self.assertNotIn('item["voidDesc"] = (proto.void_desc or "") if proto else ""', src) + + +if __name__ == "__main__": + unittest.main()