Example #1
0
 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
Example #2
0
 def filters(self):
     filters = []
     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
Example #3
0
 def filters(self):
     filters = [
         EQ('xmlns', 'xmlns'),
         IN('hiv_status', get_INFilter_bindparams('hiv_status', self.config['hiv_status']))
     ]
     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(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 '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'))
     return filters
Example #4
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     ['start_date', 'end_date']))
     elif self._is_empty():
         if self.filter.get('datatype') in [
                 DATA_TYPE_DATE, DATA_TYPE_DATETIME
         ]:
             return ISNULLFilter(self.filter['field'])
         else:
             return ORFilter([
                 EQFilter(self.filter['field'], self.filter['slug']),
                 ISNULLFilter(self.filter['field']),
             ])
     elif self._is_exists():
         if self.filter.get('datatype') in [
                 DATA_TYPE_DATE, DATA_TYPE_DATETIME
         ]:
             return NOTNULLFilter(self.filter['field'])
         else:
             # this resolves to != '', which also filters out null data in postgres
             return NOTEQFilter(self.filter['field'], self.filter['slug'])
     elif self._is_list():
         return self._array_filter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     self.value['operand']))
     else:
         return self._scalar_filter(self.filter['field'],
                                    self.filter['slug'])
Example #5
0
 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(
             IN('organization', get_INFilter_bindparams('organization', self.config['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
Example #6
0
 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(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 '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(
             IN('organization', get_INFilter_bindparams('organization', self.config['organization']))
         )
     return filters
Example #7
0
 def filters(self):
     filters = [
         EQ("domain", "domain"),
         EQ("ppt_year", "ppt_year"),
         AND([
             NOTEQ("case_status", "duplicate"),
             NOTEQ("case_status", "test")
         ])
     ]
     for k, v in six.iteritems(self.geography_config):
         if k in self.config and self.config[k]:
             filters.append(
                 IN(k, get_INFilter_bindparams(k, self.config[k])))
     if 'value_chain' in self.config and self.config['value_chain']:
         filters.append(EQ("value_chain", "value_chain"))
     if 'group_leadership' in self.config and self.config[
             'group_leadership']:
         filters.append(EQ('group_leadership', 'group_leadership'))
     if 'cbt_name' in self.config and self.config['cbt_name']:
         filters.append(
             IN(
                 'owner_id',
                 get_INFilter_bindparams('cbt_name',
                                         self.config['cbt_name'])))
     if 'real_or_test' in self.config and self.config['real_or_test']:
         filters.append(IEQ('real_or_test', 'real_or_test'))
     for column_name in ['domains', 'practices', 'schedule']:
         if column_name in self.config and self.config[
                 column_name] and self.config[column_name] != ('0', ):
             filters.append(
                 IN(
                     column_name,
                     get_INFilter_bindparams(column_name,
                                             self.config[column_name])))
     return filters
Example #8
0
 def filters(self):
     filters = []
     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
Example #9
0
 def filters(self):
     filters = []
     if 'district' in self.config and self.config['district']:
         filters.append(IN('district', get_INFilter_bindparams('district', self.config['district'])))
     if 'cbo' in self.config and self.config['cbo']:
         filters.append(IN('cbo', get_INFilter_bindparams('cbo', self.config['cbo'])))
     if 'clienttype' in self.config and self.config['clienttype']:
         filters.append(IN('clienttype', get_INFilter_bindparams('clienttype', self.config['clienttype'])))
     if 'userpl' in self.config and self.config['userpl']:
         filters.append(IN('userpl', get_INFilter_bindparams('userpl', self.config['userpl'])))
     if 'fiscal_year' in self.config and self.config['fiscal_year']:
         filters.append(EQ('fiscal_year', 'fiscal_year'))
     return filters
Example #10
0
 def filters(self):
     filters = []
     if 'district' in self.config and self.config['district']:
         filters.append(IN('district', get_INFilter_bindparams('district', self.config['district'])))
     if 'cbo' in self.config and self.config['cbo']:
         filters.append(IN('cbo', get_INFilter_bindparams('cbo', self.config['cbo'])))
     if 'clienttype' in self.config and self.config['clienttype']:
         filters.append(IN('clienttype', get_INFilter_bindparams('clienttype', self.config['clienttype'])))
     if 'userpl' in self.config and self.config['userpl']:
         filters.append(IN('userpl', get_INFilter_bindparams('userpl', self.config['userpl'])))
     if 'fiscal_year' in self.config and self.config['fiscal_year']:
         filters.append(EQ('fiscal_year', 'fiscal_year'))
     if 'organization' in self.config and self.config['organization']:
         filters.append(EQ('organization', 'organization'))
     return filters
Example #11
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter.field,
             get_INFilter_bindparams(self.filter.slug, ['start_date', 'end_date'])
         )
     elif self._is_null():
         return self._null_filter(self.filter.field)
     elif self._is_list():
         return self._array_filter(
             self.filter.field,
             get_INFilter_bindparams(self.filter.slug, self.value['operand'])
         )
     else:
         return self._scalar_filter.sql(self.filter.field, self.filter.slug)
Example #12
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter.field,
             get_INFilter_bindparams(self.filter.slug,
                                     ['start_date', 'end_date']))
     elif self._is_null():
         return self._null_filter(self.filter.field)
     elif self._is_list():
         return self._array_filter(
             self.filter.field,
             get_INFilter_bindparams(self.filter.slug,
                                     self.value['operand']))
     else:
         return self._scalar_filter.sql(self.filter.field, self.filter.slug)
Example #13
0
 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
Example #14
0
 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
Example #15
0
 def filters(self):
     filters = [
         EQ('year', 'year'),
         IN('owner_id', get_INFilter_bindparams('owner_id', self.config['users']))
     ]
     location_filter(self.request, filters=filters)
     return filters
Example #16
0
 def to_sql_filter(self):
     if self.show_all:
         return None
     if self.is_null:
         return ISNULLFilter(self.filter.field)
     return INFilter(self.filter.field,
                     get_INFilter_bindparams(self.filter.slug, self.value))
Example #17
0
 def filters(self):
     filters = [
         EQ('year', 'year'),
         IN('owner_id', get_INFilter_bindparams('owner_id', self.config['users']))
     ]
     location_filter(self.request, filters=filters)
     return filters
Example #18
0
    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 = [
                AND([
                    LTE("date", "enddate"),
                    OR([
                        GTE('closed_on', "startdate"),
                        EQ('closed_on', 'empty')
                    ])
                ])
            ]
        else:
            self.config['strsd'] = '0001-01-01'
            filters = [LTE("date", "enddate")]

        for k, v in six.iteritems(LOCATION_HIERARCHY):
            if v['prop'] in self.config and self.config[v['prop']]:
                filters.append(
                    IN(k, get_INFilter_bindparams(k, self.config[v['prop']])))
        return filters
 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
Example #20
0
    def columns(self):
        self.config['mother_ids'] = tuple(DeliveryMothersIds(config=self.config).data.keys()) + ('',)
        columns = [
            DatabaseColumn("Total children with with birthweight known",
                           CountUniqueColumn('doc_id', alias="total_birthweight_known",
                                             filters=self.filters + [NOTEQ('weight_birth', 'empty')])),
            DatabaseColumn("Total births",
                           CountUniqueColumn('doc_id',
                                             filters=[AND([IN('mother_id', get_INFilter_bindparams('mother_ids', self.config['mother_ids'])),
                                                           OR([EQ('gender', 'female'), EQ('gender', 'male')])])],
                                             alias='total_births'))]

        columns.extend([
            DatabaseColumn("Birthweight < 2.5 kg",
                CountUniqueColumn('doc_id',
                    alias="total_birthweight_lt_25",
                    filters=self.filters + [AND([LT('weight_birth', 'weight_birth_25'), NOTEQ('weight_birth', 'empty')])]
                )
            ),
            DatabaseColumn("Birthweight >= 2.5 kg",
                CountUniqueColumn('doc_id',
                    alias="total_birthweight_gte_25",
                    filters=self.filters + [AND([GTE('weight_birth', 'weight_birth_25'), NOTEQ('weight_birth', 'empty')])]
                )
            )
        ])
        return columns
Example #21
0
    def columns(self):
        self.config['mother_ids'] = tuple(DeliveryMothersIds(config=self.config).data.keys()) + ('',)
        columns = [
            DatabaseColumn("Total children with with birthweight known",
                           CountUniqueColumn('doc_id', alias="total_birthweight_known",
                                             filters=self.filters + [NOTEQ('weight_birth', 'empty')])),
            DatabaseColumn("Total births",
                           CountUniqueColumn('doc_id',
                                             filters=[AND([IN('mother_id', get_INFilter_bindparams('mother_ids', self.config['mother_ids'])),
                                                           OR([EQ('gender', 'female'), EQ('gender', 'male')])])],
                                             alias='total_births'))]

        columns.extend([
            DatabaseColumn("Birthweight < 2.5 kg",
                CountUniqueColumn('doc_id',
                    alias="total_birthweight_lt_25",
                    filters=self.filters + [AND([LT('weight_birth', 'weight_birth_25'), NOTEQ('weight_birth', 'empty')])]
                )
            ),
            DatabaseColumn("Birthweight >= 2.5 kg",
                CountUniqueColumn('doc_id',
                    alias="total_birthweight_gte_25",
                    filters=self.filters + [AND([GTE('weight_birth', 'weight_birth_25'), NOTEQ('weight_birth', 'empty')])]
                )
            )
        ])
        return columns
Example #22
0
 def filters(self):
     filters = [EQ("domain", "domain"), EQ("ppt_year", "ppt_year"), AND([NOTEQ("case_status", "duplicate"),
                                                                         NOTEQ("case_status", "test")])]
     for k, v in self.geography_config.iteritems():
         if k in self.config and self.config[k]:
             filters.append(IN(k, get_INFilter_bindparams(k, self.config[k])))
     if 'value_chain' in self.config and self.config['value_chain']:
         filters.append(EQ("value_chain", "value_chain"))
     if 'group_leadership' in self.config and self.config['group_leadership']:
         filters.append(EQ('group_leadership', 'group_leadership'))
     if 'cbt_name' in self.config and self.config['cbt_name']:
         filters.append(EQ('owner_id', 'cbt_name'))
     for column_name in ['domains', 'practices', 'schedule']:
         if column_name in self.config and self.config[column_name] and self.config[column_name] != ('0',):
             filters.append(IN(column_name, get_INFilter_bindparams(column_name, self.config[column_name])))
     return filters
Example #23
0
 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
Example #24
0
 def columns(self):
     self.config['mother_ids'] = tuple(
         DeliveryMothersIds(config=self.config).data.keys()) + ('', )
     return [
         DatabaseColumn(
             "Total births",
             CountUniqueColumn(
                 'doc_id',
                 filters=[
                     AND([
                         IN(
                             'mother_id',
                             get_INFilter_bindparams(
                                 'mother_ids', self.config['mother_ids'])),
                         OR([EQ('gender', 'female'),
                             EQ('gender', 'male')])
                     ])
                 ],
                 alias='total_births')),
         DatabaseColumn(
             "Newborn deaths (< 1 m)",
             CountUniqueColumn(
                 'doc_id',
                 filters=self.filters + [
                     AND([
                         EQ('reason_for_child_closure', 'death'),
                         EQ('type_of_child_death', 'newborn_death')
                     ])
                 ],
                 alias='newborn_death')),
         DatabaseColumn(
             "Infant deaths (< 1 y)",
             CountUniqueColumn(
                 'doc_id',
                 filters=self.filters + [
                     AND([
                         EQ('reason_for_child_closure', 'death'),
                         EQ('type_of_child_death', 'infant_death')
                     ])
                 ],
                 alias='infant_death')),
         DatabaseColumn(
             "Child deaths (2-5y)",
             CountUniqueColumn(
                 'doc_id',
                 filters=self.filters + [
                     AND([
                         EQ('reason_for_child_closure', 'death'),
                         EQ('type_of_child_death', 'child_death')
                     ])
                 ],
                 alias='child_death')),
         DatabaseColumn(
             "Total deaths",
             CountUniqueColumn('doc_id',
                               filters=self.filters +
                               [EQ('reason_for_child_closure', 'death')],
                               alias='total_deaths'))
     ]
Example #25
0
    def to_sql_filter(self):
        if self.show_all:
            return None

        return INFilter(
            self.filter.field,
            get_INFilter_bindparams(self.filter.slug,
                                    [None] if self.show_none else self.value))
Example #26
0
 def filters(self):
     filters = [
         EQ('aggregation_level', 'aggregation_level'),
         EQ('month', 'previous_month')
     ]
     if not self.show_test:
         filters.append(NOT(IN('state_id', get_INFilter_bindparams('excluded_states', self.excluded_states))))
     return filters
Example #27
0
 def to_sql_filter(self):
     if self.show_all:
         return None
     if self.is_null:
         return ISNULLFilter(self.filter.field)
     return INFilter(
         self.filter.field,
         get_INFilter_bindparams(self.filter.slug, self.value)
     )
Example #28
0
 def filters(self):
     filters = [EQ('domain', 'domain')]
     if 'is_active' in self.config and self.config['is_active']:
         filters.append(EQ('is_active', 'is_active'))
     if 'care_site' in self.config and self.config['care_site']:
         filters.append(EQ('care_site', 'care_site'))
     if 'owner_id' in self.config and self.config['owner_id']:
         filters.append(IN('owner_id', get_INFilter_bindparams('owner_id', self.config['owner_id'])))
     return filters
Example #29
0
 def filters(self):
     self.config['mother_ids'] = tuple(
         DeliveryMothersIds(config=self.config).data.keys()) + ('', )
     return [
         IN(
             'mother_id',
             get_INFilter_bindparams('mother_ids',
                                     self.config['mother_ids']))
     ]
Example #30
0
 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
Example #31
0
 def filters(self):
     for column_name in ['awc', 'gp', 'block']:
         if self.config.get(column_name):
             return [
                 IN(
                     column_name,
                     get_INFilter_bindparams(column_name,
                                             self.config[column_name]))
             ]
     return []
Example #32
0
 def to_sql_filter(self):
     if self._is_dyn_date():
         return BasicBetweenFilter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     ['start_date', 'end_date']))
     elif self._is_empty():
         return ORFilter([
             EQFilter(self.filter['field'], self.filter['slug']),
             ISNULLFilter(self.filter['field']),
         ])
     elif self._is_list():
         return self._array_filter(
             self.filter['field'],
             get_INFilter_bindparams(self.filter['slug'],
                                     self.value['operand']))
     else:
         return self._scalar_filter(self.filter['field'],
                                    self.filter['slug'])
