コード例 #1
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
コード例 #2
0
 def config(self):
     year = self.request.GET.get('year')
     params = {
         'domain': self.domain,
         'year': year
     }
     location_filter(self.request, params=params)
     update_config(params)
     return params
コード例 #3
0
    def config(self):
        week = int(self.request.GET.get('week'))
        year = self.request.GET.get('year')
        date = "%s-W%s-1" % (year, week + 1)
        monday = datetime.datetime.strptime(date, "%Y-W%W-%w")

        params = {
            'domain': self.domain,
            'week': week,
            'year': year,
            'monday': monday.replace(hour=12)
        }
        location_filter(self.request, params=params)
        update_config(params)
        return params
コード例 #4
0
    def config(self):
        week = self.request.GET.get('week')
        year = self.request.GET.get('year')
        date = "%s-W%s-1" % (year, week)
        monday = datetime.datetime.strptime(date, "%Y-W%W-%w")

        params = {
            'domain': self.domain,
            'week': week,
            'year': year,
            'monday': monday.replace(hour=12)
        }
        location_filter(self.request, params=params)
        update_config(params)
        return params
コード例 #5
0
    def rows(self):
        def cell_format(data):
            percent = 0
            if isinstance(data, dict):
                percent = 1
            return {'sort_key': percent, 'html': "oui" if percent else "non"}

        formatter = DataFormatter(
            DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data,
                                keys=self.keys,
                                group_by=self.group_by)
        selected_location = location_filter(self.request,
                                            location_filter_selected=True)
        if selected_location:
            locations = SQLLocation.objects.get(
                location_id=selected_location).get_descendants(
                    include_self=True).filter(
                        location_type__code='centre-de-sante').order_by('name')
        else:
            locations = SQLLocation.objects.filter(
                domain=self.domain,
                location_type__code='centre-de-sante',
                is_archived=False).order_by('name')
        user_locations = users_locations()
        for site in locations:
            loc_data = data.get(site.location_id, {})
            if site.location_id in user_locations:
                yield [
                    site.name,
                    cell_format(loc_data.get('completude', 0)),
                    cell_format(loc_data.get('promptitude', 0)),
                ]
コード例 #6
0
ファイル: reports.py プロジェクト: kkrampa/commcare-hq
    def rows(self):

        def cell_format(data):
            percent = 0
            if isinstance(data, dict):
                percent = 1
            return {
                'sort_key': percent,
                'html': "oui" if percent else "non"
            }

        formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)
        selected_location = location_filter(self.request, location_filter_selected=True)
        if selected_location:
            locations = SQLLocation.objects.get(
                location_id=selected_location
            ).get_descendants(include_self=True).filter(location_type__code='centre-de-sante').order_by('name')
        else:
            locations = SQLLocation.objects.filter(
                domain=self.domain,
                location_type__code='centre-de-sante',
                is_archived=False
            ).order_by('name')
        user_locations = users_locations()
        for site in locations:
            loc_data = data.get(site.location_id, {})
            if site.location_id in user_locations:
                yield [
                    site.name,
                    cell_format(loc_data.get('completude', 0)),
                    cell_format(loc_data.get('promptitude', 0)),
                ]
コード例 #7
0
    def rows(self):
        formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)

        selected_location = location_filter(self.request, location_filter_selected=True)
        selected_hierarchy = []
        if selected_location:
            selected_hierarchy = SQLLocation.objects.get(
                location_id=selected_location
            ).get_descendants(
                include_self=True
            ).filter(
                location_type__code='centre-de-sante'
            ).values_list(
                'location_id',
                flat=True
            )

        locations = SQLLocation.objects.filter(
            domain=self.domain,
            location_type__code='zone',
            is_archived=False
        ).order_by('name')
        user_locations = users_locations()
        for zone in locations:
            for reg in zone.children.order_by('name'):
                for dis in reg.children.order_by('name'):
                    for site in dis.children.order_by('name'):
                        row = data.get(site.location_id, {})
                        if show_location(site, user_locations, selected_hierarchy):
                            yield [
                                reg.name,
                                dis.name,
                                site.name,
                                row.get('cas_vus_5', EMPTY_CELL),
                                row.get('cas_suspects_5', EMPTY_CELL),
                                row.get('cas_confirmes_5', EMPTY_CELL),
                                row.get('cas_vus_5_10', EMPTY_CELL),
                                row.get('cas_suspects_5_10', EMPTY_CELL),
                                row.get('cas_confirmes_5_10', EMPTY_CELL),
                                row.get('cas_vus_10', EMPTY_CELL),
                                row.get('cas_suspects_10', EMPTY_CELL),
                                row.get('cas_confirmes_10', EMPTY_CELL),
                                row.get('cas_vus_fe', EMPTY_CELL),
                                row.get('cas_suspects_fe', EMPTY_CELL),
                                row.get('cas_confirmes_fe', EMPTY_CELL),
                                row.get('total_cas', EMPTY_CELL),
                                row.get('per_cas_5', EMPTY_CELL),
                                row.get('per_cas_5_10', EMPTY_CELL),
                                row.get('per_cas_10', EMPTY_CELL),
                                row.get('per_cas_fa', EMPTY_CELL),
                                zone.name
                            ]
