ALTER TABLE [AKUZ].[T_REHAB_REGISTRY_COURSE] DROP CONSTRAINT [FK_T_REHAB_REGISTRY_T_REHAB_REGISTRY_COURSE_RehabRegistry]
GO

ALTER TABLE [AKUZ].[T_REHAB_REGISTRY_COURSE] DROP COLUMN [RehabRegistry]
GO

DROP TABLE AKUZ.T_REHAB_REGISTRY

-- Tables

/***** Object:  Table [AKUZ].[T_REHAB_REGISTRY] *****/
CREATE TABLE [AKUZ].[T_REHAB_REGISTRY]
(
    [RehabRegistryID] uniqueidentifier NOT NULL,
    [Patient] uniqueidentifier NULL,
    [DeregisterDate] datetime NULL,
    [TakeReason] varchar(1024) NULL,
    [RegisterPost] uniqueidentifier NULL,
    [RegisterDate] datetime NULL,
    [DeregisterPost] uniqueidentifier NULL,
    [DeregisterReason] varchar(1024) NULL
)
ON [PRIMARY]
GO

-- Alters

ALTER TABLE [AKUZ].[T_REHAB_REGISTRY] ADD CONSTRAINT [PK_T_REHAB_REGISTRY]
PRIMARY KEY CLUSTERED ([RehabRegistryID]) ON [PRIMARY]
GO

ALTER TABLE [AKUZ].[T_REHAB_REGISTRY] ADD CONSTRAINT [FK_T_PATIENT_T_REHAB_REGISTRY_Patient]
FOREIGN KEY([Patient]) REFERENCES [AKUZ].[T_PATIENT] ([PatientID])
GO

ALTER TABLE [AKUZ].[T_REHAB_REGISTRY] ADD CONSTRAINT [FK_T_POST_T_REHAB_REGISTRY_RegisterPost]
FOREIGN KEY([RegisterPost]) REFERENCES [AKUZ].[T_POST] ([ResourceID])
GO

ALTER TABLE [AKUZ].[T_REHAB_REGISTRY] ADD CONSTRAINT [FK_T_POST_T_REHAB_REGISTRY_DeregisterPost]
FOREIGN KEY([DeregisterPost]) REFERENCES [AKUZ].[T_POST] ([ResourceID])
GO


-- Tables

/***** Object:  Table [AKUZ].[T_REHAB_COURSE] *****/
CREATE TABLE [AKUZ].[T_REHAB_COURSE]
(
    [RehabCourseID] uniqueidentifier NOT NULL,
    [CourseOpeningDate] datetime NULL,
    [Refferal] uniqueidentifier NULL,
    [EventBase] uniqueidentifier NULL,
    [RehabRegistry] uniqueidentifier NULL
)
ON [PRIMARY]
GO

-- Alters

ALTER TABLE [AKUZ].[T_REHAB_COURSE] ADD CONSTRAINT [PK_T_REHAB_COURSE]
PRIMARY KEY CLUSTERED ([RehabCourseID]) ON [PRIMARY]
GO

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

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

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

-- Tables

/***** Object:  Table [AKUZ].[T_REHAB_FILE] *****/
CREATE TABLE [AKUZ].[T_REHAB_FILE]
(
    [FileID] uniqueidentifier NOT NULL,
    [RehabRegistry] uniqueidentifier NULL,
    [RehabCourse] uniqueidentifier NULL,
    [isResult] bit NOT NULL,
    [RehabResult] varchar(2048) NULL,
    [BeginDate] datetime NULL,
    [EndDate] datetime NULL
)
ON [PRIMARY]
GO

-- Alters

ALTER TABLE [AKUZ].[T_REHAB_FILE] ADD CONSTRAINT [PK_T_REHAB_FILE]
PRIMARY KEY CLUSTERED ([FileID]) ON [PRIMARY]
GO

ALTER TABLE [AKUZ].[T_REHAB_FILE] ADD CONSTRAINT [FK_T_FILE_T_REHAB_FILE_FileID]
FOREIGN KEY([FileID]) REFERENCES [VCLib].[T_FILE] ([FileID])
GO

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

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





