fix(market): 催缴/运费/实验室处理列表返回样本状态
Web 三处列表 CRUD 补齐 sampleStatus/voidDesc,与缴费信息修复同类缺口(#138)。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dbc4a24543
commit
034a4da1ad
6 files changed
+158
-3
No files matched your search
@@ -269,10 +269,13 @@ def _build_cell_system(
|
||||
clear_flag = checked
|
||||
break
|
||||
|
||||
sample_status = str(getattr(sample, "sample_status", None) or "").strip()
|
||||
base: Dict[str, Any] = {
|
||||
"receptionId": rec.id,
|
||||
"sampleCode": (rec.sample_code or sample.sample_code or "").strip(),
|
||||
"labStorageCode": (rec.lab_storage_code or "").strip(),
|
||||
"sampleStatus": sample_status,
|
||||
"voidDesc": str(getattr(sample, "void_desc", None) or "").strip(),
|
||||
"motherName": (party.mother_name if party else "") or "",
|
||||
"collectionTime": ledger.format_cn_datetime(coll.sample_collect_time if coll else None),
|
||||
"collectionTimeRaw": _fmt_raw(coll.sample_collect_time if coll else None),
|
||||
@@ -353,10 +356,13 @@ def _build_donation_system(
|
||||
qc_process: Dict[str, str],
|
||||
) -> Dict[str, Any]:
|
||||
prod = prod or {}
|
||||
sample_status = str(getattr(sample, "sample_status", None) or "").strip()
|
||||
base: Dict[str, Any] = {
|
||||
"receptionId": rec.id,
|
||||
"sampleCode": (rec.sample_code or sample.sample_code or "").strip(),
|
||||
"labStorageCode": (rec.lab_storage_code or "").strip(),
|
||||
"sampleStatus": sample_status,
|
||||
"voidDesc": str(getattr(sample, "void_desc", None) or "").strip(),
|
||||
"motherName": (party.mother_name if party else "") or "",
|
||||
"receptionTime": ledger.format_cn_datetime(rec.reception_time),
|
||||
"receptionTimeRaw": _fmt_raw(rec.reception_time),
|
||||
|
||||
@@ -2245,6 +2245,40 @@ def list_payment_chase_page(
|
||||
for u in db.query(SysUser.id, SysUser.nick_name).filter(SysUser.id.in_(sales_ids)).all():
|
||||
sales_name_map[u.id] = u.nick_name or ""
|
||||
|
||||
sample_codes = list(
|
||||
{
|
||||
(sp.sample_code or sch.sample_code or "").strip()
|
||||
for sch, sp, _, _, _ in candidates
|
||||
if (sp.sample_code or sch.sample_code or "").strip()
|
||||
}
|
||||
)
|
||||
sample_status_by_code: Dict[str, Dict[str, str]] = {}
|
||||
if sample_codes:
|
||||
s_rows = (
|
||||
db.query(BizProtocolSample)
|
||||
.filter(
|
||||
BizProtocolSample.tenant_no == tenant_no,
|
||||
BizProtocolSample.del_flag == 0,
|
||||
BizProtocolSample.sample_code.in_(sample_codes),
|
||||
)
|
||||
.order_by(
|
||||
BizProtocolSample.update_time.desc(),
|
||||
BizProtocolSample.create_time.desc(),
|
||||
BizProtocolSample.id.desc(),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
for sample in s_rows:
|
||||
code = str(sample.sample_code or "").strip()
|
||||
if not code or code in sample_status_by_code:
|
||||
continue
|
||||
status = str(sample.sample_status or "").strip()
|
||||
sample_status_by_code[code] = {
|
||||
"sampleStatus": status,
|
||||
"sampleStatusLabel": _SAMPLE_STATUS_LABELS.get(status, ""),
|
||||
"voidDesc": str(getattr(sample, "void_desc", None) or "").strip(),
|
||||
}
|
||||
|
||||
ct = (chase_type or "").strip()
|
||||
rows: List[Dict[str, Any]] = []
|
||||
for sch, sp, proto, party, ci in candidates:
|
||||
@@ -2274,6 +2308,8 @@ def list_payment_chase_page(
|
||||
continue
|
||||
days_overdue = (today_d - due_d).days if overdue else 0
|
||||
days_until = (due_d - today_d).days if not overdue else 0
|
||||
sample_code = sp.sample_code or sch.sample_code or ""
|
||||
sample_state = sample_status_by_code.get(str(sample_code).strip(), {})
|
||||
rows.append(
|
||||
{
|
||||
"scheduleId": sch.id,
|
||||
@@ -2282,7 +2318,10 @@ def list_payment_chase_page(
|
||||
"protocolNo": (proto.protocol_no if proto else "") or "",
|
||||
"motherName": (party.mother_name if party else "") or "",
|
||||
"motherPhone": (party.mother_phone if party else "") or "",
|
||||
"sampleCode": sp.sample_code or sch.sample_code or "",
|
||||
"sampleCode": sample_code,
|
||||
"sampleStatus": sample_state.get("sampleStatus", ""),
|
||||
"sampleStatusLabel": sample_state.get("sampleStatusLabel", ""),
|
||||
"voidDesc": sample_state.get("voidDesc", ""),
|
||||
"salesUserId": (ci.sales_user_id if ci else "") or "",
|
||||
"salesUserName": sales_name_map.get(
|
||||
(ci.sales_user_id if ci else "") or "", ""
|
||||
|
||||
@@ -194,6 +194,14 @@ def _item_to_dict(item: BizSampleFreightItem) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
_SAMPLE_STATUS_LABELS = {
|
||||
"ycj": "已采集",
|
||||
"jcz": "检测中",
|
||||
"yrk": "已入库",
|
||||
"yzf": "已作废",
|
||||
}
|
||||
|
||||
|
||||
def _item_to_dict_enriched(
|
||||
item: BizSampleFreightItem,
|
||||
*,
|
||||
@@ -201,12 +209,19 @@ def _item_to_dict_enriched(
|
||||
sample_type_name: str = "",
|
||||
mother_name: str = "",
|
||||
newborn_name: str = "",
|
||||
sample_status: str = "",
|
||||
void_desc: str = "",
|
||||
) -> Dict[str, Any]:
|
||||
data = _item_to_dict(item)
|
||||
data["protocolNo"] = protocol_no or ""
|
||||
data["sampleTypeName"] = sample_type_name or ""
|
||||
data["motherName"] = mother_name or ""
|
||||
data["newbornName"] = newborn_name or ""
|
||||
status = str(sample_status or "").strip()
|
||||
if str(item.sample_code or "").strip():
|
||||
data["sampleStatus"] = status
|
||||
data["sampleStatusLabel"] = _SAMPLE_STATUS_LABELS.get(status, "")
|
||||
data["voidDesc"] = str(void_desc or "").strip()
|
||||
return data
|
||||
|
||||
|
||||
@@ -257,6 +272,8 @@ def _enrich_items_maps(
|
||||
BizCellSampleType.type_name,
|
||||
BizProtocolPartyCustomer.mother_name,
|
||||
BizProtocolPartyCustomer.newborn_name,
|
||||
BizProtocolSample.sample_status,
|
||||
BizProtocolSample.void_desc,
|
||||
)
|
||||
.outerjoin(
|
||||
BizCollectionProtocol,
|
||||
@@ -287,12 +304,14 @@ def _enrich_items_maps(
|
||||
)
|
||||
.all()
|
||||
)
|
||||
for sid, pno, tname, mname, nname in rows:
|
||||
for sid, pno, tname, mname, nname, status, void_desc in rows:
|
||||
out[f"{SAMPLE_SOURCE_CELL}|{sid}"] = {
|
||||
"protocolNo": pno or "",
|
||||
"sampleTypeName": tname or "",
|
||||
"motherName": mname or "",
|
||||
"newbornName": nname or "",
|
||||
"sampleStatus": str(status or "").strip(),
|
||||
"voidDesc": str(void_desc or "").strip(),
|
||||
}
|
||||
|
||||
if donation_ids:
|
||||
@@ -303,6 +322,8 @@ def _enrich_items_maps(
|
||||
BizCellSampleType.type_name,
|
||||
BizResearchDonationParty.mother_name,
|
||||
BizResearchDonationParty.newborn_name,
|
||||
BizResearchDonationSample.sample_status,
|
||||
BizResearchDonationSample.void_desc,
|
||||
)
|
||||
.outerjoin(
|
||||
BizResearchDonation,
|
||||
@@ -334,12 +355,14 @@ def _enrich_items_maps(
|
||||
)
|
||||
.all()
|
||||
)
|
||||
for sid, dno, tname, mname, nname in rows:
|
||||
for sid, dno, tname, mname, nname, status, void_desc in rows:
|
||||
out[f"{SAMPLE_SOURCE_DONATION}|{sid}"] = {
|
||||
"protocolNo": dno or "",
|
||||
"sampleTypeName": tname or "",
|
||||
"motherName": mname or "",
|
||||
"newbornName": nname or "",
|
||||
"sampleStatus": str(status or "").strip(),
|
||||
"voidDesc": str(void_desc or "").strip(),
|
||||
}
|
||||
|
||||
return out
|
||||
@@ -541,6 +564,8 @@ def list_freights(
|
||||
sample_type_name=info.get("sampleTypeName", ""),
|
||||
mother_name=info.get("motherName", ""),
|
||||
newborn_name=info.get("newbornName", ""),
|
||||
sample_status=info.get("sampleStatus", ""),
|
||||
void_desc=info.get("voidDesc", ""),
|
||||
)
|
||||
)
|
||||
data["items"] = enriched
|
||||
@@ -584,6 +609,8 @@ def get_freight_detail(
|
||||
sample_type_name=info.get("sampleTypeName", ""),
|
||||
mother_name=info.get("motherName", ""),
|
||||
newborn_name=info.get("newbornName", ""),
|
||||
sample_status=info.get("sampleStatus", ""),
|
||||
void_desc=info.get("voidDesc", ""),
|
||||
)
|
||||
)
|
||||
data["items"] = enriched
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.services.lab_sample_process import (
|
||||
format_cn_datetime,
|
||||
@@ -38,5 +39,65 @@ class LabSampleProcessServiceTests(unittest.TestCase):
|
||||
self.assertEqual(merged["motherName"], "张三")
|
||||
|
||||
|
||||
class LabSampleProcessRowStatusTests(unittest.TestCase):
|
||||
def test_cell_and_donation_rows_expose_sample_status(self):
|
||||
from app.crud.lab_sample_process import (
|
||||
_build_cell_system,
|
||||
_build_donation_system,
|
||||
)
|
||||
|
||||
rec = SimpleNamespace(
|
||||
id="r1",
|
||||
sample_code="S1",
|
||||
lab_storage_code="B0000108",
|
||||
reception_time=None,
|
||||
receive_temperature="",
|
||||
handler_name="",
|
||||
remark="",
|
||||
create_time=None,
|
||||
)
|
||||
sample = SimpleNamespace(
|
||||
sample_code="S1",
|
||||
sample_status="yrk",
|
||||
void_desc="",
|
||||
)
|
||||
voided = SimpleNamespace(
|
||||
sample_code="S2",
|
||||
sample_status="yzf",
|
||||
void_desc="溶血",
|
||||
)
|
||||
cell = _build_cell_system(
|
||||
tab_key="cell_hsc",
|
||||
rec=rec,
|
||||
sample=sample,
|
||||
party=None,
|
||||
coll=None,
|
||||
protocol=None,
|
||||
prod={},
|
||||
hospital_name="",
|
||||
check_flags={},
|
||||
storage_status="已入库",
|
||||
qc_mother={},
|
||||
qc_process={},
|
||||
)
|
||||
self.assertEqual(cell["sampleStatus"], "yrk")
|
||||
self.assertEqual(cell["voidDesc"], "")
|
||||
self.assertEqual(cell["cellCode"], "B0000108")
|
||||
|
||||
donation = _build_donation_system(
|
||||
tab_key="donation_hsc",
|
||||
rec=rec,
|
||||
sample=voided,
|
||||
party=None,
|
||||
coll=None,
|
||||
prod={},
|
||||
storage_status="",
|
||||
qc_mother={},
|
||||
qc_process={},
|
||||
)
|
||||
self.assertEqual(donation["sampleStatus"], "yzf")
|
||||
self.assertEqual(donation["voidDesc"], "溶血")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -79,12 +79,26 @@ class TestFreightListHelpers(unittest.TestCase):
|
||||
sample_type_name="脐带血",
|
||||
mother_name="张三",
|
||||
newborn_name="张小宝",
|
||||
sample_status="ycj",
|
||||
void_desc="",
|
||||
)
|
||||
self.assertEqual(d["protocolNo"], "CP001")
|
||||
self.assertEqual(d["sampleTypeName"], "脐带血")
|
||||
self.assertEqual(d["sampleSource"], "cell_storage")
|
||||
self.assertEqual(d["motherName"], "张三")
|
||||
self.assertEqual(d["newbornName"], "张小宝")
|
||||
self.assertEqual(d["sampleStatus"], "ycj")
|
||||
self.assertEqual(d["sampleStatusLabel"], "已采集")
|
||||
self.assertEqual(d["voidDesc"], "")
|
||||
|
||||
voided = _item_to_dict_enriched(
|
||||
I(),
|
||||
sample_status="yzf",
|
||||
void_desc="运输破损",
|
||||
)
|
||||
self.assertEqual(voided["sampleStatus"], "yzf")
|
||||
self.assertEqual(voided["sampleStatusLabel"], "已作废")
|
||||
self.assertEqual(voided["voidDesc"], "运输破损")
|
||||
|
||||
def test_row_dict_includes_create_by(self):
|
||||
from app.crud.sample_freight import _row_to_dict
|
||||
|
||||
@@ -97,5 +97,13 @@ class TestPaymentListSampleStatus(unittest.TestCase):
|
||||
self.assertEqual(voided["voidDesc"], "客户放弃存储")
|
||||
|
||||
|
||||
class TestPaymentChaseSampleStatusLabels(unittest.TestCase):
|
||||
def test_status_label_map_covers_voided(self):
|
||||
from app.crud.protocol_sample_payment import _SAMPLE_STATUS_LABELS
|
||||
|
||||
self.assertEqual(_SAMPLE_STATUS_LABELS.get("ycj"), "已采集")
|
||||
self.assertEqual(_SAMPLE_STATUS_LABELS.get("yzf"), "已作废")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user