-- AKUZ.T_REK_EXPERTISE_REHAB
CREATE TABLE AKUZ.T_REK_EXPERTISE_REHAB
(
    "rekexpertiseid" uuid NOT NULL,
    "mcresult" integer NULL,
    "curationlevel" integer NULL,
    "rehabroutingscale" integer NULL,
    "expertisetype" integer NULL,
    "scalecheckeditems" bytea NULL
);

ALTER TABLE AKUZ.T_REK_EXPERTISE_REHAB ADD CONSTRAINT PK_T_REK_EXPERTISE_REHAB
PRIMARY KEY (RekExpertiseID);

ALTER TABLE AKUZ.T_REK_EXPERTISE_REHAB ADD CONSTRAINT FK_T_REK_EXPERTISE_T_REK_EXPERTISE_REHAB_RekExpertiseID
FOREIGN KEY("rekexpertiseid") REFERENCES AKUZ.T_REK_EXPERTISE (RekExpertiseID);

ALTER TABLE AKUZ.T_REK_EXPERTISE_REHAB ADD CONSTRAINT FK_T_EHR_RUS_CHR367_T_REK_EXPERTISE_REHAB_ExpertiseType
FOREIGN KEY("expertisetype") REFERENCES EHR.T_EHR_RUS_CHR367 (EhrRusID);

------
--AKUZ.T_REHAB_COURSE
ALTER TABLE AKUZ.T_REHAB_COURSE alter column "refferal" uuid NOT NULL;
ALTER TABLE AKUZ.T_REHAB_COURSE DROP CONSTRAINT FK_T_AMBULANCE_CARD_RECORD_T_REHAB_COURSE_Refferal;
ALTER TABLE AKUZ.T_REHAB_COURSE RENAME COLUMN Refferal TO Referral;
ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT FK_T_REFERRAL_T_REHAB_COURSE_Referral
FOREIGN KEY("referral") REFERENCES AKUZ.T_REFERRAL (MedicalRecordID);

ALTER TABLE AKUZ.T_REHAB_COURSE ALTER COLUMN "courseopeningdate" SET NOT NULL;
ALTER TABLE AKUZ.T_REHAB_COURSE ALTER COLUMN "rehabregistry" SET NOT NULL;

ALTER TABLE AKUZ.T_REHAB_COURSE ADD "rehabilitationphase" integer NULL;

------
--AKUZ.T_REHAB_REGISTRY
ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN "registerdate" SET NOT NULL;
ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN "registerpost" SET NOT NULL;
ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN "patient" SET NOT NULL;

