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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Search for Resources at a given endpoint
        /// </summary>
        /// <param name="endpoint">The endpoint where the search request is sent.</param>
        /// <param name="count">The maximum number of resources to return</param>
        /// <param name="includes">Zero or more include paths</param>
        /// <typeparam name="TResource">The type of resource to list</typeparam>
        /// <returns>A Bundle with all resources found by the search, or an empty Bundle if none were found.</returns>
        /// <remarks>The endpoint may be a FHIR server for server-wide search or a collection endpoint
        /// (i.e. /patient) for searching within a certain type of resources. This operation supports include
        /// parameters to include resources in the bundle that the returned resources refer to.</remarks>
        public Bundle Search(Uri endpoint, SearchParam[] criteria = null, string sort = null, string[] includes = null, int?count = null)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            var rl = new ResourceLocation(endpoint);

            // Since there is confusion between using /resource/?param, /resource?param, use
            // the /resource/search?param instead
            if (rl.Collection != null)
            {
                rl.Operation = ResourceLocation.RESTOPER_SEARCH;
            }

            if (count.HasValue)
            {
                rl.AddParam(Util.SEARCH_PARAM_COUNT, count.Value.ToString());
            }

            if (sort != null)
            {
                rl.AddParam(Util.SEARCH_PARAM_SORT, sort);
            }

            if (criteria != null)
            {
                foreach (var criterium in criteria)
                {
                    rl.AddParam(criterium.QueryKey, criterium.QueryValue);
                }
            }

            if (includes != null)
            {
                foreach (string includeParam in includes)
                {
                    rl.AddParam(Util.SEARCH_PARAM_INCLUDE, includeParam);
                }
            }

            return(FetchBundle(rl.ToUri()));
        }