|
@@ -8,7 +8,8 @@ from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
from app.core.data_scope import apply_data_scope
|
|
from app.core.data_scope import apply_data_scope
|
|
|
from app.core.utils import generate_uuid
|
|
from app.core.utils import generate_uuid
|
|
|
-from app.crud import collection_protocol as cp_svc
|
|
|
|
|
|
|
+from app.crud import sample_insurance as sample_insurance_crud
|
|
|
|
|
+from app.crud import sample_storage_cert as sample_storage_cert_crud
|
|
|
from app.crud.storage_release_review import _get_user_name
|
|
from app.crud.storage_release_review import _get_user_name
|
|
|
from app.models.models import (
|
|
from app.models.models import (
|
|
|
BizCollectionProtocol,
|
|
BizCollectionProtocol,
|
|
@@ -18,7 +19,7 @@ from app.models.models import (
|
|
|
from app.models.research_donation import BizResearchDonation, BizResearchDonationSample
|
|
from app.models.research_donation import BizResearchDonation, BizResearchDonationSample
|
|
|
from app.services.sample_info_quick_register import (
|
|
from app.services.sample_info_quick_register import (
|
|
|
apply_quick_storage_payload,
|
|
apply_quick_storage_payload,
|
|
|
- unique_nonempty_ids,
|
|
|
|
|
|
|
+ unique_sample_items,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -66,7 +67,7 @@ def _pick_latest_review(
|
|
|
def batch_handle_storage_certs(
|
|
def batch_handle_storage_certs(
|
|
|
db: Session,
|
|
db: Session,
|
|
|
*,
|
|
*,
|
|
|
- protocol_ids: List[str],
|
|
|
|
|
|
|
+ items: List[Dict[str, str]],
|
|
|
tenant_no: str,
|
|
tenant_no: str,
|
|
|
user: dict,
|
|
user: dict,
|
|
|
user_id: str,
|
|
user_id: str,
|
|
@@ -74,37 +75,43 @@ def batch_handle_storage_certs(
|
|
|
handler_user_id: Optional[str],
|
|
handler_user_id: Optional[str],
|
|
|
attachments: str,
|
|
attachments: str,
|
|
|
remark: str,
|
|
remark: str,
|
|
|
|
|
+ mail_cert_time: Optional[datetime] = None,
|
|
|
|
|
+ update_mail_cert_time: bool = False,
|
|
|
) -> Dict[str, int]:
|
|
) -> Dict[str, int]:
|
|
|
- ids = unique_nonempty_ids(protocol_ids)
|
|
|
|
|
- if not ids:
|
|
|
|
|
|
|
+ pairs = unique_sample_items(items)
|
|
|
|
|
+ if not pairs:
|
|
|
raise ValueError("请选择样本")
|
|
raise ValueError("请选择样本")
|
|
|
success = 0
|
|
success = 0
|
|
|
fail = 0
|
|
fail = 0
|
|
|
- for pid in ids:
|
|
|
|
|
- if not _protocol_accessible(db, pid, tenant_no, user):
|
|
|
|
|
|
|
+ for sample_code, protocol_id in pairs:
|
|
|
|
|
+ if not protocol_id or not _protocol_accessible(db, protocol_id, tenant_no, user):
|
|
|
fail += 1
|
|
fail += 1
|
|
|
continue
|
|
continue
|
|
|
try:
|
|
try:
|
|
|
- cp_svc.upsert_storage_cert_handle(
|
|
|
|
|
|
|
+ sample_storage_cert_crud.upsert_handle(
|
|
|
db,
|
|
db,
|
|
|
- pid,
|
|
|
|
|
- tenant_no,
|
|
|
|
|
- user_id,
|
|
|
|
|
|
|
+ tenant_no=tenant_no,
|
|
|
|
|
+ sample_code=sample_code,
|
|
|
|
|
+ collection_protocol_id=protocol_id,
|
|
|
|
|
+ user_id=user_id,
|
|
|
handle_time=handle_time,
|
|
handle_time=handle_time,
|
|
|
handler_user_id=handler_user_id,
|
|
handler_user_id=handler_user_id,
|
|
|
cert_image_urls=attachments,
|
|
cert_image_urls=attachments,
|
|
|
remark=remark,
|
|
remark=remark,
|
|
|
|
|
+ mail_cert_time=mail_cert_time,
|
|
|
|
|
+ update_mail_cert_time=update_mail_cert_time,
|
|
|
)
|
|
)
|
|
|
success += 1
|
|
success += 1
|
|
|
except ValueError:
|
|
except ValueError:
|
|
|
fail += 1
|
|
fail += 1
|
|
|
|
|
+ db.commit()
|
|
|
return {"success": success, "fail": fail}
|
|
return {"success": success, "fail": fail}
|
|
|
|
|
|
|
|
|
|
|
|
|
def batch_handle_insurance(
|
|
def batch_handle_insurance(
|
|
|
db: Session,
|
|
db: Session,
|
|
|
*,
|
|
*,
|
|
|
- protocol_ids: List[str],
|
|
|
|
|
|
|
+ items: List[Dict[str, str]],
|
|
|
tenant_no: str,
|
|
tenant_no: str,
|
|
|
user: dict,
|
|
user: dict,
|
|
|
user_id: str,
|
|
user_id: str,
|
|
@@ -112,30 +119,36 @@ def batch_handle_insurance(
|
|
|
handler_user_id: Optional[str],
|
|
handler_user_id: Optional[str],
|
|
|
attachments: str,
|
|
attachments: str,
|
|
|
remark: str,
|
|
remark: str,
|
|
|
|
|
+ policy_send_time: Optional[datetime] = None,
|
|
|
|
|
+ update_policy_send_time: bool = False,
|
|
|
) -> Dict[str, int]:
|
|
) -> Dict[str, int]:
|
|
|
- ids = unique_nonempty_ids(protocol_ids)
|
|
|
|
|
- if not ids:
|
|
|
|
|
|
|
+ pairs = unique_sample_items(items)
|
|
|
|
|
+ if not pairs:
|
|
|
raise ValueError("请选择样本")
|
|
raise ValueError("请选择样本")
|
|
|
success = 0
|
|
success = 0
|
|
|
fail = 0
|
|
fail = 0
|
|
|
- for pid in ids:
|
|
|
|
|
- if not _protocol_accessible(db, pid, tenant_no, user):
|
|
|
|
|
|
|
+ for sample_code, protocol_id in pairs:
|
|
|
|
|
+ if not protocol_id or not _protocol_accessible(db, protocol_id, tenant_no, user):
|
|
|
fail += 1
|
|
fail += 1
|
|
|
continue
|
|
continue
|
|
|
try:
|
|
try:
|
|
|
- cp_svc.upsert_fullmoon_todo_handle(
|
|
|
|
|
|
|
+ sample_insurance_crud.upsert_handle(
|
|
|
db,
|
|
db,
|
|
|
- pid,
|
|
|
|
|
- tenant_no,
|
|
|
|
|
- user_id,
|
|
|
|
|
|
|
+ tenant_no=tenant_no,
|
|
|
|
|
+ sample_code=sample_code,
|
|
|
|
|
+ collection_protocol_id=protocol_id,
|
|
|
|
|
+ user_id=user_id,
|
|
|
handle_time=handle_time,
|
|
handle_time=handle_time,
|
|
|
handler_user_id=handler_user_id,
|
|
handler_user_id=handler_user_id,
|
|
|
insurance_attachments=attachments,
|
|
insurance_attachments=attachments,
|
|
|
handle_remark=remark,
|
|
handle_remark=remark,
|
|
|
|
|
+ policy_send_time=policy_send_time,
|
|
|
|
|
+ update_policy_send_time=update_policy_send_time,
|
|
|
)
|
|
)
|
|
|
success += 1
|
|
success += 1
|
|
|
except ValueError:
|
|
except ValueError:
|
|
|
fail += 1
|
|
fail += 1
|
|
|
|
|
+ db.commit()
|
|
|
return {"success": success, "fail": fail}
|
|
return {"success": success, "fail": fail}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -161,15 +174,7 @@ def batch_quick_register_storage(
|
|
|
attachments=attachments,
|
|
attachments=attachments,
|
|
|
remark=remark,
|
|
remark=remark,
|
|
|
)
|
|
)
|
|
|
- seen = set()
|
|
|
|
|
- pairs: List[tuple] = []
|
|
|
|
|
- for it in items or []:
|
|
|
|
|
- code = (it.get("sampleCode") or "").strip()
|
|
|
|
|
- pid = (it.get("protocolId") or "").strip()
|
|
|
|
|
- if not code or code in seen:
|
|
|
|
|
- continue
|
|
|
|
|
- seen.add(code)
|
|
|
|
|
- pairs.append((code, pid))
|
|
|
|
|
|
|
+ pairs = unique_sample_items(items)
|
|
|
if not pairs:
|
|
if not pairs:
|
|
|
raise ValueError("请选择样本")
|
|
raise ValueError("请选择样本")
|
|
|
|
|
|