diff --git a/backend/main.py b/backend/main.py index abcfc18..63db3b9 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1974,7 +1974,7 @@ async def _import_accident_to_db(db: Session, headers, rows, user_id: int) -> di for row_idx, row in enumerate(rows, start=2): # row_idx is the Excel 1-based row number try: submitted_at = _parse_dt(_cell(row, 0)) - employee_name = _cell(row, 1) or "" + submitter_email = _cell(row, 1) or "" department = _cell(row, 2) description = _cell(row, 3) or "" severity = str(_cell(row, 4) or "") @@ -1992,7 +1992,7 @@ async def _import_accident_to_db(db: Session, headers, rows, user_id: int) -> di date_val = submitted_at.date() # Skip rows missing critical identifiers - if not date_val or not employee_name: + if not date_val or not submitter_email: errors += 1 continue @@ -2010,7 +2010,7 @@ async def _import_accident_to_db(db: Session, headers, rows, user_id: int) -> di continue # Update fields from Excel existing.submitted_at = submitted_at - existing.employee_name = employee_name + existing.submitter_email = submitter_email existing.department = department existing.description = description existing.severity = severity @@ -2027,7 +2027,7 @@ async def _import_accident_to_db(db: Session, headers, rows, user_id: int) -> di else: rec = Accident( submitted_at=submitted_at, - employee_name=employee_name, + submitter_email=submitter_email, department=department, description=description, severity=severity, @@ -2072,7 +2072,7 @@ def _get_excel_headers_accident() -> dict: # Hardcoded column index → SQL field mapping (matches _import_accident_to_db) idx_to_sql = { 0: "submitted_at", - 1: "employee_name", + 1: "submitter_email", # was employee_name, renamed 2026-07-20 2: "department", 3: "description", 4: "severity", @@ -2108,7 +2108,7 @@ def _get_excel_column_order_accident() -> list: return [ "id", # virtual "submitted_at", - "employee_name", + "submitter_email", # was employee_name, renamed 2026-07-20 "department", "description", "severity", @@ -2390,10 +2390,13 @@ async def update_accident_record( raise HTTPException(status_code=404, detail="Record not found") # Allowed fields to edit (whitelist for safety) editable = { - "employee_name", "department", "description", "severity", + "submitter_email", # was employee_name, renamed 2026-07-20 + "injured_person_id", # was employee_id, renamed 2026-07-20 + "injured_person", # was responsible_person, renamed 2026-07-19 + "department", "description", "severity", "time", "location", "patient_or_staff", "long_description", "incident_photos", "action_taken", "needs_escalation", - "incident_score", "injured_person", # was responsible_person, renamed 2026-07-19", "medical_report", + "incident_score", "medical_report", } for k, v in payload.items(): if k in editable: @@ -2949,14 +2952,14 @@ async def accident_export_excel( "date": r.date.isoformat() if r.date else "", "time": r.time or "", "location": r.location or "", - "employee_name": r.submitter_email or "", - "employee_id": r.injured_person_id or "", + "submitter_email": r.submitter_email or "", + "injured_person_id": r.injured_person_id or "", "department": r.department or "", "description": r.description or "", "severity": str(r.severity or ""), "medical_report": r.medical_report or "", "action_taken": r.action_taken or "", - "responsible_person": r.injured_person or "", + "injured_person": r.injured_person or "", "patient_or_staff": r.patient_or_staff or "", "long_description": r.long_description or "", "incident_photos": r.incident_photos or "", @@ -3319,7 +3322,7 @@ async def export_excel( overview.write(f"G{nav_start_row + 1}", "→ 查明細", header_fmt_ov) for idx, r in enumerate(rows): row_n = nav_start_row + 2 + idx - overview.write(row_n, 1, r.submitter_email or "", cell_fmt_ov) + overview.write(row_n, 1, r.employee_name or "", cell_fmt_ov) overview.write(row_n, 2, r.department or "", cell_fmt_ov) overview.write(row_n, 3, r.date.isoformat() if r.date else "", cell_fmt_ov) overview.write(row_n, 4, r.status_text or "", cell_fmt_ov) @@ -3378,7 +3381,7 @@ async def export_excel( for r_idx, r in enumerate(rows, start=1): sc = (r.status_code or "").lower() fmt = status_fmts.get(sc, status_fmts["default"]) - ws.write(r_idx, 0, r.submitter_email or "") + ws.write(r_idx, 0, r.employee_name or "") ws.write(r_idx, 1, r.company or "") ws.write(r_idx, 2, r.department or "") ws.write(r_idx, 3, r.date.isoformat() if r.date else "")