Пример #1
0
        public HttpResponseMessage UpdateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri] int valueSetId,
            [FromUri(Name = "_format")] string format = null)
        {
            ValueSetExporter exporter         = new ValueSetExporter(this.tdb);
            ValueSetImporter importer         = new ValueSetImporter(this.tdb);
            ValueSet         originalValueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId);
            ValueSet         newValueSet      = importer.Convert(fhirValueSet, valueSet: originalValueSet);

            if (originalValueSet == null)
            {
                this.tdb.ValueSets.Add(newValueSet);
            }

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet updatedFhirValueSet = exporter.Convert(newValueSet);

            return(Shared.GetResponseMessage(this.Request, format, updatedFhirValueSet, originalValueSet != null ? 200 : 201, headers));
        }
Пример #2
0
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            var foundValueSets = (from vs in this.tdb.ValueSets
                                  join vsi in this.tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId
                                  join fvsi in fhirValueSet.Identifier on vsi.Identifier.ToLower().Trim() equals fvsi.Value.ToLower().Trim()
                                  select vs)
                                 .Distinct();

            if (foundValueSets.Count() > 0)
            {
                throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
            }

            ValueSetImporter importer = new ValueSetImporter(this.tdb);
            ValueSetExporter exporter = new ValueSetExporter(this.tdb);
            ValueSet         valueSet = importer.Convert(fhirValueSet);

            this.tdb.ValueSets.Add(valueSet);
            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet createdFhirValueSet = exporter.Convert(valueSet);

            return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers));
        }
Пример #3
0
        public HttpResponseMessage GetValueSetExpansion(
            [FromUri] int valueSetId,
            [FromUri(Name = "_format")] string format        = null,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            ValueSet         valueSet     = this.tdb.ValueSets.Single(y => y.Id == valueSetId);
            ValueSetExporter exporter     = new ValueSetExporter(this.tdb);
            FhirValueSet     fhirValueSet = exporter.Convert(valueSet, summary);

            return(Shared.GetResponseMessage(this.Request, format, fhirValueSet));
        }
Пример #4
0
        public HttpResponseMessage GetValueSets(
            [FromUri(Name = "_id")] int?valueSetId           = null,
            [FromUri(Name = "name")] string name             = null,
            [FromUri(Name = "_format")] string format        = null,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            var valueSets             = this.tdb.ValueSets.Where(y => y.Id >= 0);
            ValueSetExporter exporter = new ValueSetExporter(this.tdb);

            if (valueSetId != null)
            {
                valueSets = valueSets.Where(y => y.Id == valueSetId);
            }

            if (!string.IsNullOrEmpty(name))
            {
                valueSets = valueSets.Where(y => y.Name.ToLower().Contains(name.ToLower()));
            }

            Bundle bundle = new Bundle()
            {
                Type = Bundle.BundleType.BatchResponse
            };

            var publishedValueSets = (from ig in this.tdb.ImplementationGuides
                                      join t in this.tdb.Templates on ig.Id equals t.OwningImplementationGuideId
                                      join tc in this.tdb.TemplateConstraints on t.Id equals tc.TemplateId
                                      where ig.PublishStatus != null && ig.PublishStatus.Status == PublishStatus.PUBLISHED_STATUS && tc.ValueSet != null
                                      select tc.ValueSet)
                                     .ToList();   // Query the database immediately

            foreach (var valueSet in valueSets)
            {
                var fhirValueSet = exporter.Convert(valueSet, summary, publishedValueSets);
                var fullUrl      = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}",
                                                 this.Request.RequestUri.Scheme,
                                                 this.Request.RequestUri.Authority,
                                                 valueSet.Id);

                bundle.AddResourceEntry(fhirValueSet, fullUrl);
            }

            return(Shared.GetResponseMessage(this.Request, format, bundle));
        }
Пример #5
0
        public HttpResponseMessage CreateValueSet(
            [FromBody] FhirValueSet fhirValueSet,
            [FromUri(Name = "_format")] string format = null)
        {
            var fhirIdentifier      = fhirValueSet.Identifier.Count > 0 ? fhirValueSet.Identifier.First() : null;
            var fhirIdentifierValue = fhirIdentifier != null ? fhirIdentifier.Value : null;

            if (fhirValueSet.Identifier != null && this.tdb.ValueSets.Count(y => y.Oid == fhirIdentifierValue) > 0)
            {
                throw new Exception("ValueSet already exists with this identifier. Use a PUT instead");
            }

            ValueSetImporter importer = new ValueSetImporter(this.tdb);
            ValueSetExporter exporter = new ValueSetExporter(this.tdb);
            ValueSet         valueSet = importer.Convert(fhirValueSet);

            if (valueSet.Oid == null)
            {
                valueSet.Oid = string.Empty;
            }

            if (this.tdb.ValueSets.Count(y => y.Oid == valueSet.Oid) > 0)
            {
                throw new Exception("A ValueSet with that identifier already exists");
            }

            this.tdb.ValueSets.AddObject(valueSet);
            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            fhirValueSet.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            FhirValueSet createdFhirValueSet = exporter.Convert(valueSet);

            return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers));
        }
Пример #6
0
        public HttpResponseMessage GetValueSets(
            [FromUri(Name = "_id")] int?valueSetId           = null,
            [FromUri(Name = "name")] string name             = null,
            [FromUri(Name = "_format")] string format        = null,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            var valueSets             = this.tdb.ValueSets.Where(y => y.Id >= 0);
            ValueSetExporter exporter = new ValueSetExporter(this.tdb);

            if (valueSetId != null)
            {
                valueSets = valueSets.Where(y => y.Id == valueSetId);
            }

            if (!string.IsNullOrEmpty(name))
            {
                valueSets = valueSets.Where(y => y.Name.ToLower().Contains(name.ToLower()));
            }

            Bundle bundle = new Bundle()
            {
                Type = Bundle.BundleType.BatchResponse
            };

            foreach (var valueSet in valueSets)
            {
                var fhirValueSet = exporter.Convert(valueSet, summary);
                var fullUrl      = string.Format("{0}://{1}/api/FHIR2/{2}",
                                                 this.Request.RequestUri.Scheme,
                                                 this.Request.RequestUri.Authority,
                                                 fhirValueSet.Url);

                bundle.AddResourceEntry(fhirValueSet, fullUrl);
            }

            return(Shared.GetResponseMessage(this.Request, format, bundle));
        }
Пример #7
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));
        }