public void LocationModification()
        {
            var rl = new ResourceLocation("http://hl7.org");
            Assert.AreEqual("http://hl7.org/", rl.ToString());

            rl.Service = "svc";
            Assert.AreEqual("http://hl7.org/svc/", rl.ToString());

            rl.Operation = "tags";
            Assert.AreEqual("http://hl7.org/svc/tags", rl.ToString());

            rl.Collection = "patient";
            Assert.AreEqual("http://hl7.org/svc/patient/tags", rl.ToString());

            rl.Id = "10";
            Assert.AreEqual("http://hl7.org/svc/patient/@10/tags", rl.ToString());

            rl.VersionId = "12";
            Assert.AreEqual("http://hl7.org/svc/patient/@10/history/@12/tags", rl.ToString());

            rl.Port = 2100;
            Assert.AreEqual("http://hl7.org:2100/svc/patient/@10/history/@12/tags", rl.ToString());

            rl.Query = "?_count=50";
            Assert.AreEqual("http://hl7.org:2100/svc/patient/@10/history/@12/tags?_count=50", rl.ToString());
        }
        public void Read()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var loc = client.Read<Location>("1");
            Assert.IsNotNull(loc);
            Assert.AreEqual("Den Burg", loc.Resource.Address.City);

            string version = new ResourceLocation(loc.SelfLink).VersionId;               
            Assert.AreEqual("1", version);

            string id = new ResourceLocation(loc.Id).Id;
            Assert.AreEqual("1", id);

            try
            {
                var random = client.Read<Location>("45qq54");
                Assert.Fail();
            }
            catch (FhirOperationException)
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.NotFound);
            }

            var loc2 = client.VRead<Location>("1", version);
            Assert.IsNotNull(loc2);
            Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc),
                            FhirSerializer.SerializeBundleEntryToJson(loc2));

            var loc3 = client.Fetch<Location>(loc.SelfLink);
            Assert.IsNotNull(loc3);
            Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc),
                            FhirSerializer.SerializeBundleEntryToJson(loc3));

        }
예제 #3
0
        public void TryReadUnknownResourceType()
        {
            ResourceLocation rl = new ResourceLocation(client.Endpoint);
            rl.Collection = "thisreallywondexist";
            rl.Id = "1";

            HttpTests.AssertFail(client, () => client.Fetch<Patient>(rl.ToUri()), HttpStatusCode.NotFound);
        }
예제 #4
0
        public void AssureNavigateToRelativeResource()
        {
            var rl = new ResourceLocation("http://hl7.org/fhir/patient/@1");

            var rln = rl.NavigateTo("@2");
            Assert.AreEqual("patient/@2", rln.OperationPath.ToString());

            rln = rl.NavigateTo("../observation/@3");
            Assert.AreEqual("observation/@3", rln.OperationPath.ToString());
        }
예제 #5
0
        public static void AssertLocationPresentAndValid(FhirClient client)
        {
            if (String.IsNullOrEmpty(client.LastResponseDetails.Location))
                TestResult.Fail("Mandatory Location header missing");

            var rl = new ResourceLocation(client.LastResponseDetails.Location);

            if(rl.Id == null)
                TestResult.Fail("Location does not have an id in it");

            if (rl.VersionId == null)
                TestResult.Fail("Location is not a version-specific url");
        }
