Exemple #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));
        }
Exemple #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());
        }
Exemple #3
0
        public void TestIdReassignOnImport()
        {
            var importer = new ResourceImporter(new Uri("http://fhir.furore.com/fhir/"));

            importer.AddSharedIdSpacePrefix("http://localhost");

            importer.QueueNewResourceEntry(new Uri("http://someserver.nl/fhir/patient/@1012"), new Patient());
            importer.QueueNewResourceEntry(new Uri("http://fhir.furore.com/fhir/patient/@13"), new Patient());
            importer.QueueNewResourceEntry(new Uri("http://localhost/svc/patient/@24"), new Patient());
            importer.QueueNewResourceEntry(new Uri("cid:332211223316"), new Patient());
            importer.QueueNewDeletedEntry(new Uri("http://someserver.nl/fhir/patient/@17"));
            var imported = importer.ImportQueued();

            Assert.AreEqual("patient/@1", imported.First().Id.ToString());
            Assert.AreEqual("patient/@13", imported.Skip(1).First().Id.ToString());
            Assert.AreEqual("patient/@24", imported.Skip(2).First().Id.ToString());
            Assert.AreEqual("patient/@25", imported.Skip(3).First().Id.ToString());
            Assert.AreEqual("patient/@26", imported.Skip(4).First().Id.ToString());
        }