private void testJsonFeed(string jsonFile) { Bundle bundleResult; ErrorList errors = new Support.ErrorList(); using (JsonReader jr = new JsonTextReader(new StreamReader(jsonFile))) { Debug.WriteLine(" Reading Json feed..."); bundleResult = FhirParser.ParseBundle(jr, errors); jr.Close(); } if (errors.Count > 0) { Debug.WriteLine("=== Json Feed Parse errors ===" + Environment.NewLine + errors.ToString()); _roundTripFailed = true; } else { string xmlFile = Path.ChangeExtension(jsonFile, ".xml"); using (XmlWriter xw = new XmlTextWriter(new System.IO.StreamWriter(xmlFile))) { Debug.WriteLine(" Writing Xml feed..."); FhirSerializer.SerializeBundle(bundleResult, xw); xw.Flush(); xw.Close(); } } }
private void testFeed(string file, string baseFilename) { Bundle bundleResult; ErrorList errors = new Support.ErrorList(); using (XmlReader xr = createReader(file)) { Debug.WriteLine(" Reading Xml feed..."); bundleResult = FhirParser.ParseBundle(xr, errors); xr.Close(); } if (errors.Count > 0) { Debug.WriteLine("=== Xml Feed Parse errors ===" + Environment.NewLine + errors.ToString()); _roundTripFailed = true; } else { string jsonFile = baseFilename + "-roundtrip.json"; //string xmlFile = Path.ChangeExtension(jsonFile, ".xml"); using (JsonTextWriter jw = new JsonTextWriter(new StreamWriter(jsonFile))) { Debug.WriteLine(" Writing Xml feed..."); FhirSerializer.SerializeBundle(bundleResult, jw); jw.Flush(); jw.Close(); } testJsonFeed(jsonFile); } }
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { return(Task.Factory.StartNew(() => { StreamWriter writer = new StreamWriter(writeStream); JsonWriter jsonwriter = new JsonTextWriter(writer); if (type == typeof(OperationOutcome)) { Resource resource = (Resource)value; FhirSerializer.SerializeResource(resource, jsonwriter); } else if (type == typeof(ResourceEntry)) { ResourceEntry entry = (ResourceEntry)value; FhirSerializer.SerializeResource(entry.Resource, jsonwriter); content.Headers.SetFhirTags(entry.Tags); } else if (type == typeof(Bundle)) { FhirSerializer.SerializeBundle((Bundle)value, jsonwriter); } else if (type == typeof(TagList)) { FhirSerializer.SerializeTagList((TagList)value, jsonwriter); } writer.Flush(); })); }
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { return(Task.Factory.StartNew(() => { XmlWriter writer = new XmlTextWriter(writeStream, Encoding.UTF8); // todo: klopt het dat Bundle wel en <?xml ...> header heeft een Resource niet? // follow up: is now ticket in FhirApi. Check later. if (type == typeof(Profile)) { Profile resource = (Profile)value; FhirSerializer.SerializeResource(resource, writer); } else if (type == typeof(ResourceEntry)) { ResourceEntry entry = (ResourceEntry)value; FhirSerializer.SerializeResource(entry.Resource, writer); } else if (type == typeof(Bundle)) { FhirSerializer.SerializeBundle((Bundle)value, writer); } writer.Flush(); })); }
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { return(Task.Factory.StartNew(() => { StreamWriter writer = new StreamWriter(writeStream); JsonWriter jsonwriter = new JsonTextWriter(writer); if (type == typeof(Profile)) { Profile entry = (Profile)value; FhirSerializer.SerializeResource(entry, jsonwriter); } else if (type == typeof(ResourceEntry)) { ResourceEntry entry = (ResourceEntry)value; FhirSerializer.SerializeResource(entry.Resource, jsonwriter); } else if (type == typeof(Bundle)) { FhirSerializer.SerializeBundle((Bundle)value, jsonwriter); } writer.Flush(); })); }
private HttpResponseMessage ImportProfile(Bundle profiles, bool shouldUpdate) { using (StringWriter sw = new StringWriter()) { XmlWriter writer = null; try { writer = XmlWriter.Create(sw); FhirSerializer.SerializeBundle(profiles, writer); } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); response.Content = new StringContent("Failed to serialize request content"); return(response); } writer.Flush(); string bundleXml = sw.ToString(); try { string defaultImplementationGuideName = DEFAULT_IG_NAME; ImplementationGuideType igType = this.tdb.ImplementationGuideTypes.Single(y => y.Name == FHIR_IG_TYPE_NAME); ImplementationGuide defaultImplementationGuide = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Name.ToLower() == defaultImplementationGuideName.ToLower()); TDBOrganization defaultOrganization = this.tdb.Organizations.First(); User defaultAuthorUser = this.tdb.Users.Single(y => y.UserName == TEMPLATE_AUTHOR_USERNAME); // Create a default implementation guide for imports if one doesn't already exist if (defaultImplementationGuide == null) { defaultImplementationGuide = new ImplementationGuide() { Name = defaultImplementationGuideName, Organization = defaultOrganization, ImplementationGuideType = igType }; this.tdb.ImplementationGuides.AddObject(defaultImplementationGuide); } FHIRImporter importer = new FHIRImporter(this.tdb, shouldUpdate); importer.DefaultImplementationGuide = defaultImplementationGuide; importer.DefaultAuthorUser = defaultAuthorUser; importer.Import(bundleXml); this.tdb.SaveChanges(); } catch (AuthorizationException ex) { throw ex; } catch (Exception ex) { var response = new HttpResponseMessage(HttpStatusCode.InternalServerError); response.Content = new StringContent(ex.Message); throw new HttpResponseException(response); } } return(new HttpResponseMessage(HttpStatusCode.OK)); }