Exemplo n.º 1
1
        public static async Task<List<Medication>> GetMedicationDataForPatientAsync(string patientId, FhirClient client)
        {
            var mySearch = new SearchParams();
            mySearch.Parameters.Add(new Tuple<string, string>("patient", patientId));

            try
            {
                //Query the fhir server with search parameters, we will retrieve a bundle
                var searchResultResponse = await Task.Run(() => client.Search<Hl7.Fhir.Model.MedicationOrder>(mySearch));
                //There is an array of "entries" that can return. Get a list of all the entries.
                return
                    searchResultResponse
                        .Entry
                            .AsParallel() //as parallel since we are making network requests
                            .Select(entry =>
                            {
                                var medOrders = client.Read<MedicationOrder>("MedicationOrder/" + entry.Resource.Id);
                                var safeCast = (medOrders?.Medication as ResourceReference)?.Reference;
                                if (string.IsNullOrWhiteSpace(safeCast)) return null;
                                return client.Read<Medication>(safeCast);
                            })
                            .Where(a => a != null)
                            .ToList(); //tolist to force the queries to occur now
            }
            catch (AggregateException e)
            {
                throw e.Flatten();
            }
            catch (FhirOperationException)
            {
                // if we have issues we likely got a 404 and thus have no medication orders...
                return new List<Medication>();
            }
        }
Exemplo n.º 2
0
        public static Hl7.Fhir.Rest.SearchParams MatchOnId(this Hl7.Fhir.Rest.SearchParams searchParams, string id)
        {
            EnsureArg.IsNotNull(searchParams, nameof(searchParams));

            searchParams.Parameters.Add(new Tuple <string, string>(SearchParam.Id.ToString(), id));
            return(searchParams);
        }
Exemplo n.º 3
0
        public static Hl7.Fhir.Rest.SearchParams ToSearchPath <TResource>()
            where TResource : Hl7.Fhir.Model.Resource
        {
            var searchParams = new Hl7.Fhir.Rest.SearchParams();

            return(searchParams);
        }
Exemplo n.º 4
0
        public static Hl7.Fhir.Rest.SearchParams ToSearchParams(this Hl7.Fhir.Model.Identifier identifier)
        {
            var searchParams = new Hl7.Fhir.Rest.SearchParams();

            searchParams.Add(SearchParam.Identifier.ToString(), identifier.ToSearchToken());
            return(searchParams);
        }
Exemplo n.º 5
0
        public static Hl7.Fhir.Rest.SearchParams SetCount(this Hl7.Fhir.Rest.SearchParams searchParams, int?count)
        {
            EnsureArg.IsNotNull(searchParams, nameof(searchParams));

            searchParams.Count = count;
            return(searchParams);
        }
Exemplo n.º 6
0
        public static Hl7.Fhir.Rest.SearchParams ForSubject <TResource>(this Hl7.Fhir.Rest.SearchParams searchParams, string subjectValue)
            where TResource : Hl7.Fhir.Model.Resource
        {
            EnsureArg.IsNotNull(searchParams, nameof(searchParams));

            searchParams.Add(SearchParam.Subject.ToString(), $@"{typeof(TResource).Name}/{subjectValue}");
            return(searchParams);
        }
Exemplo n.º 7
0
        public static Hl7.Fhir.Rest.SearchParams MatchOnAnyIdentifier(this Hl7.Fhir.Rest.SearchParams searchParams, IEnumerable <Hl7.Fhir.Model.Identifier> identifiers)
        {
            searchParams.Add(SearchParam.Identifier.ToString(), identifiers
                             .Select(id => id.ToSearchToken())
                             .CompositeOr());

            return(searchParams);
        }
        public IEnumerable<Observation> GetObservationsByName(string text)
        {
            var searchParameters = new SearchParams();
            searchParameters.Add("name", text);

            var results = _client.Search(searchParameters, ResourceType.Observation.ToString());
            return results.Entry.Select(s => (Observation)s.Resource);
        }
        public IEnumerable<AllergyIntolerance> GetAllergiesByName(string text)
        {
            var searchParameters = new SearchParams();
            searchParameters.Add("name", text);

            var result = _client.Search(searchParameters, ResourceType.AllergyIntolerance.ToString());
            return result.Entry.Select(s => (AllergyIntolerance)s.Resource);
        }
        IEnumerable<Medication> GetMedicationsByName(string name)
        {
            var searchParameters = new SearchParams();
            searchParameters.Add("name", name);

            var result = _client.Search(searchParameters, ResourceType.Medication.ToString());
            return result.Entry.Select(s => (Medication)s.Resource);
        }