Example #33
0
 def to_sql_filter(self):
     if self.show_all:
         return None
     if self.is_null:
         return ORFilter(
             [ISNULLFilter(field) for field in self.filter.fields])
     return ORFilter([
         INFilter(field,
                  get_INFilter_bindparams(self.filter.slug, self.value))
         for field in self.filter.fields
     ])
Example #34
0
 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
Example #35
0
    def filters(self):
        filters = []
        infilter_params = get_INFilter_bindparams('excluded_states', self.excluded_states)

        if not self.show_test:
            filters.append(NOT(IN('state_id', infilter_params)))

        for key, value in six.iteritems(self.config):
            if key == 'domain' or key in infilter_params or 'age' in key:
                continue
            filters.append(EQ(key, key))
        return filters
Example #36
0
    def filters(self):
        filters = []
        infilter_params = get_INFilter_bindparams('excluded_states', self.excluded_states)

        if not self.show_test:
            filters.append(NOT(IN('state_id', infilter_params)))

        for key, value in six.iteritems(self.config):
            if key == 'domain' or key in infilter_params or 'age' in key:
                continue
            filters.append(EQ(key, key))
        return filters
 def filters(self):
     filters = super(AggCCSRecordMonthlyDataSource, 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(EQ('month', 'month'))
     return filters
Example #38
0
    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
Example #39
0
    def to_sql_filter(self):
        if self.show_all:
            return None
        if self.is_null:
            return ISNULLFilter(self.filter['field'])

        in_filter = INFilter(
            self.filter['field'],
            get_INFilter_bindparams(self.filter['slug'], self.value))
        if self._ancestor_filter:
            return ANDFilter([self._ancestor_filter.sql_filter(), in_filter])
        else:
            return in_filter
Example #40
0
    def filters(self):
        filters = [
            AND([GTE('opened_on', 'start_date'), LT('opened_on', '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
Example #41
0
    def to_sql_filter(self):
        if self.show_all:
            return None

        in_filter = INFilter(
            self.filter['field'],
            get_INFilter_bindparams(self.filter['slug'],
                                    [None] if self.show_none else self.value))

        if self._ancestor_filter:
            return ANDFilter([self._ancestor_filter.sql_filter(), in_filter])
        else:
            return in_filter
Example #42
0
 def filters(self):
     filters = []
     if self.config['task_responsible']:
         filters.append(EQ('task_responsible', 'task_responsible'))
     if self.config['referenced_id']:
         filters.append(EQ('referenced_id', 'referenced_id'))
     if self.config['closed']:
         filters.append(EQ('closed', 'closed'))
     or_filter = []
     if self.config['owner_ids']:
         or_filter.append(IN('owner_id', get_INFilter_bindparams('owner_ids', self.config['owner_ids'])))
     if or_filter:
         or_filter.append(EQ('user_id', 'user_id'))
         filters.append(OR(filters=or_filter))
     return filters
Example #43
0
 def filters(self):
     filters = []
     if self.config['task_responsible']:
         filters.append(EQ('task_responsible', 'task_responsible'))
     if self.config['referenced_id']:
         filters.append(EQ('referenced_id', 'referenced_id'))
     if self.config['closed']:
         filters.append(EQ('closed', 'closed'))
     or_filter = []
     if self.config['owner_ids']:
         or_filter.append(IN('owner_id', get_INFilter_bindparams('owner_ids', self.config['owner_ids'])))
     if or_filter:
         or_filter.append(EQ('user_id', 'user_id'))
         filters.append(OR(filters=or_filter))
     return filters
Example #44
0
 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
Example #45
0
    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 = [AND([LTE("date", "enddate"), OR([GTE('closed_on', "startdate"), EQ('closed_on', 'empty')])])]
        else:
            self.config['strsd'] = '0001-01-01'
            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, get_INFilter_bindparams(k, self.config[v['prop']])))
        return filters
Example #46
0
 def columns(self):
     self.config['mother_ids'] = tuple(DeliveryMothersIds(config=self.config).data.keys()) + ('',)
     return [
         DatabaseColumn("Total births",
                        CountUniqueColumn('doc_id',
                                          filters=[AND([IN('mother_id', get_INFilter_bindparams('mother_ids', self.config['mother_ids'])),
                                                        OR([EQ('gender', 'female'), EQ('gender', 'male')])])],
                                          alias='total_births')),
         DatabaseColumn("Newborn deaths (< 1 m)",
                        CountUniqueColumn('doc_id', filters=self.filters + [AND(
                            [EQ('reason_for_child_closure', 'death'),
                             EQ('type_of_child_death', 'newborn_death')])], alias='newborn_death')),
         DatabaseColumn("Infant deaths (< 1 y)",
                        CountUniqueColumn('doc_id', filters=self.filters + [AND(
                            [EQ('reason_for_child_closure', 'death'),
                             EQ('type_of_child_death', 'infant_death')])], alias='infant_death')),
         DatabaseColumn("Child deaths (2-5y)",
                        CountUniqueColumn('doc_id', filters=self.filters + [AND(
                            [EQ('reason_for_child_closure', 'death'),
                             EQ('type_of_child_death', 'child_death')])], alias='child_death')),
         DatabaseColumn("Total deaths",
                        CountUniqueColumn('doc_id', filters=self.filters + [EQ('reason_for_child_closure',
                                                                               'death')], alias='total_deaths'))
     ]
Example #47
0
 def filters(self):
     for column_name in ["awc", "gp", "block"]:
         if self.config.get(column_name):
             return [IN(column_name, get_INFilter_bindparams(column_name, self.config[column_name]))]
     return []
Example #48
0
    def filters(self):
        if not self.group_by_district:
            users = tuple([user.user_id for user in self.users])
            return[IN("user_id", get_INFilter_bindparams("users", users))]

        return []
Example #49
0
 def filters(self):
     return [
         IN('awc_id', get_INFilter_bindparams('awc_id', self.awcs)),
         EQ('month', 'month')
     ]
Example #50
0
def _locations_filter(archived_locations):
    return NOT(IN('location_id', get_INFilter_bindparams('archived_locations', archived_locations)))
Example #51
0
 def filters(self):
     self.config['mother_ids'] = tuple(DeliveryMothersIds(config=self.config).data.keys()) + ('',)
     return [IN('mother_id', get_INFilter_bindparams('mother_id', self.config['mother_ids']))]
Example #52
0
 def filters(self):
     for column_name in ['awc', 'gp', 'block']:
         if self.config.get(column_name):
             return [IN(column_name, get_INFilter_bindparams(column_name, self.config[column_name]))]
     return []