public void GetImplementationGuideVocabulary_Valueset3()
        {
            Template           t  = this.tdb.CreateTemplate("1.2.3.4.5", "Document", "Test Template 1", this.ig);
            TemplateConstraint tc = this.tdb.AddConstraintToTemplate(t, null, null, "code", "SHALL", "1..1", valueConformance: "SHALL", valueSet: this.vs3);

            tc.IsStatic = true;

            NativeTerminologyExporter exporter = new NativeTerminologyExporter(this.tdb);

            byte[]      export = exporter.GetExport(ig.Id, 0, Encoding.UTF8);
            string      vocXml = Encoding.UTF8.GetString(export);
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(vocXml);

            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);

            nsManager.AddNamespace("voc", "http://www.lantanagroup.com/voc");

            Assert.AreEqual("systems", doc.DocumentElement.LocalName);
            Assert.AreEqual(1, doc.DocumentElement.ChildNodes.Count);

            XmlElement exportValueSet = doc.DocumentElement.ChildNodes[0] as XmlElement;

            Assert.AreEqual(4, exportValueSet.ChildNodes.Count);
            Assert.IsNotNull(exportValueSet.SelectSingleNode("voc:code[@value='1']", nsManager));
            Assert.IsNotNull(exportValueSet.SelectSingleNode("voc:code[@value='2']", nsManager));
            Assert.IsNotNull(exportValueSet.SelectSingleNode("voc:code[@value='4']", nsManager));
            Assert.IsNotNull(exportValueSet.SelectSingleNode("voc:code[@value='5']", nsManager));
        }
        public void GetImplementationGuideVocabulary_NoStaticValuesets()
        {
            Template           t  = this.tdb.CreateTemplate("1.2.3.4.5", "Document", "Test Template 1", this.ig);
            TemplateConstraint tc = this.tdb.AddConstraintToTemplate(t, null, null, "code", "SHALL", "1..1", valueConformance: "SHALL", valueSet: this.vs1);

            tc.IsStatic = false;

            NativeTerminologyExporter exporter = new NativeTerminologyExporter(this.tdb);

            byte[]      export = exporter.GetExport(ig.Id, 0, Encoding.UTF8, true);
            string      vocXml = Encoding.UTF8.GetString(export);
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(vocXml);

            Assert.AreEqual("systems", doc.DocumentElement.LocalName);
            Assert.AreEqual(0, doc.DocumentElement.ChildNodes.Count);
        }