Exemplo n.º 11
0
 private static string GetFirstSort(SearchParams searchCommand)
 {
     string firstSort = null;
     if (searchCommand.Sort != null && searchCommand.Sort.Count() > 0)
     {
         firstSort = searchCommand.Sort[0].Item1; //TODO: Support sortorder and multiple sort arguments.
     }
     return firstSort;
 }
Exemplo n.º 12
0
        public static Hl7.Fhir.Rest.SearchParams MatchOnAllIdentifiers(this IEnumerable <Hl7.Fhir.Model.Identifier> identifiers)
        {
            var searchParams = new Hl7.Fhir.Rest.SearchParams();

            searchParams.Add(SearchParam.Identifier.ToString(), identifiers
                             .Select(id => id.ToSearchToken())
                             .CompositeAnd());

            return(searchParams);
        }
Exemplo n.º 13
0
 public IEnumerable<Patient> GetPatientsByName(string firstName, string lastName)
 {
     var searchParameters = new SearchParams();
     searchParameters.Add("Given", firstName);
     searchParameters.Add("Family", lastName);
     
     var matches = new List<Patient>();
     var result = _client.Search(searchParameters, ResourceType.Patient.ToString());
     return result.Entry.Select(x => (Patient) x.Resource);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Apply specified sort values to the search parameters.
        /// </summary>
        /// <param name="searchParams">The parameter collection to modify.</param>
        /// <param name="sortParameters">The parameters to sort by, applied in order. If null or empty no sorting will be applied.</param>
        /// <returns>The modified search parameter collection.</returns>
        /// <remarks>Fhir spec calls for indicating a descing sort using a minus, i.e. -date. Currently our fhir server implementation doesn't support sorting so values are ignored.</remarks>
        /// <seealso cref="https://www.hl7.org/fhir/search.html#_sort"/>
        /// <seealso cref="https://github.com/Microsoft/fhir-server/blob/master/docs/Features.md#Search"/>
        public static Hl7.Fhir.Rest.SearchParams SortBy(this Hl7.Fhir.Rest.SearchParams searchParams, params string[] sortParameters)
        {
            foreach (var sortParam in sortParameters ?? Enumerable.Empty <string>())
            {
                if (!string.IsNullOrWhiteSpace(sortParam))
                {
                    searchParams.OrderBy(sortParam);
                }
            }

            return(searchParams);
        }
Exemplo n.º 15
0
        private static List <FhirModel4.Patient> GetPatients(FhirRest.FhirR4Client fhirClient, string family)
        {
            var srch = new FhirRest.SearchParams()
                       .Where($"family={family}")
                       .LimitTo(20)
                       .SummaryOnly()
                       .OrderBy("birthdate",
                                FhirRest.SortOrder.Descending);

            var bundle = fhirClient.Search <FhirModel4.Patient>(srch);

            return(bundle.Entry.Select(b => b.Resource as FhirModel4.Patient).ToList());
        }
Exemplo n.º 16
0
        /// <summary>
        /// Conditionally add search parameter for the specified value to the parameter collection.
        /// </summary>
        /// <param name="searchParams">The search parameter collection to modify.</param>
        /// <param name="searchParam">Search parameter to add.</param>
        /// <param name="paramValue">The value of the parameter to add to the collection. If value is null no search parameter will be added.</param>
        /// <param name="searchPrefix">Optional prefix for value matching.</param>
        /// <returns>The modified search parameter collection.</returns>
        public static Hl7.Fhir.Rest.SearchParams WhenParamValue(this Hl7.Fhir.Rest.SearchParams searchParams, string searchParam, object paramValue, SearchPrefix searchPrefix = null)
        {
            if (searchParam == null)
            {
                throw new ArgumentNullException(nameof(searchParam));
            }

            if (paramValue != null)
            {
                SearchPrefix prefix = searchPrefix ?? SearchPrefix.Empty;
                searchParams.Add(searchParam, $@"{searchPrefix}{paramValue}");
            }

            return(searchParams);
        }
Exemplo n.º 17
0
        public void TestProperties()
        {
            var q = new SearchParams();
            q.Query = "special";
            q.Count = 31;
            q.Summary = SummaryType.Data;
            q.Sort.Add(Tuple.Create("sorted", SortOrder.Descending));
            q.Include.Add("Patient.name");
            q.Include.Add("Observation.subject");
            q.Elements.Add("field1");

            Assert.AreEqual("special", q.Query);
            Assert.AreEqual(31, q.Count);
            Assert.AreEqual(SummaryType.Data, q.Summary);
            Assert.AreEqual(Tuple.Create("sorted", SortOrder.Descending), q.Sort.Single());
            Assert.AreEqual(2, q.Include.Count);
            Assert.AreEqual("Patient.name", q.Include.First());
            Assert.AreEqual("Observation.subject", q.Include.Skip(1).First());
            Assert.AreEqual(1, q.Elements.Count);
            Assert.AreEqual("field1", q.Elements.First());
            
            q.Query = "special2";
            q.Count = 32;
            q.Summary = SummaryType.True;
            q.Sort.Add(Tuple.Create("sorted2", SortOrder.Ascending));
            q.Include.Add("Patient.name2");
            q.Include.Remove("Patient.name");
            q.Include.Add("Observation.subject2");
            q.Elements.Add("field2");

            Assert.AreEqual("special2", q.Query);
            Assert.AreEqual(32, q.Count);
            Assert.AreEqual(SummaryType.True, q.Summary);
            Assert.AreEqual(2,q.Sort.Count);
            Assert.AreEqual(Tuple.Create("sorted2", SortOrder.Ascending), q.Sort.Skip(1).Single());
            Assert.AreEqual(3, q.Include.Count);
            Assert.IsTrue(q.Include.Contains("Patient.name2"));
            Assert.IsFalse(q.Include.Contains("Patient.name"));
            Assert.IsTrue(q.Include.Contains("Observation.subject"));
            Assert.IsTrue(q.Include.Contains("Observation.subject2"));
            Assert.AreEqual(2, q.Elements.Count);
            Assert.AreEqual("field1", q.Elements.First());
            Assert.AreEqual("field2", q.Elements.Skip(1).First());
        }
        private void SearchAllergies(string PatientId)
        {
            WorkingMessage();
            listAllergies.Items.Clear();
            string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString();
            var    client        = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint);

            try
            {
                var p = new Hl7.Fhir.Rest.SearchParams();
                p.Add("patient", PatientId);

                var results = client.Search <AllergyIntolerance>(p);
                this.UseWaitCursor   = false;
                lblErrorMessage.Text = "";
                while (results != null)
                {
                    if (results.Total == 0)
                    {
                        lblErrorMessage.Text = "No allergies found";
                    }

                    foreach (var entry in results.Entry)
                    {
                        var    Alrgy   = (AllergyIntolerance)entry.Resource;
                        string Content = Alrgy.Code.Coding[0].Display
                                         + " / " + Alrgy.VerificationStatus.Coding[0].Code
                                         + " (" + Alrgy.ClinicalStatus.Coding[0].Code + ")";
                        listAllergies.Items.Add(Content);
                    }
                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                lblErrorMessage.Text = "Error:" + err.Message.ToString();
            }
            if (lblErrorMessage.Text != "")
            {
                lblErrorMessage.Visible = true;
            }
        }
        private void FetchPatients()
        {
            FhirClient fhirClient = new FhirClient("https://fhir-open.sandboxcernerpowerchart.com/dstu2/d075cf8b-3261-481d-97e5-ba6c48d3b41f");
            fhirClient.PreferredFormat = ResourceFormat.Json;
            fhirClient.UseFormatParam = true;

            try
            {
                EditText patientNameField = FindViewById<EditText>(Resource.Id.PatientNameField);
                string patientName = patientNameField.Text;
                SearchParams searchParams = new SearchParams();
                searchParams.Add("name", patientName);
                searchParams.Add("_count", "50");
                Hl7.Fhir.Model.Bundle patients = fhirClient.Search<Patient>(searchParams);
                Log.Info(TAG, "Retrieved patients: " + patients.Total);

                RunOnUiThread(() =>
                {
                    ListView pxListView = FindViewById<ListView>(Resource.Id.PatientListView);
                    ArrayAdapter adapter = pxListView.Adapter as ArrayAdapter;
                    Log.Debug(TAG, "Adapter: " + adapter.ToString());
                    adapter.Clear();
                    adapter.AddAll(patients.Entry);
                }
                );
            }
            catch (Exception e)
            {
                Log.Warn(TAG, e.Message);
                RunOnUiThread(() =>
                {
                    Android.Widget.Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                }
                );
            }
            finally
            {
                RunOnUiThread(() => {
                    EnableInputs();
                }
                );
            }
        }
Exemplo n.º 20
0
        public Key FindSingle(string resource, SearchParams searchCommand)
        {
            // todo: this needs optimization

            SearchResults results = _searcher.Search(resource, searchCommand);
            if (results.Count > 1)
            {
                throw Error.BadRequest("The search for a single resource yielded more than one.");
            }
            else if (results.Count == 0)
            {
                throw Error.BadRequest("No resources were found while searching for a single resource.");
            }
            else 
            {
                string location = results.FirstOrDefault();
                return Key.ParseOperationPath(location);
            }
        }
Exemplo n.º 21
0
        public SearchResults Search(string resourceType, SearchParams searchCommand)
        {
            SearchResults results = new SearchResults();

            var criteria = parseCriteria(searchCommand, results);

            if (!results.HasErrors)
            {
                results.UsedCriteria = criteria;
                var normalizedCriteria = NormalizeNonChainedReferenceCriteria(criteria, resourceType);
                List<BsonValue> keys = CollectKeys(resourceType, normalizedCriteria, results);

                int numMatches = keys.Count();

                results.AddRange(KeysToSearchResults(keys));
                results.MatchCount = numMatches;
            }

            return results;
        }
Exemplo n.º 22
0
        public void ManipulateParameters()
        {
            var q = new SearchParams();

            q.Add("testX", "someVal");
            q.Add("testX", "someVal2");
            q.Add("testXY", "someVal3");

            var paramlist = q.ToUriParamList();
            var vals = paramlist.Values("testX");
            Assert.AreEqual(2, vals.Count());
            Assert.AreEqual("someVal", vals.First());
            Assert.AreEqual("someVal2", vals.Skip(1).First());
            
            Assert.AreEqual("someVal3", paramlist.SingleValue("testXY"));

            paramlist.Remove("testXY");
            Assert.IsNull(paramlist.SingleValue("testXY"));
            Assert.AreEqual(2, paramlist.Values("testX").Count());
        }
Exemplo n.º 23
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Choose your preferred FHIR server or add your own
            // More at http://wiki.hl7.org/index.php?title=Publicly_Available_FHIR_Servers_for_testing

            //var client = new FhirClient("http://fhir2.healthintersections.com.au/open");
            var client = new FhirClient("http://spark.furore.com/fhir");
            //var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu2");
            //var client = new FhirClient("https://fhir-open-api-dstu2.smarthealthit.org/");

            try
            {
                var q = new SearchParams().Where("name=pete");
                //var q = new SearchParams().Where("name=pete").Where("birthdate=1974-12-25");

                var results = client.Search<Patient>(q);

                txtDisplay.Text = "";

                while (results != null)
                {
                    if (results.Total == 0) txtDisplay.Text = "No results found";

                    foreach (var entry in results.Entry)
                    {
                        txtDisplay.Text += "Found patient with id " + entry.Resource.Id + Environment.NewLine;
                    }

                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                txtError.Lines = new string[] { "An error has occurred:", err.Message };
            }
        }
Exemplo n.º 24
0
 public static SearchParams DataOnly(this SearchParams qry)
 {
     qry.Summary = SummaryType.Data;
     return(qry);
 }
Exemplo n.º 25
0
        public TransactionBuilder Delete(string resourceType, SearchParams condition)
        {
            var entry = newEntry(Bundle.HTTPVerb.DELETE);
            var path = newRestUrl().AddPath(resourceType);
            path.AddParams(condition.ToUriParamList());
            addEntry(entry, path);

            return this;
        }
Exemplo n.º 26
0
        //TODO: Delete, F.Query is obsolete.
        /*
        public SearchResults Search(F.Query query)
        {
            SearchResults results = new SearchResults();

            var criteria = parseCriteria(query, results);

            if (!results.HasErrors)
            {
                results.UsedCriteria = criteria;
                //TODO: ResourceType.ToString() sufficient, or need to use EnumMapping?
                var normalizedCriteria = NormalizeNonChainedReferenceCriteria(criteria, query.ResourceType.ToString());
                List<BsonValue> keys = CollectKeys(query.ResourceType.ToString(), normalizedCriteria, results);

                int numMatches = keys.Count();

                results.AddRange(KeysToSearchResults(keys));
                results.MatchCount = numMatches;
            }

            return results;
        }
        */
        private List<Criterium> parseCriteria(SearchParams searchCommand, SearchResults results)
        {
            var result = new List<Criterium>();
            foreach (var c in searchCommand.Parameters)
            {
                try
                {
                    result.Add(Criterium.Parse(c.Item1, c.Item2));
                }
                catch (Exception ex)
                {
                    results.AddIssue(String.Format("Could not parse parameter [{0}] for reason [{1}].", c.ToString(), ex.Message));
                }
            }
            return result;
        }
Exemplo n.º 27
0
 public static SearchParams TextOnly(this SearchParams qry)
 {
     qry.Summary = SummaryType.Text;
     return(qry);
 }
Exemplo n.º 28
0
        public void ParseAndSerializeParams()
        {
            var q = new SearchParams();
            q.Add("_query", "special");
            q.Add("_count", "31");
            q.Add("_summary", "true");
            q.Add("_sort:desc", "sorted");
            q.Add("_sort:asc", "sorted2");
            q.Add("_include", "Patient.name");
            q.Add("_include", "Observation.subject");

            var output = q.ToUriParamList().ToQueryString();
            Assert.AreEqual("_query=special&_count=31&_include=Patient.name&_include=Observation.subject&_sort%3Adesc=sorted&_sort%3Aasc=sorted2&_summary=true", output);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        public Snapshot CreateSnapshot(Uri selflink, IEnumerable<string> keys, SearchParams searchCommand)
        {
            string sort = GetFirstSort(searchCommand);

            int? count = null;
            if (searchCommand.Count.HasValue)
            {
                count = Math.Min(searchCommand.Count.Value, MAX_PAGE_SIZE);
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_COUNT, new string[] {count.ToString()});
            }

            if (string.IsNullOrEmpty(sort) == false)
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_SORT, new string[] {sort });
            }

            if (searchCommand.Include.Any())
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_INCLUDE,  searchCommand.Include.ToArray());
            }

            return CreateSnapshot(Bundle.BundleType.Searchset, selflink, keys, sort, count, searchCommand.Include);
        }
