feature: Schema, Migrations, Core CRUD, and Redis Threshold Cache

This commit is contained in:
voltsrage
2026-06-16 17:59:16 +08:00
commit 882d4af3e6
63 changed files with 3923 additions and 0 deletions
@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
public void Configure(EntityTypeBuilder<Order> builder)
{
builder.ToTable("orders", t =>
{
t.HasCheckConstraint("chk_orders_order_type",
"order_type IN ('LAB', 'IMAGING', 'MEDICATION', 'PROCEDURE')");
});
builder.HasKey(o => o.Id);
builder.Property(o => o.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(o => o.EncounterId).HasColumnName("encounter_id");
builder.Property(o => o.OrderType)
.HasColumnName("order_type")
.HasMaxLength(20)
.HasConversion(
v => v.ToDbString(),
v => OrderTypeExtensions.FromDbString(v))
.IsRequired();
builder.Property(o => o.Description).HasColumnName("description").IsRequired();
builder.Property(o => o.OrderedBy).HasColumnName("ordered_by").HasMaxLength(200).IsRequired();
builder.Property(o => o.Status).HasColumnName("status").HasMaxLength(20).HasDefaultValue("pending");
builder.Property(o => o.OrderedAt).HasColumnName("ordered_at").HasDefaultValueSql("NOW()");
builder.Property(o => o.ResultedAt).HasColumnName("resulted_at");
builder.HasOne(o => o.Encounter)
.WithMany(e => e.Orders)
.HasForeignKey(o => o.EncounterId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(o => new { o.EncounterId, o.OrderedAt });
builder.HasIndex(o => new { o.Status, o.OrderedAt })
.HasFilter("status IN ('pending', 'in_progress')");
}
}