コード例 #8
0
    def rows(self):
        formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)

        selected_location = location_filter(self.request, location_filter_selected=True)
        selected_hierarchy = []
        if selected_location:
            selected_hierarchy = SQLLocation.objects.get(
                location_id=selected_location
            ).get_descendants(
                include_self=True
            ).filter(
                location_type__code='centre-de-sante'
            ).values_list(
                'location_id',
                flat=True
            )

        locations = SQLLocation.objects.filter(
            domain=self.domain,
            location_type__code='zone',
            is_archived=False
        ).order_by('name')
        user_locations = users_locations()
        for zone in locations:
            for reg in zone.children.order_by('name'):
                for dis in reg.children.order_by('name'):
                    for site in dis.children.order_by('name'):
                        row = data.get(site.location_id, {})
                        if show_location(site, user_locations, selected_hierarchy):
                            yield [
                                reg.name,
                                dis.name,
                                site.name,
                                row.get('cas_vus_5', EMPTY_CELL),
                                row.get('cas_suspects_5', EMPTY_CELL),
                                row.get('cas_confirmes_5', EMPTY_CELL),
                                row.get('cas_vus_5_10', EMPTY_CELL),
                                row.get('cas_suspects_5_10', EMPTY_CELL),
                                row.get('cas_confirmes_5_10', EMPTY_CELL),
                                row.get('cas_vus_10', EMPTY_CELL),
                                row.get('cas_suspects_10', EMPTY_CELL),
                                row.get('cas_confirmes_10', EMPTY_CELL),
                                row.get('cas_vus_fe', EMPTY_CELL),
                                row.get('cas_suspects_fe', EMPTY_CELL),
                                row.get('cas_confirmes_fe', EMPTY_CELL),
                                row.get('total_cas', EMPTY_CELL),
                                row.get('per_cas_5', EMPTY_CELL),
                                row.get('per_cas_5_10', EMPTY_CELL),
                                row.get('per_cas_10', EMPTY_CELL),
                                row.get('per_cas_fa', EMPTY_CELL),
                                zone.name
                            ]
コード例 #9
0
    def rows(self):

        def cell_format(data):
            percent = 0
            if isinstance(data, dict):
                percent = 100
            return {
                'sort_key': percent,
                'html': "%.2f%%" % percent
            }

        users = CommCareUser.by_domain(self.domain)
        users_dict = {}
        for user in users:
            if user.location_id not in users_dict:
                users_dict.update({user.location_id: [user.get_id]})
            else:
                users_dict[user.location_id].append(user.get_id)

        formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)
        selected_location = location_filter(self.request, location_filter_selected=True)
        if selected_location:
            locations = SQLLocation.objects.get(
                location_id=selected_location
            ).get_descendants(include_self=True).filter(location_type__code='centre-de-sante').order_by('name')
        else:
            locations = SQLLocation.objects.filter(
                domain=self.domain,
                location_type__code='centre-de-sante',
                is_archived=False
            ).order_by('name')
        user_locations = users_locations()
        for site in locations:
            loc_data = data.get(site.location_id, {})
            if site.location_id in user_locations:
                yield [
                    site.name,
                    cell_format(loc_data.get('completude', EMPTY_CELL)),
                    cell_format(loc_data.get('promptitude', EMPTY_CELL)),
                ]
コード例 #10
0
    def rows(self):

        def cell_format(data):
            percent = 0
            if isinstance(data, dict):
                percent = 100
            return {
                'sort_key': percent,
                'html': "%.2f%%" % percent
            }

        users = CommCareUser.by_domain(self.domain)
        users_dict = {}
        for user in users:
            if user.location_id not in users_dict:
                users_dict.update({user.location_id: [user.get_id]})
            else:
                users_dict[user.location_id].append(user.get_id)

        formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
        data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)
        selected_location = location_filter(self.request, location_filter_selected=True)
        if selected_location:
            locations = SQLLocation.objects.get(
                location_id=selected_location
            ).get_descendants(include_self=True).filter(location_type__code='centre-de-sante').order_by('name')
        else:
            locations = SQLLocation.objects.filter(
                domain=self.domain,
                location_type__code='centre-de-sante',
                is_archived=False
            ).order_by('name')
        user_locations = users_locations()
        for site in locations:
            loc_data = data.get(site.location_id, {})
            if site.location_id in user_locations:
                yield [
                    site.name,
                    cell_format(loc_data.get('completude', 0)),
                    cell_format(loc_data.get('promptitude', 0)),
                ]
コード例 #11
0
 def config(self):
     year = self.request.GET.get('year')
     params = {'domain': self.domain, 'year': year}
     location_filter(self.request, params=params)
     update_config(params)
     return params