Search Providers

Performing a Provider Search

Overview

The searchProviders method in the b.well SDK is specifically designed for conducting provider searches, allowing for a range of filtering and sorting options to tailor the search results.

Method Signature

suspend fun searchProviders(providerSearchRequest: ProviderSearchRequest): BWellResult<Provider>
  • providerSearchRequest: Encapsulates search parameters for providers.
  • BWellResult<Provider>: Returns a collection of matching providers, FHIR OperationOutcome, and paging information.

Search Parameters

  • Search Term:
    • Key filter for searches, applicable for names, specialties, locations, addresses, or phone numbers.
  • Specialty Filters:
    • An array of strings to filter results by specialty.
  • Gender:
    • Filters providers based on gender (male, female, other, unknown).
  • Location:
    • Filters results by geographical location using latitude, longitude, and distance.
  • Sort By:
    • Default sorting is by relevance and is applied if no sortBy value is provided. Other options for searchProviders includes distance, which if included will sort the search results by distance to the user's location.
  • Pagination:
    • page: Specifies the page number for results.
    • pageSize: Determines the number of results per page.

Example Usage

The following example demonstrates how to use the searchProviders method and configure a ProviderSearchRequest specific to the Providers data connection category:

private fun showProvidersData(enteredText: String) {
        val searchTerm = enteredText
        val latitude = 39.2848102 // Declare latitude coordinate
        val longitude = -76.702898 // Declare longitude coordinate
        val distance = 200.0 // Set distance radius
        val page = 0
        val pageSize = 100

        val request = ProviderSearchRequest.Builder()
            .searchTerm(searchTerm)
            .location(latitude, longitude, distance)
            .sortBy(SortField.DISTANCE, SortOrder.ASC)
            .page(page)
            .pageSize(pageSize)
            .build()

        providerViewModel.searchProviders(request)

        viewLifecycleOwner.lifecycleScope.launch {
            providerViewModel.searchResults.collect { searchResult ->
                if (searchResult != null) {
                    setProviderAdapter(searchResult)
                }
            }
        }
        
        addSearchTextListeners()
    }
❗️

Note that the .organizationTypeFilter is not applied when using the searchProviders method. Applying the .organizationTypeFilter with this method will result in no returned data.

Best Practices

  • General vs. Specific Searches: Use the searchTerm for broad searches and apply filters like specialtyFilters or gender for more specific queries.
  • Sorting: Default sorting by relevance is usually most effective. Distance sorting option should be used based on specific needs.
  • Pagination: Use page and pageSize to effectively manage and navigate through search results.