-- Tables

/***** Object:  Table AKUZ.T_CDA_COMMERCIAL_RECIPE *****/
CREATE TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE
(
    "cdacommercialrecipeid" uuid NOT NULL,
    "ehrruss0jlhgtlbj" uuid NULL,
    "ehrrusd4u765t5th" uuid NULL,
    "ehrrus9a9g09e8kl" uuid NULL,
    "ehrruss0jlhgtlbj_1" uuid NULL,
    "ehrrus6kiqts8t99" uuid NULL,
    "ehrruss0jlhgtlbj_2" uuid NOT NULL,
    "consumeinstruction" varchar(255) NULL,
    "consumingduration" varchar(255) NULL,
    "numberofdoses" integer NOT NULL,
    "frequencyofreception" decimal(12, 2) NULL,
    "doseperconsume" decimal(12, 2) NULL,
    "institutionspecified" boolean NULL,
    "cdasectioncommercialrecipe" uuid NULL,
    "ehrrusje1hcqeueh" uuid NULL,
    "ehrruss0jlhgtlbj_3" uuid NULL,
    "frequencyofdispensing" integer NULL,
    "numberofdispence" integer NULL,
    "ehrruss0jlhgtlbj_4" uuid NULL,
    "institutionspectifiedfordispencing" boolean NULL,
    "ehrrus575vsf88og" uuid NULL
);

-- Alters

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT PK_T_CDA_COMMERCIAL_RECIPE
PRIMARY KEY (CdaCommercialRecipeID);

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

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_D4U765T5TH_T_CDA_COMMERCIAL_RECIPE_EhrRus_2FDC99C5
FOREIGN KEY("ehrrusd4u765t5th") REFERENCES EHR.T_EHR_RUS_D4U765T5TH (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_9A9G09E8KL_T_CDA_COMMERCIAL_RECIPE_EhrRus_EAEB8B20
FOREIGN KEY("ehrrus9a9g09e8kl") REFERENCES EHR.T_EHR_RUS_9A9G09E8KL (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_COMMERCIAL_RECIPE_EhrRus_623BD5E5
FOREIGN KEY("ehrruss0jlhgtlbj_1") REFERENCES EHR.T_EHR_RUS_S0JLHGTLBJ (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_6KIQTS8T99_T_CDA_COMMERCIAL_RECIPE_EhrRus_5FF473B2
FOREIGN KEY("ehrrus6kiqts8t99") REFERENCES EHR.T_EHR_RUS_6KIQTS8T99 (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_COMMERCIAL_RECIPE_EhrRus_FB32845F
FOREIGN KEY("ehrruss0jlhgtlbj_2") REFERENCES EHR.T_EHR_RUS_S0JLHGTLBJ (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_CDA_SECTION_T_CDA_COMMERCIAL_RECIPE_CdaSectionCom_B0008D29
FOREIGN KEY("cdasectioncommercialrecipe") REFERENCES AKUZ.T_CDA_SECTION (CdaSectionID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_JE1HCQEUEH_T_CDA_COMMERCIAL_RECIPE_EhrRus_CD9E166A
FOREIGN KEY("ehrrusje1hcqeueh") REFERENCES EHR.T_EHR_RUS_JE1HCQEUEH (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_COMMERCIAL_RECIPE_EhrRus_8C35B4C9
FOREIGN KEY("ehrruss0jlhgtlbj_3") REFERENCES EHR.T_EHR_RUS_S0JLHGTLBJ (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_S0JLHGTLBJ_T_CDA_COMMERCIAL_RECIPE_EhrRus_1251216A
FOREIGN KEY("ehrruss0jlhgtlbj_4") REFERENCES EHR.T_EHR_RUS_S0JLHGTLBJ (EhrRusID);

ALTER TABLE AKUZ.T_CDA_COMMERCIAL_RECIPE ADD CONSTRAINT FK_T_EHR_RUS_575VSF88OG_T_CDA_COMMERCIAL_RECIPE_EhrRus_53B19645
FOREIGN KEY("ehrrus575vsf88og") REFERENCES EHR.T_EHR_RUS_575VSF88OG (EhrRusID);


-------перенос данных


ALTER TABLE AKUZ.T_CDA_SECTION_RECIPE DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_SECTION_RECIPE_CdaSectionCommer_441300F5;

ALTER TABLE AKUZ.T_CDA_SECTION_RECIPE DROP COLUMN "cdasectioncommercialrecipe";


-------удаление парента на коммерческий рецепт в T_CDA_SECTION_RECIPE
drop index IX_T_CDA_SECTION_RECIPE_CdaSectionCommercialRecipe;
ALTER TABLE AKUZ.T_CDA_SECTION_RECIPE DROP CONSTRAINT FK_T_CDA_SECTION_T_CDA_SECTION_RECIPE_CdaSectionCommer_441300F5;
ALTER TABLE AKUZ.T_CDA_SECTION_RECIPE DROP COLUMN "cdasectioncommercialrecipe";

