Esempio n. 1
0
        /// <summary>
        /// Searches the NPPES NPI directory for an individual or organization based on search criteria.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task <NPPESResponse> SearchAsync(NPPESRequest request, CancellationToken cancellationToken = default)
        {
            var response = new NPPESResponse
            {
                ResultCount = 0,
                Results     = null,
                Errors      = null
            };

            using (var responseMessage = await DefaultClient.GetAsync(request.ToQuery(), cancellationToken: cancellationToken).ConfigureAwait(false))
            {
                // errors are returned with a 200 status code
                // so this handles success and error.
                if (responseMessage.IsSuccessStatusCode)
                {
                    using (var stream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
                        response = StreamToType <NPPESResponse>(stream);
                }

                // any other exceptions, return the status code for
                // troubleshooting, all other fields will be null
                response.StatusCode = responseMessage.StatusCode;
            }

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Searches the NPPES NPI directory by NPI number.
        /// </summary>
        /// <param name="npi"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static Task <NPPESResponse> SearchAsync(string npi, CancellationToken cancellationToken = default)
        {
            var request = new NPPESRequest
            {
                Number = npi
            };

            return(SearchAsync(request, cancellationToken: cancellationToken));
        }
 /// <summary>
 /// Clear the request parameters.
 /// </summary>
 /// <returns></returns>
 public NPPESRequestBuilder Clear()
 {
     request = new NPPESRequest();
     return(this);
 }
 /// <summary>
 /// Creates an instance of the <see cref="NPPESRequestBuilder"/>
 /// </summary>
 public NPPESRequestBuilder()
 {
     request = new NPPESRequest();
 }