class TauxDeRuptureFluff(fluff.IndicatorDocument): document_class = XFormInstance document_filter = ANDFilter([ FormPropertyFilter(xmlns=RAPTURE_XMLNSES[0]), IsExistFormPropertyFilter(xmlns=RAPTURE_XMLNSES[0], property_path="form", property_value='district') ]) domains = INTRAHEALTH_DOMAINS deleted_types = IH_DELETED_TYPES save_direct_to_sql = True group_by = (fluff.AttributeGetter('product_name', lambda f: get_rupture_products(f)), fluff.AttributeGetter('product_code', lambda f: get_rupture_products_code(f))) 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')) district_name = flat_field(lambda f: f.form['district']) PPS_name = flat_field( lambda f: CommCareCase.get(f.form['case']['@case_id']).name) total_stock = report_calcs.RupturesDeStocks('pps_stocked_out')
class IntraHealthFluff(fluff.IndicatorDocument): document_class = XFormInstance document_filter = 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') ]) domains = INTRAHEALTH_DOMAINS deleted_types = IH_DELETED_TYPES save_direct_to_sql = True group_by = (fluff.AttributeGetter( 'product_name', lambda f: get_products(f, 'product_name')), fluff.AttributeGetter( 'product_code', lambda f: get_products_code(f, 'product_name'))) 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)) 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')
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()
class FarmerRecordFluff(fluff.IndicatorDocument): document_class = CommCareCase document_filter = CasePropertyFilter(type='farmer_record') domains = DOMAINS group_by = ('domain', fluff.AttributeGetter('value_chain', lambda c: get_mapping(c)), fluff.AttributeGetter('domains', lambda c: get_domains(c)), fluff.AttributeGetter('practices', lambda c: get_practices(c))) lvl_1 = case_property('lvl_1') lvl_2 = case_property('lvl_2') lvl_3 = case_property('lvl_3') lvl_4 = case_property('lvl_4') lvl_5 = case_property("lvl_5") case_status = flat_field(lambda c: c.get_case_property('case_status')) group_id = flat_field(lambda c: c.get_case_property('group_id')) group_name = flat_field(lambda c: c.get_case_property('group_name')) ppt_year = flat_field(lambda c: get_ppt_year(c)) owner_id = flat_field(lambda c: c.get_case_property('owner_id')) gender = flat_field(lambda c: get_gender(c)) group_leadership = flat_field(get_group_leadership) real_or_test = flat_field(lambda c: c.get_case_property('test_or_real')) schedule = flat_field(lambda c: (c.get_case_property( 'farmer_social_category') or '').lower()) group_case_id = flat_field(lambda c: c.get_case_property('group_case_id')) prop = Property()
class FarmerRecordFluff(fluff.IndicatorDocument): document_class = CommCareCase document_filter = CasePropertyFilter(type='farmer_record') domains = ( 'pathways-india-mis', 'pathways-tanzania', ) group_by = ('domain', fluff.AttributeGetter('value_chain', lambda c: get_mapping(c)), fluff.AttributeGetter('domains', lambda c: get_domains(c)), fluff.AttributeGetter('practices', lambda c: get_practices(c))) save_direct_to_sql = True lvl_1 = case_property('lvl_1') lvl_2 = case_property('lvl_2') lvl_3 = case_property('lvl_3') lvl_4 = case_property('lvl_4') lvl_5 = case_property("lvl_5") case_status = flat_field(lambda c: c.get_case_property('case_status')) group_id = flat_field(lambda c: c.get_case_property('group_id')) group_name = flat_field(lambda c: c.get_case_property('group_name')) ppt_year = flat_field(lambda c: c.get_case_property('ppt_year')) owner_id = flat_field(lambda c: c.get_case_property('owner_id')) gender = flat_field(lambda c: get_gender(c)) group_leadership = flat_field( lambda c: c.get_case_property('farmer_is_leader')) schedule = flat_field(lambda c: (c.get_case_property( 'farmer_social_category') or '').lower()) prop = Property()
class LivraisonFluff(fluff.IndicatorDocument): document_class = XFormInstance document_filter = FormPropertyFilter(xmlns=LIVRAISON_XMLNSES[0]) domains = INTRAHEALTH_DOMAINS group_by = ('domain', ) deleted_types = IH_DELETED_TYPES month = flat_field(lambda f: get_month(f, 'mois_visite')) duree_moyenne_livraison = report_calcs.DureeMoyenneLivraison() region_id = flat_field(lambda f: get_location_id_by_type(form=f, type=u'r\xe9gion')) district_id = flat_field(lambda f: CommCareCase.get(f.form['case']['@case_id']).location_id) district_name = flat_field(lambda f: CommCareCase.get(f.form['case']['@case_id']).name)
class OpmUserFluff(fluff.IndicatorDocument): def user_data(property): """ returns a flat field with a callable looking for `property` on the user """ return flat_field(lambda user: user.user_data.get(property)) document_class = CommCareUser domains = ('opm', ) group_by = ('domain', ) # Only consider active users document_filter = CustomFilter(is_valid_user) save_direct_to_sql = True name = flat_field(lambda user: user.name) numerator = Numerator() awc_code = user_data('awc_code') bank_name = user_data('bank_name') ifs_code = user_data('ifs_code') account_number = user_data('account_number') awc = user_data('awc') block = user_data('block') gp = user_data('gp') village = user_data('village') gps = user_data('gps')
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')
class WorldVisionChildFluff(fluff.IndicatorDocument): def case_property(property): return flat_field(lambda case: case.get_case_property(property)) document_class = CommCareCase document_filter = CasePropertyFilter(type='ttc_child') deleted_types = WV_DELETED_TYPES domains = WORLD_VISION_DOMAINS group_by = ('domain', 'user_id') name = flat_field(lambda case: case.name) mother_id = flat_field(lambda case: case.indices[0]['referenced_id'] if case.indices else None) lvl_4 = flat_field(partial(referenced_case_attribute, field_name='phc')) lvl_3 = flat_field(partial(referenced_case_attribute, field_name='block')) lvl_2 = flat_field(partial(referenced_case_attribute, field_name='district')) lvl_1 = flat_field(partial(referenced_case_attribute, field_name='state')) reason_for_child_closure = case_property('reason_for_child_closure') bcg = case_property('bcg') opv0 = case_property('opv0') hepb0 = case_property('hepb0') opv1 = case_property('opv1') hepb1 = case_property('hepb1') dpt1 = case_property('dpt1') opv2 = case_property('opv2') hepb2 = case_property('hepb2') dpt2 = case_property('dpt2') opv3 = case_property('opv3') hepb3 = case_property('hepb3') dpt3 = case_property('dpt3') measles = case_property('measles') vita1 = case_property('vita1') vita2 = case_property('vita2') dpt_opv_booster = case_property('dpt_opv_booster') vita3 = case_property('vita3') type_of_child_death = case_property('type_of_child_death') cause_of_death_child = case_property('cause_of_death_child') pneumonia_since_last_visit = case_property('pneumonia_since_last_visit') has_diarrhea_since_last_visit = case_property('has_diarrhea_since_last_visit') dairrhea_treated_with_ors = case_property('dairrhea_treated_with_ors') dairrhea_treated_with_zinc = case_property('dairrhea_treated_with_zinc') weight_birth = flat_field(calculate_weight) breastfeed_1_hour = case_property('breastfeed_1_hour') exclusive_breastfeeding = case_property('exclusive_breastfeeding') comp_breastfeeding = case_property('comp_breastfeeding') supplementary_feeding_baby = case_property('supplementary_feeding_baby') deworm = case_property('deworm') ebf_stop_age_month = case_property('ebf_stop_age_month') gender = case_property('gender') opened_on = flat_field(lambda case: case.opened_on) closed_on = flat_field(lambda case: case.closed_on) dob = flat_field(lambda case: case.dob) date_of_death = case_property('child_date_of_death') month_of_death = flat_field(get_datepart) year_of_death = flat_field(partial(get_datepart, t='Y')) women_registered = user_calcs.ChildRegistered()
class RecouvrementFluff(fluff.IndicatorDocument): document_class = CommCareCase document_filter = ANDFilter([ CasePropertyFilter(type='payment'), CustomFilter(lambda c: hasattr(c, 'district_name')) ]) domains = INTRAHEALTH_DOMAINS deleted_types = IH_DELETED_CASE_TYPES group_by = ('domain', fluff.AttributeGetter('district_name', lambda case: case.get_case_property('district_name'))) region_id = flat_field(lambda c: get_region_id(c)) district_id = flat_field(lambda c: get_district_id(c)) district_name = flat_field(lambda c: c['district_name']) payments = report_calcs.Recouvrement()
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()
class OpmFormFluff(fluff.IndicatorDocument): document_class = XFormInstance domains = ('opm', ) group_by = ( 'domain', fluff.AttributeGetter('case_id', _get_case_id), ) save_direct_to_sql = True name = flat_field(lambda form: form.name) # per user service_forms = user_calcs.ServiceForms() growth_monitoring = user_calcs.GrowthMonitoring()
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()
def user_data(property): """ returns a flat field with a callable looking for `property` on the user """ return flat_field(lambda user: user.user_data.get(property))
def case_property(property): """ returns a flat field with a callable looking for `property` on the case """ return flat_field(lambda case: case.get_case_property(property))
def case_property(property): return flat_field(lambda case: get_property(case, property))
def case_property(property): return flat_field(lambda case: case.get_case_property(property))