diff --git a/backend/main.py b/backend/main.py index 63db3b9..d74bc06 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2113,6 +2113,7 @@ def _get_excel_column_order_accident() -> list: "description", "severity", "time", + "incident_datetime", # combined "YYYY-MM-DD HH:MM:SS" (computed) "location", "patient_or_staff", "long_description", @@ -2340,11 +2341,22 @@ async def accident_records( rows = q.offset((page - 1) * per_page).limit(per_page).all() def to_dict(r): + # Compose incident_datetime from date + time (display as "YYYY-MM-DD HH:MM:SS") + incident_dt = None + if r.date: + date_part = r.date.isoformat() + time_part = r.time or "00:00:00" + # Ensure time has HH:MM:SS format (may be HH:MM from Excel import) + if len(time_part) == 5: # "HH:MM" + time_part += ":00" + incident_dt = f"{date_part} {time_part}" + return { "id": r.id, "submitted_at": r.submitted_at.isoformat() if r.submitted_at else None, "date": r.date.isoformat() if r.date else None, "time": r.time, + "incident_datetime": incident_dt, # YYYY-MM-DD HH:MM:SS combined "location": r.location, "employee_name": r.submitter_email, "employee_id": r.injured_person_id, @@ -2946,11 +2958,21 @@ async def accident_export_excel( ws.freeze_panes(1, 0) for r_idx, r in enumerate(rows, start=1): + # Compose incident_datetime from date + time + incident_dt = "" + if r.date: + date_part = r.date.isoformat() + time_part = r.time or "00:00:00" + if len(time_part) == 5: + time_part += ":00" + incident_dt = f"{date_part} {time_part}" + rec = { "id": r.id, "submitted_at": r.submitted_at.isoformat() if r.submitted_at else "", "date": r.date.isoformat() if r.date else "", "time": r.time or "", + "incident_datetime": incident_dt, "location": r.location or "", "submitter_email": r.submitter_email or "", "injured_person_id": r.injured_person_id or "",