def drilldown_map(self): user_location = users_locations() locations = SQLLocation.objects.filter( domain=self.domain, location_type__code='zone', is_archived=False).order_by('name') hierarchy = [] for zone in locations: z = {'val': zone.location_id, 'text': zone.name, 'next': []} for reg in zone.children.order_by('name'): r = {'val': reg.location_id, 'text': reg.name, 'next': []} for dis in reg.children.order_by('name'): d = {'val': dis.location_id, 'text': dis.name, 'next': []} for site in dis.children.order_by('name'): if site.location_id in user_location: d['next'].append({ 'val': site.location_id, 'text': site.name, 'next': [] }) if len(d['next']) > 0: r['next'].append(d) if len(r['next']) > 0: z['next'].append(r) if len(z['next']) > 0: hierarchy.append(z) return hierarchy
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)), ]
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)), ]
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 ]
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)), ]
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)), ]
def drilldown_map(self): user_location = users_locations() locations = SQLLocation.objects.filter( domain=self.domain, location_type__code='zone', is_archived=False ).order_by('name') hierarchy = [] for zone in locations: z = { 'val': zone.location_id, 'text': zone.name, 'next': [] } for reg in zone.children.order_by('name'): r = { 'val': reg.location_id, 'text': reg.name, 'next': [] } for dis in reg.children.order_by('name'): d = { 'val': dis.location_id, 'text': dis.name, 'next': [] } for site in dis.children.order_by('name'): if site.location_id in user_location: d['next'].append({ 'val': site.location_id, 'text': site.name, 'next': [] }) if len(d['next']) > 0: r['next'].append(d) if len(r['next']) > 0: z['next'].append(r) if len(z['next']) > 0: hierarchy.append(z) return hierarchy