DROP TABLE AKUZ.T_REHAB_REGISTRY CASCADE;

-- Tables

/***** Object:  Table AKUZ.T_REHAB_REGISTRY *****/
CREATE TABLE AKUZ.T_REHAB_REGISTRY
(
    "rehabregistryid" uuid NOT NULL,
    "patient" uuid NULL,
    "deregisterdate" timestamp NULL,
    "takereason" varchar(1024) NULL,
    "registerpost" uuid NULL,
    "registerdate" timestamp NULL,
    "deregisterpost" uuid NULL,
    "deregisterreason" varchar(1024) NULL
);

-- Alters

ALTER TABLE AKUZ.T_REHAB_REGISTRY ADD CONSTRAINT PK_T_REHAB_REGISTRY
PRIMARY KEY (RehabRegistryID);

ALTER TABLE AKUZ.T_REHAB_REGISTRY ADD CONSTRAINT FK_T_PATIENT_T_REHAB_REGISTRY_Patient
FOREIGN KEY("patient") REFERENCES AKUZ.T_PATIENT (PatientID);

ALTER TABLE AKUZ.T_REHAB_REGISTRY ADD CONSTRAINT FK_T_POST_T_REHAB_REGISTRY_RegisterPost
FOREIGN KEY("registerpost") REFERENCES AKUZ.T_POST (ResourceID);

ALTER TABLE AKUZ.T_REHAB_REGISTRY ADD CONSTRAINT FK_T_POST_T_REHAB_REGISTRY_DeregisterPost
FOREIGN KEY("deregisterpost") REFERENCES AKUZ.T_POST (ResourceID);

-- Tables

/***** Object:  Table AKUZ.T_REHAB_COURSE *****/
CREATE TABLE AKUZ.T_REHAB_COURSE
(
    "rehabcourseid" uuid NOT NULL,
    "courseopeningdate" timestamp NULL,
    "refferal" uuid NULL,
    "eventbase" uuid NULL,
    "rehabregistry" uuid NULL
);

-- Alters

ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT PK_T_REHAB_COURSE
PRIMARY KEY (RehabCourseID);

ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT FK_T_AMBULANCE_CARD_RECORD_T_REHAB_COURSE_Refferal
FOREIGN KEY("refferal") REFERENCES AKUZ.T_AMBULANCE_CARD_RECORD (MedicalRecordID);

ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT FK_T_EVENT_BASE_T_REHAB_COURSE_EventBase
FOREIGN KEY("eventbase") REFERENCES AKUZ.T_EVENT_BASE (EventID);

ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT FK_T_REHAB_REGISTRY_T_REHAB_COURSE_RehabRegistry
FOREIGN KEY("rehabregistry") REFERENCES AKUZ.T_REHAB_REGISTRY (RehabRegistryID);

-- Tables

/***** Object:  Table AKUZ.T_REHAB_FILE *****/
CREATE TABLE AKUZ.T_REHAB_FILE
(
    "fileid" uuid NOT NULL,
    "rehabregistry" uuid NULL,
    "rehabcourse" uuid NULL,
    "isresult" boolean NOT NULL,
    "rehabresult" varchar(2048) NULL,
    "begindate" timestamp NULL,
    "enddate" timestamp NULL
);

-- Alters

ALTER TABLE AKUZ.T_REHAB_FILE ADD CONSTRAINT PK_T_REHAB_FILE
PRIMARY KEY (FileID);

ALTER TABLE AKUZ.T_REHAB_FILE ADD CONSTRAINT FK_T_FILE_T_REHAB_FILE_FileID
FOREIGN KEY("fileid") REFERENCES VCLib.T_FILE (FileID);

ALTER TABLE AKUZ.T_REHAB_FILE ADD CONSTRAINT FK_T_REHAB_REGISTRY_T_REHAB_FILE_RehabRegistry
FOREIGN KEY("rehabregistry") REFERENCES AKUZ.T_REHAB_REGISTRY (RehabRegistryID);

ALTER TABLE AKUZ.T_REHAB_FILE ADD CONSTRAINT FK_T_REHAB_COURSE_T_REHAB_FILE_RehabCourse
FOREIGN KEY("rehabcourse") REFERENCES AKUZ.T_REHAB_COURSE (RehabCourseID);





