feature: In-App Simulation Runner (Backend)
CI / frontend (push) Canceled after 0s
CI / backend (push) Canceled after 8m32s

This commit is contained in:
voltsrage
2026-08-06 01:52:53 +08:00
parent 943d41339c
commit 24f45851e9
83 changed files with 3974 additions and 120 deletions
@@ -16,5 +16,8 @@ public class Patient
public string Status { get; set; } = "active";
public DateTimeOffset CreatedAt { get; set; }
/// <summary>True when this patient was created by the simulation runner. Never set for ingested clinical data.</summary>
public bool IsSimulated { get; set; }
public ICollection<Encounter> Encounters { get; set; } = new List<Encounter>();
}
@@ -0,0 +1,19 @@
public class SimulationRun
{
public Guid Id { get; set; }
public string ScenarioId { get; set; } = null!;
public string ScenarioName { get; set; } = null!;
public double Speed { get; set; }
public SimulationRunStatus Status { get; set; }
public Guid? PatientId { get; set; }
public Guid? EncounterId { get; set; }
public string StartedByUserId { get; set; } = null!;
public DateTimeOffset StartedAt { get; set; }
public DateTimeOffset? CompletedAt { get; set; }
public int ObservationsSent { get; set; }
public int MedicationsSent { get; set; }
public int OrdersPlaced { get; set; }
public double LastOffsetMinutes { get; set; }
public double TotalOffsetMinutes { get; set; }
public string? FailureReason { get; set; }
}
@@ -14,6 +14,8 @@ public enum AuditAction
AlertFeedbackSubmitted,
UserLogout,
TokenRefreshed,
SimulationRunStarted,
SimulationRunStopped,
}
public static class AuditActionExtensions
@@ -34,6 +36,8 @@ public static class AuditActionExtensions
AuditAction.AlertFeedbackSubmitted => "ALERT_FEEDBACK_SUBMITTED",
AuditAction.UserLogout => "USER_LOGOUT",
AuditAction.TokenRefreshed => "TOKEN_REFRESHED",
AuditAction.SimulationRunStarted => "SIMULATION_RUN_STARTED",
AuditAction.SimulationRunStopped => "SIMULATION_RUN_STOPPED",
_ => throw new ArgumentOutOfRangeException(nameof(a))
};
@@ -53,6 +57,8 @@ public static class AuditActionExtensions
"ALERT_FEEDBACK_SUBMITTED" => AuditAction.AlertFeedbackSubmitted,
"USER_LOGOUT" => AuditAction.UserLogout,
"TOKEN_REFRESHED" => AuditAction.TokenRefreshed,
"SIMULATION_RUN_STARTED" => AuditAction.SimulationRunStarted,
"SIMULATION_RUN_STOPPED" => AuditAction.SimulationRunStopped,
_ => throw new ArgumentOutOfRangeException(nameof(v))
};
}
@@ -0,0 +1,24 @@
public enum SimulationRunStatus { Pending, Running, Completed, Cancelled, Failed }
public static class SimulationRunStatusExtensions
{
public static string ToDbString(this SimulationRunStatus s) => s switch
{
SimulationRunStatus.Pending => "PENDING",
SimulationRunStatus.Running => "RUNNING",
SimulationRunStatus.Completed => "COMPLETED",
SimulationRunStatus.Cancelled => "CANCELLED",
SimulationRunStatus.Failed => "FAILED",
_ => throw new ArgumentOutOfRangeException(nameof(s))
};
public static SimulationRunStatus FromDbString(string v) => v switch
{
"PENDING" => SimulationRunStatus.Pending,
"RUNNING" => SimulationRunStatus.Running,
"COMPLETED" => SimulationRunStatus.Completed,
"CANCELLED" => SimulationRunStatus.Cancelled,
"FAILED" => SimulationRunStatus.Failed,
_ => throw new ArgumentOutOfRangeException(nameof(v), $"Unknown simulation run status: '{v}'")
};
}