Exemplo n.º 31
0
 public static SearchParams LimitTo(this SearchParams qry, int count)
 {
     qry.Count = count;
     return(qry);
 }
Exemplo n.º 32
0
        }//end GetPatientsKnownAllergies

        /// <summary>       
        /// Returns a dictionary of patient's allergies (ICD-10-CM Diagnosis Codes) from the FHIR server
        /// </summary>       
        /// <param name="patientID"> Unique ID of patient for FHIR server</param>
        private IList<string> GetAllergyIntoleranceIDs(string patientID)
        {
            IList<string> listOfAllergyIntoleranceIDs = new List<string>();

            //First we need to set up the Search Param Object
            var mySearch = new SearchParams();

            //Create a tuple containing search parameters for SearchParam object
            // equivalent of "AllergyIntolerance?patient=6116";
            var mySearchTuple = new Tuple<string, string>("patient", patientID.ToString());
            mySearch.Parameters.Add(mySearchTuple);

            //Query the fhir server with search parameters, we will retrieve a bundle
            var searchResultResponse = fhirClient.Search<Hl7.Fhir.Model.AllergyIntolerance>(mySearch);

            //There is an array of "entries" that can return. Get a list of all the entries.
            var listOfentries = searchResultResponse.Entry;

            if (listOfentries.Count == 0)
                return listOfAllergyIntoleranceIDs;

           
            //Let us pull out only the Allery Intolerance IDs from the bundle objects
            foreach (var entry in listOfentries)
            {
                listOfAllergyIntoleranceIDs.Add(entry.Resource.Id);
            }

            return listOfAllergyIntoleranceIDs;          
        }
