Exemplo n.º 1
0
        public void UpdateAndCheckHistory()
        {
            _store.EraseData();

            var importer = new ResourceImporter(new Uri("http://localhost"));

            importer.QueueNewEntry(_stockPatient);
            importer.QueueNewEntry(_stockOrg);

            var dd = (ResourceEntry)clone(_stockPatient);

            ((Patient)dd.Resource).Name[0].Text = "Donald Duck";
            dd.Links.SelfLink = null;
            importer.QueueNewEntry(dd);

            importer.QueueNewDeletedEntry(_stockPatient.Id);
            importer.QueueNewDeletedEntry(_stockOrg.Id);

            var imported = importer.ImportQueued();
            var origId   = imported.First().Id;

            _store.AddEntries(imported);

            var history = _store.ListVersionsById(origId)
                          .OrderBy(be => new ResourceLocation(be.Links.SelfLink).VersionId);

            Assert.IsNotNull(history);
            Assert.AreEqual(3, history.Count());

            Assert.IsTrue(history.All(be => be.Id == origId));

            Assert.IsTrue(history.Last() is DeletedEntry);

            var ver1 = new ResourceLocation(history.First().Links.SelfLink).VersionId;
            var ver2 = new ResourceLocation(history.ElementAt(1).Links.SelfLink).VersionId;
            var ver3 = new ResourceLocation(history.ElementAt(2).Links.SelfLink).VersionId;

            Assert.AreNotEqual(Int32.Parse(ver1), Int32.Parse(ver2));
            Assert.AreNotEqual(Int32.Parse(ver2), Int32.Parse(ver3));
            Assert.AreNotEqual(Int32.Parse(ver1), Int32.Parse(ver3));

            var firstVersionAsEntry = _store.FindVersionByVersionId(history.First().Links.SelfLink);

            //TODO: There's a bug here...the cr+lf in the _stockPatient gets translated to \r\n in the 'firstVersion'.
            //Cannot see this in the stored version though.
            Assert.AreEqual(FhirSerializer.SerializeResourceToJson(_stockPatient.Resource),
                            FhirSerializer.SerializeResourceToJson(((ResourceEntry)firstVersionAsEntry).Resource));

            var secondVersionAsEntry = _store.FindVersionByVersionId(history.ElementAt(1).Links.SelfLink);

            Assert.AreEqual("Donald Duck", ((Patient)((ResourceEntry)secondVersionAsEntry).Resource).Name[0].Text);

            var allHistory = _store.ListVersions();

            Assert.AreEqual(5, allHistory.Count());
            Assert.AreEqual(3, allHistory.Count(be => be.Id.ToString().Contains("patient")));
            Assert.AreEqual(2, allHistory.Count(be => be.Id.ToString().Contains("organization")));
            Assert.AreEqual(2, allHistory.Count(be => be is DeletedEntry));
        }
Exemplo n.º 2
0
        public void ListRecordsByResourceType()
        {
            _store.EraseData();

            DateTimeOffset now    = DateTimeOffset.UtcNow;
            DateTime       stampi = new DateTime(now.Ticks, DateTimeKind.Unspecified);

            stampi = stampi.AddHours(5);

            DateTimeOffset stamp = new DateTimeOffset(stampi, new TimeSpan(5, 0, 0));

            var importer = new ResourceImporter(new Uri("http://localhost"));

            for (int i = 0; i < 5; i++)
            {
                var tst = _stockPatients[i];
                importer.QueueNewEntry(tst);
            }
            for (int i = 0; i < 5; i++)
            {
                var tst = _stockOrgs[i];
                importer.QueueNewEntry(tst);
            }

            importer.QueueNewDeletedEntry("patient", "31415");

            var imported = importer.ImportQueued();

            _store.AddEntries(imported);

            var recentList = _store.ListCollection("patient");

            Assert.AreEqual(5, recentList.Count(), "Should not contain deleted entries");

            var recentOrgList = _store.ListCollection("organization");

            Assert.AreEqual(5, recentOrgList.Count(), "Should not contain patients");

            recentList = _store.ListCollection("patient", includeDeleted: true);
            Assert.AreEqual(6, recentList.Count(), "Should contain deleted entries");

            var recentListWithFilter = _store.ListCollection("patient", limit: 3);

            Assert.AreEqual(3, recentListWithFilter.Count());

            var recentListWithFilter2 = _store.ListCollection("patient", since: now.AddMinutes(-1));

            Assert.AreEqual(5, recentListWithFilter2.Count());

            var recentListWithFilter3 = _store.ListCollection("patient", since: now.AddMinutes(-1), limit: 3);

            Assert.AreEqual(3, recentListWithFilter3.Count());
        }
Exemplo n.º 3
0
        public void FullExampleImport()
        {
            ExampleImporter examples = new ExampleImporter();

            examples.ImportZip("examples.zip");

            var importer = new ResourceImporter(new Uri("http://hl7.org/fhir/"));

            foreach (var resourceName in ModelInfo.SupportedResources)
            {
                var key = resourceName.ToLower();
                if (examples.ImportedEntries.ContainsKey(key))
                {
                    var exampleEntries = examples.ImportedEntries[key];

                    foreach (var exampleEntry in exampleEntries)
                    {
                        importer.QueueNewEntry(exampleEntry);
                    }
                }
            }

            var importedEntries = importer.ImportQueued();
        }
Exemplo n.º 4
0
        public void SimpleStoreSpeedTest()
        {
            Stopwatch w = new Stopwatch();

            w.Start();
            _store.EraseData();

            w.Stop();

            Debug.Print("Erasing data took {0} ms", w.ElapsedMilliseconds);

            w.Restart();
            //var errs = new ErrorList();
            //var entries = new List<BundleEntry>();

            //for (var i = 0; i < 500; i++)
            //{
            //    var xml = FhirSerializer.SerializeBundleEntryToXml(_stockPatient);
            //    var copy = FhirParser.ParseBundleEntryFromXml(xml, errs);
            //    var rl = ResourceLocation.Build("patient", i.ToString());
            //    copy.Id = rl.ToUri();
            //    rl.VersionId = "1";
            //    copy.SelfLink = rl.ToUri();
            //    entries.Add(copy);
            //}

            var bundle = loadExamples();

            w.Stop();

            Debug.Print("Loading examples took {0} ms", w.ElapsedMilliseconds);

            w.Restart();

            foreach (var entry in bundle.Entries)
            {
                var rl = new ResourceLocation(entry.Id);
                rl.VersionId   = "1";
                entry.SelfLink = rl.ToUri();
            }

            var importer = new ResourceImporter(new Uri("http://localhost"));

            importer.AddSharedIdSpacePrefix("http://hl7.org/fhir/");

            foreach (var be in bundle.Entries)
            {
                importer.QueueNewEntry(be);
            }

            w.Stop();

            Debug.Print("Queueing examples took {0} ms", w.ElapsedMilliseconds);

            w.Restart();

            var entriesToStore = importer.ImportQueued();

            w.Stop();

            Debug.Print("Importing examples took {0} ms", w.ElapsedMilliseconds);

            w.Restart();

            var guid = Guid.NewGuid();

            _store.AddEntries(entriesToStore, guid);

            w.Stop();

            Debug.Print("Storing {0} patients took {1} ms", entriesToStore.Count(), w.Elapsed.Milliseconds);
        }