DROP TABLE AKUZ.T_CDA_SECTION_LINKED_DOC_VMP;
DROP TABLE AKUZ.T_CDA_DOC_RELATED_DETAIL;
-- Tables

/***** Object:  Table AKUZ.T_CDA_DOC_RELATED_DETAIL *****/
CREATE TABLE AKUZ.T_CDA_DOC_RELATED_DETAIL
(
    "refmisdoc" varchar(255) NOT NULL,
    "documenttype" uuid NOT NULL,
    "documentremark" varchar(255) NULL,
    "docissuedate" timestamp NOT NULL,
    "documentnumber" varchar(255) NOT NULL,
    "refmisdocext" varchar(255) NULL,
    "cdasectionrelateddoc" uuid NULL,
    "cdadocrelateddetailid" uuid NOT NULL
);

-- Alters

ALTER TABLE AKUZ.T_CDA_DOC_RELATED_DETAIL ADD CONSTRAINT PK_T_CDA_DOC_RELATED_DETAIL
PRIMARY KEY (CdaDocRelatedDetailID);

ALTER TABLE AKUZ.T_CDA_DOC_RELATED_DETAIL ADD CONSTRAINT FK_T_EHR_RUS_SLM365_T_CDA_DOC_RELATED_DETAIL_DocumentType
FOREIGN KEY("documenttype") REFERENCES EHR.T_EHR_RUS_SLM365 (EhrRusID);

ALTER TABLE AKUZ.T_CDA_DOC_RELATED_DETAIL ADD CONSTRAINT FK_T_CDA_SECTION_T_CDA_DOC_RELATED_DETAIL_CdaSectionRelatedDoc
FOREIGN KEY("cdasectionrelateddoc") REFERENCES AKUZ.T_CDA_SECTION (CdaSectionID);