Exemplo n.º 33
0
  public SearchResults Search(string resource, SearchParams searchCommand)
 {
     return _searcher.Search(resource, searchCommand);
 }
Exemplo n.º 34
0
        public FhirResponse Search(string type, SearchParams searchCommand)
        {
            _log.ServiceMethodCalled("search");

            Validate.TypeName(type);
            SearchResults results = fhirIndex.Search(type, searchCommand);

            if (results.HasErrors)
            {
                throw new SparkException(HttpStatusCode.BadRequest, results.Outcome);
            }

            UriBuilder builder = new UriBuilder(localhost.Uri(type));
            builder.Query = results.UsedParameters;
            Uri link = builder.Uri;

            var snapshot = pager.CreateSnapshot(link, results, searchCommand);
            Bundle bundle = pager.GetFirstPage(snapshot);

            if (results.HasIssues)
            {
                bundle.AddResourceEntry(results.Outcome, new Uri("outcome/1", UriKind.Relative).ToString());
            }

            return Respond.WithBundle(bundle);
        }
Exemplo n.º 35
0
        public TransactionBuilder Create(Resource body, SearchParams condition)
        {
            var entry = newEntry(Bundle.HTTPVerb.POST);
            entry.Resource = body;
            var path = newRestUrl().AddPath(body.TypeName);

            var nonExist = new RestUrl(path);
            nonExist.AddParams(condition.ToUriParamList());
            entry.Request.IfNoneExist = nonExist.ToString();
            addEntry(entry, path);

            return this;
        }
