feat: add health data management workspace
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
boolean,
|
||||
index,
|
||||
integer,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
@@ -23,6 +24,9 @@ export const auditResultEnum = pgEnum("audit_result", ["success", "denied", "fai
|
||||
export const incidentStatusEnum = pgEnum("incident_status", ["open", "acknowledged", "resolved", "closed"]);
|
||||
export const incidentSeverityEnum = pgEnum("incident_severity", ["info", "warning", "critical"]);
|
||||
export const joinRequestStatusEnum = pgEnum("join_request_status", ["pending", "approved", "rejected"]);
|
||||
export const vitalRecordSourceEnum = pgEnum("vital_record_source", ["manual", "device", "import"]);
|
||||
export const chronicConditionStatusEnum = pgEnum("chronic_condition_status", ["active", "controlled", "resolved"]);
|
||||
export const healthReviewStatusEnum = pgEnum("health_review_status", ["pending", "reviewed", "resolved"]);
|
||||
|
||||
export const systemSettings = pgTable("system_settings", {
|
||||
id: text("id").primaryKey().default("global"),
|
||||
@@ -226,6 +230,75 @@ export const elders = pgTable("elders", {
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const healthProfiles = pgTable("health_profiles", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
|
||||
elderId: uuid("elder_id").notNull().references(() => elders.id, { onDelete: "cascade" }),
|
||||
allergyNotes: text("allergy_notes").notNull().default(""),
|
||||
medicalHistory: text("medical_history").notNull().default(""),
|
||||
medicationNotes: text("medication_notes").notNull().default(""),
|
||||
careRestrictions: text("care_restrictions").notNull().default(""),
|
||||
emergencyNotes: text("emergency_notes").notNull().default(""),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
}, (table) => ({
|
||||
elderUnique: uniqueIndex("health_profiles_organization_elder_unique").on(table.organizationId, table.elderId),
|
||||
}));
|
||||
|
||||
export const vitalRecords = pgTable("vital_records", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
|
||||
elderId: uuid("elder_id").notNull().references(() => elders.id, { onDelete: "cascade" }),
|
||||
recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull(),
|
||||
source: vitalRecordSourceEnum("source").notNull().default("manual"),
|
||||
systolicBp: integer("systolic_bp"),
|
||||
diastolicBp: integer("diastolic_bp"),
|
||||
heartRate: integer("heart_rate"),
|
||||
temperatureTenths: integer("temperature_tenths"),
|
||||
spo2: integer("spo2"),
|
||||
bloodGlucoseTenths: integer("blood_glucose_tenths"),
|
||||
weightTenths: integer("weight_tenths"),
|
||||
notes: text("notes").notNull().default(""),
|
||||
createdByAccountId: uuid("created_by_account_id").references(() => accounts.id),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
}, (table) => ({
|
||||
recentLookup: index("vital_records_recent_lookup").on(table.organizationId, table.elderId, table.recordedAt),
|
||||
}));
|
||||
|
||||
export const chronicConditions = pgTable("chronic_conditions", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
|
||||
elderId: uuid("elder_id").notNull().references(() => elders.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
status: chronicConditionStatusEnum("status").notNull().default("active"),
|
||||
diagnosedAt: timestamp("diagnosed_at", { withTimezone: true }),
|
||||
treatmentNotes: text("treatment_notes").notNull().default(""),
|
||||
followUpNotes: text("follow_up_notes").notNull().default(""),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
}, (table) => ({
|
||||
elderStatusLookup: index("chronic_conditions_elder_status_lookup").on(table.organizationId, table.elderId, table.status),
|
||||
}));
|
||||
|
||||
export const healthAnomalyReviews = pgTable("health_anomaly_reviews", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
|
||||
elderId: uuid("elder_id").notNull().references(() => elders.id, { onDelete: "cascade" }),
|
||||
vitalRecordId: uuid("vital_record_id").references(() => vitalRecords.id, { onDelete: "set null" }),
|
||||
severity: incidentSeverityEnum("severity").notNull(),
|
||||
status: healthReviewStatusEnum("status").notNull().default("pending"),
|
||||
title: text("title").notNull(),
|
||||
description: text("description").notNull(),
|
||||
reviewedByAccountId: uuid("reviewed_by_account_id").references(() => accounts.id),
|
||||
reviewedAt: timestamp("reviewed_at", { withTimezone: true }),
|
||||
resolutionNotes: text("resolution_notes").notNull().default(""),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
}, (table) => ({
|
||||
reviewQueueLookup: index("health_anomaly_reviews_queue_lookup").on(table.organizationId, table.status, table.severity),
|
||||
}));
|
||||
|
||||
export const admissions = pgTable("admissions", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
organizationId: uuid("organization_id").notNull().references(() => organizations.id, { onDelete: "cascade" }),
|
||||
|
||||
Reference in New Issue
Block a user