feature: a very minimal patients feature implemented. it needs lots of improvments though
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "patients" (
|
||||
"id" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"firstName" TEXT NOT NULL,
|
||||
"lastName" TEXT NOT NULL,
|
||||
"phone" TEXT,
|
||||
"email" TEXT,
|
||||
"dateOfBirth" TIMESTAMP(3),
|
||||
"notes" TEXT,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "patients_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "patient_treatment_histories" (
|
||||
"id" TEXT NOT NULL,
|
||||
"patientId" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"treatmentAt" TIMESTAMP(3) NOT NULL,
|
||||
"tooth" TEXT,
|
||||
"notes" TEXT,
|
||||
"totalCost" DOUBLE PRECISION,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "patient_treatment_histories_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "patients_organizationId_createdAt_idx" ON "patients"("organizationId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "patients_organizationId_lastName_firstName_idx" ON "patients"("organizationId", "lastName", "firstName");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "patient_treatment_histories_patientId_treatmentAt_idx" ON "patient_treatment_histories"("patientId", "treatmentAt");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "patients" ADD CONSTRAINT "patients_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "organizations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "patient_treatment_histories" ADD CONSTRAINT "patient_treatment_histories_patientId_fkey" FOREIGN KEY ("patientId") REFERENCES "patients"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -55,6 +55,7 @@ model Organization {
|
||||
|
||||
sharedWithMe OrganizationLink[] @relation("OrganizationB")
|
||||
sharedWithOthers OrganizationLink[] @relation("OrganizationA")
|
||||
patients Patient[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -62,6 +63,45 @@ model Organization {
|
||||
@@map("organizations")
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
organization Organization @relation(fields: [organizationId], references: [id])
|
||||
treatments PatientTreatmentHistory[]
|
||||
|
||||
@@index([organizationId, createdAt])
|
||||
@@index([organizationId, lastName, firstName])
|
||||
@@map("patients")
|
||||
}
|
||||
|
||||
model PatientTreatmentHistory {
|
||||
id String @id @default(uuid())
|
||||
patientId String
|
||||
title String
|
||||
status String
|
||||
treatmentAt DateTime
|
||||
tooth String?
|
||||
notes String?
|
||||
totalCost Float?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([patientId, treatmentAt])
|
||||
@@map("patient_treatment_histories")
|
||||
}
|
||||
|
||||
model Plan {
|
||||
id String @id @default(uuid())
|
||||
name String @unique // "Solo", "Small", "Medium", "Large", "Enterprise"
|
||||
|
||||
Reference in New Issue
Block a user