Exemplo n.º 36
0
        public void ReapplySingleParam()
        {
            var q = new SearchParams()
                .Custom("mySearch").OrderBy("adsfadf").OrderBy("q", SortOrder.Descending)
                    .LimitTo(10).LimitTo(20).Custom("miSearch").SummaryOnly().SummaryOnly(false);

            Assert.AreEqual("miSearch", q.Query);
            Assert.IsFalse(q.Summary.Value);

            var o = q.Sort;
            Assert.AreEqual("adsfadf", o.First().Item1);
            Assert.AreEqual(SortOrder.Ascending, o.First().Item2);
            Assert.AreEqual("q", o.Skip(1).First().Item1);
            Assert.AreEqual(SortOrder.Descending, o.Skip(1).First().Item2);

            Assert.AreEqual(20, q.Count);

            Assert.IsFalse(q.Summary.Value);
        }
Exemplo n.º 37
0
 /// <summary>
 /// Conditionally add search parameter for the specified value to the parameter collection.
 /// </summary>
 /// <param name="searchParams">The search parameter collection to modify.</param>
 /// <param name="searchParam">Search parameter to add.</param>
 /// <param name="resourceRefValue">The resource reference add to the collection. If value is null no search parameter will be added.</param>
 /// <param name="searchPrefix">Optional prefix for value matching.</param>
 /// <returns>The modified search parameter collection.</returns>
 public static Hl7.Fhir.Rest.SearchParams WhenParamValue(this Hl7.Fhir.Rest.SearchParams searchParams, SearchParam searchParam, Hl7.Fhir.Model.ResourceReference resourceRefValue, SearchPrefix searchPrefix = null)
 {
     return(searchParams.WhenParamValue(searchParam?.ToString(), resourceRefValue, searchPrefix));
 }
