-- Tables

/***** Object:  Table AKUZ.T_CHILDBIRTH_LINK_COMPLICATION *****/
CREATE TABLE AKUZ.T_CHILDBIRTH_LINK_COMPLICATION
(
    "childbirthlinkcomplicationid" uuid NOT NULL,
    "obstetrichospitalstage" uuid NULL,
    "ehrrusajc73fcbn6" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_CHILDBIRTH_LINK_COMPLICATION ADD CONSTRAINT PK_T_CHILDBIRTH_LINK_COMPLICATION
PRIMARY KEY (ChildbirthLinkComplicationID);

ALTER TABLE AKUZ.T_CHILDBIRTH_LINK_COMPLICATION ADD CONSTRAINT FK_T_OBSTETRIC_HOSPITAL_STAGE_T_CHILDBIRTH_LINK_COMPLI_7EB7C46B
FOREIGN KEY("obstetrichospitalstage") REFERENCES AKUZ.T_OBSTETRIC_HOSPITAL_STAGE (ObstetricHospitalStageID);

ALTER TABLE AKUZ.T_CHILDBIRTH_LINK_COMPLICATION ADD CONSTRAINT FK_T_EHR_RUS_AJC73FCBN6_T_CHILDBIRTH_LINK_COMPLICATION_9FD58972
FOREIGN KEY("ehrrusajc73fcbn6") REFERENCES EHR.T_EHR_RUS_AJC73FCBN6 (EhrRusID);



ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "address";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "registrationaddress";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "registrationaddressequals";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "painkillertype";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "multiplepregnancy";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "motherdischargedondaysafterbirth";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "peculiarities";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "partnerchildbirth";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "pregnancynumber";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "painkillerapplied";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "motherconditionatdischarging";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "gestationalage";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "motherpostpartumstage";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "pregnancytype";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "fio";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "painkillereffect";


ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "birthday";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "childbirthdate";

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION DROP COLUMN "conditionscale";


ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE DROP COLUMN "childbirthdate";

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE DROP CONSTRAINT FK_T_EHR_RUS_MDR308_T_OBSTETRIC_HOSPITAL_STAGE_EhrRusMdr308;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE DROP COLUMN "ehrrusmdr308";


ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "childbirthnumber" integer NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "pregnancytype" integer NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "laboractivitystart" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "anhydrousgapstart" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "fullopening" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "pushingperiodstart" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "afterbirthtime" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "totalbloodloss" integer NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "labordurationtotal" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "laborduration1" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "laborduration2" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "laborduration3" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "anhydrousperiod" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "afterbirthexaminedpost" bytea NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "finalmkb" varchar(255) NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "finaldiagnosis" varchar(255) NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "recorddate" timestamp NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "users" uuid NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD CONSTRAINT FK_T_USERS_T_OBSTETRIC_HOSPITAL_STAGE_Users
FOREIGN KEY("users") REFERENCES AKUZ.T_USERS (UserID);

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "post" bytea NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_HOSPITAL_STAGE ADD "waterdescription" varchar(255) NULL;


ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "lpumain" uuid NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "childnumber" integer NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD CONSTRAINT FK_T_LPU_MAIN_T_OBSTETRIC_NEWBORN_INFORMATION_LpuMain
FOREIGN KEY("lpumain") REFERENCES AKUZ.T_LPU_MAIN (LpuID);

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "extraconditionatbirth" varchar(255) NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "conditionatdischarging" varchar(255) NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "patient" uuid NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD CONSTRAINT FK_T_PATIENT_T_OBSTETRIC_NEWBORN_INFORMATION_Patient
FOREIGN KEY("patient") REFERENCES AKUZ.T_PATIENT (PatientID);

delete from AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD "childregistration" uuid NULL;

UPDATE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION SET "childregistration" = '00000000-0000-0000-0000-000000000000';

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ALTER COLUMN "childregistration" SET NOT NULL;

ALTER TABLE AKUZ.T_OBSTETRIC_NEWBORN_INFORMATION ADD CONSTRAINT FK_T_CHILD_REGISTRATION_T_OBSTETRIC_NEWBORN_INFORMATIO_3A61748F
FOREIGN KEY("childregistration") REFERENCES AKUZ.T_CHILD_REGISTRATION (MovementID);


ALTER TABLE AKUZ.T_CHILD_REGISTRATION ADD "mbcnumber" varchar(255) NULL;




