def percent_without_incident_in_period(self, params, incident_table): """ Percent of ppts enrolled during period who did not have an incident in the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' incident_table(str): table in database to use as incident Returns: float: Percent of ppts enrolled during period who did not have an incident in the period """ params = list(params) + list(params) query = f"""SELECT COUNT(*) FROM enrollment e WHERE NOT EXISTS (SELECT 1 FROM {incident_table} it WHERE it.member_id = e.member_id AND date_time_occurred BETWEEN ? AND ?) AND (e.disenrollment_date >= ? OR e.disenrollment_date IS NULL) AND e.enrollment_date <= ?;""" enrollment = Enrollment(self.db_filepath) return round( (self.single_value_query(query, params) / enrollment.census_during_period(params[:2]) * 100), 2, )
def percent_without_incident_overall(self, params, incident_table): """ Percent of ppts enrolled during period who never have an incident Args: params (tuple): start date and end date in format 'YYYY-MM-DD' incident_table(str): table in database to use as incident Returns: float: Percent of ppts enrolled during period who never have an incident """ query = f"""SELECT COUNT(*) FROM enrollment e WHERE NOT EXISTS (SELECT * FROM {incident_table} it WHERE it.member_id = e.member_id) AND (e.disenrollment_date >= ? OR e.disenrollment_date IS NULL) AND e.enrollment_date <= ?;""" enrollment = Enrollment(self.db_filepath) return round( (self.single_value_query(query, params) / enrollment.census_during_period(params) * 100), 2, )
def no_hosp_admission_last_year(self, params): """ Percent of ppts who do not have a recorded acute hospital admissions within the year prior to the provided end date. Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: Percent of ppts who do not have an admission in period """ params = [params[1]] + list(params) query = """SELECT COUNT(*) FROM enrollment WHERE NOT EXISTS (SELECT 1 FROM acute WHERE acute.member_id = enrollment.member_id AND acute.admission_date >= date(?, '-1 years')) AND (disenrollment_date >= ? OR disenrollment_date IS NULL) AND enrollment_date <= ?; """ enrollment = Enrollment(self.db_filepath) return round( (self.single_value_query(query, params) / enrollment.census_during_period(params[1:]) * 100), 2, )
def over_six_chronic_conditions_percent(self, params): e = Enrollment(self.db_filepath) return round( (self.over_six_chronic_conditions_count(params) / e.census_during_period(params) * 100), 2, )
def percent_attending_dc(self, params): """ Percent of ppts who are indicated to attend the day center in Cognify, enrolled during the period. Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: percent of enrolled ppts who are indicated to attend the day center """ e = Enrollment(self.db_filepath) return round( self.attending_day_center(params) / e.census_during_period(params) * 100, 2)
def living_in_community_percent(self, params): """ Percent of ppts who are not in a SNF, enrolled during the period Does not account for ppts in the hospital. Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: percent of enrolled ppts who are not in a SNF """ e = Enrollment(self.db_filepath) return round( self.living_in_community(params) / e.census_during_period(params) * 100, 2)
def uti_per_100(self, params): """ Counts of infections during the period with an infection_type of UTI, URI, or Sepsis-Urinary divided by member months in the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: UTIs per 100 member months """ enrollment = Enrollment(self.db_filepath) return round( self.uti_count(params) / enrollment.member_months(params) * 100, 2)
def age_above_65(self, params): """ Number of ppts above the age of 65 at the end date of ppts enrolled during the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: int: number of ppts above the age of 65 """ enrollment = Enrollment(self.db_filepath) return enrollment.census_during_period(params) - self.age_below_65( params)
def percent_dual(self, params): """ Calculates the percent of ppts enrolled in the program during the period that have both Medicare and medicaid Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: percent of ppts in period with both Medicare and medicaid """ enrollment = Enrollment(self.db_filepath) return (round( self.dual_count(params) / enrollment.census_during_period(params), 2) * 100)
def sepsis_per_100(self, params): """ Counts of infections during the period where 'sepsis' is in the infection_type divided by member months in the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: sepsis related infections per 100 member months """ enrollment = Enrollment(self.db_filepath) return round( self.sepsis_count(params) / enrollment.member_months(params) * 100, 2)
def pressure_ulcer_per_100(self, params): """ Pressure ulcer per 100 member months during the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: Pressure ulcer per 100 member months """ enrollment = Enrollment(self.db_filepath) return round( (self.pressure_ulcer_count(params) / enrollment.member_months(params) * 100), 2, )
def percent_private_pay(self, params): """ Calculates the percent of ppts enrolled in the program during the period that don't have medicaid or medicare Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: percent of ppts in period without medicaid and medicare """ enrollment = Enrollment(self.db_filepath) return (round( self.private_pay_count(params) / enrollment.census_during_period(params), 2, ) * 100)
def ppts_in_utl_percent(self, params, utilization_table): """ Count of admissions with a discharge date that is null or greater than the start date and an admission_date less than the end date divided by the census in the period multiplied by 100 Args: params (tuple): start date and end date in format 'YYYY-MM-DD' utilization_table(str): table in database to use as utilization Returns: int: percent of enrolled ppts in the utilization type """ e = Enrollment(self.db_filepath) return round( self.ppts_in_utl(params, utilization_table) / e.census_during_period(params) * 100, 2, )
def adjusted_per_100MM(self, params, incident_table): """ Count of incidents during period minus any incidents by ppts with an incidents count greater than the mean plus 3 standard deviations divided by the member months in the period multiplied by 100 Args: params (tuple): start date and end date in format 'YYYY-MM-DD' incident_table(str): table in database to use as incident Returns: float: adjusted count of incidents per 100 member months """ enrollment = Enrollment(self.db_filepath) return round( (self.adjusted_incident_count(params, incident_table) / enrollment.member_months(params) * 100), 2, )
def days_per_100MM(self, params, utilization_table): """ First the days for admissions that occur during the params is calculated. Next the days for admissions occurring before the period are calculated using the start date of the period as the admissions date. The sum of these two values are divided by the member months in the period. Args: params(tuple): start date and end date in format 'YYYY-MM-DD' utilization_table(str): table in database to use as utilization Returns: int: days in period that ppts are in the indicated utilization per 100 member months """ days = self.utilization_days(params, utilization_table) enrollment = Enrollment(self.db_filepath) census = enrollment.member_months(params) return round((days / census) * 100, 2)
def no_hosp_admission_since_enrollment(self, params): """ Percent of ppts who do not have a recorded acute hospital admissions. Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: Percent of ppts who do not have a recorded acute hospital admissions. """ query = """SELECT COUNT(*) FROM enrollment WHERE NOT EXISTS (SELECT 1 FROM acute WHERE acute.member_id = enrollment.member_id) AND (disenrollment_date >= ? OR disenrollment_date IS NULL) AND enrollment_date <= ?;""" enrollment = Enrollment(self.db_filepath) return round( (self.single_value_query(query, params) / enrollment.census_during_period(params) * 100), 2, )
def influ_rate(self, params): """ Rate of all enrolled ppts have or have refused the influenza vaccinations during the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: Rate of recieved or refused influenza vaccination """ received = self.has_influ_vacc_count(params) refused = self.refused_influ_vacc_count(params) eligible = Enrollment(self.db_filepath).census_during_period(params) rate = (received + refused) / eligible return round(rate, 2)
def mortality_rate(self, params, total=False): """ Number of deaths in period divided by the census during the period Args: params (tuple): start date and end date in format 'YYYY-MM-DD' Returns: float: Rate of death """ query = """SELECT COUNT(*) FROM enrollment WHERE disenroll_reason = 'Deceased' AND disenrollment_date BETWEEN ? and ? """ total = self.single_value_query(query, params) if total: return total census = Enrollment(self.db_filepath).census_during_period(params) return round(total / census, 2)
def percent_female(self, params): e = Enrollment(self.db_filepath) return round( self.female_count(params) / e.census_during_period(params) * 100, 2)
def behavorial_dx_percent(self, params): e = Enrollment(self.db_filepath) return round( (self.behavorial_dx_count(params) / e.census_during_period(params)) * 100, 2)
def percent_age_below_65(self, params): e = Enrollment(self.db_filepath) return round( self.age_below_65(params) / e.census_during_period(params) * 100, 2)