Esempio n. 1
0
 public FhirService(Uri serviceBase)
 {
     store = DependencyCoupler.Inject<IFhirStore>(); // new MongoFhirStore();
     _index = DependencyCoupler.Inject<IFhirIndex>(); // Factory.Index;
     _importer = DependencyCoupler.Inject<ResourceImporter>();
     exporter = DependencyCoupler.Inject<ResourceExporter>();
     pager = new Pager(store);
     Endpoint = serviceBase;
 }
Esempio n. 2
0
 public FhirService(Uri serviceBase)
 {
     _store    = DependencyCoupler.Inject <IFhirStore>(); // new MongoFhirStore();
     _index    = DependencyCoupler.Inject <IFhirIndex>(); // Factory.Index;
     _importer = DependencyCoupler.Inject <ResourceImporter>();
     _exporter = DependencyCoupler.Inject <ResourceExporter>();
     _pager    = new Pager(_store);
     Endpoint  = serviceBase;
 }
Esempio n. 3
0
        public static ResourceImporter GetResourceImporter()
        {
            IFhirStore store = Spark.Store.MongoStoreFactory.GetMongoFhirStore();
            ResourceImporter importer = new ResourceImporter(store, Settings.Endpoint);

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

            importer.SharedEndpoints.Add("localhost");
            importer.SharedEndpoints.Add("localhost.");

            return importer;
        }
Esempio n. 4
0
        public FhirService(Uri endpoint)
        {
            //refac: store = DependencyCoupler.Inject<IFhirStore>(); // new MongoFhirStore();

            store     = DependencyCoupler.Inject <IFhirStore>();
            tagstore  = DependencyCoupler.Inject <ITagStore>();
            generator = DependencyCoupler.Inject <IGenerator>();
            index     = DependencyCoupler.Inject <IFhirIndex>(); // Factory.Index;
            importer  = DependencyCoupler.Inject <ResourceImporter>();
            exporter  = DependencyCoupler.Inject <ResourceExporter>();
            pager     = new Pager(store, exporter);
            Endpoint  = endpoint;
        }
Esempio n. 5
0
        public FhirService(Uri endpoint)
        {
            //refac: store = DependencyCoupler.Inject<IFhirStore>(); // new MongoFhirStore();

            store = DependencyCoupler.Inject<IFhirStore>();
            tagstore = DependencyCoupler.Inject<ITagStore>();
            generator = DependencyCoupler.Inject<IGenerator>();
            index = DependencyCoupler.Inject<IFhirIndex>(); // Factory.Index;
            importer = DependencyCoupler.Inject<ResourceImporter>();
            exporter = DependencyCoupler.Inject<ResourceExporter>();
            pager = new Pager(store, exporter);
            Endpoint = endpoint;
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
        public void TestUriReassignments()
        {
            Patient p = new Patient();

            p.Link = new List<ResourceReference>() { new ResourceReference { Type = "patient", Reference = "patient/@10" } };
            p.Provider = new ResourceReference() { Type = "organization", Reference = "http://outside.com/fhir/organization/@100" };
            p.Contact = new List<Patient.ContactComponent>() {
                new Patient.ContactComponent() { 
                    Organization = new ResourceReference() { Type = "organization", Reference = "http://hl7.org/fhir/organization/@200" } } };
            p.Photo = new List<Attachment>() 
                                { new Attachment() { Url = new Uri("media/@300", UriKind.Relative) }, 
                                  new Attachment() { Url = new Uri("#containedPhoto", UriKind.Relative) },
                                  new Attachment() { Url = new Uri("http://www.nu.nl/fotos/1.jpg", UriKind.Absolute) }
                                };

            var pic300 = new Media();
            pic300.Content = new Attachment() { 
                        Url = new Uri("http://hl7.org/fhir/binary/@300") };
           
            var importer = new ResourceImporter(new Uri("http://hl7.org/fhir"));

            importer.QueueNewResourceEntry("patient", "1", p);
            importer.QueueNewResourceEntry("patient", "10", new Patient());
            importer.QueueNewResourceEntry(new Uri("http://outside.com/fhir/organization/@100"), new Organization());
            importer.QueueNewResourceEntry("media", "300", pic300);

            var result = importer.ImportQueued();

            var p1 = (ResourceEntry<Patient>)result.First();
            Assert.AreEqual("patient/@10", p1.Resource.Link[0].Reference);
            Assert.AreEqual("organization/@11", p1.Resource.Provider.Reference);
            Assert.AreEqual("organization/@200", p1.Resource.Contact.First().Organization.Reference);
            Assert.AreEqual("media/@300", p1.Resource.Photo.First().Url.ToString());
            Assert.AreEqual("#containedPhoto", p1.Resource.Photo.Skip(1).First().Url.ToString());
            Assert.AreEqual("http://www.nu.nl/fotos/1.jpg", p1.Resource.Photo.Skip(2).First().Url.ToString());
            Assert.AreEqual("binary/@300", pic300.Content.Url.ToString());
        }
Esempio n. 8
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);
        }
Esempio n. 9
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));
        }
Esempio n. 10
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());
        }
Esempio n. 11
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();
        }