public void ParseBundleXml() { Bundle result = FhirParser.ParseBundle(FhirParser.XmlReaderFromString(testBundleAsXml)); Assert.IsNotNull(result); var actual = FhirSerializer.SerializeBundleToXml(result); Assert.AreEqual(testBundleAsXml, actual); }
public void SerializeBundleWithoutId() { Bundle result = createTestBundle(); result.Id = null; var xml = FhirSerializer.SerializeBundleToXml(result); var json = FhirSerializer.SerializeBundleToJson(result); }
public void SerializeBundleXml() { Bundle b = createTestBundle(); var actual = FhirSerializer.SerializeBundleToXml(b); File.WriteAllText("c:\\temp\\bundleE.xml", testBundleAsXml); File.WriteAllText("c:\\temp\\bundleA.xml", actual); Assert.AreEqual(testBundleAsXml, actual); }
public static Bundle RefreshBundle(this FhirClient client, Bundle bundle) { if (bundle == null) { throw Error.ArgumentNull("bundle"); } // Clone old bundle, without the entries (so, just the header) var oldEntries = bundle.Entries; Bundle result; try { bundle.Entries = new List <BundleEntry>(); var xml = FhirSerializer.SerializeBundleToXml(bundle); result = FhirParser.ParseBundleFromXml(xml); } catch { throw; } finally { bundle.Entries = oldEntries; } result.Id = new Uri("urn:uuid:" + Guid.NewGuid().ToString()); result.LastUpdated = DateTimeOffset.Now; result.Entries = new List <BundleEntry>(); foreach (var entry in bundle.Entries) { if (entry is ResourceEntry) { var newEntry = client.Read(entry.Id); if (entry.Links.Related != null) { newEntry.Links.Related = entry.Links.Related; } result.Entries.Add(newEntry); } else if (entry is DeletedEntry) { result.Entries.Add(entry); } else { throw Error.NotSupported("Cannot refresh an entry of type {0}", messageArgs: entry.GetType().Name); } } return(result); }
public void ParseBundleXml() { ErrorList errors = new ErrorList(); Bundle result = FhirParser.ParseBundle(Util.XmlReaderFromString(testBundleAsXml), errors); Assert.IsNotNull(result); Assert.AreEqual(0, errors.Count, errors.Count > 0 ? errors.ToString() : null); var actual = FhirSerializer.SerializeBundleToXml(result); Assert.AreEqual(testBundleAsXml, actual); }
public void ReadBundleForPPT() { Bundle result = new Bundle() { Title = "Demo bundle" }; result.Entries.Add(new ResourceEntry <Patient>() { LastUpdated = DateTimeOffset.Now, Resource = new Patient() }); result.Entries.Add(new DeletedEntry() { Id = new Uri("http://nu.nl/fhir"), When = DateTime.Now }); var bundleXml = FhirSerializer.SerializeBundleToXml(result); }
private void convertFeed(string inputFile, string outputFile) { //TODO: call validation after reading if (inputFile.EndsWith(".xml")) { var xml = File.ReadAllText(inputFile); var resource = FhirParser.ParseBundleFromXml(xml); var json = FhirSerializer.SerializeBundleToJson(resource); File.WriteAllText(outputFile, json); } else { var json = File.ReadAllText(inputFile); var resource = FhirParser.ParseBundleFromJson(json); var xml = FhirSerializer.SerializeBundleToXml(resource); File.WriteAllText(outputFile, xml); } }
public void SerializationDoesNotEmitXmlHeader() { Bundle b = createTestBundle(); var actual = FhirSerializer.SerializeBundleToXml(b); Assert.IsFalse(actual.StartsWith("<?xml")); var data = FhirSerializer.SerializeBundleToXmlBytes(b); actual = System.Text.Encoding.UTF8.GetString(data); Assert.IsFalse(actual.StartsWith("<?xml")); Patient p = new Patient(); actual = FhirSerializer.SerializeResourceToXml(p); Assert.IsFalse(actual.StartsWith("<?xml")); data = FhirSerializer.SerializeResourceToXmlBytes(p); actual = System.Text.Encoding.UTF8.GetString(data); Assert.IsFalse(actual.StartsWith("<?xml")); }