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 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 UCLAPatientFluff(fluff.IndicatorDocument): document_class = CommCareCase domains = ('succeed',) document_filter = CustomFilter(lambda c: c.type == 'participant') deleted_types = ('CommCareCase-Deleted', ) group_by = ('domain', ) name = flat_field(lambda case: case.full_name) mrn = flat_field(lambda case: case['mrn']) owner_id = flat_field(lambda case: case.owner_id) user_id = flat_field(lambda case: case.user_id) bp_category = flat_field(lambda case: get_property(case, 'BP_category')) care_site = flat_field(lambda case: get_property(case, 'care_site_display').lower()) is_active = flat_field(lambda case: is_active(case)) visit_name = flat_field(lambda case: visit_name(case)) visit_days = flat_field(lambda case: visit_days(case)) last_interaction = flat_field(lambda case: last_interaction(case)) emitter = RandomizationDate()
class CareSAFluff(fluff.IndicatorDocument): document_class = XFormInstance wrapper = CareSAForm document_filter = ANDFilter([ NOTFilter( xcalculators.FormPropertyFilter( xmlns='http://openrosa.org/user-registration')), NOTFilter( xcalculators.FormPropertyFilter( xmlns='http://openrosa.org/user/registration')), NOTFilter( xcalculators.FormPropertyFilter( xmlns='http://code.javarosa.org/devicereport')), CustomFilter(lambda f: f.gender in ['male', 'female']), CustomFilter(lambda f: f.cbo), ]) domains = ('care-ihapc-live', ) group_by = ( 'domain', 'user_id', 'province', 'cbo', 'age_group', 'gender', ) # Report 1 # Testing and Counseling #1a # tested hiv_counseling = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/testing_consent', property_value='counseling_testing', ) #1b hiv_tested = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/hiv_tested', property_value='yes', ) #1c # no results internal_hiv_pos_test = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/test_results', property_value='hiv_pos', ) hiv_positive = xcalculators.and_calc([hiv_tested, internal_hiv_pos_test]) #1d new_hiv_tb_screen = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/test_results', operator=xcalculators.ANY, ) #1ea tb_screened = xcalculators.filtered_form_calc( xmlns=TB_XMLNS, property_path='form/tb_screening', operator=xcalculators.ANY, ) #1eb internal_tb_screening_any = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/tb_screening', operator=xcalculators.ANY, ) internal_testing_counseling = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/testing_consent', property_value='only_counseling', ) internal_testing_referral = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/testing_consent', property_value='only_referral', ) internal_testing_answers = xcalculators.or_calc( [internal_testing_counseling, internal_testing_referral]) hct_screened = xcalculators.and_calc( [internal_tb_screening_any, internal_testing_answers]) #1f referred_tb_signs = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/refer_phcf_tb', property_value='yes', ) #1g TODO NOT IN FORM #1h internal_refer_phcf = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/refer_phcf', property_value='yes', ) #1ha internal_new_patient = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/newly_diagnosed', property_value='yes', ) referred_for_cdf_new = xcalculators.and_calc( [internal_refer_phcf, internal_new_patient]) #1hb internal_existing_patient = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/newly_diagnosed', property_value='no', ) referred_for_cdf_existing = xcalculators.and_calc( [internal_refer_phcf, internal_existing_patient]) #1i internal_new_cd4 = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/new_cd4', property_value='yes', ) new_hiv_cd4_results = xcalculators.and_calc( [internal_new_cd4, internal_new_patient]) #1k internal_refer_hbc = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/refer_hbc', property_value='yes', ) internal_refer_iact = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/refer_iact', property_value='yes', ) internal_care_referral = xcalculators.or_calc( [internal_refer_hbc, internal_refer_iact]) new_hiv_in_care_program = xcalculators.and_calc( [internal_care_referral, internal_hiv_pos_test]) #1l individual_tests = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/couple', property_value='single', ) #1m couple_tests = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, indicator_calculator=xcalculators.IntegerPropertyReference( 'form/couple_number'), ) #1n (currently expected to duplicate 1b hiv_community = xcalculators.filtered_form_calc( xmlns=HCT_XMLNS, property_path='form/hiv_tested', property_value='yes', ) #2a deceased = xcalculators.filtered_form_calc( xmlns=PMM_XMLNS, property_path='form/why_close', property_value='deceased', ) #2b TODO #hbc visit date >= today - 90 #lost_to_followup = xcalculators.filtered_form_calc( #xmlns=HBC_XMLNS, #property_path='form/visit_date', #property_value='90', #) #2c TODO not in form #2d tb_treatment_completed = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/tb_treatment', property_value='completed_treatment', ) #2e #HBC>>visit_intervention = clinical_support and any other response received_cbc = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/visit_intervention', # TODO verify this operator=xcalculators.ANY, ) #2f existing_cbc = xcalculators.and_calc( [received_cbc, internal_existing_patient]) #2g new_hiv_cbc = xcalculators.and_calc([received_cbc, internal_new_patient]) #2h internal_on_ipt = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/on_ipt', property_value='yes', ) new_hiv_starting_ipt = xcalculators.and_calc( [internal_new_patient, internal_on_ipt]) #2i internal_on_bactrim = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/on_bactrim', property_value='yes', ) new_hiv_starting_bactrim = xcalculators.and_calc( [internal_new_patient, internal_on_bactrim]) #2k internal_on_arv = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/on_arv', property_value='yes', ) internal_pre_art = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/pre_art', property_value='yes', ) internal_hiv_care = xcalculators.or_calc([ internal_on_bactrim, internal_on_ipt, internal_pre_art, internal_on_arv ]) internal_tb_re_screening = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, property_path='form/tb_re_screening', operator=xcalculators.ANY, ) hiv_on_care_screened_for_tb = xcalculators.and_calc( [internal_hiv_care, internal_tb_re_screening]) #2l family_screened = xcalculators.filtered_form_calc( xmlns=HBC_XMLNS, indicator_calculator=xcalculators.IntegerPropertyReference( 'form/number_family', lambda x: x - 1), ) #2j NOT IN FORM #3a hiv_pos_enrolled = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/first_session', property_value='yes', ) #3b hiv_pos_completed = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/last_session', property_value='confirm', ) #3c hiv_pos_pipeline = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/session_no', property_value='session_5', operator=xcalculators.IN, ) #3d TODO CASE #3f internal_iact_not_complete = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/last_session', property_value='not_complete', ) internal_iact_ipt = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/on_ipt', property_value='yes', ) iact_participant_ipt = xcalculators.and_calc( [internal_iact_not_complete, internal_iact_ipt]) #3g internal_iact_bactrim = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/on_bactrim', property_value='yes', ) iact_participant_bactrim = xcalculators.and_calc( [internal_iact_not_complete, internal_iact_bactrim]) #3h internal_iact_pre_art = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/pre_art', property_value='yes', ) iact_participant_art = xcalculators.and_calc( [internal_iact_not_complete, internal_iact_pre_art]) #3i internal_iact_arv = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/on_arv', property_value='yes', ) iact_participant_arv = xcalculators.and_calc( [internal_iact_not_complete, internal_iact_arv]) #3j cd4lt200 = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/cd4_res', property_value=(0, 200), operator=xcalculators.IN_RANGE, ) #3k cd4lt350 = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/cd4_res', property_value=(200, 350), operator=xcalculators.IN_RANGE, ) #3l cd4gt350 = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/cd4_res', property_value=(350, float('inf')), operator=xcalculators.IN_RANGE, ) #3m internal_skipped_cd4 = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/cd4_res', operator=xcalculators.SKIPPED, ) internal_first_session = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/first_session', property_value='yes', ) unknown_cd4 = xcalculators.and_calc( [internal_skipped_cd4, internal_first_session]) #3n iact_support_groups = xcalculators.filtered_form_calc( xmlns=IACT_XMLNS, property_path='form/session_no', property_value=set([ 'session_1', 'session_2', 'session_3', 'session_4', 'session_5', 'session_6' ]), operator=xcalculators.IN, ) class Meta: app_label = 'care_sa'
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')), CustomFilter(lambda f: get_user_id(f) != 'demo_user'), 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'