sample_info_progress.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """样本信息管理:进度展示码、证/保险已办理判定、办理字段同步。"""
  2. from __future__ import annotations
  3. from datetime import datetime
  4. from typing import Any, Dict, Optional, Tuple
  5. def collection_progress(sample_status: str) -> Tuple[str, str]:
  6. st = (sample_status or "").strip()
  7. if not st:
  8. return "uncollected", "未采集"
  9. if st == "yzf":
  10. return "voided", "已作废"
  11. if st in ("ycj", "jcz", "yrk"):
  12. return "collected", "已采集"
  13. return "uncollected", "未采集"
  14. def reception_progress(reception: Optional[Dict[str, Any]]) -> Tuple[str, str]:
  15. if not reception:
  16. return "none", "未接收"
  17. c = (reception.get("acceptConclusion") or "").strip()
  18. if c == "js":
  19. return "js", "已接收"
  20. if c == "bj":
  21. return "bj", "拒收"
  22. return "none", "未接收"
  23. def qc_progress(qc: Optional[Dict[str, Any]]) -> Tuple[str, str]:
  24. if not qc:
  25. return "incomplete", "未完成"
  26. if (qc.get("qcWorkOrderStatus") or "").strip() == "yzf":
  27. return "voided", "已作废"
  28. conc = (qc.get("qcConclusion") or "").strip()
  29. if conc in ("tg", "btg"):
  30. return "complete", "已完成"
  31. return "incomplete", "未完成"
  32. def storage_progress(review: Optional[Dict[str, Any]]) -> Tuple[str, str]:
  33. if not review:
  34. return "none", "未入库"
  35. if (review.get("storageStatus") or "").strip() == "yrk":
  36. return "yrk", "已入库"
  37. if (review.get("reviewConclusion") or "").strip() == "btg":
  38. return "rejected", "拒绝入库"
  39. return "none", "未入库"
  40. def storage_cert_handled(row: Any) -> bool:
  41. if row is None:
  42. return False
  43. if getattr(row, "handle_time", None):
  44. return True
  45. if (getattr(row, "make_status", None) or "").strip() == "1":
  46. return True
  47. return bool((getattr(row, "make_date", None) or "").strip())
  48. def insurance_handled(row: Any) -> bool:
  49. if row is None:
  50. return False
  51. if getattr(row, "handle_time", None):
  52. return True
  53. if (getattr(row, "todo_status", None) or "").strip() == "1":
  54. return True
  55. return bool((getattr(row, "handle_date", None) or "").strip())
  56. def sync_handle_status_fields(handle_time: Optional[datetime]) -> Tuple[str, str]:
  57. if handle_time is None:
  58. return "0", ""
  59. return "1", handle_time.strftime("%Y%m%d")
  60. def apply_handle_payload(
  61. *,
  62. handle_time: Optional[datetime],
  63. handler_user_id: Optional[str],
  64. attachments: str = "",
  65. remark: str = "",
  66. ) -> Dict[str, Any]:
  67. """规范化办理写入字段。有办理时间则办理人员必填。"""
  68. uid = (handler_user_id or "").strip() or None
  69. if handle_time is not None and not uid:
  70. raise ValueError("填写办理时间时必须指定办理人员")
  71. status, legacy_date = sync_handle_status_fields(handle_time)
  72. if handle_time is None:
  73. uid = None
  74. return {
  75. "handle_time": handle_time,
  76. "handler_user_id": uid,
  77. "attachments": (attachments or "").strip(),
  78. "remark": (remark or "").strip(),
  79. "make_or_todo_status": status,
  80. "legacy_date": legacy_date,
  81. }