public FhirResponse Search(string type, SearchParams searchCommand) { Validate.TypeName(type); SearchResults results = index.Search(type, searchCommand); if (results.HasErrors) { throw new SparkException(HttpStatusCode.BadRequest, results.Outcome); } Uri link = new RestUrl(localhost.Uri(type)).AddPath(results.UsedParameters).Uri; string firstSort = null; if (searchCommand.Sort != null && searchCommand.Sort.Count() > 0) { firstSort = searchCommand.Sort[0].Item1; //TODO: Support sortorder and multiple sort arguments. } var snapshot = pager.CreateSnapshot(Bundle.BundleType.Searchset, link, results, firstSort); Bundle bundle = pager.GetFirstPage(snapshot); return(Respond.WithBundle(bundle, localhost.Base)); }
public Bundle Search(string collection, IEnumerable <Tuple <string, string> > parameters, int pageSize, string sortby) { RequestValidator.ValidateCollectionName(collection); Query query = FhirParser.ParseQueryFromUriParameters(collection, parameters); ICollection <string> includes = query.Includes; SearchResults results = index.Search(query); if (results.HasErrors) { throw new SparkException(HttpStatusCode.BadRequest, results.Outcome); } RestUrl selfLink = new RestUrl(Endpoint).AddPath(collection).AddPath(results.UsedParameters); string title = String.Format("Search on resources in collection '{0}'", collection); Snapshot snapshot = Snapshot.Create(title, selfLink.Uri, results, sortby, includes); store.AddSnapshot(snapshot); Bundle bundle = pager.GetPage(snapshot, 0, pageSize); /* * if (results.HasIssues) * { * var outcomeEntry = BundleEntryFactory.CreateFromResource(results.Outcome, new Uri("outcome/1", UriKind.Relative), DateTimeOffset.Now); * outcomeEntry.SelfLink = outcomeEntry.Id; * bundle.Entries.Add(outcomeEntry); * } */ exporter.Externalize(bundle); return(bundle); }
/// <summary> /// Find all entries in a Bundle that match the given reference. /// </summary> /// <param name="bundle">Bundle to search in</param> /// <param name="reference">An absolute reference to match against the fullUrl of the entries in the bundle</param> /// <param name="includeDeleted">Whether to include deleted entries in the search. Optional.</param> /// <returns>A list of Resources with the given identity, or an empty list if none were found.</returns> public static IEnumerable <Bundle.BundleEntryComponent> FindEntry(this Bundle bundle, string reference, bool includeDeleted = false) { if (reference == null) { throw Error.ArgumentNull("reference"); } if (bundle.Entry == null) { return(Enumerable.Empty <Bundle.BundleEntryComponent>()); } if (!new Uri(reference, UriKind.RelativeOrAbsolute).IsAbsoluteUri) { throw Error.Argument("reference", "uri should be absolute"); } string referencedVersion = ResourceIdentity.IsRestResourceIdentity(reference) ? (new ResourceIdentity(reference).VersionId) : null; reference = referencedVersion != null ? (new ResourceIdentity(reference).WithoutVersion().ToString()) : reference; var refRestUrl = new RestUrl(reference); var result = bundle.Entry.Where(be => new RestUrl(be.FullUrl).IsSameUrl(refRestUrl) && (includeDeleted == true || !be.IsDeleted())); if (referencedVersion != null) { result = result.Where(be => be.HasResource() && be.Resource.Meta.VersionId == referencedVersion); } return(result); }
public void TestBase() { var u = new RestUrl("http://www.hl7.org/svc"); Assert.IsTrue(u.IsEndpointFor("http://www.hl7.org/svc/Organization")); Assert.IsTrue(u.IsEndpointFor("http://www.hl7.org/svc/Organization/search?name=eve")); Assert.IsFalse(u.IsEndpointFor("http://www.hl7.org/svx/Organization")); }
public void testKnownUrl() { var route = RestUrl.GetRouteAttribute(typeof(TestRoutePath)); Assert.AreEqual(route.route, fakeRestPath); Assert.AreEqual(route.helpUrl, fakeHelpUrl); Assert.AreEqual(route.requestType, RestRequestType.POST); }
public void TestEscaping() { var url = new RestUrl("http://www.server.org/fhir"); url.AddParam("_since", FhirDateTime.Now().Value); var output = url.Uri; Assert.IsFalse(output.ToString().Contains("+")); // don't use un-escaped + }
public void Query() { RestUrl endpoint = new RestUrl("http://localhost/fhir"); RestUrl resturi; resturi = endpoint.Search("organization").AddParam("family", "Johnson").AddParam("given", "William"); Assert.AreEqual("http://localhost/fhir/organization/_search?family=Johnson&given=William", resturi.AsString); var rl2 = new RestUrl(resturi.Uri); rl2.AddParam("given", "Piet"); Assert.AreEqual("http://localhost/fhir/organization/_search?family=Johnson&given=William&given=Piet", rl2.AsString); }
public void CreateFromEndPoint() { RestUrl endpoint = new RestUrl("http://localhost/fhir"); RestUrl resturi; resturi = endpoint.ForCollection("patient"); Assert.AreEqual("http://localhost/fhir/patient", resturi.AsString); resturi = endpoint.Resource("patient", "1"); Assert.AreEqual("http://localhost/fhir/patient/1", resturi.AsString); resturi = endpoint.Resource("patient", "1"); Assert.AreEqual("http://localhost/fhir/patient/1", resturi.AsString); }
public void TryNavigation() { var old = new RestUrl("http://www.hl7.org/svc/Organization/"); var rl = old.NavigateTo("../Patient/1/_history"); Assert.AreEqual("http://www.hl7.org/svc/Patient/1/_history", rl.ToString()); old = new RestUrl("http://hl7.org/fhir/Patient/1"); rl = old.NavigateTo("2"); Assert.AreEqual("http://hl7.org/fhir/Patient/2", rl.ToString()); rl = old.NavigateTo("../Observation/3"); Assert.AreEqual("http://hl7.org/fhir/Observation/3", rl.ToString()); }
public Bundle History(string collection, DateTimeOffset?since) { RequestValidator.ValidateCollectionName(collection); if (since == null) { since = DateTimeOffset.MinValue; } string title = String.Format("Full server-wide history for updates since {0}", since); RestUrl self = new RestUrl(this.Endpoint).AddPath(collection, RestOperation.HISTORY); IEnumerable <BundleEntry> entries = _store.ListVersionsInCollection(collection, since, Const.MAX_HISTORY_RESULT_SIZE); Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, self.Uri, Const.AUTHOR, Settings.AuthorUri, entries); return(exportPagedBundle(bundle)); }
public void AreSame() { var rl = new RestUrl("http://someserver.org/Patient/4?oauth=xxxx"); var rl2 = new RestUrl("https://someserver.org/Patient/4"); Assert.IsTrue(rl.IsSameUrl(rl2)); Assert.IsTrue(rl2.IsSameUrl(rl)); rl2 = new RestUrl("http://someserver.org/Patient/4"); Assert.IsTrue(rl.IsSameUrl(rl2)); Assert.IsTrue(rl2.IsSameUrl(rl)); rl2 = new RestUrl("https://someserver.org:81/Patient/4"); Assert.IsFalse(rl.IsSameUrl(rl2)); Assert.IsFalse(rl2.IsSameUrl(rl)); }
public Bundle History(DateTimeOffset?since) { if (since == null) { since = DateTimeOffset.MinValue; } string title = String.Format("Full server-wide history for updates since {0}", since); RestUrl self = new RestUrl(this.Endpoint).AddPath(RestOperation.HISTORY); IEnumerable <BundleEntry> entries = _store.ListVersions(since, Const.MAX_HISTORY_RESULT_SIZE); Snapshot.Create(title, self.Uri, entries, Snapshot.NOCOUNT); Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, Endpoint, Const.AUTHOR, Settings.AuthorUri, entries); return(exportPagedBundle(bundle)); }
public Bundle Search(string collection, IEnumerable <Tuple <string, string> > parameters, int pageSize) { RequestValidator.ValidateCollectionName(collection); string title = String.Format("Search on resources in collection '{0}'", collection); RestUrl selfLink = new RestUrl(Endpoint).AddPath(collection); SearchResults results = _index.Search(collection, parameters); Snapshot snapshot = Snapshot.Create(title, selfLink.Uri, results, results.MatchCount); Bundle bundle = _pager.FirstPage(snapshot, pageSize); _exporter.EnsureAbsoluteUris(bundle); return(bundle); }
public Bundle History(string collection, DateTimeOffset?since, string sortby) { RequestValidator.ValidateCollectionName(collection); string title = String.Format("Full server-wide history for updates since {0}", since); RestUrl self = new RestUrl(this.Endpoint).AddPath(collection, RestOperation.HISTORY); IEnumerable <Uri> keys = store.History(collection, since); Snapshot snapshot = Snapshot.Create(title, self.Uri, keys, sortby); store.AddSnapshot(snapshot); Bundle bundle = pager.GetPage(snapshot); exporter.Externalize(bundle); return(bundle); }
public Bundle History(string collection, string id, DateTimeOffset?since, string sortby) { Uri key = BuildKey(collection, id); if (!store.Exists(key)) { throw new SparkException(HttpStatusCode.NotFound, "There is no history because there is no {0} resource with id {1}.", collection, id); } string title = String.Format("History for updates on '{0}' resource '{1}' since {2}", collection, id, since); RestUrl self = new RestUrl(this.Endpoint).AddPath(collection, id, RestOperation.HISTORY); IEnumerable <Uri> keys = store.History(key, since); Bundle bundle = pager.CreateSnapshotAndGetFirstPage(title, self.Uri, keys, sortby); exporter.Externalize(bundle); return(bundle); }
public Bundle History(DateTimeOffset?since, string sortby) { if (since == null) { since = DateTimeOffset.MinValue; } string title = String.Format("Full server-wide history for updates since {0}", since); RestUrl self = new RestUrl(this.Endpoint).AddPath(RestOperation.HISTORY); IEnumerable <Uri> keys = store.History(since); Snapshot snapshot = Snapshot.Create(title, self.Uri, keys, sortby); store.AddSnapshot(snapshot); Bundle bundle = pager.GetPage(snapshot, 0, Const.DEFAULT_PAGE_SIZE); exporter.Externalize(bundle); return(bundle); }
public static bool IsTargetOf(this Bundle.BundleEntryComponent entry, string reference) { // From the spec: If the reference is version specific (either relative or absolute), then remove the version from the URL // before matching fullUrl, and then match the version based on Resource.meta.versionId. if (reference == null) { throw Error.ArgumentNull("reference"); } if (!new Uri(reference, UriKind.RelativeOrAbsolute).IsAbsoluteUri) { throw Error.Argument("reference", "uri should be absolute"); } string referencedVersion = ResourceIdentity.IsRestResourceIdentity(reference) ? (new ResourceIdentity(reference).VersionId) : null; reference = referencedVersion != null ? (new ResourceIdentity(reference).WithoutVersion().ToString()) : reference; var refRestUrl = new RestUrl(reference); return(refRestUrl.IsSameUrl(new RestUrl(entry.FullUrl)) && (referencedVersion == null || (entry.HasResource() && entry.Resource.VersionId == referencedVersion))); }
public Bundle History(string collection, string id, DateTimeOffset?since) { RequestValidator.ValidateCollectionName(collection); RequestValidator.ValidateId(id); if (since == null) { since = DateTimeOffset.MinValue; } string title = String.Format("History for updates on '{0}' resource '{1}' since {2}", collection, id, since); RestUrl self = new RestUrl(this.Endpoint).AddPath(collection, id, RestOperation.HISTORY); if (!entryExists(collection, id)) { throw new SparkException(HttpStatusCode.NotFound, "There is no history because there is no {0} resource with id {1}.", collection, id); } var identity = ResourceIdentity.Build(collection, id).OperationPath; IEnumerable <BundleEntry> entries = _store.ListVersionsById(identity, since, Const.MAX_HISTORY_RESULT_SIZE); Bundle bundle = BundleEntryFactory.CreateBundleWithEntries(title, self.Uri, Const.AUTHOR, Settings.AuthorUri, entries); return(exportPagedBundle(bundle)); }
private Uri tryCreatePatient(FhirClient client, ResourceFormat formatIn, string id = null) { client.PreferredFormat = formatIn; ResourceEntry <Patient> created = null; Patient demopat = DemoData.GetDemoPatient(); if (id == null) { HttpTests.AssertSuccess(client, () => created = client.Create <Patient>(demopat)); } else { HttpTests.AssertSuccess(client, () => created = client.Create <Patient>(demopat, id)); var ep = new RestUrl(client.Endpoint); if (!ep.IsEndpointFor(created.Id)) { TestResult.Fail("Location of created resource is not located within server endpoint"); } var rl = new ResourceIdentity(created.Id); if (rl.Id != id) { TestResult.Fail("Server refused to honor client-assigned id"); } } HttpTests.AssertLocationPresentAndValid(client); // Create bevat geen response content meer. Terecht verwijderd?: // EK: Niet helemaal, er is weliswaar geen data meer gereturned, maar de headers (id, versie, modified) worden // nog wel geupdate HttpTests.AssertContentLocationValidIfPresent(client); return(created.SelfLink); }
public void ParamManipulation() { var rl = new RestUrl("http://someserver.org/fhir/Patient/search?name=Kramer&name=Moreau&oauth=XXX"); rl.AddParam("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")); rl.SetParam("newParamA", "6"); Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=6&newParamB=5")); rl.ClearParams(); Assert.IsTrue(rl.ToString().EndsWith("search")); }
public RestQueries(RestUrl restUrl) : base(restUrl) { deserial = new JsonDeserializer(); }
public void getSimpleURL() { var login = new Login("", ""); Assert.IsNotNull(RestUrl.GetURL(login)); }
public RestCrud(RestUrl restUrl) { this.restUrl = restUrl; client = new RestClient(restUrl.ReadBaseUrl()); InitDictionaryMethods(); }