			--CREATE TABLES--
-------------------------------------------------------------------------------------
-- CDA_DGN_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]
(
    [CdaDgnNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_DGN_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaDgnNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_SUM_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]
(
    [CdaSumNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_SUM_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaSumNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_RESLAB_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]
(
    [CdaReslabNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_RESLAB_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaReslabNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_SCORES_LABODELI_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]
(
    [CdaScoresLabodeliNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL,
	[PointsCount] int NULL,
    [MeasuringScaleTime] datetime NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaScoresLabodeliNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
--
-------------------------------------------------------------------------------------
--CDA_SERVICES_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]
(
    [CdaServicesNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_SERVICES_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaServicesNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_EPICRISIS_NEWBORN_DEPARTMENTS
CREATE TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]
(
    [CdaEpicrisisNewbornDepartmentsID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] ADD CONSTRAINT [PK_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]
PRIMARY KEY CLUSTERED ([CdaEpicrisisNewbornDepartmentsID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]
(
    [CdaPathologicalReactionsNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaPathologicalReactionsNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_PROCEDURE_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]
(
    [CdaProcedureNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_PROCEDURE_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaProcedureNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_RESCONS_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]
(
    [CdaResconsNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_RESCONS_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaResconsNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_RESINSTR_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]
(
    [CdaResinstrNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_RESINSTR_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaResinstrNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_SUR_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]
(
    [CdaSurNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_SUR_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaSurNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_VITALPARAM_NEWBORN_AKENEO
CREATE TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]
(
    [CdaVitalparamNewbornAkeneoID] uniqueidentifier NOT NULL,
    [CdaNewbornAkeneo] uniqueidentifier NULL
)
ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] ADD CONSTRAINT [PK_T_CDA_VITALPARAM_NEWBORN_AKENEO]
PRIMARY KEY CLUSTERED ([CdaVitalparamNewbornAkeneoID]) ON [PRIMARY]
GO
ALTER TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_NEWBORN_AKENEO_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo]
FOREIGN KEY([CdaNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_NEWBORN_AKENEO] ([CdaNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
--убирается обязательность парента, чтобы не было проблем с секциями
--VIMIS_PATIENT_STAYING_HOSPITALISATION
ALTER TABLE [AKUZ].[T_VIMIS_PATIENT_STAYING_HOSPITALISATION] ALTER COLUMN [VimisSectionEpicrisisDepartments] uniqueidentifier NULL
GO
-------------------------------------------------------------------------------------
--CDA_MEDICAMENT
ALTER TABLE [AKUZ].[T_CDA_MEDICAMENT] ALTER COLUMN [CdaSectionSum] uniqueidentifier NULL
GO
-------------------------------------------------------------------------------------
--CDA_NON_MEDICAMENT
ALTER TABLE [AKUZ].[T_CDA_NON_MEDICAMENT] ALTER COLUMN [CdaSectionSum] uniqueidentifier NULL
GO
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
ALTER TABLE [AKUZ].[T_CDA_MEDICAMENT] ADD [CdaSumNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_MEDICAMENT] ADD CONSTRAINT [FK_T_CDA_SUM_NEWBORN_AKENEO_T_CDA_MEDICAMENT_CdaSumNewbornAkeneo]
FOREIGN KEY([CdaSumNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] ([CdaSumNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
ALTER TABLE [AKUZ].[T_CDA_NON_MEDICAMENT] ADD [CdaSumNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_NON_MEDICAMENT] ADD CONSTRAINT [FK_T_CDA_SUM_NEWBORN_AKENEO_T_CDA_NON_MEDICAMENT_CdaSumNewbornAkeneo]
FOREIGN KEY([CdaSumNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] ([CdaSumNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--VIMIS_PATIENT_STAYING_HOSPITALISATION
ALTER TABLE [AKUZ].[T_VIMIS_PATIENT_STAYING_HOSPITALISATION] ADD [CdaEpicrisisNewbornDepartments] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_VIMIS_PATIENT_STAYING_HOSPITALISATION] ADD CONSTRAINT [FK_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_T_VIMIS_PATIENT_STAYING_HOSPITALISATION_CdaEpicrisisNewbornDepartments]
FOREIGN KEY([CdaEpicrisisNewbornDepartments]) REFERENCES [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] ([CdaEpicrisisNewbornDepartmentsID])
GO
-------------------------------------------------------------------------------------
--CDA_APGAR_SCALE_NEWBORN_AKENEO
--добавление нового парента для новорожденного 
ALTER TABLE [AKUZ].[T_CDA_APGAR_SCALE_NEWBORN_AKENEO] ADD [CdaScoresLabodeliNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_APGAR_SCALE_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_T_CDA_APGAR_SCALE_NEWBORN_AKENEO_CdaScoresLabodeliNewbornAkeneo]
FOREIGN KEY([CdaScoresLabodeliNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] ([CdaScoresLabodeliNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_CONS_RESULT_AKENEO
--добавление нового парента для новорожденного 
ALTER TABLE [AKUZ].[T_CDA_CONS_RESULT_AKENEO] ADD [CdaResconsNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_CONS_RESULT_AKENEO] ADD CONSTRAINT [FK_T_CDA_RESCONS_NEWBORN_AKENEO_T_CDA_CONS_RESULT_AKENEO_CdaResconsNewbornAkeneo]
FOREIGN KEY([CdaResconsNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] ([CdaResconsNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_DGN_AKENEO
ALTER TABLE [AKUZ].[T_CDA_DGN_AKENEO] ADD [CdaDgnNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_DGN_AKENEO] ADD CONSTRAINT [FK_T_CDA_DGN_NEWBORN_AKENEO_T_CDA_DGN_AKENEO_CdaDgnNewbornAkeneo]
FOREIGN KEY([CdaDgnNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] ([CdaDgnNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_INSTRUMENTAL_RESEARCH_RESINSTR_AKENEO
ALTER TABLE [AKUZ].[T_CDA_INSTRUMENTAL_RESEARCH_RESINSTR_AKENEO] ADD [CdaResinstrNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_INSTRUMENTAL_RESEARCH_RESINSTR_AKENEO] ADD CONSTRAINT [FK_T_CDA_RESINSTR_NEWBORN_AKENEO_T_CDA_INSTRUMENTAL_RESEARCH_RESINSTR_AKENEO_CdaResinstrNewbornAkeneo]
FOREIGN KEY([CdaResinstrNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] ([CdaResinstrNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_LAB_RESEARCH_MATHERINITY_AKENEO
ALTER TABLE [AKUZ].[T_CDA_LAB_RESEARCH_MATHERINITY_AKENEO] ADD [CdaReslabNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_LAB_RESEARCH_MATHERINITY_AKENEO] ADD CONSTRAINT [FK_T_CDA_RESLAB_NEWBORN_AKENEO_T_CDA_LAB_RESEARCH_MATHERINITY_AKENEO_CdaReslabNewbornAkeneo]
FOREIGN KEY([CdaReslabNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] ([CdaReslabNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_OPERATION_AKENEO
ALTER TABLE [AKUZ].[T_CDA_OPERATION_AKENEO] ADD [CdaSurNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_OPERATION_AKENEO] ADD CONSTRAINT [FK_T_CDA_SUR_NEWBORN_AKENEO_T_CDA_OPERATION_AKENEO_CdaSurNewbornAkeneo]
FOREIGN KEY([CdaSurNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] ([CdaSurNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_PATHOLOGICAL_REACTION_AKENEO
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTION_AKENEO] ADD [CdaPathologicalReactionsNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTION_AKENEO] ADD CONSTRAINT [FK_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_T_CDA_PATHOLOGICAL_REACTION_AKENEO_CdaPathologicalReactionsNewbornAkeneo]
FOREIGN KEY([CdaPathologicalReactionsNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] ([CdaPathologicalReactionsNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_PROCEDURE_AKENEO
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_AKENEO] ADD [CdaProcedureNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_AKENEO] ADD CONSTRAINT [FK_T_CDA_PROCEDURE_NEWBORN_AKENEO_T_CDA_PROCEDURE_AKENEO_CdaProcedureNewbornAkeneo]
FOREIGN KEY([CdaProcedureNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] ([CdaProcedureNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-- CDA_SERVICE_AKENEO
ALTER TABLE [AKUZ].[T_CDA_SERVICE_AKENEO] ADD [CdaServicesNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_SERVICE_AKENEO] ADD CONSTRAINT [FK_T_CDA_SERVICES_NEWBORN_AKENEO_T_CDA_SERVICE_AKENEO_CdaServicesNewbornAkeneo]
FOREIGN KEY([CdaServicesNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] ([CdaServicesNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
--CDA_VACCINATION_STATUS
ALTER TABLE [AKUZ].[T_CDA_VACCINATION_STATUS] ADD [CdaImmNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_VACCINATION_STATUS] ADD CONSTRAINT [FK_T_CDA_SECTION_IMM_T_CDA_VACCINATION_STATUS_CdaImmNewbornAkeneo]
FOREIGN KEY([CdaImmNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SECTION_IMM] ([CdaSectionID])
GO
-------------------------------------------------------------------------------------
-- CDA_VP_IN_SECTION_AKENEO
ALTER TABLE [AKUZ].[T_CDA_VP_IN_SECTION_AKENEO] ADD [CdaVitalparamNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_VP_IN_SECTION_AKENEO] ADD CONSTRAINT [FK_T_CDA_VITALPARAM_NEWBORN_AKENEO_T_CDA_VP_IN_SECTION_AKENEO_CdaVitalparamNewbornAkeneo]
FOREIGN KEY([CdaVitalparamNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] ([CdaVitalparamNewbornAkeneoID])
GO
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-- CDA_NEWBORN_AKENEO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaDgnNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_DGN_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_DGN_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]') AND name = N'UQ_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]') AND name = N'UQ_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] DROP CONSTRAINT [UQ_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaEpicrisisNewbornDepartmentsID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaPathologicalReactionsNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaProcedureNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_PROCEDURE_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_PROCEDURE_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaResconsNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_RESCONS_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESCONS_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaResinstrNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_RESINSTR_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESINSTR_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaReslabNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_RESLAB_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_RESLAB_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaScoresLabodeliNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_SCORES_LABODELI_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SCORES_LABODELI_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaServicesNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_SERVICES_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SERVICES_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaSumNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_SUM_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SUM_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaSurNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_SUR_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_SUR_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]') AND name = N'UQ_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] DROP CONSTRAINT [UQ_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]') AND name = N'CdaNewbornAkeneo_UQ')
ALTER TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] DROP COLUMN [CdaNewbornAkeneo_UQ]
GO

ALTER TABLE [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO]ADD [CdaNewbornAkeneo_UQ] AS (CASE WHEN [CdaNewbornAkeneo] IS NOT NULL THEN NULL ELSE [CdaVitalparamNewbornAkeneoID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_VITALPARAM_NEWBORN_AKENEO_CdaNewbornAkeneo] ON [AKUZ].[T_CDA_VITALPARAM_NEWBORN_AKENEO] ([CdaNewbornAkeneo] ASC, [CdaNewbornAkeneo_UQ] ASC) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------
ALTER TABLE [AKUZ].[T_CDA_NEWBORN_AKENEO] ADD [CdaImmNewbornAkeneo] uniqueidentifier NULL
GO
ALTER TABLE [AKUZ].[T_CDA_NEWBORN_AKENEO] ADD CONSTRAINT [FK_T_CDA_SECTION_IMM_T_CDA_NEWBORN_AKENEO_CdaImmNewbornAkeneo]
FOREIGN KEY([CdaImmNewbornAkeneo]) REFERENCES [AKUZ].[T_CDA_SECTION_IMM] ([CdaSectionID])
GO
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_DGN_NEWBORN_AKENEO(CdaDgnNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionDgnAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionDgnAkeneo is not null
update cda
set cda.CdaDgnNewbornAkeneo = cda.CdaSectionDgn, cda.CdaSectionDgn = null
from akuz.T_CDA_DGN_AKENEO cda
	join akuz.T_CDA_DGN_NEWBORN_AKENEO aa on aa.CdaDgnNewbornAkeneoID = cda.CdaSectionDgn
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS(CdaEpicrisisNewbornDepartmentsID, CdaNewbornAkeneo) 
select cdasec.VimisSectionEpicrisisDepartments, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec	 
	 where cdasec.VimisSectionEpicrisisDepartments is not null
update cda
set cda.CdaEpicrisisNewbornDepartments = cda.VimisSectionEpicrisisDepartments, cda.VimisSectionEpicrisisDepartments = null
from akuz.T_VIMIS_PATIENT_STAYING_HOSPITALISATION cda 
join akuz.T_CDA_EPICRISIS_NEWBORN_DEPARTMENTS aa on aa.CdaEpicrisisNewbornDepartmentsID = cda.VimisSectionEpicrisisDepartments
-------------------------------------------------------------------------------------
update cda
set cda.CdaImmNewbornAkeneo = cda.CdaSectionImmAkeneo, CdaSectionImmAkeneo = null
from akuz.T_CDA_VACCINATION_STATUS cda
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO(CdaPathologicalReactionsNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionAllAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionAllAkeneo is not null
update cda
set cda.CdaPathologicalReactionsNewbornAkeneo = cda.CdaSectionAllAkeneo, cda.CdaSectionAllAkeneo = null
from akuz.T_CDA_PATHOLOGICAL_REACTION_AKENEO cda
join akuz.T_CDA_PATHOLOGICAL_REACTIONS_NEWBORN_AKENEO aa on aa.CdaPathologicalReactionsNewbornAkeneoID = cda.CdaSectionAllAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_PROCEDURE_NEWBORN_AKENEO (CdaProcedureNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionProcedureAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec	 
	 where cdasec.CdaSectionProcedureAkeneo is not null
update cda
set cda.CdaProcedureNewbornAkeneo = cda.CdaSectionProcedureAkeneo, cda.CdaSectionProcedureAkeneo = null
from akuz.T_CDA_PROCEDURE_AKENEO cda
join akuz.T_CDA_PROCEDURE_NEWBORN_AKENEO aa on aa.CdaProcedureNewbornAkeneoID = cda.CdaSectionProcedureAkeneo
-------------------------------------------------------------------------------------	 	 
INSERT INTO AKUZ.T_CDA_RESCONS_NEWBORN_AKENEO (CdaResconsNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionResconsAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionResconsAkeneo is not null
update cda
set cda.CdaResconsNewbornAkeneo = cda.CdaSectionResconsAkeneo, cda.CdaSectionResconsAkeneo = null
from akuz.T_CDA_CONS_RESULT_AKENEO cda
join akuz.T_CDA_RESCONS_NEWBORN_AKENEO aa on aa.CdaResconsNewbornAkeneoID = cda.CdaSectionResconsAkeneo
-------------------------------------------------------------------------------------	 
INSERT INTO AKUZ.T_CDA_RESINSTR_NEWBORN_AKENEO (CdaResinstrNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionResinstrAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionResinstrAkeneo is not null
update cda
set cda.CdaResinstrNewbornAkeneo = cda.CdaSectionResinstrAkeneo, cda.CdaSectionResinstrAkeneo = null
from akuz.T_CDA_INSTRUMENTAL_RESEARCH_RESINSTR_AKENEO cda
join akuz.T_CDA_RESINSTR_NEWBORN_AKENEO aa on aa.CdaResinstrNewbornAkeneoID = cda.CdaSectionResinstrAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_RESLAB_NEWBORN_AKENEO(CdaReslabNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionReslabMatherinityAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionReslabMatherinityAkeneo is not null
update cda
set cda.CdaReslabNewbornAkeneo = cda.CdaSectionReslabMatherinityAkeneo, cda.CdaSectionReslabMatherinityAkeneo = null
from akuz.T_CDA_LAB_RESEARCH_MATHERINITY_AKENEO cda
join akuz.T_CDA_RESLAB_NEWBORN_AKENEO aa on aa.CdaReslabNewbornAkeneoID = cda.CdaSectionReslabMatherinityAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_SCORES_LABODELI_NEWBORN_AKENEO (CdaScoresLabodeliNewbornAkeneoID, CdaNewbornAkeneo, PointsCount, MeasuringScaleTime) 
select cdasec.CdaSectionScoresLabodeliAkeneo, cdasec.CdaNewbornAkeneoID, labodeli.PointsCount, labodeli.MeasuringScaleTime
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 join AKUZ.T_CDA_SECTION_SCORES_LABODELI_AKENEO labodeli on cdasec.CdaSectionLabodeliAkeneo = labodeli.CdaSectionID
	 where cdasec.CdaSectionScoresLabodeliAkeneo is not null
update cda
set cda.CdaScoresLabodeliNewbornAkeneo = cda.CdaSectionScoresLabodeliAkeneo, cda.CdaSectionScoresLabodeliAkeneo = null
from akuz.T_CDA_APGAR_SCALE_NEWBORN_AKENEO cda
join akuz.T_CDA_SCORES_LABODELI_NEWBORN_AKENEO aa on aa.CdaScoresLabodeliNewbornAkeneoID = cda.CdaSectionScoresLabodeliAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_SERVICES_NEWBORN_AKENEO (CdaServicesNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionServicesAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionServicesAkeneo is not null
update cda
set cda.CdaServicesNewbornAkeneo = cda.CdaSectionServicesAkeneo, cda.CdaSectionServicesAkeneo = null
from akuz.T_CDA_SERVICE_AKENEO cda
join akuz.T_CDA_SERVICES_NEWBORN_AKENEO aa on aa.CdaServicesNewbornAkeneoID = cda.CdaSectionServicesAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_SUM_NEWBORN_AKENEO (CdaSumNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionSum, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionSum is not null
update cda
set cda.CdaSumNewbornAkeneo = cda.CdaSectionSum, cda.CdaSectionSum = null
from akuz.T_CDA_MEDICAMENT cda
join akuz.T_CDA_SUM_NEWBORN_AKENEO aa on aa.CdaSumNewbornAkeneoID = cda.CdaSectionSum
update cda
set cda.CdaSumNewbornAkeneo = cda.CdaSectionSum, CdaSectionSum = null
from akuz.T_CDA_NON_MEDICAMENT cda
join akuz.T_CDA_SUM_NEWBORN_AKENEO aa on aa.CdaSumNewbornAkeneoID = cda.CdaSectionSum
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_SUR_NEWBORN_AKENEO (CdaSurNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionSurAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionSurAkeneo is not null
update cda
set cda.CdaSurNewbornAkeneo = cda.CdaSectionSurAkeneo, cda.CdaSectionSurAkeneo = null
from akuz.T_CDA_OPERATION_AKENEO cda
join akuz.T_CDA_SUR_NEWBORN_AKENEO aa on aa.CdaSurNewbornAkeneoID = cda.CdaSectionSurAkeneo
-------------------------------------------------------------------------------------
INSERT INTO AKUZ.T_CDA_VITALPARAM_NEWBORN_AKENEO (CdaVitalparamNewbornAkeneoID, CdaNewbornAkeneo) 
select cdasec.CdaSectionVitalparamEpicrisisAkeneo, cdasec.CdaNewbornAkeneoID
     from AKUZ.T_CDA_NEWBORN_AKENEO cdasec
	 where cdasec.CdaSectionVitalparamEpicrisisAkeneo is not null
update cda
set cda.CdaVitalparamNewbornAkeneo = cda.CdaSectionVitalparamEpicrisisAkeneo, cda.CdaSectionVitalparamEpicrisisAkeneo = null
from akuz.T_CDA_VP_IN_SECTION_AKENEO cda
join akuz.T_CDA_VITALPARAM_NEWBORN_AKENEO aa on aa.CdaVitalparamNewbornAkeneoID = cda.CdaSectionVitalparamEpicrisisAkeneo
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionDgnAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionDgnAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_VimisSectionEpicrisisDepartments
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN VimisSectionEpicrisisDepartments
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_IMM_T_CDA_NEWBORN_AKENEO_CdaSectionImmAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionImmAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionAllAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionAllAkeneo
GO
------------------------------------------------------------------------------------- 
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionProcedureAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionProcedureAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionResconsAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionResconsAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionResinstrAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionResinstrAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionReslabMatherinityAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionReslabMatherinityAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_SCORES_LABODELI_AKENEO_T_CDA_NEWBORN_AKENEO_CdaSectionScoresLabodeliAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionScoresLabodeliAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionServicesAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionServicesAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionSum
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionSum
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionSurAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionSurAkeneo
GO
-------------------------------------------------------------------------------------
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_NEWBORN_AKENEO_CdaSectionVitalparamEpicrisisAkeneo
GO
ALTER TABLE AKUZ.T_CDA_NEWBORN_AKENEO DROP COLUMN CdaSectionVitalparamEpicrisisAkeneo
GO
