def filters(self): filters = [EQ('xmlns', 'xmlns')] if 'age' in self.config and self.config['age']: if len(self.config['age']) == 1: filters.append(BETWEEN('age', 'age_start_0', 'age_end_0')) else: between_filters = [] for idx, age in enumerate(self.config['age']): between_filters.append(BETWEEN('age', 'age_start_{}'.format(idx), 'age_end_{}'.format(idx))) filters.append(OR(between_filters)) if 'district' in self.config and self.config['district']: filters.append(IN('district', get_INFilter_bindparams('district', self.config['district']))) if ( 'visit_date_start' in self.config and self.config['visit_date_start'] and 'visit_date_end' in self.config and self.config['visit_date_end'] ): filters.append(BETWEEN('visit_date', 'visit_date_start', 'visit_date_end')) if 'type_visit' in self.config and self.config['type_visit']: filters.append(EQ('type_visit', 'type_visit')) if 'activity_type' in self.config and self.config['activity_type']: filters.append(EQ('activity_type', 'activity_type')) if 'client_type' in self.config and self.config['client_type']: filters.append(IN('client_type', get_INFilter_bindparams('client_type', self.config['client_type']))) if 'user_id' in self.config and self.config['user_id']: filters.append(IN('user_id', get_INFilter_bindparams('user_id', self.config['user_id']))) if 'organization' in self.config and self.config['organization']: filters.append(EQ('organization', 'organization')) if 'want_hiv_test' in self.config and self.config['want_hiv_test']: filters.append(EQ('want_hiv_test', 'want_hiv_test')) return filters
def filters(self): filters = [EQ('xmlns', 'xmlns')] if ('posttest_date_start' in self.config and self.config['posttest_date_start'] and 'posttest_date_end' in self.config and self.config['posttest_date_end']): filters.append( BETWEEN('posttest_date', 'posttest_date_start', 'posttest_date_end')) if ('hiv_test_date_start' in self.config and self.config['hiv_test_date_start'] and 'hiv_test_date_end' in self.config and self.config['hiv_test_date_end']): filters.append( BETWEEN('hiv_test_date', 'hiv_test_date_start', 'hiv_test_date_end')) if 'age_range' in self.config and self.config['age_range']: filters.append(EQ('age_range', 'age_range')) if 'district' in self.config and self.config['district']: filters.append(EQ('district', 'district')) if 'client_type' in self.config and self.config['client_type']: filters.append(EQ('client_type', 'client_type')) if 'user_id' in self.config and self.config['user_id']: filters.append( IN('user_id', get_INFilter_bindparams('user_id', self.config['user_id']))) if 'organization' in self.config and self.config['organization']: filters.append(EQ('organization', 'organization')) return filters
def columns(self): cols = [ self.location_column, dynamic_date_aggregation(DatabaseColumn( "Incidents of Abuse", SumColumn('incidents_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')] + self.filters), ), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Outreach activities", SumColumn('outreach_total', filters=self.filters + [BETWEEN('date', 'startdate', 'enddate')])), date_column='date'), dynamic_date_aggregation(DatabaseColumn( "IGA Reports", SumColumn('iga_total', filters=self.filters + [BETWEEN('start_date', 'startdate', 'enddate')])), date_column='start_date'), AggregateColumn("Total", self.sum, [ AliasColumn('incidents_total'), AliasColumn('outreach_total') ]), ] cols[0] = self.date_column return cols
def columns(self): cols = [ self.location_column, dynamic_date_aggregation(DatabaseColumn( "Counselling", SumColumn('service_counselling_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Psychosocial Support", SumColumn('service_psychosocial_support_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "First Aid", SumColumn('service_first_aid_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Shelter", SumColumn('service_shelter_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Referral", SumColumn('service_referral_total', filters=self.filters + [ BETWEEN('date_reported_mediated', 'startdate', 'enddate') ])), date_column='date_reported_mediated'), dynamic_date_aggregation(DatabaseColumn( "Mediation", SumColumn('service_mediation_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Other", SumColumn('service_other_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), date_column='date_reported'), dynamic_date_aggregation(DatabaseColumn( "Total", SumColumn('service_total_total', filters=self.filters + [ BETWEEN('date_reported_mediated', 'startdate', 'enddate') ])), date_column='date_reported_mediated'), ] cols[0] = self.date_column return cols
def filters(self): filters = super(AggChildHealthMonthlyDataSource, self).filters if not self.show_test: filters.append(NOT(IN('state_id', get_INFilter_bindparams('excluded_states', self.excluded_states)))) if 'month' in self.config and self.config['month']: filters.append(BETWEEN('month', 'two_before', 'month')) return filters
def filters(self): filters = [BETWEEN("date", "startdate", "enddate")] if 'region_id' in self.config: filters.append(EQ("region_id", "region_id")) elif 'district_id' in self.config: filters.append(EQ("district_id", "district_id")) return filters
def filters(self): filters = [EQ('xmlns', 'xmlns')] if 'age' in self.config and self.config['age']: filters.append(EQ('age', 'age')) if 'district' in self.config and self.config['district']: filters.append(EQ('district', 'district')) if ('visit_date_start' in self.config and self.config['visit_date_start'] and 'visit_date_end' in self.config and self.config['visit_date_end']): filters.append( BETWEEN('visit_date', 'visit_date_start', 'visit_date_end')) if 'type_visit' in self.config and self.config['type_visit']: filters.append(EQ('type_visit', 'type_visit')) if 'activity_type' in self.config and self.config['activity_type']: filters.append(EQ('activity_type', 'activity_type')) if 'client_type' in self.config and self.config['client_type']: filters.append(EQ('client_type', 'client_type')) if 'user_id' in self.config and self.config['user_id']: filters.append( IN('user_id', get_INFilter_bindparams('user_id', self.config['user_id']))) if 'organization' in self.config and self.config['organization']: filters.append(EQ('organization', 'organization')) return filters
def filters(self): filters = [ EQ('xmlns', 'xmlns'), NOT(EQ('date_last_vl_test', 'empty_date_last_vl_test')) ] if 'hiv_status' in self.config and self.config['hiv_status']: filters.append(EQ('hiv_status', 'hiv_status')) if 'client_type' in self.config and self.config['client_type']: filters.append(EQ('client_type', 'client_type')) if 'age_range' in self.config and self.config['age_range']: filters.append(EQ('age_range', 'age_range')) if 'district' in self.config and self.config['district']: filters.append(EQ('district', 'district')) if ('date_last_vl_test_start' in self.config and self.config['date_last_vl_test_start'] and 'date_last_vl_test_end' in self.config and self.config['date_last_vl_test_end']): filters.append( BETWEEN('date_last_vl_test', 'date_last_vl_test_start', 'date_last_vl_test_end')) if 'undetect_vl' in self.config and self.config['undetect_vl']: filters.append(EQ('undetect_vl', 'undetect_vl')) if 'user_id' in self.config and self.config['user_id']: filters.append( IN('user_id', get_INFilter_bindparams('user_id', self.config['user_id']))) if 'organization' in self.config and self.config['organization']: filters.append(EQ('organization', 'organization')) return filters
def filters(self): filters = [BETWEEN('date', 'startdate', 'enddate'), NOTEQ('hf', 'empty')] if 'district' in self.config and self.config['district']: filters.append(EQ('district', 'district')) elif 'hf' in self.config and self.config['hf']: filters.append(EQ('hf', 'hf')) return filters
def filters(self): filters = [ BETWEEN('opened_on', 'start_date', 'end_date'), ] locations_id = filter(lambda x: bool(x), self.config.locations_id) if locations_id: filters.append( IN('person_owner_id', get_INFilter_bindparams('locations_id', locations_id))) return filters
def columns(self): return [ self.location_column, DatabaseColumn( "Incidents of Abuse", SumColumn('incidents_total', filters=self.filters + [BETWEEN('date_reported', 'startdate', 'enddate')])), DatabaseColumn( "Outreach activities", SumColumn('outreach_total', filters=self.filters + [BETWEEN('date', 'startdate', 'enddate')])), DatabaseColumn( "IGA Reports", SumColumn('iga_total', filters=self.filters + [BETWEEN('start_date', 'startdate', 'enddate')])), AggregateColumn("Total", self.sum, [ AliasColumn('incidents_total'), AliasColumn('outreach_total') ]), ]
def filters(self): filters = None if 'enddate' not in self.config: self.config['enddate'] = self.config['today'] self.config['stred'] = self.config['today'] if 'startdate' in self.config: filters = [BETWEEN("date", "startdate", "enddate")] elif 'startdate' not in self.config: filters = [LTE("date", 'enddate')] for k, v in LOCATION_HIERARCHY.iteritems(): if v['prop'] in self.config and self.config[v['prop']]: filters.append(IN(k, v['prop'])) return filters
def filters(self): filters = [ EQ('xmlns', 'xmlns'), NOT(EQ('first_art_date', 'empty_first_art_date')) ] if 'hiv_status' in self.config and self.config['hiv_status']: filters.append( IN( 'hiv_status', get_INFilter_bindparams('hiv_status', self.config['hiv_status']))) if 'client_type' in self.config and self.config['client_type']: filters.append( IN( 'client_type', get_INFilter_bindparams('client_type', self.config['client_type']))) if 'age_range' in self.config and self.config['age_range']: filters.append( IN( 'age_range', get_INFilter_bindparams('age_range', self.config['age_range']))) if 'district' in self.config and self.config['district']: filters.append( IN( 'district', get_INFilter_bindparams('district', self.config['district']))) if ('first_art_date_start' in self.config and self.config['first_art_date_start'] and 'first_art_date_end' in self.config and self.config['first_art_date_end']): filters.append( BETWEEN('first_art_date', 'first_art_date_start', 'first_art_date_end')) if 'user_id' in self.config and self.config['user_id']: filters.append( IN('user_id', get_INFilter_bindparams('user_id', self.config['user_id']))) return filters
def filters(self): filters = [] if 'start_date' in self.config and 'end_date' in self.config: filters.append( BETWEEN("date_of_data_collection", "start_date", "end_date")) if 'country' in self.config: filters.append( IN( 'country', get_INFilter_bindparams('country', self.__getattribute__("country")))) if 'level_1' in self.config: filters.append( IN( 'level_1', get_INFilter_bindparams('level_1', self.__getattribute__("level_1")))) if 'level_2' in self.config: filters.append( IN( 'level_2', get_INFilter_bindparams('level_2', self.__getattribute__("level_2")))) if 'level_3' in self.config: filters.append( IN( 'level_3', get_INFilter_bindparams('level_3', self.__getattribute__("level_3")))) if 'level_4' in self.config: filters.append( IN( 'level_4', get_INFilter_bindparams('level_4', self.__getattribute__("level_4")))) return filters
def filters(self): return [BETWEEN('date_reported', 'startdate', 'enddate')] + super( ChildProtectionData, self).filters[1:]
def filters(self): filters = super(ChildrenInHouseholdData, self).filters[1:] return [BETWEEN('date_reported', 'startdate', 'enddate')] + filters
def filters(self): return [BETWEEN("date", "startdate", "enddate"), EQ('owner_id', 'af'), EQ('is_checklist', 'is_checklist')]
def columns(self): return [ DatabaseColumn( _("Total number of ASHAs under the Facilitator"), CountUniqueColumn( "case_id", filters=[ EQ('owner_id', 'af'), OR([ISNULL('closed_on'), GTE('closed_on', 'enddate')]), LTE('registration_date', 'enddate') ], alias="total_ashas" ) ), DatabaseColumn( _("Total number of ASHAs for whom functionality checklist was filled"), CountUniqueColumn( "case_id", filters=[ EQ('owner_id', 'af'), EQ('is_checklist', 'is_checklist'), BETWEEN('date', 'startdate', 'enddate') ], alias="total_ashas_checklist" ) ), DatabaseColumn( _("Newborn visits within first day of birth in case of home deliveries"), FunctionalityChecklistColumn('hv_fx_home_birth_visits', whens={1: 1}), ), DatabaseColumn( _("Set of home visits for newborn care as specified in the HBNC guidelines<br/>" "(six visits in case of Institutional delivery and seven in case of a home delivery)"), FunctionalityChecklistColumn('hv_fx_newborns_visited', whens={1: 1}), ), DatabaseColumn( _("Attending VHNDs/Promoting immunization"), FunctionalityChecklistColumn('hv_fx_vhnd', whens={1: 1}), ), DatabaseColumn( _("Supporting institutional delivery"), FunctionalityChecklistColumn('hv_fx_support_inst_delivery', whens={1: 1}), ), DatabaseColumn( _("Management of childhood illness - especially diarrhea and pneumonia"), FunctionalityChecklistColumn('hv_fx_child_illness_mgmt', whens={1: 1}), ), DatabaseColumn( _("Household visits with nutrition counseling"), FunctionalityChecklistColumn('hv_fx_nut_counseling', whens={1: 1}), ), DatabaseColumn( _("Fever cases seen/malaria slides made in malaria endemic area"), FunctionalityChecklistColumn('hv_fx_malaria', whens={1: 1}), ), DatabaseColumn( _("Acting as DOTS provider"), FunctionalityChecklistColumn('hv_fx_dots', whens={1: 1}), ), DatabaseColumn( _("Holding or attending village/VHSNC meeting"), FunctionalityChecklistColumn('hv_fx_vhsnc', whens={1: 1}), ), DatabaseColumn( _("Successful referral of the IUD, " "female sterilization or male sterilization cases and/or providing OCPs/Condoms"), FunctionalityChecklistColumn('hv_fx_fp', whens={1: 1}), ), AggregateColumn( _("<b>Total number of ASHAs who are functional on at least %s of the tasks</b>") % "60%", aggregate_fn=lambda x, y: { 'sort_key': ((x or 0) * 100 / (y or 1)), 'html': '{0}/{1} ({2}%)'.format((x or 0), y, ((x or 0) * 100 // (y or 1))) }, columns=[ FunctionalityChecklistColumn( whens={'hv_percent_functionality >= 60': 1}, alias='percent_functionality'), AliasColumn('total_ashas_checklist') ], format_fn=lambda x: x ), ]
def filters(self): return [ BETWEEN("completed_on", "startdate", "enddate"), EQ('owner_id', 'af') ]
def columns(self): cols = [ self.location_column, dynamic_date_aggregation(DatabaseColumn( "Resolved at CVSU", SumColumn('resolution_resolved_at_cvsu_total', filters=self.filters + [ BETWEEN('mediation_provided_date', 'startdate', 'enddate') ])), date_column='mediation_provided_date'), dynamic_date_aggregation( DatabaseColumn( "Referred to TA", SumColumn('resolution_referred_ta_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation( DatabaseColumn( "Referred to TA Court", SumColumn('resolution_referral_ta_court_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation( DatabaseColumn( "Referred to Police", SumColumn('resolution_referral_police_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation( DatabaseColumn( "Referred to Social Welfare", SumColumn('resolution_referral_social_welfare_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation( DatabaseColumn( "Referred to NGO", SumColumn('resolution_referral_ngo_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation( DatabaseColumn( "Referred to Other", SumColumn('resolution_referral_other_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), dynamic_date_aggregation(DatabaseColumn( "Unresolved", SumColumn('resolution_unresolved_total', filters=self.filters + [ BETWEEN('mediation_provided_date', 'startdate', 'enddate') ])), date_column='mediation_provided_date'), dynamic_date_aggregation(DatabaseColumn( "Case Withdrawn", SumColumn('resolution_case_withdrawn_total', filters=self.filters + [ BETWEEN('mediation_provided_date', 'startdate', 'enddate') ])), date_column='mediation_provided_date'), dynamic_date_aggregation(DatabaseColumn( "Other", SumColumn('resolution_other_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='mediation_provided_date'), dynamic_date_aggregation( DatabaseColumn( "Total", SumColumn('resolution_total_total', filters=self.filters + [ BETWEEN('date_reported_provided_mediated', 'startdate', 'enddate') ])), date_column='date_reported_provided_mediated'), ] cols[0] = self.date_column return cols