Ejemplo n.º 1
0
class RecapPassageFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ANDFilter([
        ORFilter(
            [FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0]), FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1])]
        ),
        ORFilter([
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0], property_path="form", property_value='PPS_name'),
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1], property_path="form", property_value='PPS_name')
        ])

    ])

    domains = INTRAHEALTH_DOMAINS
    deleted_types = IH_DELETED_TYPES
    group_by = (fluff.AttributeGetter('product_name', lambda f: get_products(f, 'product_name')),
                fluff.AttributeGetter('product_id', lambda f: get_products_id(f, 'product_name')))

    location_id = flat_field(get_location_id)
    region_id = flat_field(lambda f: get_location_id_by_type(form=f, type=u'r\xe9gion'))
    district_id = flat_field(lambda f: get_location_id_by_type(form=f, type='district'))
    real_date_repeat = flat_field(get_real_date)
    PPS_name = flat_field(lambda f: f.form['PPS_name'])

    product = report_calcs.RecapPassage()
Ejemplo n.º 2
0
class BaseM4ChangeCaseFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter(_get_all_m4change_forms())
    domains = M4CHANGE_DOMAINS

    class Meta(object):
        app_label = 'm4change'
Ejemplo n.º 3
0
def date_reported_provided_mediated(form):
    if form.xmlns == FOLLOWUP_FORM_XMLNS:
        return date_mediated(form)
    elif ORFilter(
        [filter_action('immediate_referral'),
         filter_action('actions_other')]).filter(form):
        return date_reported(form)
    else:
        return date_provided(form)
Ejemplo n.º 4
0
def filter_referral_org(org):
    return ORFilter([
        xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS,
                                 operator=IN_MULTISELECT,
                                 property_path='form/mediation_referral',
                                 property_value=org),
        xcalc.FormPropertyFilter(xmlns=FOLLOWUP_FORM_XMLNS,
                                 operator=IN_MULTISELECT,
                                 property_path='form/mediation_referral',
                                 property_value=org)
    ])
Ejemplo n.º 5
0
def or_calc(calculators, date_provider=default_date, indicator_calculator=None,
            group_by_provider=None, window=timedelta(days=1)):
    """
    Shortcut function for creating a SimpleCalculator with a filter that combines
    the filters of the calculators in an ORFilter
    """
    return SimpleCalculator(
        date_provider=date_provider,
        filter=ORFilter([calc._filter for calc in calculators if calc._filter]),
        indicator_calculator=indicator_calculator,
        group_by_provider=group_by_provider,
        window=window
    )
Ejemplo n.º 6
0
def filter_outcome(outcome, xmlns=None):
    if xmlns:
        return xcalc.FormPropertyFilter(xmlns=xmlns,
                                        property_path='form/mediation_outcome',
                                        property_value=outcome)
    else:
        return ORFilter([
            xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS,
                                     property_path='form/mediation_outcome',
                                     property_value=outcome),
            xcalc.FormPropertyFilter(xmlns=FOLLOWUP_FORM_XMLNS,
                                     property_path='form/mediation_outcome',
                                     property_value=outcome)
        ])
Ejemplo n.º 7
0
class TauxDeSatisfactionFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter([
        FormPropertyFilter(xmlns=COMMANDE_XMLNSES[0]),
        FormPropertyFilter(xmlns=COMMANDE_XMLNSES[1]),
        FormPropertyFilter(xmlns=COMMANDE_XMLNSES[2])
    ])
    deleted_types = IH_DELETED_TYPES

    domains = INTRAHEALTH_DOMAINS
    group_by = (fluff.AttributeGetter('product_name', lambda f: get_products(f, 'productName')),
                fluff.AttributeGetter('product_id', lambda f: get_products_id(f, 'productName')))

    region_id = flat_field(lambda f: get_location_id_by_type(form=f, type=u'r\xe9gion'))
    district_id = flat_field(lambda f: get_location_id_by_type(form=f, type='district'))
    commandes = report_calcs.TauxCalculator(property_name='amountOrdered')
    recus = report_calcs.TauxCalculator(property_name='amountReceived')
Ejemplo n.º 8
0
class IntraHealthFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter([
        ANDFilter([
            FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0]),
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0],
                                      property_path="form",
                                      property_value='district_name'),
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0],
                                      property_path="form",
                                      property_value='PPS_name')
        ]),
        ANDFilter([
            FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1]),
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1],
                                      property_path="form",
                                      property_value='district_name'),
            IsExistFormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1],
                                      property_path="form",
                                      property_value='PPS_name')
        ]),
    ])
    domains = INTRAHEALTH_DOMAINS
    deleted_types = IH_DELETED_TYPES
    group_by = (fluff.AttributeGetter(
        'product_name', lambda f: get_products(f, 'product_name')),
                fluff.AttributeGetter(
                    'product_id',
                    lambda f: get_products_id(f, 'product_name')))

    region_id = flat_field(
        lambda f: get_location_id_by_type(form=f, type='r\xe9gion'))
    district_id = flat_field(
        lambda f: get_location_id_by_type(form=f, type='district'))
    PPS_name = flat_field(lambda f: get_pps_name(f))
    district_name = flat_field(lambda f: get_district_name(f))
    location_id = flat_field(get_location_id)

    actual_consumption = report_calcs.PPSConsumption()
    billed_consumption = report_calcs.PPSConsumption(
        field='billed_consumption')
    stock = report_calcs.PPSConsumption('old_stock_total')
    total_stock = report_calcs.PPSConsumption('total_stock')
    quantity = report_calcs.PPSConsumption('display_total_stock')
    cmm = report_calcs.PPSConsumption('default_consumption')
