public static ClinicalDocument CreateDocument(string id, string title, CE code, ConfidentialityCodes confidentiality, Author author, Custodian custodian, RecordTarget recordTarget)
        {
            using (new ClinicalDocumentDesigner())
            {
                ClinicalDocument cda = new ClinicalDocument()
                {
                    Id = new II(id),
                    Code = code,
                    Confidentiality = confidentiality,
                    Title = new ST(title),
                    TypeId = new InfrastructureRootTypeId(TypeIdRoot, TypeIdExtension),
                    EffectiveTime = new TS(GetDateNow()),
                    Custodian = custodian,
                };

                cda.RealmCodes.Add(new CS(DefaultRealmCode));
                cda.Authors.Add(author);
                cda.RecordTargets.Add(recordTarget);

                return cda;
            }
        }
        public void CreateDocumentTest()
        {
            string title = "Test Document Title";
            string id = Guid.NewGuid().ToString();

            Author author = new Author(new II("20cf14fb-b65c-4c8c-a54d-b0cca834c18c"), DateTime.Now);
            RecordTarget recordTarget = new RecordTarget(new II("2.16.840.1.113883.19.5", "996-756-495"));
            Custodian custodian = new Custodian(new II("2.16.840.1.113883.19.5"), "Good Health Clinic");

            ClinicalDocument cda = null;

            using (new ClinicalDocumentDesigner())
            {
                cda = ClinicalDocumentFactory.CreateDocument(
                    id,
                    title,
                    new CE("34133-9", "2.16.840.1.113883.6.1", null, "Summarization of episode note"),
                    ConfidentialityCodes.Normal,
                    author,
                    custodian,
                    recordTarget);

                Act newAct = new Act(ActClassCodes.ACT, ActMoodCodes.EVN, new CE("1234", "2.16.840.1.113883.6.1"));
                Encounter newEncounter = new Encounter(EncounterMoodCodes.EVN);
                Observation newObservation = new Observation(ActClassObservationClassCodes.OBS, ObservationMoodCodes.EVN, new CD("1234", "2.16.840.1.113883.6.1"));
                ObservationMedia newObservationMedia = new ObservationMedia(new ED());
                Organizer newOrganizer = new Organizer(OrganizerClassCodes.BATTERY, new CS());
                Procedure newProcedure = new Procedure(ProcedureMoodCodes.EVN);
                RegionOfInterest newRegionOfInterest = new RegionOfInterest(new II(), RegionOfInterestCodes.CIRCLE, new RegionOfInterestvalue());
                SubstanceAdministration newSubstanceAdmin = new SubstanceAdministration(SubstanceMoodCodes.EVN,
                            new Consumable(
                                new ManufacturedProduct(
                                    new Material())));
                Supply newSupply = new Supply(SupplyClassCodes.SPLY, SubstanceMoodCodes.EVN);

                Section firstSection = new Section(
                    new CE("2342", "2.16.840.1.113883.6.1"),
                    new ST("Test section's title"));

                firstSection.AddEntries(
                    newAct,
                    newEncounter,
                    newObservation,
                    newObservationMedia,
                    newOrganizer,
                    newProcedure,
                    newRegionOfInterest,
                    newSubstanceAdmin,
                    newSupply);

                StructuredBody body = cda.AddStructuredBody(firstSection);
            }

            Assert.IsNotNull(cda.Title);
            Assert.IsNotNull(cda.Title.Text);
            Assert.AreEqual(1, cda.Title.Text.Length);
            Assert.AreEqual(title, cda.Title.Text[0]);
            Assert.AreEqual(ClinicalDocumentFactory.TypeIdRoot, cda.TypeId.Root);
            Assert.AreEqual(ClinicalDocumentFactory.TypeIdExtension, cda.TypeId.Extension);

            string xml = cda.GetXml();
            bool valid = Helper.ValidateCDA(xml);

            Assert.AreEqual(true, valid, "Expected CDA document to validate against the CDA schema");
        }