feature: phase0 - Global patients + mobile normalization
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
-- Global patients: mobile is cloud-wide unique identity; org scope removed.
|
||||
-- Test/dev data only — clear patient-linked rows before reshape.
|
||||
|
||||
DELETE FROM "treatment_case_sends";
|
||||
DELETE FROM "treatment_case_attachments";
|
||||
DELETE FROM "treatment_cases";
|
||||
DELETE FROM "treatments";
|
||||
DELETE FROM "appointments";
|
||||
DELETE FROM "patients";
|
||||
|
||||
ALTER TABLE "patients" DROP CONSTRAINT IF EXISTS "patients_organizationId_fkey";
|
||||
|
||||
DROP INDEX IF EXISTS "patients_organizationId_createdAt_idx";
|
||||
DROP INDEX IF EXISTS "patients_organizationId_lastName_firstName_idx";
|
||||
|
||||
ALTER TABLE "patients" DROP COLUMN "organizationId";
|
||||
ALTER TABLE "patients" DROP COLUMN "phone";
|
||||
|
||||
ALTER TABLE "patients" ADD COLUMN "mobile" TEXT NOT NULL;
|
||||
ALTER TABLE "patients" ADD COLUMN "createdByOrganizationId" TEXT;
|
||||
|
||||
CREATE UNIQUE INDEX "patients_mobile_key" ON "patients"("mobile");
|
||||
CREATE INDEX "patients_lastName_firstName_idx" ON "patients"("lastName", "firstName");
|
||||
|
||||
ALTER TABLE "patients"
|
||||
ADD CONSTRAINT "patients_createdByOrganizationId_fkey"
|
||||
FOREIGN KEY ("createdByOrganizationId") REFERENCES "organizations"("id")
|
||||
ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -60,7 +60,7 @@ model Organization {
|
||||
sharedWithMe OrganizationLink[] @relation("OrganizationB")
|
||||
sharedWithOthers OrganizationLink[] @relation("OrganizationA")
|
||||
sentOrganizationInvitations OrganizationInvitation[] @relation("OrganizationInvitationInviter")
|
||||
patients Patient[]
|
||||
createdPatients Patient[] @relation("PatientCreatedBy")
|
||||
appointments Appointment[]
|
||||
treatments Treatment[]
|
||||
caseSends TreatmentCaseSend[]
|
||||
@@ -72,24 +72,23 @@ model Organization {
|
||||
}
|
||||
|
||||
model Patient {
|
||||
id String @id @default(uuid())
|
||||
organizationId String
|
||||
firstName String
|
||||
lastName String
|
||||
phone String?
|
||||
email String?
|
||||
dateOfBirth DateTime?
|
||||
notes String?
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
firstName String
|
||||
lastName String
|
||||
mobile String @unique
|
||||
email String?
|
||||
dateOfBirth DateTime?
|
||||
notes String?
|
||||
isActive Boolean @default(true)
|
||||
createdByOrganizationId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
organization Organization @relation(fields: [organizationId], references: [id])
|
||||
treatments Treatment[]
|
||||
appointments Appointment[]
|
||||
createdByOrganization Organization? @relation("PatientCreatedBy", fields: [createdByOrganizationId], references: [id], onDelete: SetNull)
|
||||
treatments Treatment[]
|
||||
appointments Appointment[]
|
||||
|
||||
@@index([organizationId, createdAt])
|
||||
@@index([organizationId, lastName, firstName])
|
||||
@@index([lastName, firstName])
|
||||
@@map("patients")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user