예제 #6
0
        public static void AssertContentLocationValidIfPresent(FhirClient client)
        {
            if (!String.IsNullOrEmpty(client.LastResponseDetails.ContentLocation))
            {
                var rl = new ResourceLocation(client.LastResponseDetails.ContentLocation);

                if (rl.Id == null)
                    TestResult.Fail("Content-Location does not have an id in it");

                if (rl.VersionId == null)
                    TestResult.Fail("Content-Location is not a version-specific url");
            }
        }
        public void TryParseNonIdLocations()
        {
            var rl = new ResourceLocation("http://hl7.org/patient/validate/@1");
            Assert.IsNull(rl.Service);
            Assert.AreEqual("validate", rl.Operation);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);

            rl = new ResourceLocation("http://hl7.org/svc/patient/myoperation");
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("myoperation", rl.Operation);
            Assert.IsNull(rl.Id);
            Assert.IsNull(rl.VersionId);

            rl = new ResourceLocation("http://hl7.org/svc/history");
            Assert.AreEqual("http://hl7.org/svc/history", rl.ToString());
            Assert.AreEqual("svc", rl.Service);
            Assert.IsNull(rl.Collection);
            Assert.AreEqual("history", rl.Operation);
            Assert.AreEqual("history", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://hl7.org/svc/history?_since=2010-10-30&_count=50");
            Assert.AreEqual("http://hl7.org/svc/history?_since=2010-10-30&_count=50", rl.ToString());
            Assert.AreEqual("svc", rl.Service);
            Assert.IsNull(rl.Collection);
            Assert.AreEqual("?_since=2010-10-30&_count=50", rl.Query);
            Assert.AreEqual("history", rl.Operation);
            Assert.AreEqual("history?_since=2010-10-30&_count=50", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://hl7.org:1234/svc/patient");
            Assert.AreEqual("http://hl7.org:1234/svc/patient", rl.ToString());
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual(1234, rl.Port);
            Assert.IsNull(rl.Operation);
            Assert.AreEqual("patient", rl.Collection);

            rl = new ResourceLocation("http://hl7.org/svc/patient");
            Assert.AreEqual("svc", rl.Service);
            Assert.IsNull(rl.Operation);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("patient", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://hl7.org/patient");
            Assert.IsNull(rl.Service);
            Assert.IsNull(rl.Operation);
            Assert.AreEqual("patient", rl.Collection);

            rl = new ResourceLocation("http://hl7.org/svc");
            Assert.AreEqual("http://hl7.org/svc", rl.ToString());
            Assert.AreEqual("svc", rl.Service);
            Assert.IsNull(rl.Operation);
            Assert.IsNull(rl.Collection);

            rl = new ResourceLocation("http://hl7.org");
            Assert.AreEqual("http://hl7.org/", rl.ToString());
            Assert.IsNull(rl.Service);
            Assert.IsNull(rl.Operation);
            Assert.IsNull(rl.Collection);

            try
            {
                rl = new ResourceLocation("relative");
                Assert.Fail("Single-argument constructor should throw exception on relative path");
            }
            catch
            {
                // Ok!
            }
        }
예제 #8
0
        public void UpdateTagsOnVersionUsingPost()
        {
            var rl = new ResourceLocation(latest.SelfLink);

            var update = new Tag(NUTAG, Tag.FHIRTAGNS, "newVersionForVersion");
            var existing = new Tag(OTHERTAG, Tag.FHIRTAGNS);

            HttpTests.AssertSuccess(client, () => client.AffixTags(
                        new List<Tag> { update }, ResourceType.Patient, rl.Id, rl.VersionId));

            var result = client.Fetch<Patient>(latest.Id);

            if (result.Tags.Count() != 2)
                TestResult.Fail("update modified the number of tags");

            if (!result.Tags.Any(t => t.Equals(existing)))
                TestResult.Fail("update removed an existing but unchanged tag");

            if (!result.Tags.Any(t => t.Equals(update) && t.Label == update.Label))
                TestResult.Fail("update did not change the tag");

            if (result.SelfLink != latest.SelfLink)
                TestResult.Fail("updating the tags created a new version");

            //TODO: Check whether taglists on older versions remain unchanged
        }
예제 #9
0
        public void DeleteTagsOnVersionUsingDelete()
        {
            var rl = new ResourceLocation(latest.SelfLink);

            var delete = new Tag(NUTAG, Tag.FHIRTAGNS);
            var existing = new Tag(OTHERTAG, Tag.FHIRTAGNS);

            HttpTests.AssertSuccess(client, () => client.DeleteTags(
                new List<Tag> { delete }, ResourceType.Patient, rl.Id, rl.VersionId));

            var result = client.Fetch<Patient>(latest.Id);

            if (result.Tags.Count() != 1)
                TestResult.Fail("delete resulted in an unexpected number of remaining tags");

            if (!result.Tags.Any(t => t.Equals(existing)))
                TestResult.Fail("delete removed an existing tag the should be untouched");

            if (result.Tags.Any(t => t.Equals(delete)))
                TestResult.Fail("delete did not remove the tag");

            if (result.SelfLink != latest.SelfLink)
                TestResult.Fail("deleting the tags created a new version");

            //TODO: Check whether taglists on older versions remain unchanged
        }
        public void ParamManipulation()
        {
            var rl = new ResourceLocation("patient/search?name=Kramer&name=Moreau&oauth=XXX");

            rl.SetParam("newParamA", "1");
            rl.SetParam("newParamB", "2");
            Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=1&newParamB=2"));

            rl.SetParam("newParamA", "3");
            rl.ClearParam("newParamB");
            Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3"));

            rl.AddParam("newParamA", "4");
            Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3&newParamA=4"));

            rl.AddParam("newParamB", "5");
            Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3&newParamA=4&newParamB=5"));

            Assert.AreEqual("patient/search?name=Kramer&name=Moreau&oauth=XXX&newParamA=3&newParamA=4&newParamB=5",
                    rl.OperationPath.ToString());

            rl = new ResourceLocation("patient/search");
            rl.SetParam("firstParam", "1");
            rl.SetParam("sndParam", "2");
            rl.ClearParam("sndParam");
            Assert.AreEqual("patient/search?firstParam=1", rl.OperationPath.ToString());

            rl.ClearParam("firstParam");
            Assert.AreEqual("patient/search", rl.OperationPath.ToString());

            rl.SetParam("firstParam", "1");
            rl.SetParam("sndParam", "2");
            rl.ClearParams();
            Assert.AreEqual("patient/search", rl.OperationPath.ToString());
        }
예제 #11
0
        public void GetInstanceHistoryTags()
        {
            IEnumerable<Tag> tags = null;

            var rl = new ResourceLocation(latest.SelfLink);

            HttpTests.AssertSuccess(client, () => tags = client.GetTags(ResourceType.Patient, rl.Id, rl.VersionId));

            var tagStrings = tags.FilterFhirTags().Where(t => t.Term != null).Select(t => t.Term);

            if (!tagStrings.Contains(NUTAG) || !tagStrings.Contains(OTHERTAG))
                TestResult.Fail("expected tags not found in resource instance tag list");
        }
예제 #12
0
        public void SearchConditionByPatientReference()
        {
            var conditions = client.Search(ResourceType.Condition);

            if (conditions.Entries.Count == 0)
                TestResult.Fail("no conditions found - cannot run test");
            
            var condition = conditions.Entries.ByResourceType<Condition>()
                .Where(c => c.Resource.Subject != null && c.Resource.Subject.Type == "Patient")
                .First();

            var patientRef = new ResourceLocation(condition.Resource.Subject.Url);

            var patient = client.Read<Patient>(patientRef.Id);

            if(patient == null)
                TestResult.Fail("failed to find patient condition is referring to");

            var result = client.Search(ResourceType.Condition, "subject", "patient/" + patientRef.Id);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject=)");

            result = client.Search(ResourceType.Condition, "subject._id", patientRef.Id);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject._id=)");

            string patFirstName = patient.Resource.Name[0].Family.First().Substring(2, 3);
            var param = new SearchParam("subject.name", new StringParamValue(patFirstName));
            result = client.Search(ResourceType.Condition, new SearchParam[] { param });
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject.name)");

            result = client.Search(ResourceType.Condition, "subject.identifier", patient.Resource.Identifier[0].Key);
            if (result.Entries.Count() == 0)
                TestResult.Fail("failed to find any conditions (using subject.identifier)");

        }
        public void UseOfRelativePaths()
        {
            Assert.AreEqual("patient/@1", ResourceLocation.Build("patient", "1").OperationPath.ToString());
            Assert.AreEqual("patient/@1", new ResourceLocation("patient/@1").OperationPath.ToString());

            Assert.AreEqual("patient/@1/history/@4", ResourceLocation.Build("patient","1","4").OperationPath.ToString());
            Assert.AreEqual("patient/@1/history/@4", new ResourceLocation("patient/@1/history/@4").OperationPath.ToString());

            var rl = ResourceLocation.Build("patient", "1");
            rl.Operation = "x-history";
            Assert.AreEqual("patient/@1/x-history", rl.OperationPath.ToString());

            rl = new ResourceLocation("patient/@1/history/@4");

            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("4", rl.VersionId);
            Assert.AreEqual("patient", rl.Collection);
            Assert.IsNull(rl.Operation);
        }
