285 lines
11 KiB
SQL
285 lines
11 KiB
SQL
/*
|
|
Warnings:
|
|
|
|
- You are about to drop the column `code` on the `Image` table. All the data in the column will be lost.
|
|
- You are about to drop the column `name` on the `Image` table. All the data in the column will be lost.
|
|
- You are about to drop the column `url` on the `Image` table. All the data in the column will be lost.
|
|
- The primary key for the `Patient` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
|
- You are about to drop the column `country_code` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `country_name` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `dob` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `first_name` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `last_name` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `phone_number` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `status` on the `Patient` table. All the data in the column will be lost.
|
|
- You are about to drop the column `bio` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `createdAt` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `image` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `name` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `phone_number` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `profile_photo_id` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `role` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the column `socials` on the `Users` table. All the data in the column will be lost.
|
|
- You are about to drop the `AdmissionForm` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `DefaultInfo` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `File` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Language` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `MedicalDocument` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Package` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `PackageItem` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Page` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `PageBlock` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Service` table. If the table is not empty, all the data it contains will be lost.
|
|
- Added the required column `firstName` to the `Patient` table without a default value. This is not possible if the table is not empty.
|
|
- Added the required column `lastName` to the `Patient` table without a default value. This is not possible if the table is not empty.
|
|
- Added the required column `firstName` to the `Users` table without a default value. This is not possible if the table is not empty.
|
|
- Added the required column `lastName` to the `Users` table without a default value. This is not possible if the table is not empty.
|
|
- Made the column `position` on table `Users` required. This step will fail if there are existing NULL values in that column.
|
|
|
|
*/
|
|
-- CreateEnum
|
|
CREATE TYPE "CaseStatus" AS ENUM ('NEW', 'CONTACTED', 'DOCS_PENDING', 'REVIEWING', 'PRE_APPROVED', 'REJECTED', 'CLOSED', 'CONVERTED_TO_HIS');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "DocumentType" AS ENUM ('PASSPORT', 'MEDICAL_RECORD', 'IMAGING', 'LAB_RESULT', 'OTHER');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "InteractionType" AS ENUM ('PHONE', 'WHATSAPP', 'EMAIL', 'SYSTEM');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "UsersType" AS ENUM ('DOCTOR', 'TRANSFER_TEAM', 'DEPARTMENT');
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "AdmissionForm" DROP CONSTRAINT "AdmissionForm_patient_id_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "File" DROP CONSTRAINT "File_documentId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "MedicalDocument" DROP CONSTRAINT "MedicalDocument_patient_id_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "Package" DROP CONSTRAINT "Package_service_id_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "PackageItem" DROP CONSTRAINT "PackageItem_package_id_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "PageBlock" DROP CONSTRAINT "PageBlock_pageId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "Users" DROP CONSTRAINT "Users_profile_photo_id_fkey";
|
|
|
|
-- DropIndex
|
|
DROP INDEX "Patient_email_key";
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "Image" DROP COLUMN "code",
|
|
DROP COLUMN "name",
|
|
DROP COLUMN "url",
|
|
ADD COLUMN "filename" TEXT,
|
|
ALTER COLUMN "mimeType" DROP NOT NULL,
|
|
ALTER COLUMN "size" DROP NOT NULL;
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "Patient" DROP CONSTRAINT "Patient_pkey",
|
|
DROP COLUMN "country_code",
|
|
DROP COLUMN "country_name",
|
|
DROP COLUMN "dob",
|
|
DROP COLUMN "first_name",
|
|
DROP COLUMN "last_name",
|
|
DROP COLUMN "phone_number",
|
|
DROP COLUMN "status",
|
|
ADD COLUMN "age" INTEGER,
|
|
ADD COLUMN "countryCode" TEXT,
|
|
ADD COLUMN "firstName" TEXT NOT NULL,
|
|
ADD COLUMN "lastName" TEXT NOT NULL,
|
|
ADD COLUMN "nationality" TEXT,
|
|
ADD COLUMN "phone" TEXT,
|
|
ADD COLUMN "preferredLanguage" TEXT,
|
|
ALTER COLUMN "id" DROP DEFAULT,
|
|
ALTER COLUMN "id" SET DATA TYPE TEXT,
|
|
ADD CONSTRAINT "Patient_pkey" PRIMARY KEY ("id");
|
|
DROP SEQUENCE "Patient_id_seq";
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "Users" DROP COLUMN "bio",
|
|
DROP COLUMN "createdAt",
|
|
DROP COLUMN "image",
|
|
DROP COLUMN "name",
|
|
DROP COLUMN "phone_number",
|
|
DROP COLUMN "profile_photo_id",
|
|
DROP COLUMN "role",
|
|
DROP COLUMN "socials",
|
|
ADD COLUMN "firstName" TEXT NOT NULL,
|
|
ADD COLUMN "imageId" INTEGER,
|
|
ADD COLUMN "lastName" TEXT NOT NULL,
|
|
ADD COLUMN "phone" TEXT,
|
|
ADD COLUMN "type" "UsersType" NOT NULL DEFAULT 'DOCTOR',
|
|
ALTER COLUMN "position" SET NOT NULL;
|
|
|
|
-- DropTable
|
|
DROP TABLE "AdmissionForm";
|
|
|
|
-- DropTable
|
|
DROP TABLE "DefaultInfo";
|
|
|
|
-- DropTable
|
|
DROP TABLE "File";
|
|
|
|
-- DropTable
|
|
DROP TABLE "Language";
|
|
|
|
-- DropTable
|
|
DROP TABLE "MedicalDocument";
|
|
|
|
-- DropTable
|
|
DROP TABLE "Package";
|
|
|
|
-- DropTable
|
|
DROP TABLE "PackageItem";
|
|
|
|
-- DropTable
|
|
DROP TABLE "Page";
|
|
|
|
-- DropTable
|
|
DROP TABLE "PageBlock";
|
|
|
|
-- DropTable
|
|
DROP TABLE "Service";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "BlockType";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "FormStatus";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "PageStatus";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "PageType";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "PatientStatus";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "UploadedBy";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "UserRoles";
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "OnlineCase" (
|
|
"id" TEXT NOT NULL,
|
|
"patientId" TEXT NOT NULL,
|
|
"trackingCode" TEXT NOT NULL,
|
|
"message" TEXT,
|
|
"specialty" TEXT,
|
|
"formData" JSONB,
|
|
"status" "CaseStatus" NOT NULL DEFAULT 'NEW',
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "OnlineCase_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "Document" (
|
|
"id" TEXT NOT NULL,
|
|
"caseId" TEXT,
|
|
"patientId" TEXT,
|
|
"uploadedById" TEXT,
|
|
"type" "DocumentType" NOT NULL,
|
|
"fileKey" TEXT NOT NULL,
|
|
"filename" TEXT,
|
|
"mimeType" TEXT,
|
|
"size" INTEGER,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "Document_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "Interaction" (
|
|
"id" TEXT NOT NULL,
|
|
"caseId" TEXT NOT NULL,
|
|
"staffId" TEXT,
|
|
"type" "InteractionType" NOT NULL,
|
|
"message" TEXT,
|
|
"direction" TEXT,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "Interaction_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "Review" (
|
|
"id" TEXT NOT NULL,
|
|
"caseId" TEXT NOT NULL,
|
|
"doctorId" TEXT,
|
|
"note" TEXT,
|
|
"result" TEXT,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "Review_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "CaseStatusHistory" (
|
|
"id" TEXT NOT NULL,
|
|
"caseId" TEXT NOT NULL,
|
|
"from" "CaseStatus",
|
|
"to" "CaseStatus" NOT NULL,
|
|
"changedBy" TEXT,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "CaseStatusHistory_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "Staff" (
|
|
"id" TEXT NOT NULL,
|
|
"username" TEXT NOT NULL,
|
|
"role" TEXT NOT NULL,
|
|
"email" TEXT NOT NULL,
|
|
|
|
CONSTRAINT "Staff_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "OnlineCase_trackingCode_key" ON "OnlineCase"("trackingCode");
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "Staff_email_key" ON "Staff"("email");
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "OnlineCase" ADD CONSTRAINT "OnlineCase_patientId_fkey" FOREIGN KEY ("patientId") REFERENCES "Patient"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Document" ADD CONSTRAINT "Document_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "OnlineCase"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Document" ADD CONSTRAINT "Document_patientId_fkey" FOREIGN KEY ("patientId") REFERENCES "Patient"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Document" ADD CONSTRAINT "Document_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Interaction" ADD CONSTRAINT "Interaction_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "OnlineCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Interaction" ADD CONSTRAINT "Interaction_staffId_fkey" FOREIGN KEY ("staffId") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Review" ADD CONSTRAINT "Review_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "OnlineCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Review" ADD CONSTRAINT "Review_doctorId_fkey" FOREIGN KEY ("doctorId") REFERENCES "Staff"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "CaseStatusHistory" ADD CONSTRAINT "CaseStatusHistory_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "OnlineCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "Users" ADD CONSTRAINT "Users_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "Image"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|