feature: Approval and Promotion to VigilCareClinical
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user