|
|
@@ -607,12 +607,17 @@ def _transport_to_dict(t: BizProtocolSampleTransport) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
def _storage_cert_to_dict(s: BizProtocolStorageCert) -> Dict[str, Any]:
|
|
|
+ from app.services.sample_info_progress import storage_cert_handled
|
|
|
+
|
|
|
return {
|
|
|
"id": s.id,
|
|
|
"collectionProtocolId": s.collection_protocol_id,
|
|
|
"makeStatus": s.make_status or "0",
|
|
|
"certImageUrls": s.cert_image_urls or "",
|
|
|
"makeDate": (s.make_date or "").strip() if s.make_date else "",
|
|
|
+ "handleTime": _fmt_dt(s.handle_time) if getattr(s, "handle_time", None) else "",
|
|
|
+ "handlerUserId": getattr(s, "handler_user_id", None) or "",
|
|
|
+ "handled": storage_cert_handled(s),
|
|
|
"tenantNo": s.tenant_no,
|
|
|
"orderNum": s.order_num if s.order_num is not None else 0,
|
|
|
"remark": s.remark or "",
|
|
|
@@ -1348,12 +1353,21 @@ def get_protocol_detail_bundle(
|
|
|
)
|
|
|
unit_name_map = _load_unit_name_map(db, s_rows)
|
|
|
type_name_map = _load_sample_type_name_map(db, s_rows)
|
|
|
+ from app.crud import sample_freight as sample_freight_svc
|
|
|
+
|
|
|
+ freight_by_sample = sample_freight_svc.freight_map_for_samples(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ sample_source=sample_freight_svc.SAMPLE_SOURCE_CELL,
|
|
|
+ sample_ids=[s.id for s in s_rows],
|
|
|
+ )
|
|
|
samples_out: List[Dict[str, Any]] = []
|
|
|
for s in s_rows:
|
|
|
item = _sample_to_dict(s)
|
|
|
item["sampleTypeName"] = type_name_map.get(s.sample_type_id or "", "")
|
|
|
item["unitName"] = unit_name_map.get(s.unit_id or "", "")
|
|
|
item["transport"] = transport_by_sample.get(s.id)
|
|
|
+ item["freight"] = freight_by_sample.get(s.id)
|
|
|
item["sampleReception"] = reception_by_sample.get(s.id)
|
|
|
item["productionReception"] = (reception_by_sample.get(s.id) or {}).get(
|
|
|
"productionReception"
|
|
|
@@ -1365,9 +1379,22 @@ def get_protocol_detail_bundle(
|
|
|
samples_out.append(item)
|
|
|
out["samples"] = samples_out
|
|
|
out["storageCert"] = _storage_cert_to_dict(sc) if sc else None
|
|
|
+ if out["storageCert"]:
|
|
|
+ hid = (out["storageCert"].get("handlerUserId") or "").strip()
|
|
|
+ if hid:
|
|
|
+ hu = db.query(SysUser).filter(SysUser.id == hid).first()
|
|
|
+ out["storageCert"]["handlerUserName"] = (hu.nick_name or "") if hu else ""
|
|
|
+ else:
|
|
|
+ out["storageCert"]["handlerUserName"] = ""
|
|
|
ft = get_fullmoon_todo(db, protocol_id, tenant_no)
|
|
|
delivery_dt = pc.newborn_delivery_time if pc else None
|
|
|
out["fullmoonTodo"] = _fullmoon_todo_detail_dict(ft, newborn_delivery_time=delivery_dt)
|
|
|
+ hid2 = (out["fullmoonTodo"].get("handlerUserId") or "").strip()
|
|
|
+ if hid2:
|
|
|
+ hu2 = db.query(SysUser).filter(SysUser.id == hid2).first()
|
|
|
+ out["fullmoonTodo"]["handlerUserName"] = (hu2.nick_name or "") if hu2 else ""
|
|
|
+ else:
|
|
|
+ out["fullmoonTodo"]["handlerUserName"] = ""
|
|
|
out["attachments"] = urls_to_attachment_list(p.protocol_attachments, db, tenant_no)
|
|
|
out["consentAttachmentFiles"] = urls_to_attachment_list(p.consent_form_urls, db, tenant_no)
|
|
|
out["healthSurveyAttachmentFiles"] = urls_to_attachment_list(
|
|
|
@@ -1969,7 +1996,7 @@ def _apply_payment_detail_draft_fields(
|
|
|
from app.crud.dict_data import normalize_transfer_type
|
|
|
|
|
|
if d.pay_status != "dfj":
|
|
|
- raise ValueError("仅待缴费状态可编辑缴费明细")
|
|
|
+ raise ValueError("仅已缴费状态可编辑缴费明细")
|
|
|
if "transfer_type" in fields:
|
|
|
d.transfer_type = normalize_transfer_type(
|
|
|
db, value=str(fields.get("transfer_type") or ""), tenant_no=tenant_no
|
|
|
@@ -2024,7 +2051,7 @@ def _apply_submit_receipt_finance(
|
|
|
user_id: Optional[str],
|
|
|
) -> None:
|
|
|
if d.pay_status != "dfj":
|
|
|
- raise ValueError("仅待缴费状态可提交财务确认")
|
|
|
+ raise ValueError("仅已缴费状态可提交财务确认")
|
|
|
d.pay_status = "jfqrz"
|
|
|
d.update_by = user_id
|
|
|
d.update_time = datetime.now()
|
|
|
@@ -2797,7 +2824,19 @@ def save_samples(
|
|
|
db.commit()
|
|
|
for o in result:
|
|
|
db.refresh(o)
|
|
|
- save_sample_transports(db, collection_protocol_id, tenant_no, user_id, result, samples)
|
|
|
+ # 本阶段停写旧运输明细,改挂运费批次
|
|
|
+ from app.crud import sample_freight as sample_freight_svc
|
|
|
+
|
|
|
+ sample_freight_svc.apply_freight_on_protocol_save(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ user_id=user_id,
|
|
|
+ sample_source=sample_freight_svc.SAMPLE_SOURCE_CELL,
|
|
|
+ protocol_id=collection_protocol_id,
|
|
|
+ saved_samples=result,
|
|
|
+ input_samples=samples,
|
|
|
+ )
|
|
|
+ db.commit()
|
|
|
return result
|
|
|
|
|
|
|
|
|
@@ -3357,11 +3396,13 @@ def upsert_storage_cert(
|
|
|
) -> BizProtocolStorageCert:
|
|
|
fields = _normalize_fields(fields)
|
|
|
obj = get_storage_cert(db, collection_protocol_id, tenant_no)
|
|
|
- _STR_FIELDS = ["make_status", "cert_image_urls", "make_date"]
|
|
|
+ _STR_FIELDS = ["make_status", "cert_image_urls", "make_date", "handler_user_id"]
|
|
|
if obj:
|
|
|
for k in _STR_FIELDS:
|
|
|
if k in fields:
|
|
|
- setattr(obj, k, (fields[k] or "").strip() or None)
|
|
|
+ setattr(obj, k, (fields[k] or "").strip() or None if isinstance(fields[k], str) or fields[k] is None else fields[k])
|
|
|
+ if "handle_time" in fields:
|
|
|
+ obj.handle_time = fields.get("handle_time")
|
|
|
if "remark" in fields:
|
|
|
obj.remark = (fields["remark"] or "").strip() or None
|
|
|
obj.update_by = user_id
|
|
|
@@ -3385,13 +3426,49 @@ def upsert_storage_cert(
|
|
|
)
|
|
|
for k in _STR_FIELDS:
|
|
|
if k in fields:
|
|
|
- setattr(obj, k, (fields[k] or "").strip() or None)
|
|
|
+ val = fields[k]
|
|
|
+ setattr(obj, k, (val or "").strip() or None if isinstance(val, str) or val is None else val)
|
|
|
+ if "handle_time" in fields:
|
|
|
+ obj.handle_time = fields.get("handle_time")
|
|
|
db.add(obj)
|
|
|
db.commit()
|
|
|
db.refresh(obj)
|
|
|
return obj
|
|
|
|
|
|
|
|
|
+def upsert_storage_cert_handle(
|
|
|
+ db: Session,
|
|
|
+ collection_protocol_id: str,
|
|
|
+ tenant_no: str,
|
|
|
+ user_id: Optional[str],
|
|
|
+ *,
|
|
|
+ handle_time: Optional[datetime] = None,
|
|
|
+ handler_user_id: Optional[str] = None,
|
|
|
+ cert_image_urls: Optional[str] = None,
|
|
|
+ remark: Optional[str] = None,
|
|
|
+) -> BizProtocolStorageCert:
|
|
|
+ from app.services.sample_info_progress import apply_handle_payload
|
|
|
+
|
|
|
+ payload = apply_handle_payload(
|
|
|
+ handle_time=handle_time,
|
|
|
+ handler_user_id=handler_user_id,
|
|
|
+ attachments=cert_image_urls or "",
|
|
|
+ remark=remark or "",
|
|
|
+ )
|
|
|
+ return upsert_storage_cert(
|
|
|
+ db,
|
|
|
+ collection_protocol_id,
|
|
|
+ tenant_no,
|
|
|
+ user_id,
|
|
|
+ handle_time=payload["handle_time"],
|
|
|
+ handler_user_id=payload["handler_user_id"],
|
|
|
+ make_status=payload["make_or_todo_status"],
|
|
|
+ make_date=payload["legacy_date"] or None,
|
|
|
+ cert_image_urls=payload["attachments"] or None,
|
|
|
+ remark=payload["remark"] or None,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
# ---------------------------------------------------------------------------
|
|
|
# 子表:满月待办
|
|
|
# ---------------------------------------------------------------------------
|
|
|
@@ -3401,6 +3478,9 @@ def _fullmoon_todo_empty_dict() -> Dict[str, Any]:
|
|
|
return {
|
|
|
"todoStatus": "0",
|
|
|
"handleDate": "",
|
|
|
+ "handleTime": "",
|
|
|
+ "handlerUserId": "",
|
|
|
+ "handled": False,
|
|
|
"handleRemark": "",
|
|
|
"insuranceAttachments": "",
|
|
|
"insuranceCompanyId": "",
|
|
|
@@ -3435,11 +3515,16 @@ def _fullmoon_todo_detail_dict(
|
|
|
|
|
|
|
|
|
def _fullmoon_todo_to_dict(ft: BizProtocolFullmoonTodo) -> Dict[str, Any]:
|
|
|
+ from app.services.sample_info_progress import insurance_handled
|
|
|
+
|
|
|
return {
|
|
|
"id": ft.id,
|
|
|
"collectionProtocolId": ft.collection_protocol_id,
|
|
|
"todoStatus": ft.todo_status or "0",
|
|
|
"handleDate": (ft.handle_date or "").strip() if ft.handle_date else "",
|
|
|
+ "handleTime": _fmt_dt(ft.handle_time) if getattr(ft, "handle_time", None) else "",
|
|
|
+ "handlerUserId": getattr(ft, "handler_user_id", None) or "",
|
|
|
+ "handled": insurance_handled(ft),
|
|
|
"handleRemark": ft.handle_remark or "",
|
|
|
"insuranceAttachments": ft.insurance_attachments or "",
|
|
|
"insuranceCompanyId": ft.insurance_company_id or "",
|
|
|
@@ -3486,7 +3571,7 @@ def upsert_fullmoon_todo(
|
|
|
fields = _normalize_fields(fields)
|
|
|
obj = get_fullmoon_todo(db, collection_protocol_id, tenant_no)
|
|
|
_STR_FIELDS = [
|
|
|
- "todo_status", "handle_date", "handle_remark",
|
|
|
+ "todo_status", "handle_date", "handle_remark", "handler_user_id",
|
|
|
"insurance_attachments", "insurance_company_id",
|
|
|
"insurance_company_name", "insurance_type",
|
|
|
"insurance_policy_no", "insurance_effective_date",
|
|
|
@@ -3497,6 +3582,8 @@ def upsert_fullmoon_todo(
|
|
|
for k in _STR_FIELDS:
|
|
|
if k in fields:
|
|
|
setattr(obj, k, (fields[k] or "").strip() or None)
|
|
|
+ if "handle_time" in fields:
|
|
|
+ obj.handle_time = fields.get("handle_time")
|
|
|
for k in _DEC_FIELDS:
|
|
|
if k in fields and fields[k] is not None:
|
|
|
setattr(obj, k, Decimal(str(fields[k])))
|
|
|
@@ -3524,6 +3611,8 @@ def upsert_fullmoon_todo(
|
|
|
for k in _STR_FIELDS:
|
|
|
if k in fields:
|
|
|
setattr(obj, k, (fields[k] or "").strip() or None)
|
|
|
+ if "handle_time" in fields:
|
|
|
+ obj.handle_time = fields.get("handle_time")
|
|
|
for k in _DEC_FIELDS:
|
|
|
if k in fields and fields[k] is not None:
|
|
|
setattr(obj, k, Decimal(str(fields[k])))
|
|
|
@@ -3533,6 +3622,39 @@ def upsert_fullmoon_todo(
|
|
|
return obj
|
|
|
|
|
|
|
|
|
+def upsert_fullmoon_todo_handle(
|
|
|
+ db: Session,
|
|
|
+ collection_protocol_id: str,
|
|
|
+ tenant_no: str,
|
|
|
+ user_id: Optional[str],
|
|
|
+ *,
|
|
|
+ handle_time: Optional[datetime] = None,
|
|
|
+ handler_user_id: Optional[str] = None,
|
|
|
+ insurance_attachments: Optional[str] = None,
|
|
|
+ handle_remark: Optional[str] = None,
|
|
|
+) -> BizProtocolFullmoonTodo:
|
|
|
+ from app.services.sample_info_progress import apply_handle_payload
|
|
|
+
|
|
|
+ payload = apply_handle_payload(
|
|
|
+ handle_time=handle_time,
|
|
|
+ handler_user_id=handler_user_id,
|
|
|
+ attachments=insurance_attachments or "",
|
|
|
+ remark=handle_remark or "",
|
|
|
+ )
|
|
|
+ return upsert_fullmoon_todo(
|
|
|
+ db,
|
|
|
+ collection_protocol_id,
|
|
|
+ tenant_no,
|
|
|
+ user_id,
|
|
|
+ handle_time=payload["handle_time"],
|
|
|
+ handler_user_id=payload["handler_user_id"],
|
|
|
+ todo_status=payload["make_or_todo_status"],
|
|
|
+ handle_date=payload["legacy_date"] or None,
|
|
|
+ insurance_attachments=payload["attachments"] or None,
|
|
|
+ handle_remark=payload["remark"] or None,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
# ---------------------------------------------------------------------------
|
|
|
# 开票申请(主表 + 明细子表)
|
|
|
# ---------------------------------------------------------------------------
|