Ejemplo n.º 9
0
class TauxDeSatisfactionFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter([
        FormPropertyFilter(xmlns=COMMANDE_XMLNSES[0]),
        FormPropertyFilter(xmlns=COMMANDE_XMLNSES[1])
    ])

    domains = INTRAHEALTH_DOMAINS
    group_by = (fluff.AttributeGetter(
        'product_name', lambda f: get_products(f, 'productName')), )
    save_direct_to_sql = True

    region_id = flat_field(
        lambda f: get_location_id_by_type(form=f, type=u'r\xe9gion'))
    district_id = flat_field(
        lambda f: get_location_id_by_type(form=f, type='district'))
    commandes = report_calcs.Commandes()
    recus = report_calcs.Recus()
Ejemplo n.º 10
0
class CouvertureFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter([
        FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0]),
        FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[1]),
    ])

    domains = INTRAHEALTH_DOMAINS
    group_by = ('domain', fluff.AttributeGetter('location_id', get_location_id))
    deleted_types = IH_DELETED_TYPES

    location_id = flat_field(get_location_id)
    region_id = flat_field(lambda f: get_location_id_by_type(form=f, type=u'r\xe9gion'))
    district_id = flat_field(lambda f: get_location_id_by_type(form=f, type='district'))
    pps_name = flat_field(lambda f: get_pps_name(f))
    district_name = flat_field(lambda f: get_district_name(f))
    month = flat_field(lambda f: get_month(f, 'real_date'))
    real_date_repeat = flat_field(get_real_date)
    registered = report_calcs.PPSRegistered()
    planned = report_calcs.PPSPlaned()
Ejemplo n.º 11
0
class BaseM4ChangeCaseFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ORFilter(_get_all_m4change_forms())
    domains = M4CHANGE_DOMAINS
    save_direct_to_sql = True
