-- Tables

/***** Object:  Table AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD *****/
CREATE TABLE AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD
(
    "medicalrecordid" uuid NOT NULL,
    "mkbcode" varchar(255) NOT NULL,
    "diagnosis" varchar(255) NULL,
    "patient" uuid NULL,
    "emergencynotificationnumber" integer NULL,
    "emergencynotificationdate" timestamp NULL,
    "emergencysenderpost" integer NULL,
    "emergencyrecipientpost" varchar(255) NULL,
    "detectiondate" timestamp NULL,
    "detectionplace" varchar(255) NULL,
    "foreigner" boolean NOT NULL,
    "comefrom" varchar(255) NULL,
    "previousinfectiousdisease" integer NULL,
    "othervaccinations" varchar(512) NULL,
    "rash" boolean NOT NULL,
    "rashcharacteristic" integer NULL,
    "rashappearancedate" timestamp NULL,
    "rashdatedoesntremember" boolean NOT NULL,
    "rashduration" integer NULL,
    "rashfirstplace" integer NULL,
    "otherrashfirstplace" varchar(255) NULL,
    "rashstageappearance" boolean NOT NULL,
    "suscontact" integer NULL,
    "suscontactplace" integer NULL,
    "suscontactotherplace" varchar(255) NULL,
    "suscontactaround" integer NULL,
    "travelanywherebeforerash" integer NULL,
    "travelwhere" varchar(255) NULL,
    "importedcase" integer NULL,
    "country" uuid NULL,
    "region" uuid NULL,
    "lymphadenopathy" boolean NOT NULL,
    "arthralgia" boolean NOT NULL,
    "lymphnodesenlargement" boolean NOT NULL,
    "lymphnodesplace" integer NULL,
    "temprise" integer NULL,
    "temprisedate" timestamp NULL,
    "maxtemprise" integer NULL,
    "maxtempriselast" integer NULL,
    "cough" integer NULL,
    "rhinitis" integer NULL,
    "conjunctivitis" integer NULL,
    "kopliksspots" integer NULL,
    "enantheme" integer NULL,
    "pigmentation" integer NULL,
    "postoperativewound" boolean NOT NULL,
    "postoperativewoundinfo" varchar(255) NULL,
    "catheters" boolean NOT NULL,
    "cathetersinfo" varchar(255) NULL,
    "antimicrobialtherapy" boolean NOT NULL,
    "additionalinfo" varchar(4096) NULL
);

-- Alters

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD ADD CONSTRAINT PK_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD
PRIMARY KEY (MedicalRecordID);

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

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

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD ADD CONSTRAINT FK_T_POST_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_Emergen_D38461E6
FOREIGN KEY("emergencysenderpost") REFERENCES AKUZ.T_POST (ResourceID);

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD ADD CONSTRAINT FK_T_COUNTRY_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_Country
FOREIGN KEY("country") REFERENCES AKUZ.T_COUNTRY (CountryID);

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD ADD CONSTRAINT FK_T_REGION_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_Region
FOREIGN KEY("region") REFERENCES AKUZ.T_REGION (RegionID);

-- Tables

