open_fda_drug_label.drug
Classes
OVERVIEW: |
Module Contents
- class open_fda_drug_label.drug.Drug(meta: dict, result: dict)[source]
- OVERVIEW:
Drug object is the primary object used to engage with drugs in the openFDA drug/label dataset after retrieved from API call. Drugs are generated by inputting the “meta” and “results” sections of the raw json return, and can be generated with make_drug in our final package implementation. Drugs allow users to call a number of different functions to collect individual parameter values from the openFDA dataset or to provide high level overviews, risk scores, or comprehensive data structure with all fields from the raw json file. This class is designed to make accessing information about a particular drug extremely easy based on the raw json file.
- ATTRIBUTES
raw: core json output for results of an individual query about a drug meta: meta information from a query used to produce this individual drug openfda: specific openfda subsection of the json output for this drug
- USAGE EXAMPLE:
>>> # User function loads in API key as api_key >>> client = Drug_Label_Client(api_key) >>> advil_items = generic_search("brand_name", "Advil") >>> advil_json = search_request(advil_items, limit=1) >>> advil_drug = Drug(advil_json["meta"], advil_json["results"][0]) >>> advil_drug.drug_overview() # returns overall dict about drug stats
- raw
- meta
- openfda
- raw_drug()[source]
- OVERVIEW:
Returns the raw json of the results without any processing for interested parties to manipulate with their own functions.
- Parameters:
None – simply takes the object and returns an attribute
- RETURN VALUE:
raw (dict): returns the json format of the results section
- USAGE EXAMPLE:
>>> Advil.raw_drug() # returns raw value of self.raw
- get_name()[source]
- OVERVIEW:
Returns the drug’s name from the openfda subsection of results by checking for name in “brand_name.” If not available in that field, checks backups of “generic_name” and “substance_name” to try and locate an appropriate name. Returns None if not possible.
- Parameters:
None – simply takes the object and returns an attribute
- RETURN VALUE:
name (str/None): returns the name of a given drug if available
- USAGE EXAMPLE:
>>> Advil.get_name() # returns full name of advil drug if available
- get_parameter(parameter: str)[source]
- OVERVIEW:
Returns (if available) the field for a provided parameter of the drug in whatever contained format is present. If field is not available, returns None as a value to the user. Rejects name parameters and asks user to use get_name function shown above.
- Parameters:
parameter (str) – field we want to extract value of for Drug
- RETURN VALUE:
value (str/list/None): value contained in dict for parameter # if parameter contains a list, returns the first element
- USAGE EXAMPLE:
>>> Advil.get_parameter("ingredients") # returns advil ingredients
- drug_overview()[source]
- OVERVIEW:
Function that provides a dictionary with a high level overview of descriptive statistics on the drug object. Includes drug name, universal production code, manufacturer name, product type, route, description, and risk score, which measures number of fields with high risks that are actually populated using risk_score function below.
- Parameters:
None
- RETURN VALUE:
- drug_info (dict): contains keys for overview parameters and values
name (str): name of drug upc (str): universal product code of drug manufacturer name (str): man. who made the drug product type (str): kind of product sold route (str): how to take this drug (e.g. “ORAL”) description (str): description string for this drug risk score (float): percentage of risky fields filled in risk_score
- USAGE EXAMPLE:
>>> advil = Drug(meta, result) >>> overview = advil.drug_overview() # returns dict with overview fields
- get_date()[source]
- OVERVIEW:
Returns date of most recently published drug in the drug query used to collect original json of this drug.
- Parameters:
None
- RETURN VALUE:
Date (str): date of most recent pull from meta field of drug
- USAGE EXAMPLE:
>>> advil = Drug(meta, result) >>> date = advil.get_date() # returns most recent update date of advil
- risk_score()[source]
- OVERVIEW:
Returns computed risk dict/score for 9 core categories of risk. If these fields contain any non-None data, they receive a True in the risk dictionary and add to the total risk tally. Total risk tally is taken as a percentage of nine and also returned with function output. Thus, function provides flexibility of seeing which individual risks are True (or exist) and total percentage of risks that this drug carries.
- Parameters:
None
- RETURN VALUE:
risk_list (list): list containing risk dictionary with booleans and risk score
- USAGE EXAMPLE:
>>> advil = Drug(meta, result) >>> date = advil.risk_score() # returns [advil_risk_info, advil_risk_score]
- drug_comprehensive()[source]
- OVERVIEW:
Provides a comprehensive dictionary covering all fields contained in results ection of the Drug object. Iterates through json format and appends to all_info dict, returning result.
- Parameters:
None
- RETURN VALUE:
all_info (dict): dictionary containing all parameters and stored values in Drug
- USAGE EXAMPLE:
>>> advil = Drug(meta, result) >>> date = advil.drug_comprehensive() # returns all parameters and fields in a dict