Ejemplo n.º 12
0
class UnicefMalawiFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = ANDFilter([
        NOTFilter(
            xcalc.FormPropertyFilter(
                xmlns='http://openrosa.org/user-registration')),
        NOTFilter(
            xcalc.FormPropertyFilter(
                xmlns='http://openrosa.org/user/registration')),
        NOTFilter(
            xcalc.FormPropertyFilter(
                xmlns='http://code.javarosa.org/devicereport')),
        xcalc.CustomFilter(lambda f: get_user_id(f) != 'demo_user'),
        xcalc.CustomFilter(lambda f: get_group_id(f)),
    ])

    domains = ('cvsulive', )
    group_by = (
        'domain',
        fluff.AttributeGetter('user_id', get_user_id),
        fluff.AttributeGetter('group_id', get_group_id),
        fluff.AttributeGetter('age', get_age),
        fluff.AttributeGetter('sex', get_sex),
    )
    group_by_type_map = {'age': fluff.TYPE_INTEGER}

    # ---------------------------------------------------------------------
    # incident resolution
    # ---------------------------------------------------------------------

    resolution_resolved_at_cvsu = SimpleCalculator(
        date_provider=date_provided,
        filter=ORFilter([
            ANDFilter([
                filter_action('mediation_provided'),
                filter_outcome('resolved', REPORT_INCIDENT_XMLNS)
            ]),
            filter_outcome('resolved', FOLLOWUP_FORM_XMLNS)
        ]))

    resolution_unresolved = SimpleCalculator(
        date_provider=date_provided,
        filter=ORFilter([
            ANDFilter([
                filter_action('mediation_provided'),
                filter_outcome('unresolved', REPORT_INCIDENT_XMLNS)
            ]),
            filter_outcome('unresolved', FOLLOWUP_FORM_XMLNS)
        ]))

    resolution_case_withdrawn = SimpleCalculator(
        date_provider=date_provided,
        filter=ORFilter([
            ANDFilter([
                filter_action('mediation_provided'),
                filter_outcome('case_withdrawn', REPORT_INCIDENT_XMLNS)
            ]),
            filter_outcome('case_withdrawn', FOLLOWUP_FORM_XMLNS)
        ]))

    resolution_referred_ta = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('ta')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('ta')
            ])
        ]))

    resolution_referral_ta_court = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('ta_court')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('ta_court')
            ])
        ]))

    resolution_referral_police = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('police')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('med_ref_police')
            ])
        ]))

    resolution_referral_social_welfare = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('social_welfare')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('med_ref_social_welfare')
            ])
        ]))

    resolution_referral_ngo = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('ngo')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('med_ref_ngo')
            ])
        ]))

    resolution_referral_other = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            ANDFilter([
                filter_action('immediate_referral'),
                filter_immediate_referral_org('referral_other')
            ]),
            ANDFilter([
                filter_outcome('mediation_outcome_referred'),
                filter_referral_org('med_ref_other')
            ])
        ]))

    resolution_other = SimpleCalculator(
        date_provider=date_reported_provided_mediated,
        filter=ORFilter([
            filter_action('actions_other'),
            filter_outcome('other_mediation_outcome', REPORT_INCIDENT_XMLNS),
            filter_outcome('other', FOLLOWUP_FORM_XMLNS)
        ]),
    )

    resolution_total = xcalc.or_calc(
        [
            resolution_resolved_at_cvsu, resolution_referred_ta,
            resolution_referral_ta_court, resolution_referral_police,
            resolution_referral_social_welfare, resolution_referral_ngo,
            resolution_referral_other, resolution_unresolved, resolution_other
        ],
        date_provider=date_reported_provided_mediated,
    )

    # ---------------------------------------------------------------------
    # services
    # ---------------------------------------------------------------------

    service_referral = SimpleCalculator(
        date_provider=date_reported_mediated,
        filter=ORFilter([
            filter_action('immediate_referral'),
            filter_service('referral_hostpital'),
            filter_outcome('mediation_outcome_referred')
        ]))

    service_mediation = SimpleCalculator(
        date_provider=date_reported,
        filter=ORFilter([
            filter_action('mediation_scheduled'),
            filter_action('mediation_provided')
        ]))

    service_counselling = SimpleCalculator(date_provider=date_reported,
                                           filter=ORFilter([
                                               filter_service('counselling'),
                                               filter_service('couselling')
                                           ]))

    service_psychosocial_support = SimpleCalculator(
        date_provider=date_reported,
        filter=filter_service('psychosocial_support'))

    service_first_aid = SimpleCalculator(date_provider=date_reported,
                                         filter=filter_service('first_aid'))

    service_shelter = SimpleCalculator(date_provider=date_reported,
                                       filter=filter_service('shelter'))

    service_other = SimpleCalculator(date_provider=date_reported,
                                     filter=ORFilter([
                                         filter_action('actions_other'),
                                         filter_service('services_other')
                                     ]))

    service_total = xcalc.or_calc(
        [
            service_referral, service_mediation, service_counselling,
            service_psychosocial_support, service_first_aid, service_shelter,
            service_other
        ],
        date_provider=date_reported_mediated,
    )

    # ---------------------------------------------------------------------
    # outreach
    # ---------------------------------------------------------------------

    incidents = SimpleCalculator(
        date_provider=date_reported,
        filter=xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS))

    outreach = SimpleCalculator(
        date_provider=lambda form: form.form.get('date', form.received_on),
        filter=xcalc.FormPropertyFilter(xmlns=OUTREACH_FORM_XMLNS))

    iga = SimpleCalculator(
        date_provider=lambda form: form.form.get('start_date', form.received_on
                                                 ),
        filter=xcalc.FormPropertyFilter(xmlns=IGA_FORM_XMLNS))

    # ---------------------------------------------------------------------
    # abuse
    # ---------------------------------------------------------------------

    abuse_children_in_household = SimpleCalculator(
        date_provider=date_reported,
        filter=xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS),
        indicator_calculator=IntegerPropertyReference(
            'form/nr_children_in_household',
            transform=lambda x: 0 if x == 999 else x)  # unknown value = 999
    )

    abuse_children_abused = SimpleCalculator(
        date_provider=date_reported,
        filter=xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS),
        indicator_calculator=IntegerPropertyReference(
            'form/no_children_abused',
            transform=lambda x: 0 if x == 999 else x)  # unknown value = 999
    )

    abuse_category_physical = SimpleCalculator(date_provider=date_reported,
                                               filter=filter_abuse('physical'))

    abuse_category_sexual = SimpleCalculator(date_provider=date_reported,
                                             filter=filter_abuse('sexual'))

    abuse_category_psychological = SimpleCalculator(
        date_provider=date_reported, filter=filter_abuse('psychological'))

    abuse_category_exploitation = SimpleCalculator(
        date_provider=date_reported, filter=filter_abuse('exploitation'))

    abuse_category_neglect = SimpleCalculator(date_provider=date_reported,
                                              filter=filter_abuse('neglect'))

    abuse_category_other = SimpleCalculator(date_provider=date_reported,
                                            filter=filter_abuse('abuse_other'))

    abuse_category_total = xcalc.or_calc([
        abuse_category_physical, abuse_category_sexual,
        abuse_category_psychological, abuse_category_exploitation,
        abuse_category_neglect, abuse_category_other
    ],
                                         date_provider=date_reported)

    class Meta:
        app_label = 'cvsu'
Ejemplo n.º 13
0
def _or_alias(calculators):
    return SimpleCalculator(
        date_provider=xcalculators.default_date,
        filter=ORFilter([calc._filter for calc in calculators if calc._filter]),
        window=timedelta(days=1)
    )