/***** Object:  Table AKUZ.T_ANTIMICROBIAL_THERAPY *****/
CREATE TABLE AKUZ.T_ANTIMICROBIAL_THERAPY
(
    "antimicrobialtherapyid" uuid NOT NULL,
    "appointmentdate" timestamp NOT NULL,
    "epidemiologicalinvestigationcard" uuid NOT NULL,
    "dose" varchar(255) NULL,
    "frequency" varchar(255) NULL,
    "billofgoods" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_ANTIMICROBIAL_THERAPY ADD CONSTRAINT PK_T_ANTIMICROBIAL_THERAPY
PRIMARY KEY (AntimicrobialTherapyID);

ALTER TABLE AKUZ.T_ANTIMICROBIAL_THERAPY ADD CONSTRAINT FK_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_T_ANTIMICROBIA_694FF168
FOREIGN KEY("epidemiologicalinvestigationcard") REFERENCES AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD (MedicalRecordID);

ALTER TABLE AKUZ.T_ANTIMICROBIAL_THERAPY ADD CONSTRAINT FK_T_BILL_OF_GOODS_T_ANTIMICROBIAL_THERAPY_BillOfGoods
FOREIGN KEY("billofgoods") REFERENCES PHARM.T_BILL_OF_GOODS (BillOfGoodsID);

-- Tables

/***** Object:  Table AKUZ.T_EPIDEMIOLOGICAL_VACCINATION_INFO *****/
CREATE TABLE AKUZ.T_EPIDEMIOLOGICAL_VACCINATION_INFO
(
    "epidemiologicalvaccinationinfohistoryid" uuid NOT NULL,
    "vaccinationdate" timestamp NOT NULL,
    "vaccinelibrary" uuid NOT NULL,
    "recorddate" timestamp NULL,
    "epidemiologicalinvestigationcard" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_VACCINATION_INFO ADD CONSTRAINT PK_T_EPIDEMIOLOGICAL_VACCINATION_INFO
PRIMARY KEY (EpidemiologicalVaccinationInfoHistoryID);

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_VACCINATION_INFO ADD CONSTRAINT FK_T_VACCINE_LIBRARY_T_EPIDEMIOLOGICAL_VACCINATION_INF_3053C4B0
FOREIGN KEY("vaccinelibrary") REFERENCES AKUZ.T_VACCINE_LIBRARY (VaccineLibraryID);

ALTER TABLE AKUZ.T_EPIDEMIOLOGICAL_VACCINATION_INFO ADD CONSTRAINT FK_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_T_EPIDEMIOLOGI_1594ED96
FOREIGN KEY("epidemiologicalinvestigationcard") REFERENCES AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD (MedicalRecordID);

-- Tables

/***** Object:  Table AKUZ.T_MICROBIOLOGICAL_RESEARCH *****/
CREATE TABLE AKUZ.T_MICROBIOLOGICAL_RESEARCH
(
    "microbiologicalresearchid" uuid NOT NULL,
    "biomaterialtakingdate" timestamp NOT NULL,
    "ehrrusnbpeonsbp4" integer NOT NULL,
    "result" integer NOT NULL,
    "resultinfo" varchar(255) NULL,
    "cgiedate" timestamp NULL,
    "rcdate" timestamp NULL,
    "epidemiologicalinvestigationcard" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_MICROBIOLOGICAL_RESEARCH ADD CONSTRAINT PK_T_MICROBIOLOGICAL_RESEARCH
PRIMARY KEY (MicrobiologicalResearchID);

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

ALTER TABLE AKUZ.T_MICROBIOLOGICAL_RESEARCH ADD CONSTRAINT FK_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_T_MICROBIOLOGI_044B77B1
FOREIGN KEY("epidemiologicalinvestigationcard") REFERENCES AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD (MedicalRecordID);

-- Tables

/***** Object:  Table AKUZ.T_PAST_INFECTIOUS_DISEASE *****/
CREATE TABLE AKUZ.T_PAST_INFECTIOUS_DISEASE
(
    "pastinfectiousdiseaseid" uuid NOT NULL,
    "mkbcode" varchar(255) NULL,
    "diagnosis" varchar(255) NULL,
    "diseasedate" timestamp NULL,
    "doesntremember" boolean NOT NULL,
    "comment" varchar(255) NULL,
    "epidemiologicalinvestigationcard" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_PAST_INFECTIOUS_DISEASE ADD CONSTRAINT PK_T_PAST_INFECTIOUS_DISEASE
PRIMARY KEY (PastInfectiousDiseaseID);

ALTER TABLE AKUZ.T_PAST_INFECTIOUS_DISEASE ADD CONSTRAINT FK_T_EPIDEMIOLOGICAL_INVESTIGATION_CARD_T_PAST_INFECTI_5DA10183
FOREIGN KEY("epidemiologicalinvestigationcard") REFERENCES AKUZ.T_EPIDEMIOLOGICAL_INVESTIGATION_CARD (MedicalRecordID);

-- Tables

-- Alters

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencynotificationnumber" integer NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencynotificationdate" timestamp NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencysenderpost" integer NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencyrecipientpost" varchar(255) NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencydiseasedate" timestamp NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencyoutcome" integer NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "emergencyadditionalinfo" varchar(255) NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "schoollastvisit" varchar(255) NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "epidnumber" varchar(255) NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "regnumber" integer NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD "uzrn" varchar(255) NULL;

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD CONSTRAINT FK_T_POST_T_PREPARE_DATA_HOSPITALISATION_EmergencySenderPost
FOREIGN KEY("emergencysenderpost") REFERENCES AKUZ.T_POST (ResourceID);

ALTER TABLE AKUZ.T_PREPARE_DATA_HOSPITALISATION ADD CONSTRAINT FK_T_EHR_RUS_C43006_T_PREPARE_DATA_HOSPITALISATION_Eme_603D8653
FOREIGN KEY("emergencyoutcome") REFERENCES EHR.T_EHR_RUS_C43006 (EhrRusID);

