CREATE TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT
(
    "cdasectionspecimenscytexamelementid" uuid NOT NULL,
    "materialcount" decimal(31, 10) NULL,
    "ehrruss0jlhgtlbj" integer NULL,
    "materialdesc" varchar(1000) NOT NULL,
    "ehrrus72qgp117qf" integer NULL,
    "ehrrusnbpeonsbp4" integer NULL,
    "cdasectionspecimenscytexam" uuid NOT NULL
);

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT ADD CONSTRAINT PK_T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT
PRIMARY KEY (CdaSectionSpecimensCytExamElementID);

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT ADD CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_SECTION_SPECIMENS_CYT_EX_3B84B233
FOREIGN KEY("ehrruss0jlhgtlbj") REFERENCES EHR.T_EHR_RUS_S0JLHGTLBJ (EhrRusID);

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT ADD CONSTRAINT FK_T_EHR_RUS_72QGP117QF_T_CDA_SECTION_SPECIMENS_CYT_EX_B2A35361
FOREIGN KEY("ehrrus72qgp117qf") REFERENCES EHR.T_EHR_RUS_72QGP117QF (EhrRusID);

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT ADD CONSTRAINT FK_T_EHR_RUS_NBPEONSBP4_T_CDA_SECTION_SPECIMENS_CYT_EX_AA159DCD
FOREIGN KEY("ehrrusnbpeonsbp4") REFERENCES EHR.T_EHR_RUS_NBPEONSBP4 (EhrRusID);

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT ADD CONSTRAINT FK_T_CDA_SECTION_SPECIMENS_CYT_EXAM_T_CDA_SECTION_SPEC_D082F5CC
FOREIGN KEY("cdasectionspecimenscytexam") REFERENCES AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM (CdaSectionSpecimensCytExamID);

INSERT INTO akuz.T_CDA_SECTION_SPECIMENS_CYT_EXAM_ELEMENT
(
	CdaSectionSpecimensCytExamElementID,
	MaterialCount,
	EhrRusS0JLHGTLBJ, 
	MaterialDesc, 
	EhrRusNbpeonsbp4, 
	CdaSectionSpecimensCytExam
)
SELECT
    gen_random_uuid(), 
	exam.MaterialCount, 
	exam.EhrRusS0JLHGTLBJ, 
	exam.MaterialDesc, 
	exam.EhrRusNbpeonsbp4, 
	exam.CdaSectionSpecimensCytExamID
FROM akuz.t_CDA_SECTION_SPECIMENS_CYT_EXAM exam;

ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_SECTION_SPECIMENS_CYT_EX_9A93E073;
ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP CONSTRAINT FK_T_EHR_RUS_NBPEONSBP4_T_CDA_SECTION_SPECIMENS_CYT_EX_CAE590AD;
ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP COLUMN "materialcount";
ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP COLUMN "ehrruss0jlhgtlbj";
ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP COLUMN "materialdesc";
ALTER TABLE AKUZ.T_CDA_SECTION_SPECIMENS_CYT_EXAM DROP COLUMN "ehrrusnbpeonsbp4";


ALTER TABLE AKUZ.T_CDA_SECTION_DOCINFO_HEIGHTWORK DROP CONSTRAINT FK_T_EHR_RUS_PRP365_T_CDA_SECTION_DOCINFO_HEIGHTWORK_E_6CA258A4;
ALTER TABLE AKUZ.T_CDA_SECTION_DOCINFO_HEIGHTWORK ALTER COLUMN "ehrrusprp365" DROP NOT NULL;
ALTER TABLE AKUZ.T_CDA_SECTION_DOCINFO_HEIGHTWORK ADD CONSTRAINT FK_T_EHR_RUS_PRP365_T_CDA_SECTION_DOCINFO_HEIGHTWORK_E_6CA258A4
FOREIGN KEY("ehrrusprp365") REFERENCES EHR.T_EHR_RUS_PRP365 (EhrRusID);