예제 #14
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));
        }
        public void TryParseLocationWithId()
        {
            ResourceLocation rl = new ResourceLocation("http://fhir.server.com/svc/patient/@1");
            Assert.AreEqual("http://fhir.server.com/svc/patient/@1", rl.ToString());
            Assert.AreEqual("http", rl.Scheme);
            Assert.AreEqual("fhir.server.com", rl.Host);
            Assert.AreEqual("/svc/patient/@1", rl.Path);
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("http://fhir.server.com/svc/", rl.ServiceUri.ToString());
            Assert.AreEqual("patient/@1", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://fhir.server.com/patient/@1/history/@9/myoperation");
            Assert.AreEqual("http://fhir.server.com/patient/@1/history/@9/myoperation", rl.ToString());
            Assert.AreEqual("fhir.server.com", rl.Host);
            Assert.IsNull(rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("9", rl.VersionId);
            Assert.AreEqual("myoperation", rl.Operation);
            Assert.AreEqual("patient/@1/history/@9/myoperation", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://fhir.server.com/patient/@1/history/@9");
            Assert.AreEqual("http://fhir.server.com/patient/@1/history/@9", rl.ToString());
            Assert.IsNull(rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("9", rl.VersionId);
            Assert.IsNull(rl.Operation);
            Assert.AreEqual("patient/@1/history/@9", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://fhir.server.com/patient/@1/history");
            Assert.AreEqual("http://fhir.server.com/patient/@1/history", rl.ToString());
            Assert.IsNull(rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.IsNull(rl.VersionId);
            Assert.AreEqual("history",rl.Operation);
            Assert.AreEqual("patient/@1/history", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://fhir.server.com/patient/@1");
            Assert.AreEqual("http://fhir.server.com/patient/@1", rl.ToString());
            Assert.IsNull(rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.IsNull(rl.VersionId);
            Assert.IsNull(rl.Operation);
            Assert.AreEqual("patient/@1", rl.OperationPath.ToString());

            rl = new ResourceLocation("http://www.hl7.org", "svc/patient/@1");
            Assert.AreEqual("http://www.hl7.org/svc/patient/@1", rl.ToString());
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);

            rl = new ResourceLocation("http://www.hl7.org/root", "svc/patient/@1");
            Assert.AreEqual("http://www.hl7.org/root/svc/patient/@1", rl.ToString());
            Assert.AreEqual("root/svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);

            rl = new ResourceLocation("http://www.hl7.org/svc/organization/", "../patient/@1/myoperation");
            Assert.AreEqual("www.hl7.org", rl.Host);
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("myoperation", rl.Operation);
        }
        public void TryNavigation()
        {
            var old = new ResourceLocation("http://www.hl7.org/svc/organization/");
            var rl = old.NavigateTo("../patient/@1/history");

            Assert.AreEqual("www.hl7.org", rl.Host);
            Assert.AreEqual("svc", rl.Service);
            Assert.AreEqual("patient", rl.Collection);
            Assert.AreEqual("1", rl.Id);
            Assert.AreEqual("history", rl.Operation);

            old = new ResourceLocation("http://hl7.org/fhir/patient/@1");
            rl = old.NavigateTo("@2");
            Assert.AreEqual("patient/@2", rl.OperationPath.ToString());

            rl = old.NavigateTo("../observation/@3");
            Assert.AreEqual("observation/@3", rl.OperationPath.ToString());

            old = new ResourceLocation("patient/@1");
            rl = old.NavigateTo("@2");
            Assert.AreEqual("patient/@2", rl.OperationPath.ToString());

            rl = old.NavigateTo("../observation/@3");
            Assert.AreEqual("observation/@3", rl.OperationPath.ToString());
        }
예제 #17
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);
        }
예제 #18
0
        public void FindSpecificVersionOfResource()
        {
            _store.EraseData();

            _store.AddEntry(_stockPatient);

            ResourceLocation rl = new ResourceLocation(_stockPatient.SelfLink);

            var dd = (ResourceEntry)clone(_stockPatient);

            ((Patient)dd.Resource).Name[0].Given = new string[] { "Donald Duck" };
            rl.VersionId = (Int32.Parse(rl.VersionId) + 1).ToString();
            dd.SelfLink = rl.ToUri();
            _store.AddEntry(dd);

            var specificVersion = _store.FindVersionByVersionId(dd.SelfLink);

            Assert.IsNotNull(specificVersion);
            Assert.AreEqual(specificVersion.SelfLink, dd.SelfLink);
            Assert.AreEqual(specificVersion.Id, dd.Id);
            Assert.AreEqual("Donald Duck", ((Patient)((ResourceEntry)specificVersion).Resource)
                .Name[0].Given.First());

            var originalVersion = _store.FindVersionByVersionId(_stockPatient.Links.SelfLink);
            Assert.IsNotNull(originalVersion);
            Assert.AreEqual("Eve", ((Patient)((ResourceEntry)originalVersion).Resource)
                .Name[0].Given.First());
        }