-- AKUZ.T_REK_EXPERTISE_REHAB
CREATE TABLE AKUZ.T_REK_EXPERTISE_REHAB
(
    RekExpertiseID uniqueidentifier NOT NULL,
    MCResult int NULL,
    CurationLevel int NULL,
    RehabRoutingScale int NULL,
    ExpertiseType int NULL,
    ScaleCheckedItems varbinary(max) NULL
)
ON [PRIMARY]
GO

ALTER TABLE AKUZ.T_REK_EXPERTISE_REHAB ADD CONSTRAINT PK_T_REK_EXPERTISE_REHAB
PRIMARY KEY CLUSTERED (RekExpertiseID) ON [PRIMARY]
GO

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)
GO

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)
GO

--------
-- переименование с Refferal на Referral + проставление обязательности
ALTER TABLE AKUZ.T_REHAB_COURSE ALTER COLUMN Refferal uniqueidentifier NOT NULL
GO
alter table AKUZ.T_REHAB_COURSE drop constraint FK_T_AMBULANCE_CARD_RECORD_T_REHAB_COURSE_Refferal
GO
exec sp_rename 'AKUZ.T_REHAB_COURSE.Refferal', 'Referral', 'column';
GO
ALTER TABLE AKUZ.T_REHAB_COURSE ADD CONSTRAINT FK_T_REFERRAL_T_REHAB_COURSE_Referral
FOREIGN KEY(Referral) REFERENCES AKUZ.T_REFERRAL (MedicalRecordID)
GO
-- проставление обязательности у CourseOpeningDate и RehabRegistry
ALTER TABLE AKUZ.T_REHAB_COURSE ALTER COLUMN CourseOpeningDate datetime NOT NULL
GO
ALTER TABLE AKUZ.T_REHAB_COURSE ALTER COLUMN RehabRegistry uniqueidentifier NOT NULL
GO
--добавление этапа реабилитации
ALTER TABLE AKUZ.T_REHAB_COURSE ADD RehabilitationPhase int NULL
GO
--------

ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN RegisterDate datetime NOT NULL
GO
ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN RegisterPost int NOT NULL
GO
ALTER TABLE AKUZ.T_REHAB_REGISTRY ALTER COLUMN Patient uniqueidentifier NOT NULL
GO