// <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 VigilCareClinicalAPI.Migrations
{
    [DbContext(typeof(AppDbContext))]
    [Migration("20260625055721_AddRefreshTokens")]
    partial class AddRefreshTokens
    {
        /// <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("AlertFeedback", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("AlertId")
                        .HasColumnType("uuid")
                        .HasColumnName("alert_id");

                    b.Property<string>("Comment")
                        .HasMaxLength(1000)
                        .HasColumnType("character varying(1000)")
                        .HasColumnName("comment");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("FeedbackType")
                        .IsRequired()
                        .HasMaxLength(30)
                        .HasColumnType("character varying(30)")
                        .HasColumnName("feedback_type");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id");

                    b.HasIndex("AlertId");

                    b.HasIndex("FeedbackType");

                    b.HasIndex("AlertId", "UserId")
                        .IsUnique();

                    b.ToTable("alert_feedbacks", (string)null);
                });

            modelBuilder.Entity("AlertQualityMetric", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("AcknowledgedCount")
                        .HasColumnType("integer")
                        .HasColumnName("acknowledged_count");

                    b.Property<double>("AcknowledgementRate")
                        .HasColumnType("double precision")
                        .HasColumnName("acknowledgement_rate");

                    b.Property<string>("AlertType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("alert_type");

                    b.Property<double>("AvgSecondsToAcknowledge")
                        .HasColumnType("double precision")
                        .HasColumnName("avg_seconds_to_acknowledge");

                    b.Property<double>("AvgSecondsToResolution")
                        .HasColumnType("double precision")
                        .HasColumnName("avg_seconds_to_resolution");

                    b.Property<DateTimeOffset>("ComputedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("computed_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<int>("EscalatedCount")
                        .HasColumnType("integer")
                        .HasColumnName("escalated_count");

                    b.Property<double>("FalsePositiveRate")
                        .HasColumnType("double precision")
                        .HasColumnName("false_positive_rate");

                    b.Property<int>("FeedbackCount")
                        .HasColumnType("integer")
                        .HasColumnName("feedback_count");

                    b.Property<int>("FeedbackFalsePositiveCount")
                        .HasColumnType("integer")
                        .HasColumnName("feedback_false_positive_count");

                    b.Property<int>("FeedbackUsefulCount")
                        .HasColumnType("integer")
                        .HasColumnName("feedback_useful_count");

                    b.Property<int>("FeedbackWouldActCount")
                        .HasColumnType("integer")
                        .HasColumnName("feedback_would_act_count");

                    b.Property<int>("ResolvedCount")
                        .HasColumnType("integer")
                        .HasColumnName("resolved_count");

                    b.Property<int>("TotalAlerts")
                        .HasColumnType("integer")
                        .HasColumnName("total_alerts");

                    b.Property<double>("UsefulRate")
                        .HasColumnType("double precision")
                        .HasColumnName("useful_rate");

                    b.Property<DateTimeOffset>("WindowEnd")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("window_end");

                    b.Property<DateTimeOffset>("WindowStart")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("window_start");

                    b.Property<double>("WouldActRate")
                        .HasColumnType("double precision")
                        .HasColumnName("would_act_rate");

                    b.HasKey("Id");

                    b.HasIndex("WindowStart");

                    b.HasIndex("AlertType", "WindowStart", "WindowEnd")
                        .IsUnique();

                    b.ToTable("alert_quality_metrics", (string)null);
                });

            modelBuilder.Entity("AlertThreshold", 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<decimal?>("CriticalHigh")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("critical_high");

                    b.Property<decimal?>("CriticalLow")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("critical_low");

                    b.Property<string>("DisplayName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("display_name");

                    b.Property<string>("ObservationCode")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("observation_code");

                    b.Property<int?>("SuppressionWindowMinutes")
                        .HasColumnType("integer")
                        .HasColumnName("suppression_window_minutes");

                    b.Property<string>("Unit")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("unit");

                    b.Property<decimal?>("WarningHigh")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("warning_high");

                    b.Property<decimal?>("WarningLow")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("warning_low");

                    b.HasKey("Id");

                    b.HasIndex("ObservationCode")
                        .IsUnique();

                    b.ToTable("alert_thresholds", (string)null);
                });

            modelBuilder.Entity("ClinicalAlert", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("AcknowledgedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("acknowledged_at");

                    b.Property<string>("AcknowledgedBy")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("acknowledged_by");

                    b.Property<string>("AlertType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("alert_type");

                    b.Property<Guid?>("ClientAlertId")
                        .HasColumnType("uuid")
                        .HasColumnName("client_alert_id");

                    b.Property<string>("Details")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("details");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<string>("Explanation")
                        .HasColumnType("jsonb")
                        .HasColumnName("explanation");

                    b.Property<bool>("FeedbackReceived")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(false)
                        .HasColumnName("feedback_received");

                    b.Property<string>("ObservationCode")
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("observation_code");

                    b.Property<Guid?>("ObservationId")
                        .HasColumnType("uuid")
                        .HasColumnName("observation_id");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("severity");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'OPEN'");

                    b.Property<bool>("SyncedFromGateway")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(false)
                        .HasColumnName("synced_from_gateway");

                    b.Property<DateTimeOffset>("TriggeredAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("triggered_at")
                        .HasDefaultValueSql("NOW()");

                    b.HasKey("Id");

                    b.HasIndex("ClientAlertId")
                        .IsUnique()
                        .HasFilter("client_alert_id IS NOT NULL");

                    b.HasIndex("EncounterId", "TriggeredAt");

                    b.HasIndex("PatientId", "TriggeredAt");

                    b.HasIndex("Severity", "TriggeredAt")
                        .HasFilter("status = 'OPEN'");

                    b.HasIndex("EncounterId", "AlertType", "ObservationCode")
                        .HasFilter("status IN ('OPEN', 'ESCALATED')");

                    b.ToTable("clinical_alerts", null, t =>
                        {
                            t.HasCheckConstraint("chk_clinical_alerts_alert_type", "alert_type IN ('SEPSIS_WARNING', 'CRITICAL_HEART_RATE', 'CRITICAL_TEMP_C', 'CRITICAL_POTASSIUM_MEQ_L', 'CRITICAL_SPO2', 'CRITICAL_RESP_RATE', 'CRITICAL_WBC_K_UL', 'CRITICAL_SYSTOLIC_BP', 'CRITICAL_DIASTOLIC_BP', 'CRITICAL_LACTATE_MMOL_L', 'CRITICAL_AVPU', 'CRITICAL_GLUCOSE_MG_DL', 'CRITICAL_PAO2_MMHG', 'CRITICAL_PLATELET_K_UL', 'CRITICAL_BILIRUBIN_MG_DL', 'CRITICAL_CREATININE_MG_DL', 'WARNING_HEART_RATE', 'WARNING_TEMP_C', 'WARNING_POTASSIUM_MEQ_L', 'WARNING_SPO2', 'WARNING_RESP_RATE', 'WARNING_WBC_K_UL', 'WARNING_SYSTOLIC_BP', 'WARNING_DIASTOLIC_BP', 'WARNING_LACTATE_MMOL_L', 'WARNING_GLUCOSE_MG_DL', 'WARNING_PAO2_MMHG', 'WARNING_PLATELET_K_UL', 'WARNING_BILIRUBIN_MG_DL', 'WARNING_CREATININE_MG_DL', 'NEWS2_WARNING', 'NEWS2_EMERGENCY', 'RAPID_DETERIORATION', 'QSOFA_WARNING', 'QSOFA_SCREEN', 'GCS_CRITICAL', 'GCS_WARNING', 'SOFA_SEPSIS', 'SOFA_WARNING')");

                            t.HasCheckConstraint("chk_clinical_alerts_severity", "severity IN ('WARNING', 'CRITICAL')");

                            t.HasCheckConstraint("chk_clinical_alerts_status", "status IN ('OPEN', 'ACKNOWLEDGED', 'RESOLVED', 'ESCALATED')");
                        });
                });

            modelBuilder.Entity("ClinicalAuditLog", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Action")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("action");

                    b.Property<string>("CorrelationId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("correlation_id");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<Guid>("EntityId")
                        .HasColumnType("uuid")
                        .HasColumnName("entity_id");

                    b.Property<string>("EntityType")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("entity_type");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(45)
                        .HasColumnType("character varying(45)")
                        .HasColumnName("ip_address");

                    b.Property<string>("NewValueJson")
                        .HasColumnType("jsonb")
                        .HasColumnName("new_value_json");

                    b.Property<string>("PreviousValueJson")
                        .HasColumnType("jsonb")
                        .HasColumnName("previous_value_json");

                    b.Property<string>("Reason")
                        .HasColumnType("text")
                        .HasColumnName("reason");

                    b.Property<string>("UserDisplayName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("user_display_name");

                    b.Property<Guid?>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id");

                    b.HasIndex("CreatedAt");

                    b.HasIndex("EntityId");

                    b.HasIndex("EntityType");

                    b.HasIndex("UserId");

                    b.ToTable("clinical_audit_logs", (string)null);
                });

            modelBuilder.Entity("ClinicalSite", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<bool>("Active")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(true)
                        .HasColumnName("active");

                    b.Property<string>("Address")
                        .HasColumnType("text")
                        .HasColumnName("address");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("name");

                    b.Property<string>("SiteCode")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("site_code");

                    b.HasKey("Id");

                    b.HasIndex("SiteCode")
                        .IsUnique();

                    b.ToTable("clinical_sites", (string)null);
                });

            modelBuilder.Entity("ClinicalSyncBatch", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("BatchReference")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_reference");

                    b.Property<Guid>("GatewayId")
                        .HasColumnType("uuid")
                        .HasColumnName("gateway_id");

                    b.Property<string>("Payload")
                        .IsRequired()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload");

                    b.Property<DateTimeOffset?>("ProcessedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("processed_at");

                    b.Property<Guid>("SiteId")
                        .HasColumnType("uuid")
                        .HasColumnName("site_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(16)
                        .HasColumnType("character varying(16)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'RECEIVED'");

                    b.Property<DateTimeOffset>("SubmittedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("submitted_at")
                        .HasDefaultValueSql("NOW()");

                    b.HasKey("Id");

                    b.HasIndex("BatchReference")
                        .IsUnique();

                    b.HasIndex("SiteId");

                    b.HasIndex("GatewayId", "SubmittedAt");

                    b.ToTable("clinical_sync_batches", null, t =>
                        {
                            t.HasCheckConstraint("chk_clinical_sync_batches_status", "status IN ('RECEIVED','PROCESSING','APPLIED','CONFLICT','REJECTED')");
                        });
                });

            modelBuilder.Entity("ClinicalSyncConflict", 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<Guid>("ClientRef")
                        .HasColumnType("uuid")
                        .HasColumnName("client_ref");

                    b.Property<string>("ConflictReason")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("conflict_reason");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("character varying(16)")
                        .HasColumnName("item_type");

                    b.HasKey("Id");

                    b.HasIndex("BatchId");

                    b.ToTable("clinical_sync_conflicts", (string)null);
                });

            modelBuilder.Entity("ClinicalUser", 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>("DisplayName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("display_name");

                    b.Property<bool>("IsActive")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(true)
                        .HasColumnName("is_active");

                    b.Property<DateTimeOffset?>("LastLoginAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_login_at");

                    b.Property<string>("PasswordHash")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("password_hash");

                    b.Property<string>("Role")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("role");

                    b.Property<string>("Username")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("username");

                    b.HasKey("Id");

                    b.HasIndex("Username")
                        .IsUnique();

                    b.ToTable("clinical_users", (string)null);
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AdmissionReason")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("admission_reason");

                    b.Property<DateTimeOffset>("AdmittedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("admitted_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("AttendingPhysician")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("attending_physician");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("Department")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("department");

                    b.Property<string>("DischargeDiagnosis")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("discharge_diagnosis");

                    b.Property<DateTimeOffset?>("DischargedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("discharged_at");

                    b.Property<string>("EncounterType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("encounter_type");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<string>("RoomBed")
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("room_bed");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'SCHEDULED'");

                    b.HasKey("Id");

                    b.HasIndex("PatientId", "AdmittedAt");

                    b.HasIndex("PatientId", "EncounterType")
                        .IsUnique()
                        .HasDatabaseName("ix_encounters_patient_active_type")
                        .HasFilter("status = 'ACTIVE'");

                    b.HasIndex("Status", "AdmittedAt")
                        .HasFilter("status = 'ACTIVE'");

                    b.ToTable("encounters", null, t =>
                        {
                            t.HasCheckConstraint("chk_encounters_department", "department IN ('ICU', 'GENERAL_MEDICINE', 'EMERGENCY', 'CARDIOLOGY', 'SURGERY', 'PEDIATRICS')");

                            t.HasCheckConstraint("chk_encounters_encounter_type", "encounter_type IN ('INPATIENT', 'OUTPATIENT', 'EMERGENCY')");

                            t.HasCheckConstraint("chk_encounters_status", "status IN ('SCHEDULED', 'ACTIVE', 'DISCHARGED', 'CANCELLED')");
                        });
                });

            modelBuilder.Entity("ExternalResourceIdentifier", 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>("InternalId")
                        .HasColumnType("uuid")
                        .HasColumnName("internal_id");

                    b.Property<string>("ResourceType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("resource_type");

                    b.Property<string>("System")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("system");

                    b.Property<string>("Value")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("value");

                    b.HasKey("Id");

                    b.HasIndex("ResourceType", "InternalId");

                    b.HasIndex("ResourceType", "System", "Value")
                        .IsUnique();

                    b.ToTable("external_resource_identifiers", (string)null);
                });

            modelBuilder.Entity("GcsScore", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CalculatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("calculated_at");

                    b.Property<string>("Classification")
                        .IsRequired()
                        .HasMaxLength(16)
                        .HasColumnType("character varying(16)")
                        .HasColumnName("classification");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<int>("EyeScore")
                        .HasColumnType("integer")
                        .HasColumnName("eye_score");

                    b.Property<int>("MotorScore")
                        .HasColumnType("integer")
                        .HasColumnName("motor_score");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<int>("TotalScore")
                        .HasColumnType("integer")
                        .HasColumnName("total_score");

                    b.Property<int>("VerbalScore")
                        .HasColumnType("integer")
                        .HasColumnName("verbal_score");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "CalculatedAt");

                    b.ToTable("gcs_scores", null, t =>
                        {
                            t.HasCheckConstraint("chk_gcs_scores_classification", "classification IN ('MILD', 'MODERATE', 'SEVERE')");
                        });
                });

            modelBuilder.Entity("MedicationAdministration", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("AdministeredAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("administered_at");

                    b.Property<string>("AdministeredBy")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("administered_by");

                    b.Property<decimal>("Dose")
                        .HasPrecision(10, 4)
                        .HasColumnType("numeric(10,4)")
                        .HasColumnName("dose");

                    b.Property<string>("DoseUnit")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("dose_unit");

                    b.Property<string>("DrugName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("drug_name");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<string>("Route")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("route");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "AdministeredAt");

                    b.HasIndex("EncounterId", "DrugName");

                    b.ToTable("medication_administrations", (string)null);
                });

            modelBuilder.Entity("News2Score", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CalculatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("calculated_at");

                    b.Property<int>("ConsciousnessScore")
                        .HasColumnType("integer")
                        .HasColumnName("consciousness_score");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<bool>("HasSingleParamThree")
                        .HasColumnType("boolean")
                        .HasColumnName("has_single_param_three");

                    b.Property<int>("HeartRateScore")
                        .HasColumnType("integer")
                        .HasColumnName("heart_rate_score");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<int>("RespRateScore")
                        .HasColumnType("integer")
                        .HasColumnName("resp_rate_score");

                    b.Property<string>("RiskLevel")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("risk_level");

                    b.Property<int>("Spo2Score")
                        .HasColumnType("integer")
                        .HasColumnName("spo2_score");

                    b.Property<int>("SupplementalO2Score")
                        .HasColumnType("integer")
                        .HasColumnName("supplemental_o2_score");

                    b.Property<int>("SystolicBpScore")
                        .HasColumnType("integer")
                        .HasColumnName("systolic_bp_score");

                    b.Property<int>("TemperatureScore")
                        .HasColumnType("integer")
                        .HasColumnName("temperature_score");

                    b.Property<int>("TotalScore")
                        .HasColumnType("integer")
                        .HasColumnName("total_score");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "CalculatedAt");

                    b.HasIndex("PatientId", "CalculatedAt");

                    b.ToTable("news2_scores", null, t =>
                        {
                            t.HasCheckConstraint("chk_news2_scores_risk_level", "risk_level IN ('LOW', 'LOW_MEDIUM', 'MEDIUM', 'HIGH')");
                        });
                });

            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>("IdempotencyKey")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("idempotency_key");

                    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>("Source")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("source")
                        .HasDefaultValueSql("'MANUAL'");

                    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("IdempotencyKey")
                        .IsUnique()
                        .HasFilter("idempotency_key IS NOT NULL");

                    b.HasIndex("EncounterId", "ObservationCode", "RecordedAt");

                    b.ToTable("observations", null, t =>
                        {
                            t.HasCheckConstraint("chk_observations_source", "source IN ('MANUAL', 'DEVICE', 'LAB')");
                        });
                });

            modelBuilder.Entity("Order", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Description")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<string>("OrderType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("order_type");

                    b.Property<DateTimeOffset>("OrderedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ordered_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("OrderedBy")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("ordered_by");

                    b.Property<string>("ResultSummary")
                        .HasColumnType("text")
                        .HasColumnName("result_summary");

                    b.Property<DateTimeOffset?>("ResultedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resulted_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'PENDING'");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "OrderedAt");

                    b.HasIndex("Status", "OrderedAt")
                        .HasFilter("status IN ('PENDING', 'IN_PROGRESS')");

                    b.ToTable("orders", null, t =>
                        {
                            t.HasCheckConstraint("chk_orders_order_type", "order_type IN ('LAB', 'IMAGING', 'MEDICATION', 'PROCEDURE')");

                            t.HasCheckConstraint("chk_orders_status", "status IN ('PENDING', 'IN_PROGRESS', 'RESULTED', 'CANCELLED')");
                        });
                });

            modelBuilder.Entity("OutboxEvent", 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?>("FailedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("failed_at");

                    b.Property<string>("LastError")
                        .HasColumnType("text")
                        .HasColumnName("last_error");

                    b.Property<string>("PartitionKey")
                        .HasMaxLength(36)
                        .HasColumnType("character varying(36)")
                        .HasColumnName("partition_key");

                    b.Property<string>("Payload")
                        .IsRequired()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload");

                    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.Property<string>("Topic")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("topic");

                    b.HasKey("Id");

                    b.HasIndex("CreatedAt")
                        .HasFilter("processed_at IS NULL AND failed_at IS NULL");

                    b.ToTable("outbox_events", (string)null);
                });

            modelBuilder.Entity("Patient", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Allergies")
                        .HasColumnType("text")
                        .HasColumnName("allergies");

                    b.Property<string>("BloodType")
                        .HasMaxLength(5)
                        .HasColumnType("character varying(5)")
                        .HasColumnName("blood_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("DateOfBirth")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("date_of_birth");

                    b.Property<string>("EmergencyContactName")
                        .HasMaxLength(200)
                        .HasColumnType("text")
                        .HasColumnName("emergency_contact_name");

                    b.Property<string>("EmergencyContactPhone")
                        .HasMaxLength(20)
                        .HasColumnType("text")
                        .HasColumnName("emergency_contact_phone");

                    b.Property<string>("FirstName")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("text")
                        .HasColumnName("first_name");

                    b.Property<string>("Gender")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("gender");

                    b.Property<string>("LastName")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("text")
                        .HasColumnName("last_name");

                    b.Property<string>("Mrn")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("mrn");

                    b.Property<string>("NameSearchToken")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("name_search_token");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasDefaultValue("active")
                        .HasColumnName("status");

                    b.HasKey("Id");

                    b.HasIndex("Mrn")
                        .IsUnique();

                    b.HasIndex("NameSearchToken");

                    b.ToTable("patients", (string)null);
                });

            modelBuilder.Entity("PhiAccessLog", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AccessType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("access_type");

                    b.Property<DateTimeOffset>("AccessedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("accessed_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("CorrelationId")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("correlation_id");

                    b.Property<string>("IpAddress")
                        .HasMaxLength(45)
                        .HasColumnType("character varying(45)")
                        .HasColumnName("ip_address");

                    b.Property<Guid?>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<string>("ResourcePath")
                        .IsRequired()
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("resource_path");

                    b.Property<int?>("ResultCount")
                        .HasColumnType("integer")
                        .HasColumnName("result_count");

                    b.Property<string>("SearchQueryHash")
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("search_query_hash");

                    b.Property<string>("UserDisplayName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("user_display_name");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id");

                    b.HasIndex("AccessedAt");

                    b.HasIndex("PatientId");

                    b.HasIndex("UserId");

                    b.ToTable("phi_access_logs", (string)null);
                });

            modelBuilder.Entity("QsofaEvaluation", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<int>("ActiveCriteria")
                        .HasColumnType("integer")
                        .HasColumnName("active_criteria");

                    b.Property<decimal?>("Avpu")
                        .HasColumnType("numeric")
                        .HasColumnName("avpu");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<DateTimeOffset>("EvaluatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("evaluated_at");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<decimal?>("RespRate")
                        .HasColumnType("numeric")
                        .HasColumnName("resp_rate");

                    b.Property<bool>("ScreenAlertFired")
                        .HasColumnType("boolean")
                        .HasColumnName("screen_alert_fired");

                    b.Property<decimal?>("SystolicBp")
                        .HasColumnType("numeric")
                        .HasColumnName("systolic_bp");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "EvaluatedAt");

                    b.ToTable("qsofa_evaluations", null, t =>
                        {
                            t.HasCheckConstraint("chk_qsofa_evaluations_active_criteria", "active_criteria >= 0 AND active_criteria <= 3");
                        });
                });

            modelBuilder.Entity("ReconciliationAlert", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("CheckType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("check_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("Details")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("details");

                    b.Property<Guid?>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<Guid?>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId");

                    b.HasIndex("PatientId");

                    b.HasIndex("CheckType", "EncounterId")
                        .HasFilter("resolved_at IS NULL");

                    b.ToTable("reconciliation_alerts", null, t =>
                        {
                            t.HasCheckConstraint("chk_reconciliation_alerts_check_type", "check_type IN ('UNACKNOWLEDGED_CRITICAL_ALERT', 'PENDING_ORDER_NO_RESULT', 'ACTIVE_INPATIENT_NO_OBSERVATION')");
                        });
                });

            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<DateTimeOffset?>("RevokedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("revoked_at");

                    b.Property<string>("Token")
                        .IsRequired()
                        .HasMaxLength(256)
                        .HasColumnType("character varying(256)")
                        .HasColumnName("token");

                    b.Property<Guid>("UserId")
                        .HasColumnType("uuid")
                        .HasColumnName("user_id");

                    b.HasKey("Id");

                    b.HasIndex("Token")
                        .IsUnique();

                    b.HasIndex("UserId");

                    b.ToTable("refresh_tokens", (string)null);
                });

            modelBuilder.Entity("SepsisBundle", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<string>("ComplianceStatus")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("compliance_status")
                        .HasDefaultValueSql("'IN_PROGRESS'");

                    b.Property<DateTimeOffset>("DeadlineAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("deadline_at");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<DateTimeOffset>("RecognizedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("recognized_at");

                    b.Property<Guid>("TriggeringAlertId")
                        .HasColumnType("uuid")
                        .HasColumnName("triggering_alert_id");

                    b.Property<string>("TriggeringAlertType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("triggering_alert_type");

                    b.HasKey("Id");

                    b.HasIndex("ComplianceStatus");

                    b.HasIndex("TriggeringAlertId");

                    b.HasIndex("EncounterId", "RecognizedAt");

                    b.ToTable("sepsis_bundles", null, t =>
                        {
                            t.HasCheckConstraint("chk_sepsis_bundles_compliance_status", "compliance_status IN ('IN_PROGRESS', 'COMPLIANT', 'NON_COMPLIANT')");
                        });
                });

            modelBuilder.Entity("SepsisBundleElement", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<Guid>("BundleId")
                        .HasColumnType("uuid")
                        .HasColumnName("bundle_id");

                    b.Property<DateTimeOffset?>("CompletedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("completed_at");

                    b.Property<string>("ElementType")
                        .IsRequired()
                        .HasMaxLength(40)
                        .HasColumnType("character varying(40)")
                        .HasColumnName("element_type");

                    b.Property<Guid?>("OrderId")
                        .HasColumnType("uuid")
                        .HasColumnName("order_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'PENDING'");

                    b.HasKey("Id");

                    b.HasIndex("OrderId");

                    b.HasIndex("BundleId", "ElementType")
                        .IsUnique();

                    b.ToTable("sepsis_bundle_elements", null, t =>
                        {
                            t.HasCheckConstraint("chk_sepsis_bundle_elements_element_type", "element_type IN ('BLOOD_CULTURES', 'SERUM_LACTATE', 'BROAD_SPECTRUM_ANTIBIOTICS', 'IV_FLUID_RESUSCITATION')");

                            t.HasCheckConstraint("chk_sepsis_bundle_elements_status", "status IN ('PENDING', 'COMPLETED')");
                        });
                });

            modelBuilder.Entity("SofaScore", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CalculatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("calculated_at");

                    b.Property<int>("CardiovascularScore")
                        .HasColumnType("integer")
                        .HasColumnName("cardiovascular_score");

                    b.Property<int>("CnsScore")
                        .HasColumnType("integer")
                        .HasColumnName("cns_score");

                    b.Property<int>("CoagulationScore")
                        .HasColumnType("integer")
                        .HasColumnName("coagulation_score");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at");

                    b.Property<int?>("DeltaFromBaseline")
                        .HasColumnType("integer")
                        .HasColumnName("delta_from_baseline");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<bool>("IsBaseline")
                        .HasColumnType("boolean")
                        .HasColumnName("is_baseline");

                    b.Property<int>("LiverScore")
                        .HasColumnType("integer")
                        .HasColumnName("liver_score");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<int>("RenalScore")
                        .HasColumnType("integer")
                        .HasColumnName("renal_score");

                    b.Property<int>("RespiratoryScore")
                        .HasColumnType("integer")
                        .HasColumnName("respiratory_score");

                    b.Property<string>("StalenessFlags")
                        .HasColumnType("jsonb")
                        .HasColumnName("staleness_flags");

                    b.Property<int>("TotalScore")
                        .HasColumnType("integer")
                        .HasColumnName("total_score");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId")
                        .HasDatabaseName("idx_sofa_scores_baseline")
                        .HasFilter("is_baseline = true");

                    b.HasIndex("EncounterId", "CalculatedAt");

                    b.ToTable("sofa_scores", (string)null);
                });

            modelBuilder.Entity("WardGateway", 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>("Department")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("department");

                    b.Property<string>("GatewayCode")
                        .IsRequired()
                        .HasMaxLength(64)
                        .HasColumnType("character varying(64)")
                        .HasColumnName("gateway_code");

                    b.Property<DateTimeOffset?>("LastHeartbeatAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_heartbeat_at");

                    b.Property<DateTimeOffset?>("LastSyncAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("last_sync_at");

                    b.Property<int>("ReportedBufferDepth")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("integer")
                        .HasDefaultValue(0)
                        .HasColumnName("reported_buffer_depth");

                    b.Property<Guid>("SiteId")
                        .HasColumnType("uuid")
                        .HasColumnName("site_id");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(16)
                        .HasColumnType("character varying(16)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'OFFLINE'");

                    b.HasKey("Id");

                    b.HasIndex("Status")
                        .HasFilter("status != 'ONLINE'");

                    b.HasIndex("SiteId", "Department");

                    b.HasIndex("SiteId", "GatewayCode")
                        .IsUnique();

                    b.ToTable("ward_gateways", null, t =>
                        {
                            t.HasCheckConstraint("chk_ward_gateways_status", "status IN ('ONLINE','DEGRADED','OFFLINE')");
                        });
                });

            modelBuilder.Entity("AlertFeedback", b =>
                {
                    b.HasOne("ClinicalAlert", "Alert")
                        .WithMany("Feedbacks")
                        .HasForeignKey("AlertId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired();

                    b.Navigation("Alert");
                });

            modelBuilder.Entity("ClinicalAlert", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Alerts")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("ClinicalSyncBatch", b =>
                {
                    b.HasOne("WardGateway", "Gateway")
                        .WithMany()
                        .HasForeignKey("GatewayId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ClinicalSite", null)
                        .WithMany()
                        .HasForeignKey("SiteId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Gateway");
                });

            modelBuilder.Entity("ClinicalSyncConflict", b =>
                {
                    b.HasOne("ClinicalSyncBatch", "Batch")
                        .WithMany("Conflicts")
                        .HasForeignKey("BatchId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Batch");
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.HasOne("Patient", "Patient")
                        .WithMany("Encounters")
                        .HasForeignKey("PatientId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Patient");
                });

            modelBuilder.Entity("GcsScore", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("MedicationAdministration", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("News2Score", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("Observation", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Observations")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("Order", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Orders")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("QsofaEvaluation", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("ReconciliationAlert", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.SetNull);

                    b.HasOne("Patient", "Patient")
                        .WithMany()
                        .HasForeignKey("PatientId")
                        .OnDelete(DeleteBehavior.SetNull);

                    b.Navigation("Encounter");

                    b.Navigation("Patient");
                });

            modelBuilder.Entity("RefreshToken", b =>
                {
                    b.HasOne("ClinicalUser", "User")
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired();

                    b.Navigation("User");
                });

            modelBuilder.Entity("SepsisBundle", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.HasOne("ClinicalAlert", "TriggeringAlert")
                        .WithMany()
                        .HasForeignKey("TriggeringAlertId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");

                    b.Navigation("TriggeringAlert");
                });

            modelBuilder.Entity("SepsisBundleElement", b =>
                {
                    b.HasOne("SepsisBundle", "Bundle")
                        .WithMany("Elements")
                        .HasForeignKey("BundleId")
                        .OnDelete(DeleteBehavior.Cascade)
                        .IsRequired();

                    b.HasOne("Order", "Order")
                        .WithMany()
                        .HasForeignKey("OrderId")
                        .OnDelete(DeleteBehavior.SetNull);

                    b.Navigation("Bundle");

                    b.Navigation("Order");
                });

            modelBuilder.Entity("SofaScore", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("WardGateway", b =>
                {
                    b.HasOne("ClinicalSite", "Site")
                        .WithMany("Gateways")
                        .HasForeignKey("SiteId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Site");
                });

            modelBuilder.Entity("ClinicalAlert", b =>
                {
                    b.Navigation("Feedbacks");
                });

            modelBuilder.Entity("ClinicalSite", b =>
                {
                    b.Navigation("Gateways");
                });

            modelBuilder.Entity("ClinicalSyncBatch", b =>
                {
                    b.Navigation("Conflicts");
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.Navigation("Alerts");

                    b.Navigation("Observations");

                    b.Navigation("Orders");
                });

            modelBuilder.Entity("Patient", b =>
                {
                    b.Navigation("Encounters");
                });

            modelBuilder.Entity("SepsisBundle", b =>
                {
                    b.Navigation("Elements");
                });
#pragma warning restore 612, 618
        }
    }
}
