public Trifolia.Shared.ImportExport.Model.Trifolia ExportTrifoliaModel(XMLSettingsModel model) { if (model == null) { throw new ArgumentNullException("model"); } if (model.ImplementationGuideId == 0) { throw new ArgumentNullException("model.ImplementationGuideId"); } ImplementationGuide ig = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == model.ImplementationGuideId); if (ig == null) { throw new Exception("Implementation guide with id " + model.ImplementationGuideId + " was not found"); } List <Template> templates = this.tdb.Templates.Where(y => model.TemplateIds.Contains(y.Id)).ToList(); IGSettingsManager igSettings = new IGSettingsManager(this.tdb, model.ImplementationGuideId); string fileName = string.Format("{0}.xml", ig.GetDisplayName(true)); string export = string.Empty; try { NativeExporter exporter = new NativeExporter(this.tdb, templates, igSettings, categories: model.SelectedCategories); return(exporter.GenerateExport()); } catch (Exception ex) { Log.For(this).Error("Error creating Trifolia export", ex); throw; } }
public HttpResponseMessage ExportXML(XMLSettingsModel model) { if (model == null) { throw new ArgumentNullException("model"); } if (model.ImplementationGuideId == 0) { throw new ArgumentNullException("model.ImplementationGuideId"); } ImplementationGuide ig = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == model.ImplementationGuideId); if (ig == null) { throw new Exception("Implementation guide with id " + model.ImplementationGuideId + " was not found"); } List <Template> templates = this.tdb.Templates.Where(y => model.TemplateIds.Contains(y.Id)).ToList(); IGSettingsManager igSettings = new IGSettingsManager(this.tdb, model.ImplementationGuideId); string fileName = string.Format("{0}.xml", ig.GetDisplayName(true)); string export = string.Empty; bool returnJson = Request.Headers.Accept.Count(y => y.MediaType == "application/json") == 1; bool includeVocabulary = model.IncludeVocabulary == true; var igTypePlugin = IGTypePluginFactory.GetPlugin(ig.ImplementationGuideType); var schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, ig.ImplementationGuideType); if (model.XmlType == XMLSettingsModel.ExportTypes.Proprietary) { export = igTypePlugin.Export(tdb, schema, ExportFormats.Proprietary, igSettings, model.SelectedCategories, templates, includeVocabulary, returnJson); } else if (model.XmlType == XMLSettingsModel.ExportTypes.DSTU) { export = igTypePlugin.Export(tdb, schema, ExportFormats.TemplatesDSTU, igSettings, model.SelectedCategories, templates, includeVocabulary, returnJson); } else if (model.XmlType == XMLSettingsModel.ExportTypes.FHIR) { export = igTypePlugin.Export(this.tdb, schema, ExportFormats.FHIR, igSettings, model.SelectedCategories, templates, includeVocabulary, returnJson); } else if (model.XmlType == XMLSettingsModel.ExportTypes.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 = jsonSerializer.Serialize(dataModel); // Set the filename to JSON fileName = string.Format("{0}.json", ig.GetDisplayName(true)); } byte[] data = System.Text.ASCIIEncoding.UTF8.GetBytes(export); return(GetExportResponse(fileName, data)); }
public IEnumerable <string> ValidateXml(XMLSettingsModel model) { List <string> messages = new List <string>(); ImplementationGuide ig = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == model.ImplementationGuideId); var templates = (from t in this.tdb.Templates join tid in model.TemplateIds on t.Id equals tid select t); if (ig == null) { messages.Add("Could not find implementation guide with id " + model.ImplementationGuideId); return(messages); } switch (model.XmlType) { case XMLSettingsModel.ExportTypes.FHIRBuild: // Check that the implementation guide has a base identifier/url if (string.IsNullOrEmpty(ig.Identifier)) { messages.Add("Implementation guide does not have a base identifier/url."); } // Check that each FHIR resource instance is valid and has the required fields foreach (var file in ig.Files) { var fileData = file.GetLatestData(); fhir_stu3.Hl7.Fhir.Model.Resource resource = null; try { string fileContent = System.Text.Encoding.UTF8.GetString(fileData.Data); if (file.MimeType == "application/xml" || file.MimeType == "text/xml") { resource = fhir_stu3.Hl7.Fhir.Serialization.FhirParser.ParseResourceFromXml(fileContent); } else if (file.MimeType == "application/json") { resource = fhir_stu3.Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(fileContent); } } catch { } if (resource == null) { string msg = string.Format("FHIR resource instance \"" + file.FileName + "\" cannot be parsed as a valid XML or JSON resource."); messages.Add(msg); } if (string.IsNullOrEmpty(resource.Id)) { string msg = string.Format("FHIR resource instance \"" + file.FileName + "\" does not have an \"id\" property."); messages.Add(msg); } } // Validate that each of the samples associated with profiles has the required fields var templateExamples = (from t in templates join ts in this.tdb.TemplateSamples on t.Id equals ts.TemplateId select new { Template = t, Sample = ts }); foreach (var templateExample in templateExamples) { fhir_stu3.Hl7.Fhir.Model.Resource resource = null; try { resource = fhir_stu3.Hl7.Fhir.Serialization.FhirParser.ParseResourceFromXml(templateExample.Sample.XmlSample); } catch { } try { if (resource == null) { resource = fhir_stu3.Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(templateExample.Sample.XmlSample); } } catch { } if (resource == null) { string msg = string.Format("Profile sample \"" + templateExample.Sample.Name + "\" cannot be parsed as a valid XML or JSON resource."); messages.Add(msg); } else if (string.IsNullOrEmpty(resource.Id)) { string msg = string.Format("Profile sample \"" + templateExample.Sample.Name + "\" does not have an \"id\" property."); messages.Add(msg); } } break; } return(messages); }