예제 #1
0
        public void ParseBundleXml()
        {
            Bundle result = FhirParser.ParseBundle(FhirParser.XmlReaderFromString(testBundleAsXml));

            Assert.IsNotNull(result);
            var actual = FhirSerializer.SerializeBundleToXml(result);

            Assert.AreEqual(testBundleAsXml, actual);
        }
예제 #2
0
        public void SerializeBundleWithoutId()
        {
            Bundle result = createTestBundle();

            result.Id = null;

            var xml  = FhirSerializer.SerializeBundleToXml(result);
            var json = FhirSerializer.SerializeBundleToJson(result);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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"));
        }