feature: Approval and Promotion to VigilCareClinical

This commit is contained in:
voltsrage
2026-06-26 15:05:02 +08:00
parent 470df683dd
commit 706318e5d2
40 changed files with 5639 additions and 3 deletions
+5
View File
@@ -13,6 +13,11 @@ public class AppDbContext : DbContext
public DbSet<DigitizationEvent> DigitizationEvents => Set<DigitizationEvent>();
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
public DbSet<AuthAuditEvent> AuthAuditEvents => Set<AuthAuditEvent>();
public DbSet<IdempotencyRecord> IdempotencyRecords => Set<IdempotencyRecord>();
public DbSet<Patient> Patients => Set<Patient>();
public DbSet<Encounter> Encounters => Set<Encounter>();
public DbSet<Observation> Observations => Set<Observation>();
public DbSet<OutboxEvent> OutboxEvents => Set<OutboxEvent>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class EncounterConfiguration : IEntityTypeConfiguration<Encounter>
{
public void Configure(EntityTypeBuilder<Encounter> builder)
{
builder.ToTable("encounters", "clinical", t =>
{
t.HasCheckConstraint("chk_encounters_department",
"department IS NULL OR department IN ('Emergency Department', 'Internal Medicine', 'General Medicine', 'Surgery', 'ICU', 'NICU', 'Medical-Surgical', 'Outpatient Clinic', 'Pediatrics', 'Obstetrics & Gynecology', 'Labor & Delivery', 'Cardiology', 'Orthopedics', 'Neurology', 'Oncology', 'Radiology', 'Laboratory', 'Psychiatry', 'Physical Therapy', 'Anesthesiology')");
});
builder.HasKey(e => e.Id);
builder.Property(e => e.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(e => e.PatientId).HasColumnName("patient_id").IsRequired();
builder.Property(e => e.AdmissionDate).HasColumnName("admission_date");
builder.Property(e => e.Department)
.HasColumnName("department")
.HasMaxLength(100)
.HasConversion(
v => v.HasValue ? v.Value.ToDbString() : null,
v => v == null ? null : DepartmentExtensions.FromDbString(v));
builder.Property(e => e.RoomBed).HasColumnName("room_bed").HasMaxLength(50);
builder.Property(e => e.AdmissionReason).HasColumnName("admission_reason").HasMaxLength(500);
builder.Property(e => e.DischargeDiagnosis).HasColumnName("discharge_diagnosis").HasMaxLength(500);
builder.Property(e => e.Status).HasColumnName("status").HasMaxLength(20).IsRequired();
builder.Property(e => e.SourceBatchId).HasColumnName("source_batch_id");
builder.Property(e => e.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.Property(e => e.UpdatedAt).HasColumnName("updated_at").HasDefaultValueSql("NOW()");
builder.HasOne(e => e.Patient).WithMany().HasForeignKey(e => e.PatientId).OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(e => new { e.PatientId, e.Status }).HasDatabaseName("ix_encounters_patient_status");
}
}
@@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class IdempotencyRecordConfiguration : IEntityTypeConfiguration<IdempotencyRecord>
{
public void Configure(EntityTypeBuilder<IdempotencyRecord> builder)
{
builder.ToTable("idempotency_records");
builder.HasKey(r => r.Id);
builder.Property(r => r.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(r => r.IdempotencyKey).HasColumnName("idempotency_key").HasMaxLength(100).IsRequired();
builder.Property(r => r.OperationName).HasColumnName("operation_name").HasMaxLength(100).IsRequired();
builder.Property(r => r.ResourceId).HasColumnName("resource_id").IsRequired();
builder.Property(r => r.HttpStatusCode).HasColumnName("http_status_code").IsRequired();
builder.Property(r => r.ResponseBodyJson).HasColumnName("response_body_json").HasColumnType("jsonb").IsRequired();
builder.Property(r => r.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.Property(r => r.ExpiresAt).HasColumnName("expires_at").IsRequired();
builder.HasIndex(r => new { r.IdempotencyKey, r.OperationName })
.IsUnique()
.HasDatabaseName("ix_idempotency_records_key_operation");
builder.HasIndex(r => r.ExpiresAt)
.HasDatabaseName("ix_idempotency_records_expires_at");
}
}
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class ObservationConfiguration : IEntityTypeConfiguration<Observation>
{
public void Configure(EntityTypeBuilder<Observation> builder)
{
builder.ToTable("observations", "clinical");
builder.HasKey(o => o.Id);
builder.Property(o => o.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(o => o.EncounterId).HasColumnName("encounter_id").IsRequired();
builder.Property(o => o.PatientId).HasColumnName("patient_id").IsRequired();
builder.Property(o => o.ObservationCode).HasColumnName("observation_code").HasMaxLength(50).IsRequired();
builder.Property(o => o.Value).HasColumnName("value").HasColumnType("decimal(10,3)").IsRequired();
builder.Property(o => o.Unit).HasColumnName("unit").HasMaxLength(20).IsRequired();
builder.Property(o => o.RecordedAt).HasColumnName("recorded_at").IsRequired();
builder.Property(o => o.Note).HasColumnName("note").HasMaxLength(500);
builder.Property(o => o.Source).HasColumnName("source").HasMaxLength(30).IsRequired();
builder.Property(o => o.SourceDraftObservationId).HasColumnName("source_draft_observation_id");
builder.Property(o => o.SourceBatchId).HasColumnName("source_batch_id");
builder.Property(o => o.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.HasOne(o => o.Encounter).WithMany().HasForeignKey(o => o.EncounterId).OnDelete(DeleteBehavior.Restrict);
builder.HasOne(o => o.Patient).WithMany().HasForeignKey(o => o.PatientId).OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(o => new { o.EncounterId, o.ObservationCode }).HasDatabaseName("ix_observations_encounter_code");
builder.HasIndex(o => o.SourceBatchId).HasFilter("source_batch_id IS NOT NULL").HasDatabaseName("ix_observations_source_batch");
}
}
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class OutboxEventConfiguration : IEntityTypeConfiguration<OutboxEvent>
{
public void Configure(EntityTypeBuilder<OutboxEvent> builder)
{
builder.ToTable("outbox_events", "clinical");
builder.HasKey(e => e.Id);
builder.Property(e => e.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(e => e.EventType).HasColumnName("event_type").HasMaxLength(100).IsRequired();
builder.Property(e => e.AggregateType).HasColumnName("aggregate_type").HasMaxLength(50).IsRequired();
builder.Property(e => e.AggregateId).HasColumnName("aggregate_id").IsRequired();
builder.Property(e => e.PayloadJson).HasColumnName("payload_json").HasColumnType("jsonb").IsRequired();
builder.Property(e => e.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.Property(e => e.ProcessedAt).HasColumnName("processed_at");
builder.Property(e => e.RetryCount).HasColumnName("retry_count").HasDefaultValue(0);
builder.HasIndex(e => e.ProcessedAt)
.HasFilter("processed_at IS NULL")
.HasDatabaseName("ix_outbox_events_unprocessed");
}
}
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public class PatientConfiguration : IEntityTypeConfiguration<Patient>
{
public void Configure(EntityTypeBuilder<Patient> builder)
{
builder.ToTable("patients", "clinical", t =>
{
t.HasCheckConstraint("chk_patients_blood_type",
"blood_type IS NULL OR blood_type IN ('A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-')");
});
builder.HasKey(p => p.Id);
builder.Property(p => p.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
builder.Property(p => p.Mrn).HasColumnName("mrn").HasMaxLength(20).IsRequired();
builder.Property(p => p.FullName).HasColumnName("full_name").HasMaxLength(200).IsRequired();
builder.Property(p => p.DateOfBirth).HasColumnName("date_of_birth");
builder.Property(p => p.Sex).HasColumnName("sex").HasMaxLength(10);
builder.Property(p => p.BloodType)
.HasColumnName("blood_type")
.HasMaxLength(10)
.HasConversion(
v => v.HasValue ? v.Value.ToDbString() : null,
v => v == null ? null : BloodTypeExtensions.FromDbString(v));
builder.Property(p => p.EmergencyContact).HasColumnName("emergency_contact").HasMaxLength(500);
builder.Property(p => p.AllergiesJson).HasColumnName("allergies_json").HasColumnType("jsonb");
builder.Property(p => p.NoKnownAllergies).HasColumnName("no_known_allergies").HasDefaultValue(false);
builder.Property(p => p.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.Property(p => p.UpdatedAt).HasColumnName("updated_at").HasDefaultValueSql("NOW()");
builder.HasIndex(p => p.Mrn).IsUnique().HasDatabaseName("ix_patients_mrn");
}
}
@@ -0,0 +1,768 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace VigilCareRecordsAPI.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260626060803_AddIdempotencyRecords")]
partial class AddIdempotencyRecords
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("AuthAuditEvent", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("event_type");
b.Property<string>("MetadataJson")
.HasColumnType("jsonb")
.HasColumnName("metadata_json");
b.Property<DateTimeOffset>("OccurredAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("occurred_at")
.HasDefaultValueSql("NOW()");
b.Property<Guid>("UserId")
.HasColumnType("uuid")
.HasColumnName("user_id");
b.HasKey("Id");
b.HasIndex("UserId", "OccurredAt");
b.ToTable("auth_audit_events", null, t =>
{
t.HasCheckConstraint("chk_auth_audit_events_event_type", "event_type IN ('USER_LOGOUT', 'TOKEN_REFRESHED')");
});
});
modelBuilder.Entity("DigitizationBatch", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid?>("ApprovedByUserId")
.HasColumnType("uuid")
.HasColumnName("approved_by_user_id");
b.Property<string>("BatchType")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("batch_type");
b.Property<bool>("ClinicianAttestation")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("clinician_attestation");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("DocumentRef")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("document_ref");
b.Property<string>("DocumentSha256")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("document_sha256");
b.Property<bool>("EnableRetroactiveAlerts")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("enable_retroactive_alerts");
b.Property<Guid?>("EncounterDraftId")
.HasColumnType("uuid")
.HasColumnName("encounter_draft_id");
b.Property<Guid?>("EnteredByUserId")
.HasColumnType("uuid")
.HasColumnName("entered_by_user_id");
b.Property<Guid?>("PatientId")
.HasColumnType("uuid")
.HasColumnName("patient_id");
b.Property<DateTimeOffset?>("PromotedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("promoted_at");
b.Property<Guid?>("PromotionEncounterId")
.HasColumnType("uuid")
.HasColumnName("promotion_encounter_id");
b.Property<string>("RejectionReason")
.HasColumnType("text")
.HasColumnName("rejection_reason");
b.Property<string>("Status")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("status")
.HasDefaultValueSql("'UPLOADED'");
b.Property<Guid?>("SupersedesBatchId")
.HasColumnType("uuid")
.HasColumnName("supersedes_batch_id");
b.Property<string>("Track")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("track")
.HasDefaultValueSql("'BACKFILL'");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("NOW()");
b.Property<Guid?>("VerifiedByUserId")
.HasColumnType("uuid")
.HasColumnName("verified_by_user_id");
b.HasKey("Id");
b.HasIndex("ApprovedByUserId");
b.HasIndex("EnteredByUserId");
b.HasIndex("Status");
b.HasIndex("SupersedesBatchId")
.HasFilter("supersedes_batch_id IS NOT NULL");
b.HasIndex("VerifiedByUserId");
b.HasIndex("DocumentSha256", "PatientId", "CreatedAt");
b.ToTable("digitization_batches", null, t =>
{
t.HasCheckConstraint("chk_batches_batch_type", "batch_type IN ('PATIENT_REGISTRATION', 'ENCOUNTER_SUMMARY', 'VITALS_SHEET', 'LAB_RESULTS', 'MEDICATION_LIST', 'ALLERGY_UPDATE', 'MIXED')");
t.HasCheckConstraint("chk_batches_status", "status IN ('UPLOADED', 'IN_ENTRY', 'PENDING_VERIFICATION', 'REJECTED', 'VERIFIED', 'AWAITING_CLINICAL_APPROVAL', 'APPROVED', 'PROMOTED')");
t.HasCheckConstraint("chk_batches_track", "track IN ('BACKFILL', 'LIVE_CAPTURE')");
});
});
modelBuilder.Entity("DigitizationEvent", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid>("ActorUserId")
.HasColumnType("uuid")
.HasColumnName("actor_user_id");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("event_type");
b.Property<string>("MetadataJson")
.HasColumnType("jsonb")
.HasColumnName("metadata_json");
b.Property<DateTimeOffset>("OccurredAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("occurred_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("ActorUserId");
b.HasIndex("BatchId", "OccurredAt");
b.ToTable("digitization_events", null, t =>
{
t.HasCheckConstraint("chk_digitization_events_event_type", "event_type IN ('uploaded', 'entry_started', 'submitted_for_verification', 'rejected', 'verified', 'verified_pending_clinical', 'awaiting_clinical_approval', 'approved', 'promoted', 'live_capture_attested', 'correction_requested', 'verification_failed', 'superseded', 'correction_promoted', 'correction_uploaded', 'promotion_retry_succeeded', 'promotion_retry_failed', 'promotion_retry_exhausted', 'promotion_failed')");
});
});
modelBuilder.Entity("DraftEncounter", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset?>("AdmissionDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("admission_date");
b.Property<string>("AdmissionReason")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("admission_reason");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("Department")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("department");
b.Property<string>("DischargeDiagnosis")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("discharge_diagnosis");
b.Property<string>("RoomBed")
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("room_bed");
b.Property<string>("Status")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("status");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("BatchId")
.IsUnique();
b.ToTable("draft_encounters", null, t =>
{
t.HasCheckConstraint("chk_draft_encounters_department", "department IS NULL OR department IN ('Emergency Department', 'Internal Medicine', 'General Medicine', 'Surgery', 'ICU', 'NICU', 'Medical-Surgical', 'Outpatient Clinic', 'Pediatrics', 'Obstetrics & Gynecology', 'Labor & Delivery', 'Cardiology', 'Orthopedics', 'Neurology', 'Oncology', 'Radiology', 'Laboratory', 'Psychiatry', 'Physical Therapy', 'Anesthesiology')");
});
});
modelBuilder.Entity("DraftObservation", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("Note")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("note");
b.Property<string>("ObservationCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("observation_code");
b.Property<DateTimeOffset>("RecordedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("recorded_at");
b.Property<string>("Unit")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("unit");
b.Property<decimal>("Value")
.HasColumnType("decimal(10,3)")
.HasColumnName("value");
b.HasKey("Id");
b.HasIndex("BatchId", "ObservationCode");
b.ToTable("draft_observations", (string)null);
});
modelBuilder.Entity("DraftPatient", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<string>("AllergiesJson")
.HasColumnType("jsonb")
.HasColumnName("allergies_json");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<string>("BloodType")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("blood_type");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<DateOnly?>("DateOfBirth")
.HasColumnType("date")
.HasColumnName("date_of_birth");
b.Property<string>("EmergencyContact")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("emergency_contact");
b.Property<string>("FullName")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("full_name");
b.Property<string>("MedicationsJson")
.HasColumnType("jsonb")
.HasColumnName("medications_json");
b.Property<bool>("NoActiveMedications")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("no_active_medications");
b.Property<bool>("NoKnownAllergies")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("no_known_allergies");
b.Property<string>("Sex")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("sex");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("BatchId")
.IsUnique();
b.ToTable("draft_patients", null, t =>
{
t.HasCheckConstraint("chk_draft_patients_blood_type", "blood_type IS NULL OR blood_type IN ('A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-')");
});
});
modelBuilder.Entity("IdempotencyRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<DateTimeOffset>("ExpiresAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expires_at");
b.Property<int>("HttpStatusCode")
.HasColumnType("integer")
.HasColumnName("http_status_code");
b.Property<string>("IdempotencyKey")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("idempotency_key");
b.Property<string>("OperationName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("operation_name");
b.Property<Guid>("ResourceId")
.HasColumnType("uuid")
.HasColumnName("resource_id");
b.Property<string>("ResponseBodyJson")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("response_body_json");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("ix_idempotency_records_expires_at");
b.HasIndex("IdempotencyKey", "OperationName")
.IsUnique()
.HasDatabaseName("ix_idempotency_records_key_operation");
b.ToTable("idempotency_records", (string)null);
});
modelBuilder.Entity("RefreshToken", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<DateTimeOffset>("ExpiresAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expires_at");
b.Property<Guid?>("ReplacedByTokenId")
.HasColumnType("uuid")
.HasColumnName("replaced_by_token_id");
b.Property<DateTimeOffset?>("RevokedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("revoked_at");
b.Property<string>("TokenHash")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("token_hash");
b.Property<Guid>("UserId")
.HasColumnType("uuid")
.HasColumnName("user_id");
b.HasKey("Id");
b.HasIndex("ReplacedByTokenId");
b.HasIndex("TokenHash")
.IsUnique();
b.HasIndex("UserId", "RevokedAt");
b.ToTable("refresh_tokens", (string)null);
});
modelBuilder.Entity("ScannedDocument", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid>("BatchId")
.HasColumnType("uuid")
.HasColumnName("batch_id");
b.Property<string>("ContentType")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("content_type");
b.Property<long>("FileSizeBytes")
.HasColumnType("bigint")
.HasColumnName("file_size_bytes");
b.Property<string>("ObjectKey")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("object_key");
b.Property<string>("Sha256")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("sha256");
b.Property<DateTimeOffset>("UploadedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("uploaded_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("BatchId")
.IsUnique();
b.HasIndex("Sha256");
b.ToTable("scanned_documents", (string)null);
});
modelBuilder.Entity("User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("FullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("full_name");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(true)
.HasColumnName("is_active");
b.Property<string>("PasswordHash")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("password_hash");
b.Property<string>("Role")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("role");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("username");
b.HasKey("Id");
b.HasIndex("Username")
.IsUnique();
b.ToTable("users", null, t =>
{
t.HasCheckConstraint("chk_users_role", "role IN ('INTAKE_CLERK', 'DATA_ENTRY_CLERK', 'VERIFIER', 'CLINICAL_APPROVER', 'CLINICIAN', 'ADMINISTRATOR')");
});
});
modelBuilder.Entity("AuthAuditEvent", b =>
{
b.HasOne("User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DigitizationBatch", b =>
{
b.HasOne("User", "ApprovedByUser")
.WithMany()
.HasForeignKey("ApprovedByUserId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("User", "EnteredByUser")
.WithMany()
.HasForeignKey("EnteredByUserId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("User", "VerifiedByUser")
.WithMany()
.HasForeignKey("VerifiedByUserId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("ApprovedByUser");
b.Navigation("EnteredByUser");
b.Navigation("VerifiedByUser");
});
modelBuilder.Entity("DigitizationEvent", b =>
{
b.HasOne("User", "Actor")
.WithMany()
.HasForeignKey("ActorUserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("DigitizationBatch", "Batch")
.WithMany("Events")
.HasForeignKey("BatchId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Actor");
b.Navigation("Batch");
});
modelBuilder.Entity("DraftEncounter", b =>
{
b.HasOne("DigitizationBatch", "Batch")
.WithOne("DraftEncounter")
.HasForeignKey("DraftEncounter", "BatchId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Batch");
});
modelBuilder.Entity("DraftObservation", b =>
{
b.HasOne("DigitizationBatch", "Batch")
.WithMany("DraftObservations")
.HasForeignKey("BatchId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Batch");
});
modelBuilder.Entity("DraftPatient", b =>
{
b.HasOne("DigitizationBatch", "Batch")
.WithOne("DraftPatient")
.HasForeignKey("DraftPatient", "BatchId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Batch");
});
modelBuilder.Entity("RefreshToken", b =>
{
b.HasOne("RefreshToken", "ReplacedByToken")
.WithMany()
.HasForeignKey("ReplacedByTokenId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ReplacedByToken");
b.Navigation("User");
});
modelBuilder.Entity("ScannedDocument", b =>
{
b.HasOne("DigitizationBatch", "Batch")
.WithOne("Document")
.HasForeignKey("ScannedDocument", "BatchId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Batch");
});
modelBuilder.Entity("DigitizationBatch", b =>
{
b.Navigation("Document");
b.Navigation("DraftEncounter");
b.Navigation("DraftObservations");
b.Navigation("DraftPatient");
b.Navigation("Events");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VigilCareRecordsAPI.Data.Migrations
{
/// <inheritdoc />
public partial class AddIdempotencyRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "idempotency_records",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
idempotency_key = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
operation_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
resource_id = table.Column<Guid>(type: "uuid", nullable: false),
http_status_code = table.Column<int>(type: "integer", nullable: false),
response_body_json = table.Column<string>(type: "jsonb", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_idempotency_records", x => x.id);
});
migrationBuilder.CreateIndex(
name: "ix_idempotency_records_expires_at",
table: "idempotency_records",
column: "expires_at");
migrationBuilder.CreateIndex(
name: "ix_idempotency_records_key_operation",
table: "idempotency_records",
columns: new[] { "idempotency_key", "operation_name" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "idempotency_records");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,186 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VigilCareRecordsAPI.Data.Migrations
{
/// <inheritdoc />
public partial class AddClinicalSchemaAndPromotion : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "clinical");
migrationBuilder.CreateTable(
name: "outbox_events",
schema: "clinical",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
aggregate_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
aggregate_id = table.Column<Guid>(type: "uuid", nullable: false),
payload_json = table.Column<string>(type: "jsonb", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
retry_count = table.Column<int>(type: "integer", nullable: false, defaultValue: 0)
},
constraints: table =>
{
table.PrimaryKey("PK_outbox_events", x => x.id);
});
migrationBuilder.CreateTable(
name: "patients",
schema: "clinical",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
mrn = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
full_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
date_of_birth = table.Column<DateOnly>(type: "date", nullable: true),
sex = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
blood_type = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
emergency_contact = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
allergies_json = table.Column<string>(type: "jsonb", nullable: true),
no_known_allergies = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
},
constraints: table =>
{
table.PrimaryKey("PK_patients", x => x.id);
table.CheckConstraint("chk_patients_blood_type", "blood_type IS NULL OR blood_type IN ('A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-')");
});
migrationBuilder.CreateTable(
name: "encounters",
schema: "clinical",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
patient_id = table.Column<Guid>(type: "uuid", nullable: false),
admission_date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
department = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
room_bed = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
admission_reason = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
discharge_diagnosis = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
source_batch_id = table.Column<Guid>(type: "uuid", nullable: true),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
},
constraints: table =>
{
table.PrimaryKey("PK_encounters", x => x.id);
table.CheckConstraint("chk_encounters_department", "department IS NULL OR department IN ('Emergency Department', 'Internal Medicine', 'General Medicine', 'Surgery', 'ICU', 'NICU', 'Medical-Surgical', 'Outpatient Clinic', 'Pediatrics', 'Obstetrics & Gynecology', 'Labor & Delivery', 'Cardiology', 'Orthopedics', 'Neurology', 'Oncology', 'Radiology', 'Laboratory', 'Psychiatry', 'Physical Therapy', 'Anesthesiology')");
table.ForeignKey(
name: "FK_encounters_patients_patient_id",
column: x => x.patient_id,
principalSchema: "clinical",
principalTable: "patients",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "observations",
schema: "clinical",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
encounter_id = table.Column<Guid>(type: "uuid", nullable: false),
patient_id = table.Column<Guid>(type: "uuid", nullable: false),
observation_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
value = table.Column<decimal>(type: "numeric(10,3)", nullable: false),
unit = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
recorded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
note = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
source = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
source_draft_observation_id = table.Column<Guid>(type: "uuid", nullable: true),
source_batch_id = table.Column<Guid>(type: "uuid", nullable: true),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
},
constraints: table =>
{
table.PrimaryKey("PK_observations", x => x.id);
table.ForeignKey(
name: "FK_observations_encounters_encounter_id",
column: x => x.encounter_id,
principalSchema: "clinical",
principalTable: "encounters",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_observations_patients_patient_id",
column: x => x.patient_id,
principalSchema: "clinical",
principalTable: "patients",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "ix_encounters_patient_status",
schema: "clinical",
table: "encounters",
columns: new[] { "patient_id", "status" });
migrationBuilder.CreateIndex(
name: "ix_observations_encounter_code",
schema: "clinical",
table: "observations",
columns: new[] { "encounter_id", "observation_code" });
migrationBuilder.CreateIndex(
name: "IX_observations_patient_id",
schema: "clinical",
table: "observations",
column: "patient_id");
migrationBuilder.CreateIndex(
name: "ix_observations_source_batch",
schema: "clinical",
table: "observations",
column: "source_batch_id",
filter: "source_batch_id IS NOT NULL");
migrationBuilder.CreateIndex(
name: "ix_outbox_events_unprocessed",
schema: "clinical",
table: "outbox_events",
column: "processed_at",
filter: "processed_at IS NULL");
migrationBuilder.CreateIndex(
name: "ix_patients_mrn",
schema: "clinical",
table: "patients",
column: "mrn",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "observations",
schema: "clinical");
migrationBuilder.DropTable(
name: "outbox_events",
schema: "clinical");
migrationBuilder.DropTable(
name: "encounters",
schema: "clinical");
migrationBuilder.DropTable(
name: "patients",
schema: "clinical");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VigilCareRecordsAPI.Data.Migrations
{
/// <inheritdoc />
public partial class AddMrnSequence : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(
"CREATE SEQUENCE IF NOT EXISTS clinical.mrn_sequence START WITH 1 INCREMENT BY 1;");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DROP SEQUENCE IF EXISTS clinical.mrn_sequence;");
}
}
}
@@ -423,6 +423,332 @@ namespace VigilCareRecordsAPI.Data.Migrations
});
});
modelBuilder.Entity("Encounter", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset?>("AdmissionDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("admission_date");
b.Property<string>("AdmissionReason")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("admission_reason");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("Department")
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("department");
b.Property<string>("DischargeDiagnosis")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("discharge_diagnosis");
b.Property<Guid>("PatientId")
.HasColumnType("uuid")
.HasColumnName("patient_id");
b.Property<string>("RoomBed")
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("room_bed");
b.Property<Guid?>("SourceBatchId")
.HasColumnType("uuid")
.HasColumnName("source_batch_id");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("status");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("PatientId", "Status")
.HasDatabaseName("ix_encounters_patient_status");
b.ToTable("encounters", "clinical", t =>
{
t.HasCheckConstraint("chk_encounters_department", "department IS NULL OR department IN ('Emergency Department', 'Internal Medicine', 'General Medicine', 'Surgery', 'ICU', 'NICU', 'Medical-Surgical', 'Outpatient Clinic', 'Pediatrics', 'Obstetrics & Gynecology', 'Labor & Delivery', 'Cardiology', 'Orthopedics', 'Neurology', 'Oncology', 'Radiology', 'Laboratory', 'Psychiatry', 'Physical Therapy', 'Anesthesiology')");
});
});
modelBuilder.Entity("IdempotencyRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<DateTimeOffset>("ExpiresAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expires_at");
b.Property<int>("HttpStatusCode")
.HasColumnType("integer")
.HasColumnName("http_status_code");
b.Property<string>("IdempotencyKey")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("idempotency_key");
b.Property<string>("OperationName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("operation_name");
b.Property<Guid>("ResourceId")
.HasColumnType("uuid")
.HasColumnName("resource_id");
b.Property<string>("ResponseBodyJson")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("response_body_json");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("ix_idempotency_records_expires_at");
b.HasIndex("IdempotencyKey", "OperationName")
.IsUnique()
.HasDatabaseName("ix_idempotency_records_key_operation");
b.ToTable("idempotency_records", (string)null);
});
modelBuilder.Entity("Observation", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<Guid>("EncounterId")
.HasColumnType("uuid")
.HasColumnName("encounter_id");
b.Property<string>("Note")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("note");
b.Property<string>("ObservationCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("observation_code");
b.Property<Guid>("PatientId")
.HasColumnType("uuid")
.HasColumnName("patient_id");
b.Property<DateTimeOffset>("RecordedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("recorded_at");
b.Property<string>("Source")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)")
.HasColumnName("source");
b.Property<Guid?>("SourceBatchId")
.HasColumnType("uuid")
.HasColumnName("source_batch_id");
b.Property<Guid?>("SourceDraftObservationId")
.HasColumnType("uuid")
.HasColumnName("source_draft_observation_id");
b.Property<string>("Unit")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("unit");
b.Property<decimal>("Value")
.HasColumnType("decimal(10,3)")
.HasColumnName("value");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("SourceBatchId")
.HasDatabaseName("ix_observations_source_batch")
.HasFilter("source_batch_id IS NOT NULL");
b.HasIndex("EncounterId", "ObservationCode")
.HasDatabaseName("ix_observations_encounter_code");
b.ToTable("observations", "clinical");
});
modelBuilder.Entity("OutboxEvent", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid>("AggregateId")
.HasColumnType("uuid")
.HasColumnName("aggregate_id");
b.Property<string>("AggregateType")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)")
.HasColumnName("aggregate_type");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("event_type");
b.Property<string>("PayloadJson")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("payload_json");
b.Property<DateTimeOffset?>("ProcessedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("processed_at");
b.Property<int>("RetryCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(0)
.HasColumnName("retry_count");
b.HasKey("Id");
b.HasIndex("ProcessedAt")
.HasDatabaseName("ix_outbox_events_unprocessed")
.HasFilter("processed_at IS NULL");
b.ToTable("outbox_events", "clinical");
});
modelBuilder.Entity("Patient", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<string>("AllergiesJson")
.HasColumnType("jsonb")
.HasColumnName("allergies_json");
b.Property<string>("BloodType")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("blood_type");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("NOW()");
b.Property<DateOnly?>("DateOfBirth")
.HasColumnType("date")
.HasColumnName("date_of_birth");
b.Property<string>("EmergencyContact")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("emergency_contact");
b.Property<string>("FullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("full_name");
b.Property<string>("Mrn")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("mrn");
b.Property<bool>("NoKnownAllergies")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("no_known_allergies");
b.Property<string>("Sex")
.HasMaxLength(10)
.HasColumnType("character varying(10)")
.HasColumnName("sex");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("NOW()");
b.HasKey("Id");
b.HasIndex("Mrn")
.IsUnique()
.HasDatabaseName("ix_patients_mrn");
b.ToTable("patients", "clinical", t =>
{
t.HasCheckConstraint("chk_patients_blood_type", "blood_type IS NULL OR blood_type IN ('A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-')");
});
});
modelBuilder.Entity("RefreshToken", b =>
{
b.Property<Guid>("Id")
@@ -663,6 +989,36 @@ namespace VigilCareRecordsAPI.Data.Migrations
b.Navigation("Batch");
});
modelBuilder.Entity("Encounter", b =>
{
b.HasOne("Patient", "Patient")
.WithMany()
.HasForeignKey("PatientId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Patient");
});
modelBuilder.Entity("Observation", b =>
{
b.HasOne("Encounter", "Encounter")
.WithMany()
.HasForeignKey("EncounterId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Patient", "Patient")
.WithMany()
.HasForeignKey("PatientId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Encounter");
b.Navigation("Patient");
});
modelBuilder.Entity("RefreshToken", b =>
{
b.HasOne("RefreshToken", "ReplacedByToken")