ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] ADD [NoIndications] bit NOT NULL CONSTRAINT [df_NoIndications] DEFAULT 0 WITH VALUES
ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] DROP CONSTRAINT [df_NoIndications]

ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] ADD [NoRestrictions] bit NOT NULL CONSTRAINT [df_NoRestrictions] DEFAULT 0 WITH VALUES
ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] DROP CONSTRAINT [df_NoRestrictions]

ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] ADD [NoContraindications] bit NOT NULL CONSTRAINT [df_NoContraindications] DEFAULT 0 WITH VALUES
ALTER TABLE [AKUZ].[T_CDA_SECTION_DRIVER_LICENSE_RESINFO] DROP CONSTRAINT [df_NoContraindications]

go

update resinfo
set NoIndications = 1
from akuz.t_CDA_SECTION_DRIVER_LICENSE_RESINFO resinfo
where not exists (
    select 1 from akuz.t_CDA_DRIVER_LICENSE_RESINFO_INDICATIONS_LINK indication 
where indication.CdaSectionDriverLicenseResinfo = resinfo.CdaSectionDriverLicenseResinfoID
)

update resinfo
set NoRestrictions = 1
from akuz.t_CDA_SECTION_DRIVER_LICENSE_RESINFO resinfo
where not exists (
    select 1 from akuz.t_CDA_DRIVER_LICENSE_RESINFO_RESTRICTIONS_LINK restriction 
    where restriction.CdaSectionDriverLicenseResinfo = resinfo.CdaSectionDriverLicenseResinfoID
)

update resinfo
set NoContraindications = case
    when ehr.IdEHR = 39 then 1 else 0 end
from akuz.t_CDA_SECTION_DRIVER_LICENSE_RESINFO resinfo
join akuz.t_CDA_DRIVER_LICENSE_RESINFO_CONCLUSION_LINK conclusion 
	on conclusion.CdaSectionDriverLicenseResinfo = resinfo.CdaSectionDriverLicenseResinfoID
join ehr.T_EHR_RUS_876TV2P893 ehr on ehr.EhrRusID = conclusion.EhrRus876TV2P893
