Ejemplo n.º 1
0
    def report_context(self):

        site_map = self.selected_site_map or self.site_map
        facilities = IHForCHFField.get_selected_facilities(site_map)

        return dict(ihf_data=self._get_data(facilities['ihf']),
                    chf_data=self._get_data(facilities['chf']))
Ejemplo n.º 2
0
    def rows(self):
        db = get_db()
        site_map = self.selected_site_map or self.site_map
       
        # hack
        facilities = IHForCHFField.get_selected_facilities(
                site_map, domain=self.domain)
        facilities = facilities['ihf'] + facilities['chf']

        rows = []



        for user in self.users:
            for site_id in facilities:
                key = [self.domain, user.get('user_id'), site_id]
                data = db.view('hsph/facility_registrations',
                    startkey=key + [self.datespan.startdate_param_utc],
                    endkey=key + [self.datespan.enddate_param_utc],
                    reduce=True,
                    wrapper=lambda r: r['value']
                ).first()
                
                if data:
                    rows.append([
                        self.facility_name_map[site_id],
                        self.table_cell(user.get('raw_username'), user.get('username_in_report')),
                        numeric_cell(data.get('facilityVisits', 0)),
                        numeric_cell(data.get('birthRegistrations', 0)),
                        numeric_cell(data.get('noPhoneDetails', 0)),
                        numeric_cell(data.get('noAddress', 0)),
                        numeric_cell(data.get('noContactInfo', 0)),
                    ])

        return rows
    def report_context(self):
        key_prefix = ["all"]
        key_suffix = []
        if self.region and self.district and self.site:
            key_prefix = ["full"]
            key_suffix = [self.region, self.district, self.site]
        elif self.region and self.district:
            key_prefix = ["district"]
            key_suffix = [self.region, self.district]
        elif self.region:
            key_prefix = ["region"]
            key_suffix = [self.region]

        facilities = IHForCHFField.get_facilities()

        ihf_data, ihf_collectors = self._gen_facility_data(key_prefix, key_suffix, facilities['ihf'])
        chf_data, chf_collectors = self._gen_facility_data(key_prefix, key_suffix, facilities['chf'])

        collectors = ihf_collectors.union(chf_collectors)
        dctls = set()

        users_per_dctls = NameOfDCTLField.get_users_per_dctl()
        for dctl, users in users_per_dctls.items():
            if len(users.intersection(collectors)) > 0:
                dctls.add(dctl)

        staff_stats = [dict(title="Number of Active Staff", val=len(collectors)+len(dctls)),
                       dict(title="DCTL", val=len(dctls))]

        for group in ["DCO", "DCP", "DCC"]:
            grp = Group.by_name(self.domain, group)
            users = set(grp.get_user_ids() if grp else [])
            staff_stats.append(dict(title=group, val=len(users.intersection(collectors))))

        citl_stat = lambda x: (float(x)/120)*100
        summary = [
            dict(title="Facilities with no status", stat=citl_stat),
            dict(title="No of facilities where S.B.R has been deployed", stat=citl_stat),
            dict(title="No. of Facilities where Baseline data collection has begun", stat=citl_stat),
            dict(title="No of Facilities where Data collection for Trial has begun", stat=citl_stat),
            dict(title="No of Birth events observed for Processes", stat=lambda x: (float(x)/2400)*100),
            dict(title="No of Outcome Data Collection Completed", stat=lambda x: (float(x)//172000)*100),
            dict(title="No of Process Data Collection Completed", stat=lambda x: (float(x)//2400)*100)]

        data = []
        for ind in range(len(summary)):
            data.append(dict(
                    title=summary[ind].get("title", ""),
                    ihf=ihf_data[ind],
                    chf=chf_data[ind],
                    total=ihf_data[ind]+chf_data[ind],
                    summary="%.2f%%" % summary[ind].get("stat", lambda x: x)(ihf_data[ind]+chf_data[ind])
                ))
        return dict(
            staff=staff_stats,
            status_data=data
        )
Ejemplo n.º 4
0
    def report_context(self):
        site_map = self.selected_site_map or self.site_map
        facilities = IHForCHFField.get_selected_facilities(
                site_map, domain=self.domain)

        return dict(
            ihf_data=self._get_data(facilities['ihf']),
            chf_data=self._get_data(facilities['chf'])
        )
Ejemplo n.º 5
0
    def rows(self):
        rows = []
        if not self.selected_site_map:
            self._selected_site_map = self.site_map
        site_keys = self.generate_keys()
        facilities = IHForCHFField.get_facilities()

        key_prefix = ["status"] if self.facility_status else ["all"]
        key_suffix = [self.facility_status] if self.facility_status else []

        for user in self.users:
            for site in site_keys:
                ihf_chf = '--'
                site_id = ''.join(site)
                if site_id in facilities['ihf']:
                    ihf_chf = 'IHF'
                elif site_id in facilities['chf']:
                    ihf_chf = 'CHF'

                if self.facility_type and self.facility_type != ihf_chf:
                    continue

                key = key_prefix + site + [user.user_id] + key_suffix
                data = get_db().view('hsph/pm_implementation_status_old',
                        reduce=True,
                        startkey=key+[self.datespan.startdate_param_utc],
                        endkey=key+[self.datespan.enddate_param_utc]
                    ).all()
                region, district, site = self.get_site_table_values(site)

                pb_temp = '<div class="progress"><div class="bar" style="width: %(percent)d%%;"></div></div>'

                if data:
                    for item in data:
                        item = item.get('value', {})
                        fac_stat = item.get('facilityStatus', -1)
                        try:
                            last_updated = dateutil.parser.parse(item.get('lastUpdated', "--")).replace(tzinfo=None)
                        except ValueError:
                            last_updated_str = item.get('lastUpdated', "--")
                        else:
                            last_updated_str = (
                                ServerTime(last_updated)
                                .user_time(self.timezone).ui_string()
                            )
                        rows.append([
                            self.table_cell(fac_stat, pb_temp % dict(percent=(fac_stat+2)*25)),
                            region,
                            district,
                            ihf_chf,
                            user.username_in_report,
                            site,
                            FacilityStatusField.options[fac_stat+1]['text'],
                            last_updated_str,
                        ])
        return rows
    def rows(self):
        rows = []
        if not self.selected_site_map:
            self._selected_site_map = self.site_map
        site_keys = self.generate_keys()
        facilities = IHForCHFField.get_facilities()

        key_prefix = ["status"] if self.facility_status else ["all"]
        key_suffix = [self.facility_status] if self.facility_status else []

        for user in self.users:
            for site in site_keys:
                ihf_chf = '--'
                site_id = ''.join(site)
                if site_id in facilities['ihf']:
                    ihf_chf = 'IHF'
                elif site_id in facilities['chf']:
                    ihf_chf = 'CHF'

                if self.facility_type and self.facility_type != ihf_chf:
                    continue

                key = key_prefix + site + [user.get('user_id')] + key_suffix
                data = get_db().view(
                    'hsph/pm_implementation_status_old',
                    reduce=True,
                    startkey=key + [self.datespan.startdate_param_utc],
                    endkey=key + [self.datespan.enddate_param_utc]).all()
                region, district, site = self.get_site_table_values(site)

                pb_temp = '<div class="progress"><div class="bar" style="width: %(percent)d%%;"></div></div>'

                if data:
                    for item in data:
                        item = item.get('value', {})
                        fac_stat = item.get('facilityStatus', -1)
                        rows.append([
                            self.table_cell(
                                fac_stat,
                                pb_temp % dict(percent=(fac_stat + 2) * 25)),
                            region, district, ihf_chf,
                            user.get('username_in_report'), site,
                            FacilityStatusField.options[fac_stat + 1]['text'],
                            tz_utils.string_to_prertty_time(
                                item.get('lastUpdated', "--"),
                                to_tz=self.timezone)
                        ])
        return rows
Ejemplo n.º 7
0
    def report_context(self):
        site_map = self.selected_site_map or self.site_map
        facilities = IHForCHFField.get_selected_facilities(site_map, self.domain)

        startdate = self.datespan.startdate_param_utc[:10]
        enddate = self.datespan.enddate_param_utc[:10]

        user_ids = self.user_ids
       
        return {
            'ihf': self.get_values(
                    self.domain, (startdate, enddate),
                    site_ids=facilities['ihf'],
                    user_ids=user_ids),
            'chf': self.get_values(
                    self.domain, (startdate, enddate),
                    site_ids=facilities['chf'],
                    user_ids=user_ids)
        }
Ejemplo n.º 8
0
    def rows(self):
        user_data = DCTLToFIDAFilter.get_user_data(
                self.request_params, domain=self.domain)
        self.override_user_ids = user_data['leaf_user_ids']

        db = get_db()
        site_map = self.selected_site_map or self.site_map
       
        # hack
        facilities = IHForCHFField.get_selected_facilities(
                site_map, domain=self.domain)
        facilities = facilities['ihf'] + facilities['chf']

        rows = []

        for user in self.users:
            for site_id in facilities:
                key = [self.domain, user.user_id, site_id]
                data = db.view('hsph/facility_registrations',
                    startkey=key + [self.datespan.startdate_param_utc],
                    endkey=key + [self.datespan.enddate_param_utc],
                    reduce=True,
                    wrapper=lambda r: r['value']
                ).first()
                
                if data:
                    dctl = user_data['user_parent_map'][user['user_id']]
                    rows.append([
                        self.facility_name_map[site_id],
                        self.table_cell(
                            user.raw_username,
                            user.username_in_report),
                        self.table_cell(
                            dctl.raw_username,
                            dctl.username_in_report),
                        numeric_cell(data.get('facilityVisits', 0)),
                        numeric_cell(data.get('birthRegistrations', 0)),
                        numeric_cell(data.get('noPhoneDetails', 0)),
                        numeric_cell(data.get('noAddress', 0)),
                        numeric_cell(data.get('noContactInfo', 0)),
                    ])

        return rows
Ejemplo n.º 9
0
    def rows(self):
        user_data = DCTLToFIDAFilter.get_user_data(
                self.request_params, domain=self.domain)
        self.override_user_ids = user_data['leaf_user_ids']

        db = get_db()
        site_map = self.selected_site_map or self.site_map
       
        # hack
        facilities = IHForCHFField.get_selected_facilities(
                site_map, domain=self.domain)
        facilities = facilities['ihf'] + facilities['chf']

        rows = []

        for user in self.users:
            for site_id in facilities:
                key = [self.domain, user.get('user_id'), site_id]
                data = db.view('hsph/facility_registrations',
                    startkey=key + [self.datespan.startdate_param_utc],
                    endkey=key + [self.datespan.enddate_param_utc],
                    reduce=True,
                    wrapper=lambda r: r['value']
                ).first()
                
                if data:
                    dctl = user_data['user_parent_map'][user['user_id']]
                    rows.append([
                        self.facility_name_map[site_id],
                        self.table_cell(
                            user.get('raw_username'),
                            user.get('username_in_report')),
                        self.table_cell(
                            dctl.raw_username,
                            dctl.username_in_report),
                        numeric_cell(data.get('facilityVisits', 0)),
                        numeric_cell(data.get('birthRegistrations', 0)),
                        numeric_cell(data.get('noPhoneDetails', 0)),
                        numeric_cell(data.get('noAddress', 0)),
                        numeric_cell(data.get('noContactInfo', 0)),
                    ])

        return rows
Ejemplo n.º 10
0
    def report_context(self):
        key_prefix = ["all"]
        key_suffix = []
        if self.region and self.district and self.site:
            key_prefix = ["full"]
            key_suffix = [self.region, self.district, self.site]
        elif self.region and self.district:
            key_prefix = ["district"]
            key_suffix = [self.region, self.district]
        elif self.region:
            key_prefix = ["region"]
            key_suffix = [self.region]

        facilities = IHForCHFField.get_facilities()

        ihf_data, ihf_collectors = self._gen_facility_data(
            key_prefix, key_suffix, facilities['ihf'])
        chf_data, chf_collectors = self._gen_facility_data(
            key_prefix, key_suffix, facilities['chf'])

        collectors = ihf_collectors.union(chf_collectors)
        dctls = set()

        users_per_dctls = NameOfDCTLField.get_users_per_dctl()
        for dctl, users in users_per_dctls.items():
            if len(users.intersection(collectors)) > 0:
                dctls.add(dctl)

        staff_stats = [
            dict(title="Number of Active Staff",
                 val=len(collectors) + len(dctls)),
            dict(title="DCTL", val=len(dctls))
        ]

        for group in ["DCO", "DCP", "DCC"]:
            grp = Group.by_name(self.domain, group)
            users = set(grp.get_user_ids() if grp else [])
            staff_stats.append(
                dict(title=group, val=len(users.intersection(collectors))))

        citl_stat = lambda x: (float(x) / 120) * 100
        summary = [
            dict(title="Facilities with no status", stat=citl_stat),
            dict(title="No of facilities where S.B.R has been deployed",
                 stat=citl_stat),
            dict(title=
                 "No. of Facilities where Baseline data collection has begun",
                 stat=citl_stat),
            dict(title=
                 "No of Facilities where Data collection for Trial has begun",
                 stat=citl_stat),
            dict(title="No of Birth events observed for Processes",
                 stat=lambda x: (float(x) / 2400) * 100),
            dict(title="No of Outcome Data Collection Completed",
                 stat=lambda x: (float(x) // 172000) * 100),
            dict(title="No of Process Data Collection Completed",
                 stat=lambda x: (float(x) // 2400) * 100)
        ]

        data = []
        for ind in range(len(summary)):
            data.append(
                dict(title=summary[ind].get("title", ""),
                     ihf=ihf_data[ind],
                     chf=chf_data[ind],
                     total=ihf_data[ind] + chf_data[ind],
                     summary="%.2f%%" % summary[ind].get(
                         "stat", lambda x: x)(ihf_data[ind] + chf_data[ind])))
        return dict(staff=staff_stats, status_data=data)