initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class DigitizationBatchConfiguration : IEntityTypeConfiguration<DigitizationBatch>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DigitizationBatch> builder)
|
||||
{
|
||||
builder.ToTable("digitization_batches", t =>
|
||||
{
|
||||
t.HasCheckConstraint("chk_batches_status",
|
||||
"status IN ('UPLOADED', 'IN_ENTRY', 'PENDING_VERIFICATION', 'REJECTED', 'VERIFIED', 'AWAITING_CLINICAL_APPROVAL', 'APPROVED', 'PROMOTED')");
|
||||
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_track",
|
||||
"track IN ('BACKFILL', 'LIVE_CAPTURE')");
|
||||
});
|
||||
builder.HasKey(b => b.Id);
|
||||
builder.Property(b => b.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(b => b.Status)
|
||||
.HasColumnName("status")
|
||||
.HasMaxLength(30)
|
||||
.HasConversion(v => v.ToDbString(), v => BatchStatusExtensions.FromDbString(v))
|
||||
.HasDefaultValueSql("'UPLOADED'")
|
||||
.HasSentinel((BatchStatus)(-1));
|
||||
builder.Property(b => b.BatchType)
|
||||
.HasColumnName("batch_type")
|
||||
.HasMaxLength(30)
|
||||
.HasConversion(v => v.ToDbString(), v => BatchTypeExtensions.FromDbString(v))
|
||||
.IsRequired();
|
||||
builder.Property(b => b.Track)
|
||||
.HasColumnName("track")
|
||||
.HasMaxLength(20)
|
||||
.HasConversion(v => v.ToDbString(), v => BatchTrackExtensions.FromDbString(v))
|
||||
.HasDefaultValueSql("'BACKFILL'")
|
||||
.HasSentinel((BatchTrack)(-1));
|
||||
builder.Property(b => b.PatientId).HasColumnName("patient_id");
|
||||
builder.Property(b => b.EncounterDraftId).HasColumnName("encounter_draft_id");
|
||||
builder.Property(b => b.DocumentRef).HasColumnName("document_ref").HasMaxLength(500).IsRequired();
|
||||
builder.Property(b => b.DocumentSha256).HasColumnName("document_sha256").HasMaxLength(64).IsRequired();
|
||||
builder.Property(b => b.EnableRetroactiveAlerts).HasColumnName("enable_retroactive_alerts").HasDefaultValue(false);
|
||||
builder.Property(b => b.EnteredByUserId).HasColumnName("entered_by_user_id");
|
||||
builder.Property(b => b.VerifiedByUserId).HasColumnName("verified_by_user_id");
|
||||
builder.Property(b => b.ApprovedByUserId).HasColumnName("approved_by_user_id");
|
||||
builder.Property(b => b.RejectionReason).HasColumnName("rejection_reason");
|
||||
builder.Property(b => b.PromotedAt).HasColumnName("promoted_at");
|
||||
builder.Property(b => b.PromotionEncounterId).HasColumnName("promotion_encounter_id");
|
||||
builder.Property(b => b.SupersedesBatchId).HasColumnName("supersedes_batch_id");
|
||||
builder.Property(b => b.ClinicianAttestation).HasColumnName("clinician_attestation").HasDefaultValue(false);
|
||||
builder.Property(b => b.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
|
||||
builder.Property(b => b.UpdatedAt).HasColumnName("updated_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasOne(b => b.EnteredByUser).WithMany().HasForeignKey(b => b.EnteredByUserId).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne(b => b.VerifiedByUser).WithMany().HasForeignKey(b => b.VerifiedByUserId).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne(b => b.ApprovedByUser).WithMany().HasForeignKey(b => b.ApprovedByUserId).OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasIndex(b => b.Status);
|
||||
builder.HasIndex(b => new { b.DocumentSha256, b.PatientId, b.CreatedAt });
|
||||
builder.HasIndex(b => b.SupersedesBatchId).HasFilter("supersedes_batch_id IS NOT NULL");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class DigitizationEventConfiguration : IEntityTypeConfiguration<DigitizationEvent>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DigitizationEvent> builder)
|
||||
{
|
||||
builder.ToTable("digitization_events", 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')");
|
||||
});
|
||||
builder.HasKey(e => e.Id);
|
||||
builder.Property(e => e.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(e => e.BatchId).HasColumnName("batch_id").IsRequired();
|
||||
builder.Property(e => e.EventType)
|
||||
.HasColumnName("event_type")
|
||||
.HasMaxLength(50)
|
||||
.HasConversion(
|
||||
v => v.ToDbString(),
|
||||
v => DigitizationEventTypeExtensions.FromDbString(v))
|
||||
.IsRequired();
|
||||
builder.Property(e => e.ActorUserId).HasColumnName("actor_user_id").IsRequired();
|
||||
builder.Property(e => e.OccurredAt).HasColumnName("occurred_at").HasDefaultValueSql("NOW()");
|
||||
builder.Property(e => e.MetadataJson).HasColumnName("metadata_json").HasColumnType("jsonb");
|
||||
|
||||
builder.HasOne(e => e.Batch).WithMany(b => b.Events).HasForeignKey(e => e.BatchId).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne(e => e.Actor).WithMany().HasForeignKey(e => e.ActorUserId).OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasIndex(e => new { e.BatchId, e.OccurredAt });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class DraftEncounterConfiguration : IEntityTypeConfiguration<DraftEncounter>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DraftEncounter> builder)
|
||||
{
|
||||
builder.ToTable("draft_encounters", 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')");
|
||||
});
|
||||
builder.HasKey(e => e.Id);
|
||||
builder.Property(e => e.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(e => e.BatchId).HasColumnName("batch_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);
|
||||
builder.Property(e => e.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
|
||||
builder.Property(e => e.UpdatedAt).HasColumnName("updated_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasOne(e => e.Batch).WithOne(b => b.DraftEncounter).HasForeignKey<DraftEncounter>(e => e.BatchId).OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class DraftObservationConfiguration : IEntityTypeConfiguration<DraftObservation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DraftObservation> builder)
|
||||
{
|
||||
builder.ToTable("draft_observations");
|
||||
builder.HasKey(o => o.Id);
|
||||
builder.Property(o => o.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(o => o.BatchId).HasColumnName("batch_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.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasOne(o => o.Batch).WithMany(b => b.DraftObservations).HasForeignKey(o => o.BatchId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasIndex(o => new { o.BatchId, o.ObservationCode });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class DraftPatientConfiguration : IEntityTypeConfiguration<DraftPatient>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<DraftPatient> builder)
|
||||
{
|
||||
builder.ToTable("draft_patients", t =>
|
||||
{
|
||||
t.HasCheckConstraint("chk_draft_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.BatchId).HasColumnName("batch_id").IsRequired();
|
||||
builder.Property(p => p.FullName).HasColumnName("full_name").HasMaxLength(200);
|
||||
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.MedicationsJson).HasColumnName("medications_json").HasColumnType("jsonb");
|
||||
builder.Property(p => p.NoActiveMedications).HasColumnName("no_active_medications").HasDefaultValue(false);
|
||||
builder.Property(p => p.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
|
||||
builder.Property(p => p.UpdatedAt).HasColumnName("updated_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasOne(p => p.Batch).WithOne(b => b.DraftPatient).HasForeignKey<DraftPatient>(p => p.BatchId).OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class ScannedDocumentConfiguration : IEntityTypeConfiguration<ScannedDocument>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ScannedDocument> builder)
|
||||
{
|
||||
builder.ToTable("scanned_documents");
|
||||
builder.HasKey(d => d.Id);
|
||||
builder.Property(d => d.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(d => d.BatchId).HasColumnName("batch_id").IsRequired();
|
||||
builder.Property(d => d.ObjectKey).HasColumnName("object_key").HasMaxLength(500).IsRequired();
|
||||
builder.Property(d => d.Sha256).HasColumnName("sha256").HasMaxLength(64).IsRequired();
|
||||
builder.Property(d => d.ContentType).HasColumnName("content_type").HasMaxLength(100).IsRequired();
|
||||
builder.Property(d => d.FileSizeBytes).HasColumnName("file_size_bytes").IsRequired();
|
||||
builder.Property(d => d.UploadedAt).HasColumnName("uploaded_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasOne(d => d.Batch).WithOne(b => b.Document).HasForeignKey<ScannedDocument>(d => d.BatchId).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasIndex(d => d.Sha256);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
builder.ToTable("users", t =>
|
||||
{
|
||||
t.HasCheckConstraint("chk_users_role",
|
||||
"role IN ('INTAKE_CLERK', 'DATA_ENTRY_CLERK', 'VERIFIER', 'CLINICAL_APPROVER', 'CLINICIAN', 'ADMINISTRATOR')");
|
||||
});
|
||||
builder.HasKey(u => u.Id);
|
||||
builder.Property(u => u.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
|
||||
builder.Property(u => u.Username).HasColumnName("username").HasMaxLength(100).IsRequired();
|
||||
builder.Property(u => u.PasswordHash).HasColumnName("password_hash").HasMaxLength(200).IsRequired();
|
||||
builder.Property(u => u.FullName).HasColumnName("full_name").HasMaxLength(200).IsRequired();
|
||||
builder.Property(u => u.Role)
|
||||
.HasColumnName("role")
|
||||
.HasMaxLength(30)
|
||||
.HasConversion(
|
||||
v => v.ToDbString(),
|
||||
v => UserRoleExtensions.FromDbString(v))
|
||||
.IsRequired();
|
||||
builder.Property(u => u.IsActive).HasColumnName("is_active").HasDefaultValue(true);
|
||||
builder.Property(u => u.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
|
||||
|
||||
builder.HasIndex(u => u.Username).IsUnique();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user