Module dbops.providers
db funcs for pushing providers to facility list
Functions
def select_providers(predicate: str, predicate_params: tuple, strict=True) ‑> list[ProviderRecord]-
supplied with a where clause and parameters to populate it return a list of matching providers from the local table
Args
predicate:str- the query predicate. 'where ' is assumed (DO NOT SUPPLY 'WHERE ')
predicate_params:tuple- tuple of params matching %s entries in predicate
strict:bool- if True, add facility condition to supplied predicate
Returns
list[ProviderRecord]- list of matched providers from local list
def upsert_provider(provider: ProviderRecord) ‑> bool-
insert provider info into facility table if not already present. if provider with supplied npi exists, update lastReferenceDate
Classes
class ProviderData (name: dict[str, str] = <factory>, aliases: list[str] = <factory>, licenses: list[dict] = <factory>, facilities: list[str] = <factory>, usStates: list[str] = <factory>)-
Represents the json content contained in the provider_data_column
Attributes
name:dict[str, str]- name dict as returned by public API
aliases:list[str]- list of full names linked to this provider
licenses:list[dict]- licenses as returned by public API
facilities:list[str]- all facilities provider has worked
usStates:list[str]- all states referenced in API result
Class variables
var aliases : list[str]var facilities : list[str]var licenses : list[dict]var name : dict[str, str]var usStates : list[str]
Methods
def merge(self, other: ProviderData) ‑> bool-
merge this object's fields with other returning True if any data is adjusted in self
def to_dict(self, include_licenses=True) ‑> dict[str, dict | list]-
return asdict(self) after deduping list[str] objects
class ProviderRecord (npi: str, full_name: str, specialty: str, provider_data: ProviderData = <factory>, selected: bool = False, cached: bool = False)-
Represents the complete set of data required to update or insert records into the shared.providers table
Attributes
npi:str- a numeric string containing a national provider identifier
full_name:str- name in LAST, FIRST [MIDDLE], [CRED, e.g. MD]
specialty:str- provider_type from NLM clinicaltables API
provider_data:dict[str, Any]- metadata, e.g. facilities supported
Class variables
var cached : boolvar full_name : strvar npi : strvar provider_data : ProviderDatavar selected : boolvar specialty : str
Static methods
def from_query(row: tuple[str, str, str, dict]) ‑> ProviderRecord-
construct a new instance from a single db row
Args
row:tuple[str, str, str, dict[str, list]]- row value from db
Returns
ProviderRecord- ProviderRecord for the row with selected=True
Instance variables
prop provider_record : ProviderRecord-
Included as a convenience for easier ProviderIntegrator caching behavior
prop updated : bool-
indicates whether the record was updated, e.g. to add a facility
Methods
def as_params(self) ‑> dict[str, str]-
return asdict with provider_data converted with json.dumps
def set_cached(self) ‑> ProviderRecord-
set the cached attribute to bool(self) and return True if successful