Clinical Sync Batch Engine: first commit
This commit is contained in:
+1635
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace VigilCareClinicalAPI.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddClinicalSyncInfrastructure : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "client_alert_id",
|
||||
table: "clinical_alerts",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "synced_from_gateway",
|
||||
table: "clinical_alerts",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "clinical_sites",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
site_code = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
||||
address = table.Column<string>(type: "text", nullable: true),
|
||||
active = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_clinical_sites", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ward_gateways",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
site_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
gateway_code = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
department = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
status = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false, defaultValueSql: "'OFFLINE'"),
|
||||
reported_buffer_depth = table.Column<int>(type: "integer", nullable: false, defaultValue: 0),
|
||||
last_heartbeat_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
last_sync_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ward_gateways", x => x.id);
|
||||
table.CheckConstraint("chk_ward_gateways_status", "status IN ('ONLINE','DEGRADED','OFFLINE')");
|
||||
table.ForeignKey(
|
||||
name: "FK_ward_gateways_clinical_sites_site_id",
|
||||
column: x => x.site_id,
|
||||
principalTable: "clinical_sites",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "clinical_sync_batches",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
gateway_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
site_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
batch_reference = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
status = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false, defaultValueSql: "'RECEIVED'"),
|
||||
payload = table.Column<string>(type: "jsonb", nullable: false),
|
||||
submitted_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()"),
|
||||
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_clinical_sync_batches", x => x.id);
|
||||
table.CheckConstraint("chk_clinical_sync_batches_status", "status IN ('RECEIVED','PROCESSING','APPLIED','CONFLICT','REJECTED')");
|
||||
table.ForeignKey(
|
||||
name: "FK_clinical_sync_batches_clinical_sites_site_id",
|
||||
column: x => x.site_id,
|
||||
principalTable: "clinical_sites",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_clinical_sync_batches_ward_gateways_gateway_id",
|
||||
column: x => x.gateway_id,
|
||||
principalTable: "ward_gateways",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "clinical_sync_conflicts",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
batch_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
client_ref = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
item_type = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
||||
conflict_reason = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_clinical_sync_conflicts", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_clinical_sync_conflicts_clinical_sync_batches_batch_id",
|
||||
column: x => x.batch_id,
|
||||
principalTable: "clinical_sync_batches",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_alerts_client_alert_id",
|
||||
table: "clinical_alerts",
|
||||
column: "client_alert_id",
|
||||
unique: true,
|
||||
filter: "client_alert_id IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_sites_site_code",
|
||||
table: "clinical_sites",
|
||||
column: "site_code",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_sync_batches_batch_reference",
|
||||
table: "clinical_sync_batches",
|
||||
column: "batch_reference",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_sync_batches_gateway_id_submitted_at",
|
||||
table: "clinical_sync_batches",
|
||||
columns: new[] { "gateway_id", "submitted_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_sync_batches_site_id",
|
||||
table: "clinical_sync_batches",
|
||||
column: "site_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_clinical_sync_conflicts_batch_id",
|
||||
table: "clinical_sync_conflicts",
|
||||
column: "batch_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ward_gateways_site_id_department",
|
||||
table: "ward_gateways",
|
||||
columns: new[] { "site_id", "department" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ward_gateways_site_id_gateway_code",
|
||||
table: "ward_gateways",
|
||||
columns: new[] { "site_id", "gateway_code" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ward_gateways_status",
|
||||
table: "ward_gateways",
|
||||
column: "status",
|
||||
filter: "status != 'ONLINE'");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "clinical_sync_conflicts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "clinical_sync_batches");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ward_gateways");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "clinical_sites");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_clinical_alerts_client_alert_id",
|
||||
table: "clinical_alerts");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "client_alert_id",
|
||||
table: "clinical_alerts");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "synced_from_gateway",
|
||||
table: "clinical_alerts");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,10 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("alert_type");
|
||||
|
||||
b.Property<Guid?>("ClientAlertId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("client_alert_id");
|
||||
|
||||
b.Property<string>("Details")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
@@ -144,6 +148,12 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
.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")
|
||||
@@ -152,6 +162,10 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientAlertId")
|
||||
.IsUnique()
|
||||
.HasFilter("client_alert_id IS NOT NULL");
|
||||
|
||||
b.HasIndex("EncounterId", "TriggeredAt");
|
||||
|
||||
b.HasIndex("PatientId", "TriggeredAt");
|
||||
@@ -246,6 +260,149 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
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")
|
||||
@@ -1192,6 +1349,74 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
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("ClinicalAlert", b =>
|
||||
{
|
||||
b.HasOne("Encounter", "Encounter")
|
||||
@@ -1203,6 +1428,34 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
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")
|
||||
@@ -1334,6 +1587,27 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
b.Navigation("Encounter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("WardGateway", b =>
|
||||
{
|
||||
b.HasOne("ClinicalSite", "Site")
|
||||
.WithMany("Gateways")
|
||||
.HasForeignKey("SiteId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Site");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ClinicalSite", b =>
|
||||
{
|
||||
b.Navigation("Gateways");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ClinicalSyncBatch", b =>
|
||||
{
|
||||
b.Navigation("Conflicts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Encounter", b =>
|
||||
{
|
||||
b.Navigation("Alerts");
|
||||
|
||||
Reference in New Issue
Block a user