Accident: add incident_datetime computed field (date HH:MM:SS)
Backend: - to_dict() now includes incident_datetime: "YYYY-MM-DD HH:MM:SS" - Composed from r.date (YYYY-MM-DD) + r.time (HH:MM:SS, padded if HH:MM) - _get_excel_column_order_accident() adds incident_datetime column after time - Export xlsx rec dict now includes incident_datetime Verified: - /api/accident/records: incident_datetime = "2026-07-30 09:40:00" - column_order includes incident_datetime column - /api/accident/export/excel: xlsx 明細 sheet now has incident_datetime column - Time edge case: HH:MM auto-padded to HH:MM:SS Frontend: - Accident list page auto-displays new column via column_order - No frontend changes needed (renders record[h] as string)
This commit is contained in:
@@ -2113,6 +2113,7 @@ def _get_excel_column_order_accident() -> list:
|
|||||||
"description",
|
"description",
|
||||||
"severity",
|
"severity",
|
||||||
"time",
|
"time",
|
||||||
|
"incident_datetime", # combined "YYYY-MM-DD HH:MM:SS" (computed)
|
||||||
"location",
|
"location",
|
||||||
"patient_or_staff",
|
"patient_or_staff",
|
||||||
"long_description",
|
"long_description",
|
||||||
@@ -2340,11 +2341,22 @@ async def accident_records(
|
|||||||
rows = q.offset((page - 1) * per_page).limit(per_page).all()
|
rows = q.offset((page - 1) * per_page).limit(per_page).all()
|
||||||
|
|
||||||
def to_dict(r):
|
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 {
|
return {
|
||||||
"id": r.id,
|
"id": r.id,
|
||||||
"submitted_at": r.submitted_at.isoformat() if r.submitted_at else None,
|
"submitted_at": r.submitted_at.isoformat() if r.submitted_at else None,
|
||||||
"date": r.date.isoformat() if r.date else None,
|
"date": r.date.isoformat() if r.date else None,
|
||||||
"time": r.time,
|
"time": r.time,
|
||||||
|
"incident_datetime": incident_dt, # YYYY-MM-DD HH:MM:SS combined
|
||||||
"location": r.location,
|
"location": r.location,
|
||||||
"employee_name": r.submitter_email,
|
"employee_name": r.submitter_email,
|
||||||
"employee_id": r.injured_person_id,
|
"employee_id": r.injured_person_id,
|
||||||
@@ -2946,11 +2958,21 @@ async def accident_export_excel(
|
|||||||
ws.freeze_panes(1, 0)
|
ws.freeze_panes(1, 0)
|
||||||
|
|
||||||
for r_idx, r in enumerate(rows, start=1):
|
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 = {
|
rec = {
|
||||||
"id": r.id,
|
"id": r.id,
|
||||||
"submitted_at": r.submitted_at.isoformat() if r.submitted_at else "",
|
"submitted_at": r.submitted_at.isoformat() if r.submitted_at else "",
|
||||||
"date": r.date.isoformat() if r.date else "",
|
"date": r.date.isoformat() if r.date else "",
|
||||||
"time": r.time or "",
|
"time": r.time or "",
|
||||||
|
"incident_datetime": incident_dt,
|
||||||
"location": r.location or "",
|
"location": r.location or "",
|
||||||
"submitter_email": r.submitter_email or "",
|
"submitter_email": r.submitter_email or "",
|
||||||
"injured_person_id": r.injured_person_id or "",
|
"injured_person_id": r.injured_person_id or "",
|
||||||
|
|||||||
Reference in New Issue
Block a user