示例#1
0
    def rows(self):
        rows = []
        locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id'])
        dg = []
        for date in list(rrule.rrule(rrule.MONTHLY, dtstart=self.config['startdate'],
                                     until=self.config['enddate'])):
            dg.extend(DeliveryGroups().submitting(locations, date.month))

        for child in dg:
            total_responses = 0
            total_possible = 0
            submitted, rr_value = randr_value(child.location_id, self.config['startdate'], self.config['enddate'])
            if child.is_archived and not rr_value:
                continue

            group_summaries = GroupSummary.objects.filter(
                org_summary__date__lte=self.config['startdate'],
                org_summary__location_id=child.location_id,
                title=SupplyPointStatusTypes.R_AND_R_FACILITY
            )

            for group_summary in group_summaries:
                if group_summary:
                    total_responses += group_summary.responded
                    total_possible += group_summary.total
            hist_resp_rate = rr_format_percent(total_responses, total_possible)

            url = make_url(FacilityDetailsReport, self.config['domain'],
                           '?location_id=%s&filter_by_program=%s&'
                           'datespan_type=%s&datespan_first=%s&datespan_second=%s',
                           (self.config['location_id'],
                            self.config['program'], self.config['datespan_type'],
                            self.config['datespan_first'], self.config['datespan_second']))

            contact = CommCareUser.get_db().view(
                'locations/users_by_location_id',
                startkey=[child.location_id],
                endkey=[child.location_id, {}],
                include_docs=True
            ).first()

            if contact and contact['doc']:
                contact = CommCareUser.wrap(contact['doc'])
                role = contact.user_data.get('role') or ""
                args = (contact.first_name, contact.last_name, role, contact.default_phone_number)
                contact_string = "%s %s (%s) %s" % args
            else:
                contact_string = ""

            rows.append(
                [
                    child.site_code,
                    link_format(child.name, url),
                    get_span(submitted) % (rr_value.strftime("%d %b %Y") if rr_value else "Not reported"),
                    contact_string,
                    hist_resp_rate
                ]
            )

        return rows
示例#2
0
    def rows(self):
        rows = []
        locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id'],
                                               site_code__icontains=self.config['msd_code'])
        dg = DeliveryGroups().submitting(locations, int(self.config['month']))
        for child in dg:
            total_responses = 0
            total_possible = 0
            group_summaries = GroupSummary.objects.filter(
                org_summary__date__lte=datetime(int(self.config['year']), int(self.config['month']), 1),
                org_summary__supply_point=child.location_id, title='rr_fac'
            )

            for g in group_summaries:
                if g:
                    total_responses += g.responded
                    total_possible += g.total
            hist_resp_rate = rr_format_percent(total_responses, total_possible)

            url = make_url(FacilityDetailsReport, self.config['domain'],
                           '?location_id=%s&filter_by_program=%s%s',
                           (child.location_id, self.config['program'], self.config['prd_part_url']))

            rr_value = randr_value(child.location_id, int(self.config['month']), int(self.config['year']))
            contact = get_default_contact_for_location(self.config['domain'], child.location_id)

            if contact:
                role = contact.user_data.get('role') or ""
                args = (contact.first_name, contact.last_name, role, contact.default_phone_number)
                contact_string = "%s %s (%s) %s" % args
            else:
                contact_string = ""

            rows.append(
                [
                    child.site_code,
                    link_format(child.name, url),
                    get_span(rr_value) % (format(rr_value, "d M Y") if rr_value else "Not reported"),
                    contact_string,
                    hist_resp_rate
                ]
            )

        return rows
示例#3
0
    def rows(self):
        rows = []
        locations = SQLLocation.objects.filter(
            parent__location_id=self.config['location_id'])
        dg = []
        for date in list(
                rrule.rrule(rrule.MONTHLY,
                            dtstart=self.config['startdate'],
                            until=self.config['enddate'])):
            dg.extend(DeliveryGroups().submitting(locations, date.month))

        for child in dg:
            total_responses = 0
            total_possible = 0
            submitted, rr_value = randr_value(child.location_id,
                                              self.config['startdate'],
                                              self.config['enddate'])
            if child.is_archived and not rr_value:
                continue

            group_summaries = GroupSummary.objects.filter(
                org_summary__date__lte=self.config['startdate'],
                org_summary__location_id=child.location_id,
                title=SupplyPointStatusTypes.R_AND_R_FACILITY,
                total=1)

            if not group_summaries:
                continue

            for group_summary in group_summaries:
                if group_summary:
                    total_responses += group_summary.responded
                    total_possible += group_summary.total
            hist_resp_rate = rr_format_percent(total_responses, total_possible)

            url = make_url(
                FacilityDetailsReport, self.config['domain'],
                '?location_id=%s&filter_by_program=%s&'
                'datespan_type=%s&datespan_first=%s&datespan_second=%s',
                (child.location_id, self.config['program'],
                 self.config['datespan_type'], self.config['datespan_first'],
                 self.config['datespan_second']))

            contact = get_one_user_at_location(self.config['domain'],
                                               child.location_id)

            if contact:
                role = contact.user_data.get('role') or ""
                args = (contact.first_name, contact.last_name, role,
                        contact.default_phone_number)
                contact_string = "%s %s (%s) %s" % args
            else:
                contact_string = ""

            rows.append([
                child.site_code,
                link_format(child.name, url),
                get_span(submitted) % (rr_value.strftime("%d %b %Y")
                                       if rr_value else "Not reported"),
                contact_string, hist_resp_rate
            ])

        return rows