ALTER TABLE AKUZ.T_UNDERAGE_EXAMINATION ADD "healthgoodbefore" boolean NULL;

update AKUZ.T_UNDERAGE_EXAMINATION ue
set HealthGoodBefore = true
where not exists
(
	select *
	from AKUZ.T_EXAMINATION_DIAGNOSIS_BEFORE edb
	inner join AKUZ.T_EXAMINATION_DIAGNOSIS ed
		on ed.ExaminationDiagnosisID = edb.ExaminationDiagnosisID
		and ed.UnderageExamination = ue.MedicalRecordID
);

update AKUZ.T_UNDERAGE_EXAMINATION
set HealthGoodBefore = false
where HealthGoodBefore is null;

ALTER TABLE AKUZ.T_UNDERAGE_EXAMINATION ALTER COLUMN "healthgoodbefore" SET NOT NULL;

ALTER TABLE AKUZ.T_UNDERAGE_EXAMINATION ADD "healthgoodafter" boolean NULL;

update AKUZ.T_UNDERAGE_EXAMINATION ue
set HealthGoodAfter = true
where not exists
(
	select *
	from AKUZ.T_EXAMINATION_DIAGNOSIS_AFTER eda
	inner join AKUZ.T_EXAMINATION_DIAGNOSIS ed
		on ed.ExaminationDiagnosisID = eda.ExaminationDiagnosisID
		and ed.UnderageExamination = ue.MedicalRecordID
);

update AKUZ.T_UNDERAGE_EXAMINATION
set HealthGoodAfter = false
where HealthGoodAfter is null;

ALTER TABLE AKUZ.T_UNDERAGE_EXAMINATION ALTER COLUMN "healthgoodafter" SET NOT NULL;