CREATE TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW
(
    "medicalrecordid" uuid NOT NULL,
    "motheraddress" uuid NULL,
    "docseries" varchar(255) NOT NULL,
    "documentnumber" varchar(255) NOT NULL,
    "executedate" timestamp NULL,
    "presenceelectdoc" boolean NULL,
    "ehrrus6cm4779hld" uuid NOT NULL,
    "motherfirstname" varchar(255) NULL,
    "motherlastname" varchar(255) NULL,
    "motherfathname" varchar(255) NULL,
    "motherbirthday" timestamp NULL,
    "departmentcode" varchar(255) NULL,
    "ehrrusjjd6fhfvqc" uuid NOT NULL,
    "ehrrussrml41u2ge" uuid NOT NULL,
    "ehrrusnn5meatu5t" uuid NOT NULL,
    "omspolicy" varchar(255) NULL,
    "birthcount" integer NULL,
    "issuedby" varchar(255) NOT NULL,
    "issuedate" timestamp NULL,
    "ehrrusprk438" uuid NULL,
    "firstcontactdate" integer NOT NULL,
    "ehrrusanhco4hvbo" uuid NOT NULL,
    "childbirthpost" uuid NULL,
    "ehrrusnoterddv83" uuid NOT NULL,
    "childcount" integer NOT NULL,
    "ehrrus2pgin0j8k4" uuid NOT NULL,
    "termofdelivery" integer NULL,
    "childbirthday" timestamp NOT NULL,
    "childtimebirthday" varchar(255) NOT NULL,
    "childname" varchar(255) NULL,
    "childfamilyname" varchar(255) NOT NULL,
    "childsecondname" varchar(255) NULL,
    "childcountinfamily" integer NOT NULL,
    "childcountindelivery" integer NOT NULL,
    "ehrrusprk438child" uuid NOT NULL,
    "birthmass" integer NOT NULL,
    "sex" integer NOT NULL,
    "birthheight" integer NOT NULL,
    "patientaddress" uuid NULL,
    "snils" varchar(255) NULL,
    "ehrrus7c1skgluah" uuid NOT NULL,
    "receivingdate" timestamp NOT NULL,
    "licensedate" timestamp NOT NULL,
    "licensenumber" varchar(255) NULL,
    "republicregion" varchar(255) NULL,
    "rajon" varchar(255) NULL,
    "city" varchar(255) NULL,
    "ismother" boolean NULL,
    "namerec" varchar(255) NULL,
    "surnamerec" varchar(255) NULL,
    "patronymicrec" varchar(255) NULL,
    "ehrrusnn5meatu5trec" uuid NULL,
    "recdocseries" varchar(255) NOT NULL,
    "recdocnumber" varchar(255) NOT NULL,
    "recissue" varchar(255) NULL,
    "recissuedate" timestamp NULL,
    "motherseries" varchar(255) NOT NULL,
    "mothernumber" varchar(255) NOT NULL,
    "recdepartmentcode" varchar(255) NULL
);

-- Alters

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT PK_T_BIRTH_CERTIFICATE_NEW
PRIMARY KEY (MedicalRecordID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_AMBULANCE_CARD_RECORD_T_BIRTH_CERTIFICATE_NEW_MedicalRecordID
FOREIGN KEY("medicalrecordid") REFERENCES AKUZ.T_AMBULANCE_CARD_RECORD (MedicalRecordID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_PATIENT_ADDRESS_T_BIRTH_CERTIFICATE_NEW_MotherAddress
FOREIGN KEY("motheraddress") REFERENCES AKUZ.T_PATIENT_ADDRESS (AddressID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRus6cm4779hld
FOREIGN KEY("ehrrus6cm4779hld") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRusJjd6fhfvqc
FOREIGN KEY("ehrrusjjd6fhfvqc") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_SRML41U2GE_T_BIRTH_CERTIFICATE_NEW_EhrRusSrml41u2ge
FOREIGN KEY("ehrrussrml41u2ge") REFERENCES EHR.T_EHR_RUS_SRML41U2GE (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_NN5MEATU5T_T_BIRTH_CERTIFICATE_NEW_EhrRusNn5meatu5t
FOREIGN KEY("ehrrusnn5meatu5t") REFERENCES EHR.T_EHR_RUS_NN5MEATU5T (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRusPrk438
FOREIGN KEY("ehrrusprk438") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_ANHCO4HVBO_T_BIRTH_CERTIFICATE_NEW_EhrRusAnhco4hvbo
FOREIGN KEY("ehrrusanhco4hvbo") REFERENCES EHR.T_EHR_RUS_ANHCO4HVBO (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_POST_T_BIRTH_CERTIFICATE_NEW_ChildbirthPost
FOREIGN KEY("childbirthpost") REFERENCES AKUZ.T_POST (ResourceID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRusNoterddv83
FOREIGN KEY("ehrrusnoterddv83") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRus2pgin0j8k4
FOREIGN KEY("ehrrus2pgin0j8k4") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRusPrk438Child
FOREIGN KEY("ehrrusprk438child") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_ENUMS_T_BIRTH_CERTIFICATE_NEW_Sex
FOREIGN KEY("sex") REFERENCES VCLib.T_ENUMS (EnumID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_PATIENT_ADDRESS_T_BIRTH_CERTIFICATE_NEW_PatientAddress
FOREIGN KEY("patientaddress") REFERENCES AKUZ.T_PATIENT_ADDRESS (AddressID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_T_BIRTH_CERTIFICATE_NEW_EhrRus7c1skgluah
FOREIGN KEY("ehrrus7c1skgluah") REFERENCES EHR.T_EHR_RUS (EhrRusID);

ALTER TABLE AKUZ.T_BIRTH_CERTIFICATE_NEW ADD CONSTRAINT FK_T_EHR_RUS_NN5MEATU5T_T_BIRTH_CERTIFICATE_NEW_EhrRusNn5meatu5tRec
FOREIGN KEY("ehrrusnn5meatu5trec") REFERENCES EHR.T_EHR_RUS_NN5MEATU5T (EhrRusID);