Exemplo n.º 38
0
        public void SerializeParams()
        {
            var q = new SearchParams();
            q.Query = "special";
            q.Count = 31;
            q.Summary = true;
            q.Sort.Add(Tuple.Create("sorted", SortOrder.Descending));
            q.Sort.Add(Tuple.Create("sorted2", SortOrder.Ascending));
            q.Include.Add("Patient.name");
            q.Include.Add("Observation.subject");

            var output = q.ToUriParamList().ToQueryString();
            Assert.AreEqual("_query=special&_count=31&_include=Patient.name&_include=Observation.subject&_sort%3Adesc=sorted&_sort%3Aasc=sorted2&_summary=true", output);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Conditionally add search parameter for the specified value to the parameter collection.
 /// </summary>
 /// <param name="searchParams">The search parameter collection to modify.</param>
 /// <param name="searchParam">Search parameter to add.</param>
 /// <param name="paramValue">The value of to add to the collection. If value is null no search parameter will be added.</param>
 /// <param name="searchPrefix">Optional prefix for value matching.</param>
 /// <returns>The modified search parameter collection.</returns>
 public static Hl7.Fhir.Rest.SearchParams WhenParamValue(this Hl7.Fhir.Rest.SearchParams searchParams, SearchParam searchParam, object paramValue, SearchPrefix searchPrefix = null)
 {
     return(searchParams.WhenParamValue(searchParam?.ToString(), paramValue, searchPrefix));
 }
Exemplo n.º 40
0
 public void CountSetToNullAndGet()
 {
     var q = new SearchParams();
     q.Count = null;
     Assert.IsFalse(q.Count.HasValue);
 }
Exemplo n.º 41
0
        public ISearchParameterGeneric Parse(Hl7.Fhir.Rest.SearchParams SearchParams)
        {
            this.ParameterList = new List <Tuple <string, string> >();

            //We need to go through the SearchParams.Parameters and pull out the
            //includes. This is because the API correctly pulls out the normal '_includes'
            //into it's set property yet '_includes:recurse' incorrectly are placed in the
            //SearchParams.Parameters list.

            if (SearchParams.Include != null && SearchParams.Include.Count > 0)
            {
                if (this.Include == null)
                {
                    this.Include = new List <Tuple <string, string> >();
                }
                foreach (var Inc in SearchParams.Include)
                {
                    this.Include.Add(new Tuple <string, string>(SearchParams.SEARCH_PARAM_INCLUDE, Inc.Trim()));
                }
            }

            if (SearchParams.RevInclude != null && SearchParams.RevInclude.Count > 0)
            {
                if (this.RevInclude == null)
                {
                    this.RevInclude = new List <Tuple <string, string> >();
                }
                foreach (var Inc in SearchParams.RevInclude)
                {
                    this.RevInclude.Add(new Tuple <string, string>(SearchParams.SEARCH_PARAM_REVINCLUDE, Inc.Trim()));
                }
            }



            foreach (var Para in SearchParams.Parameters)
            {
                bool IsNoramlParameter = true;
                if (ParseIncludeSearchParameters(Para.Item1, Para.Item2) != null)
                {
                    if (this.Include == null)
                    {
                        this.Include = new List <Tuple <string, string> >();
                    }
                    this.Include.Add(ParseIncludeSearchParameters(Para.Item1, Para.Item2));
                    IsNoramlParameter = false;
                }

                if (ParseRevIncludeSearchParameters(Para.Item1, Para.Item2) != null)
                {
                    if (this.RevInclude == null)
                    {
                        this.RevInclude = new List <Tuple <string, string> >();
                    }
                    this.RevInclude.Add(ParseRevIncludeSearchParameters(Para.Item1, Para.Item2));
                    IsNoramlParameter = false;
                }
                //Add parameters left to the main search parameter list
                if (IsNoramlParameter)
                {
                    this.ParameterList.Add(Para);
                }
            }

            this.Sort        = SearchParams.Sort;
            this.Count       = SearchParams.Count;
            this.SummaryType = SearchParams.Summary;
            return(this);
        }
Exemplo n.º 42
0
        public void ManageSearchResult()
        {
            var q = new SearchParams()
               .Where("name:exact=ewout").OrderBy("birthDate", SortOrder.Descending)
                .SummaryOnly().Include("Patient.managingOrganization")
                .LimitTo(20);

            var parameters = q.ToUriParamList();

            var p = parameters.Single("name");
            Assert.AreEqual("name:exact", p.Item1);
            Assert.AreEqual("ewout", p.Item2);

            var o = q.Sort;
            Assert.AreEqual("birthDate", o.First().Item1);
            Assert.AreEqual(SortOrder.Descending, o.First().Item2);

            Assert.IsTrue(q.Summary.Value);
            Assert.IsTrue(q.Include.Contains("Patient.managingOrganization"));
            Assert.AreEqual(20, q.Count);
        }
Exemplo n.º 43
0
 public static Hl7.Fhir.Rest.SearchParams SetCount(this Hl7.Fhir.Rest.SearchParams searchParams, int?count)
 {
     searchParams.Count = count;
     return(searchParams);
 }
Exemplo n.º 44
0
 public static SearchParams SummaryOnly(this SearchParams qry, SummaryType summaryOnly = SummaryType.True)
 {
     qry.Summary = summaryOnly;
     return(qry);
 }
        private void SearchPatients()
        {
            WorkingMessage();
            listCandidates.Items.Clear();
            string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString();
            var    client        = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint);

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                // Replace with a valid bearer token for the server
                // e.RawRequest.Headers.Add("Authorization", "Bearer ya29.QQIBibTwvKkE39hY8mdkT_mXZoRh7Ub9cK9hNsqrxem4QJ6sQa36VHfyuBe");
            };
            try
            {
                string patId   = txtPatientID.Text.ToString();
                string patName = txtPatientName.Text.ToString();
                var    p       = new Hl7.Fhir.Rest.SearchParams();

                switch (SearchOption)
                {
                case 1:
                    p.Add("_id", patId);
                    break;

                case 2:
                    p.Add("name", patName);
                    break;

                case 3:
                    p.Add("name", patName);
                    p.Add("birthdate", dateTimeDob.Text);
                    break;
                }

                var results = client.Search <Patient>(p);
                this.UseWaitCursor   = false;
                lblErrorMessage.Text = "";

                while (results != null)
                {
                    if (results.Total == 0)
                    {
                        lblErrorMessage.Text = "No patients found";
                    }
                    btnShowAllergies.Enabled = true;
                    foreach (var entry in results.Entry)
                    {
                        var    Pat = (Patient)entry.Resource;
                        string Fam = "", Giv = "", ideS = "", ideV = "";
                        if (Pat.Name.Count > 0)
                        {
                            Fam = Pat.Name[0].Family;
                            Giv = Pat.Name[0].GivenElement[0].ToString();
                        }
                        if (Pat.Identifier.Count > 0)
                        {
                            ideS = Pat.Identifier[0]?.System;
                            ideV = Pat.Identifier[0]?.Value;
                        }

                        string       Content = Fam + " " + Giv + " (" + ideS + "-" + ideV + ")";
                        ListViewItem l       = new ListViewItem
                        {
                            Text = Content,
                            Tag  = entry.Resource.Id
                        };
                        listCandidates.Items.Add(l);
                    }

                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                lblErrorMessage.Text = "Error:" + err.Message.ToString();
            }
            if (lblErrorMessage.Text != "")
            {
                lblErrorMessage.Visible = true;
            }
        }