Esempio n. 3
0
        public HttpResponseMessage Export(ExportSettingsModel model)
        {
            ImplementationGuide ig = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == model.ImplementationGuideId);

            if (model.TemplateIds == null)
            {
                model.TemplateIds = ig.GetRecursiveTemplates(this.tdb, categories: model.SelectedCategories.ToArray()).Select(y => y.Id).ToList();
            }

            List <Template>   templates    = this.tdb.Templates.Where(y => model.TemplateIds.Contains(y.Id)).ToList();
            SimpleSchema      schema       = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, ig.ImplementationGuideType);
            IIGTypePlugin     igTypePlugin = IGTypePluginFactory.GetPlugin(ig.ImplementationGuideType);
            IGSettingsManager igSettings   = new IGSettingsManager(this.tdb, model.ImplementationGuideId);
            bool   isCDA = ig.ImplementationGuideType.SchemaURI == "urn:hl7-org:v3";
            string fileName;

            byte[] export;
            string contentType = null;

            switch (model.ExportFormat)
            {
            case ExportFormats.FHIR_Build_Package:
            case ExportFormats.FHIR_Bundle:
            case ExportFormats.Native_XML:
            case ExportFormats.Templates_DSTU_XML:
                string fileExtension = model.ReturnJson ? "json" : "xml";
                contentType = model.ReturnJson ? JSON_MIME_TYPE : XML_MIME_TYPE;

                if (model.ExportFormat == ExportFormats.FHIR_Build_Package)
                {
                    fileExtension = "zip";
                    contentType   = ZIP_MIME_TYPE;
                }

                fileName = string.Format("{0}.{1}", ig.GetDisplayName(true), fileExtension);
                var pluginExporter = igTypePlugin.GetExporter();
                export = pluginExporter.Export(this.tdb, schema, model.ExportFormat, igSettings, model.SelectedCategories, templates, model.IncludeVocabulary, model.ReturnJson);
                break;

            case ExportFormats.Snapshot_JSON:
                ImplementationGuideController ctrl = new ImplementationGuideController(this.tdb);
                var dataModel = ctrl.GetViewData(model.ImplementationGuideId, null, null, true);

                // Serialize the data to JSON
                var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                jsonSerializer.MaxJsonLength = Int32.MaxValue;
                export = System.Text.Encoding.UTF8.GetBytes(jsonSerializer.Serialize(dataModel));

                // Set the filename to JSON
                fileName    = string.Format("{0}.json", ig.GetDisplayName(true));
                contentType = JSON_MIME_TYPE;
                break;

            case ExportFormats.Microsoft_Word_DOCX:
                ImplementationGuideGenerator generator = new ImplementationGuideGenerator(this.tdb, model.ImplementationGuideId, model.TemplateIds);
                fileName = string.Format("{0}.docx", ig.GetDisplayName(true));

                ExportSettings lConfig = new ExportSettings();
                lConfig.Use(c =>
                {
                    c.GenerateTemplateConstraintTable = model.TemplateTables == TemplateTableOptions.ConstraintOverview || model.TemplateTables == TemplateTableOptions.Both;
                    c.GenerateTemplateContextTable    = model.TemplateTables == TemplateTableOptions.Context || model.TemplateTables == TemplateTableOptions.Both;
                    c.GenerateDocTemplateListTable    = model.DocumentTables == DocumentTableOptions.List || model.DocumentTables == DocumentTableOptions.Both;
                    c.GenerateDocContainmentTable     = model.DocumentTables == DocumentTableOptions.Containment || model.DocumentTables == DocumentTableOptions.Both;
                    c.AlphaHierarchicalOrder          = model.TemplateSortOrder == TemplateSortOrderOptions.AlphaHierarchically;
                    c.DefaultValueSetMaxMembers       = model.ValueSetTables ? model.MaximumValueSetMembers : 0;
                    c.GenerateValueSetAppendix        = model.ValueSetAppendix;
                    c.IncludeXmlSamples     = model.IncludeXmlSample;
                    c.IncludeChangeList     = model.IncludeChangeList;
                    c.IncludeTemplateStatus = model.IncludeTemplateStatus;
                    c.IncludeNotes          = model.IncludeNotes;
                    c.IncludeVolume1        = model.IncludeVolume1;
                    c.SelectedCategories    = model.SelectedCategories;
                    c.GenerateRequiredAndOptionalSectionsTable = model.GenerateRequiredAndOptionalSectionsTable;
                    c.DocumentTemplateTypeId = model.DocumentTemplateTypeId;
                    c.SectionTemplateTypeId  = model.SectionTemplateTypeId;
                });

                if (model.ValueSetOid != null && model.ValueSetOid.Count > 0)
                {
                    Dictionary <string, int> valueSetMemberMaximums = new Dictionary <string, int>();

                    for (int i = 0; i < model.ValueSetOid.Count; i++)
                    {
                        if (valueSetMemberMaximums.ContainsKey(model.ValueSetOid[i]))
                        {
                            continue;
                        }

                        valueSetMemberMaximums.Add(model.ValueSetOid[i], model.ValueSetMaxMembers[i]);
                    }

                    lConfig.ValueSetMaxMembers = valueSetMemberMaximums;
                }

                generator.BuildImplementationGuide(lConfig, ig.ImplementationGuideType.GetPlugin());
                export      = generator.GetDocument();
                contentType = DOCX_MIME_TYPE;
                break;

            case ExportFormats.Schematron_SCH:
                string schematronResult = SchematronGenerator.Generate(tdb, ig, model.IncludeCustomSchematron, VocabularyOutputType.Default, model.VocabularyFileName, templates, model.SelectedCategories, model.DefaultSchematron);
                export      = ASCIIEncoding.UTF8.GetBytes(schematronResult);
                fileName    = string.Format("{0}.sch", ig.GetDisplayName(true));
                contentType = XML_MIME_TYPE;

                if (model.IncludeVocabulary)
                {
                    using (ZipFile zip = new ZipFile())
                    {
                        zip.AddEntry(fileName, export);

                        NativeTerminologyExporter nativeTermExporter = new NativeTerminologyExporter(this.tdb);
                        byte[] vocData     = nativeTermExporter.GetExport(ig.Id, model.MaximumValueSetMembers, this.GetExportEncoding(model));
                        string vocFileName = string.Format("{0}", model.VocabularyFileName);

                        //Ensuring the extension is present in case input doesn't have it
                        if (vocFileName.IndexOf(".xml") == -1)
                        {
                            vocFileName += ".xml";
                        }

                        zip.AddEntry(vocFileName, vocData);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            zip.Save(ms);

                            fileName    = string.Format("{0}.zip", ig.GetDisplayName(true));
                            contentType = ZIP_MIME_TYPE;
                            export      = ms.ToArray();
                        }
                    }
                }
                break;

            case ExportFormats.Vocabulary_XLSX:
                fileName    = string.Format("{0}.xlsx", ig.GetDisplayName(true));
                contentType = XLSX_MIME_TYPE;

                ExcelExporter excelExporter = new ExcelExporter(this.tdb);
                export = excelExporter.GetSpreadsheet(ig.Id, model.MaximumValueSetMembers);

                break;

            case ExportFormats.Vocbulary_Single_SVS_XML:
                fileName    = string.Format("{0}_SingleSVS.xml", ig.GetDisplayName(true));
                contentType = XML_MIME_TYPE;

                SingleSVSExporter ssvsExporter = new SingleSVSExporter(this.tdb);
                export = ssvsExporter.GetExport(ig.Id, model.MaximumValueSetMembers, this.GetExportEncoding(model));

                break;

            case ExportFormats.Vocabulary_Multiple_SVS_XML:
                fileName    = string.Format("{0}_MultipleSVS.xml", ig.GetDisplayName(true));
                contentType = XML_MIME_TYPE;

                MultipleSVSExporter msvsExporter = new MultipleSVSExporter(this.tdb);
                export = msvsExporter.GetExport(ig.Id, model.MaximumValueSetMembers, this.GetExportEncoding(model));

                break;

            case ExportFormats.Vocabulary_Native_XML:
                fileName    = string.Format("{0}_MultipleSVS.xml", ig.GetDisplayName(true));
                contentType = XML_MIME_TYPE;

                NativeTerminologyExporter nativeExporter = new NativeTerminologyExporter(this.tdb);
                export = nativeExporter.GetExport(ig.Id, model.MaximumValueSetMembers, this.GetExportEncoding(model));

                break;

            case ExportFormats.Web_HTML:
                // Get the data from the API controller
                HtmlExporter exporter      = new HtmlExporter(this.tdb);
                var          templateIds   = templates.Select(y => y.Id).ToArray();
                var          htmlDataModel = exporter.GetExportData(ig.Id, null, templateIds, model.IncludeInferred);

                IGController igController    = new IGController(this.tdb);
                var          downloadPackage = igController.GetDownloadPackage(ig, JsonConvert.SerializeObject(htmlDataModel));

                export      = downloadPackage.Content;
                fileName    = downloadPackage.FileName;
                contentType = ZIP_MIME_TYPE;
                break;

            case ExportFormats.Vocbulary_Bundle_FHIR_XML:
                ValueSetExporter vsExporter = new ValueSetExporter(this.tdb);
                var bundle = vsExporter.GetImplementationGuideValueSets(ig);

                if (model.ReturnJson)
                {
                    export      = fhir_stu3.Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJsonBytes(bundle);
                    fileName    = string.Format("{0}_fhir_voc.json", ig.GetDisplayName(true));
                    contentType = JSON_MIME_TYPE;
                }
                else
                {
                    export      = fhir_stu3.Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXmlBytes(bundle);
                    fileName    = string.Format("{0}_fhir_voc.xml", ig.GetDisplayName(true));
                    contentType = XML_MIME_TYPE;
                }

                break;

            default:
                throw new NotSupportedException();
            }

            return(GetExportResponse(fileName, contentType, export));
        }