Module integrators.provider_integrator

implement provider lookups from both local tables and public API

Classes

class ProviderAPIParams (terms: str = '', maxList: str = '10', sf: str = '', df: str = 'name,NPI,provider_type,licenses,name_other,other_ids.state,addr_mailing.state,addr_practice.state')

Parameters passed to public NLM API for global search

Class variables

var df : str
var maxList : str
var sf : str
var terms : str

Instance variables

prop base_params : str

url parameters supplied to all requests, 1-to-1 with class fields

prop last_query : str

return the URL parameter q from the last API request

Methods

def query_by_name(self, provider_name: str, is_anes_provider: bool) ‑> str

set value of "q" in url parameters based on supplied name and type

def query_by_npi(self, npi: str) ‑> str

set value of "q" in url parameters based on supplied name and type

class ProviderAPIResponse (count: int = 0, NPIs: list[str] = <factory>, ef: Any = None, results: list[list[Any]] = <factory>, original_name: str = '', original_npi: str = '')

top level fields in nlm API response as documented at https://clinicaltables.nlm.nih.gov/apidoc/npi_idv/v3/doc.html

Attributes

count : int
number of results returned
NPIs : list[str]
NPIs of returned providers
ef : str
no use case. present in output. see link above.
results : list[dict[str, Any]]
raw representation as returned by API call

Class variables

var NPIs : list[str]
var count : int
var ef : Any
var original_name : str
var original_npi : str
var results : list[list[typing.Any]]

Instance variables

prop provider_results : list[ProviderAPIResult]

results after conversion to dbops.ProviderRecord dataclass objects

class ProviderAPIResult (names: list[dict[str, str]], npi: str, provider_type: str, licenses: list[dict], states: Collection[str])

single result from ProviderAPIResponse.provider_results. Contains all necessary data for creation of dbops.ProviderRecord via convenience method self.to_record()

Instance variables

prop full_name : str

full name constructed from primary name object in result

prop provider_dataProviderData

return a dbops.ProviderData instance from self fields names, licenses, and states. facilities always set to current.

Methods

def to_record(self) ‑> ProviderRecord

return self as dbops.ProviderRecord

class ProviderIntegrator (public_only: bool = False, api_url: str = 'https://clinicaltables.nlm.nih.gov/api/npi_idv/v3/search', url_params: ProviderAPIParams = <factory>)

performs lookups of extracted provider information against local DB tables with fallback to the public API maintained by the National Library of Medicine at https://clinicaltables.nlm.nih.gov/. also updates "lastOccurrence" info in local DB tables after a successful match.

Ancestors

  • utilities.protocols.ProviderIntegratorProtocol
  • typing.Protocol
  • typing.Generic

Class variables

var api_url : str
var full_name : utilities.v_str.vStr
var is_anes_provider : bool
var mode : str | None
var npi : str | utilities.v_str.vStr
var public_only : bool
var url_paramsProviderAPIParams

Static methods

def cache_check(*, provider: ProviderIntegrator | ProviderRecord, facility: str = 'Initializing', update_only: bool = False) ‑> list[ProviderRecord]

check provider cache before search public API / DB and update cache if NPI has been found.

KwArgs

provider : ProviderIntegrator
provider integrator instance containing
search criteria.
facility : str
facility name, resets the cache if changed
update_only : bool
initialize cache value without "found in cache" log

Returns

list[ProviderRecord]
list containing a single provider record if

found in cache. list emulates return value of other search functions.

Instance variables

prop last_api_response : None | dict[str, Any]

last public API query response

prop last_url_params : dict[str, Any]

last public API query parameters

prop query_name

name of last query function

Methods

def next_query(self) ‑> Iterator[list[ProviderRecord] | list[ProviderAPIResult]]

generate all valid local and query parameterizations in order of priority for successive db searches

def search(self, is_anes_provider: bool, full_name: str | vStr, npi: str | vStr = '', mode: str | None = None) ‑> tuple[utilities.v_str.vStr, utilities.v_str.vStr]

progressively search local DB and public API with supplied provider data and return (a) fully populated vStr objects for the provider name and NPI upon a successful lookup or (b) an 'original value only' vStr object for the provider name and a "null" vStr upon failure.