Exemplo n.º 46
0
 public static SearchParams CountOnly(this SearchParams qry)
 {
     qry.Summary = SummaryType.Count;
     return(qry);
 }
Exemplo n.º 47
0
 public static Hl7.Fhir.Rest.SearchParams MatchOnId(this Hl7.Fhir.Rest.SearchParams searchParams, string id)
 {
     searchParams.Parameters.Add(new Tuple <string, string>(SearchParam.Id.ToString(), id));
     return(searchParams);
 }
Exemplo n.º 48
0
        public TransactionBuilder Search(SearchParams q = null, string resourceType = null)
        {
            var entry = newEntry(Bundle.HTTPVerb.GET);
            var path = newRestUrl();
            if (resourceType != null) path.AddPath(resourceType);
            if(q != null) path.AddParams(q.ToUriParamList());
            addEntry(entry, path);

            return this;
        }
Exemplo n.º 49
0
        public TransactionBuilder Update(SearchParams condition, Resource body, string ifMatch=null)
        {
            var entry = newEntry(Bundle.HTTPVerb.PUT);
            entry.Resource = body;
            var path = newRestUrl().AddPath(body.TypeName);
            path.AddParams(condition.ToUriParamList());
            addEntry(entry, path);

            return this;
        }
Exemplo n.º 50
0
 public FhirResponse ConditionalUpdate(Key key, Resource resource, SearchParams _params)
 {
     Key existing = fhirIndex.FindSingle(key.TypeName, _params).WithoutVersion();
     return this.Update(existing, resource);
 }
