Exemple #1
0
    def generate_data(self, domain):
        config = {
            'domain':
            domain,
            'district':
            self.get_list_property('district'),
            'type_visit':
            self.post_data.get('visit_type', None),
            'activity_type':
            self.post_data.get('activity_type', None),
            'client_type':
            self.get_list_property('client_type'),
            'user_id':
            get_user_ids_for_group(self.get_list_property('organization')),
            'fiscal_year':
            self.post_data.get('fiscal_year', None),
        }

        update_date_property(config, self.post_data, 'visit_date',
                             'visit_date')
        update_date_property(config, self.post_data, 'posttest_date',
                             'posttest_date')
        update_date_property(config, self.post_data, 'first_art_date',
                             'first_art_date')
        update_date_property(config, self.post_data, 'date_handshake',
                             'date_handshake')
        update_date_property(config, self.post_data, 'date_last_vl_test',
                             'date_last_vl_test')

        target_client_types = []
        for client_type in config['client_type']:
            if client_type == 'client_fsw':
                client_type = 'cfsw'
            target_client_types.append(client_type.lower())
        config.update({'clienttype': target_client_types})
        targets = TargetsDataSource(config=config.copy()).data
        kp_prev = UICFromEPMDataSource(config=config.copy()).data
        htc_tst = UICFromCCDataSource(config=config.copy()).data
        htc_pos = HivStatusDataSource(config=config.copy()).data
        care_new = FormCompletionDataSource(config=config.copy()).data
        tx_new = FirstArtDataSource(config=config.copy()).data
        tz_undetect = LastVLTestDataSource(config=config).data

        return {
            'target_kp_prev': (targets.get('target_kp_prev', 0) or 0),
            'target_htc_tst': (targets.get('target_htc_tst', 0) or 0),
            'target_htc_pos': (targets.get('target_htc_pos', 0) or 0),
            'target_care_new': (targets.get('target_care_new', 0) or 0),
            'target_tx_new': (targets.get('target_tx_new', 0) or 0),
            'target_tx_undetect': (targets.get('target_tx_undetect', 0) or 0),
            'kp_prev': (kp_prev.get(PREVENTION_XMLNS, {}).get('uic', 0) or 0),
            'htc_tst': (htc_tst.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'htc_pos': (htc_pos.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'care_new': (care_new.get(ACCOMPAGNEMENT_XMLNS, {}).get('uic', 0)
                         or 0),
            'tx_new': (tx_new.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
            'tx_undetect':
            (tz_undetect.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
        }
Exemple #2
0
 def get_care_new_achivement(self, domain):
     config = {
         'domain': domain,
         'hiv_status': self.get_list_property('care_new_hiv_status'),
         'client_type': self.get_list_property('care_new_client_type'),
         'age_range': self.get_list_property('care_new_age_range'),
         'district': self.get_list_property('care_new_district'),
         'user_id': get_user_ids_for_group(self.get_list_property('care_new_user_group')),
     }
     update_date_property(config, self.post_data, 'care_new_date_handshake', 'date_handshake')
     achievement = FormCompletionDataSource(config=config).data
     return achievement.get(ACCOMPAGNEMENT_XMLNS, {}).get('uic', 0)
Exemple #3
0
 def get_care_new_achivement(self, domain):
     config = {
         'domain': domain,
         'hiv_status': self.get_list_property('care_new_hiv_status'),
         'client_type': self.get_list_property('care_new_client_type'),
         'age_range': self.get_list_property('care_new_age_range'),
         'district': self.get_list_property('care_new_district'),
         'date_handshake_start': self.post_data.get('care_new_date_handshake_start', None),
         'date_handshake_end': self.post_data.get('care_new_date_handshake_end', None),
         'user_id': get_user_ids_for_group(self.get_list_property('care_new_user_group')),
     }
     achievement = FormCompletionDataSource(config=config).data
     return achievement.get(ACCOMPAGNEMENT_XMLNS, {}).get('uic', 0)
Exemple #4
0
    def generate_data(self, domain):
        config = {
            'domain': domain,
            'district': self.get_list_property('district'),
            'cbo': self.get_list_property('cbo'),
            'type_visit': self.post_data.get('visit_type', None),
            'activity_type': self.post_data.get('activity_type', None),
            'client_type': self.get_list_property('client_type'),
            'user_id': get_user_ids_for_group(self.get_list_property('organization')),
            'fiscal_year': self.post_data.get('fiscal_year', None),
        }

        update_date_property(config, self.post_data, 'visit_date', 'visit_date')
        update_date_property(config, self.post_data, 'posttest_date', 'posttest_date')
        update_date_property(config, self.post_data, 'first_art_date', 'first_art_date')
        update_date_property(config, self.post_data, 'date_handshake', 'date_handshake')
        update_date_property(config, self.post_data, 'date_last_vl_test', 'date_last_vl_test')

        target_client_types = []
        for client_type in config['client_type']:
            if client_type == 'client_fsw':
                client_type = 'cfsw'
            target_client_types.append(client_type.lower())
        config.update({'clienttype': target_client_types})
        targets = TargetsDataSource(config=config.copy()).data
        kp_prev = UICFromEPMDataSource(config=config.copy()).data
        htc_tst = UICFromCCDataSource(config=config.copy()).data
        htc_pos = HivStatusDataSource(config=config.copy()).data
        care_new = FormCompletionDataSource(config=config.copy()).data
        tx_new = FirstArtDataSource(config=config.copy()).data
        tz_undetect = LastVLTestDataSource(config=config).data

        return {
            'target_kp_prev': (targets.get('target_kp_prev', 0) or 0),
            'target_htc_tst': (targets.get('target_htc_tst', 0) or 0),
            'target_htc_pos': (targets.get('target_htc_pos', 0) or 0),
            'target_care_new': (targets.get('target_care_new', 0) or 0),
            'target_tx_new': (targets.get('target_tx_new', 0) or 0),
            'target_tx_undetect': (targets.get('target_tx_undetect', 0) or 0),
            'kp_prev': (kp_prev.get(PREVENTION_XMLNS, {}).get('uic', 0) or 0),
            'htc_tst': (htc_tst.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'htc_pos': (htc_pos.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'care_new': (care_new.get(ACCOMPAGNEMENT_XMLNS, {}).get('uic', 0) or 0),
            'tx_new': (tx_new.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
            'tx_undetect': (tz_undetect.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
        }
Exemple #5
0
    def generate_data(self, domain):
        month_start = self.post_data.get('month_start', 1)
        year_start = self.post_data.get('year_start', datetime.now().year)
        month_end = self.post_data.get('month_end', datetime.now().month)
        year_end = self.post_data.get('year_end', datetime.now().year)

        start_date = datetime(year_start, month_start, 1)
        end_date = (datetime(year_end, month_end, 1) +
                    relativedelta(months=1)) - relativedelta(days=1)

        config = {
            'domain':
            domain,
            'district':
            self.get_list_property('district'),
            'type_visit':
            self.post_data.get('visit_type', None),
            'activity_type':
            self.post_data.get('activity_type', None),
            'client_type':
            self.get_list_property('client_type'),
            'user_id':
            get_user_ids_for_group(self.get_list_property('organization')),
            'visit_date_start':
            start_date,
            'visit_date_end':
            end_date,
            'posttest_date_start':
            start_date,
            'posttest_date_end':
            end_date,
            'date_handshake_start':
            start_date,
            'date_handshake_end':
            end_date,
        }

        kp_prev = UICFromEPMDataSource(config=config.copy(),
                                       replace_group_by='kp_prev_month').data
        htc_tst = UICFromCCDataSource(config=config.copy(),
                                      replace_group_by='htc_month').data
        htc_pos = HivStatusDataSource(config=config.copy(),
                                      replace_group_by='htc_month').data
        care_new = FormCompletionDataSource(
            config=config, replace_group_by='care_new_month').data

        htc_uptake_chart_data = OrderedDict()
        htc_yield_chart_data = OrderedDict()
        link_chart_data = OrderedDict()

        rrule_dates = [
            rrule_date for rrule_date in rrule(
                MONTHLY, dtstart=start_date, until=end_date)
        ]
        tickValues = []
        for rrule_dt in rrule_dates:
            date_in_milliseconds = int(rrule_dt.date().strftime("%s")) * 1000
            tickValues.append(date_in_milliseconds)
            htc_uptake_chart_data.update({date_in_milliseconds: 0})
            htc_yield_chart_data.update({date_in_milliseconds: 0})
            link_chart_data.update({date_in_milliseconds: 0})

        for row in htc_tst.values():
            date = row['htc_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (kp_prev[date]['uic'] or 1) if date in kp_prev else 1
            htc_uptake_chart_data[date_in_milliseconds] = nom / denom

        for row in htc_pos.values():
            date = row['htc_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (htc_tst[date]['uic'] or 1) if date in htc_tst else 1
            htc_yield_chart_data[date_in_milliseconds] = nom / denom

        for row in care_new.values():
            date = row['care_new_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (htc_pos[date]['uic'] or 1) if date in htc_pos else 1
            link_chart_data[date_in_milliseconds] = nom / denom

        return {
            'chart': [{
                "values": [{
                    'x': key,
                    'y': value
                } for key, value in htc_uptake_chart_data.items()],
                "key":
                "HTC_uptake",
                "strokeWidth":
                2,
                "classed":
                "dashed",
                "color":
                "blue"
            }, {
                "values": [{
                    'x': key,
                    'y': value
                } for key, value in htc_yield_chart_data.items()],
                "key":
                "HTC_yield",
                "strokeWidth":
                2,
                "classed":
                "dashed",
                "color":
                "orange"
            }, {
                "values": [{
                    'x': key,
                    'y': value
                } for key, value in link_chart_data.items()],
                "key":
                "Link to care",
                "strokeWidth":
                2,
                "classed":
                "dashed",
                "color":
                "gray"
            }],
            'tickValues':
            tickValues
        }
Exemple #6
0
    def generate_data(self, domain):
        config = {
            'domain':
            domain,
            'district':
            self.post_data.get('district', None),
            'type_visit':
            self.post_data.get('visit_type', None),
            'activity_type':
            self.post_data.get('activity_type', None),
            'client_type':
            self.post_data.get('client_type', None),
            'organization':
            self.post_data.get('organization', None),
            'visit_date_start':
            self.post_data.get('visit_date_start', None),
            'visit_date_end':
            self.post_data.get('visit_date_end', None),
            'posttest_date_start':
            self.post_data.get('post_date_start', None),
            'posttest_date_end':
            self.post_data.get('post_date_end', None),
            'first_art_date_start':
            self.post_data.get('first_art_date_start', None),
            'first_art_date_end':
            self.post_data.get('first_art_date_end', None),
            'date_handshake_start':
            self.post_data.get('date_handshake_start', None),
            'date_handshake_end':
            self.post_data.get('date_handshake_end', None),
            'date_last_vl_test_start':
            self.post_data.get('date_last_vl_test_start', None),
            'date_last_vl_test_end':
            self.post_data.get('date_last_vl_test_end', None),
            'fiscal_year':
            self.post_data.get('fiscal_year', None),
        }
        client_type = self.post_data.get('client_type', None)
        if client_type:
            if client_type == 'client_fsw':
                client_type = 'cfsw'
            client_type = client_type.lower()
        config.update({'clienttype': client_type})

        targets = TargetsDataSource(config=config).data
        kp_prev = UICFromEPMDataSource(config=config).data
        htc_tst = UICFromCCDataSource(config=config).data
        htc_pos = HivStatusDataSource(config=config).data
        care_new = FormCompletionDataSource(config=config).data
        tx_new = FirstArtDataSource(config=config).data
        tz_undetect = LastVLTestDataSource(config=config).data

        return {
            'target_kp_prev': (targets.get('target_kp_prev', 0) or 0),
            'target_htc_tst': (targets.get('target_htc_tst', 0) or 0),
            'target_htc_pos': (targets.get('target_htc_pos', 0) or 0),
            'target_care_new': (targets.get('target_care_new', 0) or 0),
            'target_tx_new': (targets.get('target_tx_new', 0) or 0),
            'target_tx_undetect': (targets.get('target_tx_undetect', 0) or 0),
            'kp_prev': (kp_prev.get(PREVENTION_XMLNS, {}).get('uic', 0) or 0),
            'htc_tst': (htc_tst.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'htc_pos': (htc_pos.get(POST_TEST_XMLNS, {}).get('uic', 0) or 0),
            'care_new': (care_new.get(ACCOMPAGNEMENT_XMLNS, {}).get('uic', 0)
                         or 0),
            'tx_new': (tx_new.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
            'tx_undetect':
            (tz_undetect.get(SUIVI_MEDICAL_XMLNS, {}).get('uic', 0) or 0),
        }
Exemple #7
0
    def generate_data(self, domain):
        month_start = self.post_data.get('month_start', 1)
        year_start = self.post_data.get('year_start', datetime.now().year)
        month_end = self.post_data.get('month_end', datetime.now().month)
        year_end = self.post_data.get('year_end', datetime.now().year)

        start_date = datetime(year_start, month_start, 1)
        end_date = (datetime(year_end, month_end, 1) + relativedelta(months=1)) - relativedelta(days=1)

        config = {
            'domain': domain,
            'district': self.get_list_property('district'),
            'type_visit': self.post_data.get('visit_type', None),
            'activity_type': self.post_data.get('activity_type', None),
            'client_type': self.get_list_property('client_type'),
            'user_id': get_user_ids_for_group(self.get_list_property('organization')),
            'visit_date_start': start_date,
            'visit_date_end': end_date,
            'posttest_date_start': start_date,
            'posttest_date_end': end_date,
            'date_handshake_start': start_date,
            'date_handshake_end': end_date,
        }

        kp_prev = UICFromEPMDataSource(config=config.copy(), replace_group_by='kp_prev_month').data
        htc_tst = UICFromCCDataSource(config=config.copy(), replace_group_by='htc_month').data
        htc_pos = HivStatusDataSource(config=config.copy(), replace_group_by='htc_month').data
        care_new = FormCompletionDataSource(config=config, replace_group_by='care_new_month').data

        htc_uptake_chart_data = OrderedDict()
        htc_yield_chart_data = OrderedDict()
        link_chart_data = OrderedDict()

        rrule_dates = [
            rrule_date for rrule_date in rrule(
                MONTHLY,
                dtstart=start_date,
                until=end_date
            )
        ]
        tickValues = []
        for rrule_dt in rrule_dates:
            date_in_milliseconds = int(rrule_dt.date().strftime("%s")) * 1000
            tickValues.append(date_in_milliseconds)
            htc_uptake_chart_data.update({date_in_milliseconds: 0})
            htc_yield_chart_data.update({date_in_milliseconds: 0})
            link_chart_data.update({date_in_milliseconds: 0})

        for row in htc_tst.values():
            date = row['htc_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (kp_prev[date]['uic'] or 1) if date in kp_prev else 1
            htc_uptake_chart_data[date_in_milliseconds] = nom / denom

        for row in htc_pos.values():
            date = row['htc_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (htc_tst[date]['uic'] or 1) if date in htc_tst else 1
            htc_yield_chart_data[date_in_milliseconds] = nom / denom

        for row in care_new.values():
            date = row['care_new_month']
            date_in_milliseconds = int(date.strftime("%s")) * 1000
            nom = (row['uic'] or 0)
            denom = (htc_pos[date]['uic'] or 1) if date in htc_pos else 1
            link_chart_data[date_in_milliseconds] = nom / denom

        return {
            'chart': [
                {
                    "values": [
                        {'x': key, 'y': value} for key, value in htc_uptake_chart_data.items()
                    ],
                    "key": "HTC_uptake",
                    "strokeWidth": 2,
                    "classed": "dashed",
                    "color": "blue"
                },
                {
                    "values": [
                        {'x': key, 'y': value} for key, value in htc_yield_chart_data.items()
                    ],
                    "key": "HTC_yield",
                    "strokeWidth": 2,
                    "classed": "dashed",
                    "color": "orange"
                },
                {
                    "values": [
                        {'x': key, 'y': value} for key, value in link_chart_data.items()
                    ],
                    "key": "Link to care",
                    "strokeWidth": 2,
                    "classed": "dashed",
                    "color": "gray"
                }
            ],
            'tickValues': tickValues
        }