Exemplo n.º 51
0
        public void ParamOrderHasDefault()
        {
            var q = new SearchParams();

            q.Add("_sort", "birthdate");
            q.Add("_sort:asc", "name");
            q.Add("_sort:desc", "active");
            Assert.AreEqual(3, q.Sort.Count());
            Assert.AreEqual(Tuple.Create("birthdate", SortOrder.Ascending), q.Sort.First());
            Assert.AreEqual(Tuple.Create("name", SortOrder.Ascending), q.Sort.Skip(1).First());
            Assert.AreEqual(Tuple.Create("active", SortOrder.Descending), q.Sort.Skip(2).First());
        }
Exemplo n.º 52
0
        public void ParseAndSerializeParams()
        {
            var q = new SearchParams();
            q.Add("_query", "special");
            q.Add("_count", "31");
            q.Add("_summary", "data");
            q.Add("_sort:desc", "sorted");
            q.Add("_sort:asc", "sorted2");
            q.Add("_include", "Patient.name");
            q.Add("_include", "Observation.subject");
            q.Add("image:missing", "true");
            q.Add("_elements", "field1,field2");
            var output = q.ToUriParamList().ToQueryString();
            Assert.AreEqual("_query=special&_count=31&_include=Patient.name&_include=Observation.subject&_sort%3Adesc=sorted&_sort%3Aasc=sorted2&_summary=data&_elements=field1%2Cfield2&image%3Amissing=true", output);

            var q2 = SearchParams.FromUriParamList(UriParamList.FromQueryString(output));

            Assert.AreEqual(q.Query, q2.Query);
            Assert.AreEqual(q.Count, q2.Count);
            Assert.AreEqual(q.Summary, q2.Summary);
            
            CollectionAssert.AreEquivalent(q.Sort.ToList(), q2.Sort.ToList());
            CollectionAssert.AreEquivalent(q.Include.ToList(), q2.Include.ToList());
            CollectionAssert.AreEquivalent(q.Parameters.ToList(), q2.Parameters.ToList());
            CollectionAssert.AreEquivalent(q.Elements.ToList(), q2.Elements.ToList());
        }
Exemplo n.º 53
0
        public static SearchParams Include(this SearchParams qry, string path)
        {
            qry.Include.Add(path);

            return(qry);
        }