Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
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.º 6
0
class MockIndicatorsWithGetters(fluff.IndicatorDocument):

    document_class = MockDoc
    group_by = (fluff.AttributeGetter('domain'),
                fluff.AttributeGetter(
                    'owner_id', getter_function=lambda item: item['owner_id']))
    group_by_type_map = {'domain': fluff.TYPE_INTEGER}
    domains = ('test', )

    value_week = ValueCalculator(window=WEEK)

    class Meta:
        app_label = 'Mock'
Ejemplo n.º 7
0
class MockIndicatorsWithGetters(fluff.IndicatorDocument):

    document_class = MockDoc
    group_by = (fluff.AttributeGetter('domain'),
                fluff.AttributeGetter(
                    'owner_id', getter_function=lambda item: item['owner_id']))
    group_by_type_map = {'domain': fluff.TYPE_INTEGER}
    domains = ('mock', )
    deleted_types = ('MockArchive', )
    save_direct_to_sql = False

    value_week = ValueCalculator(window=WEEK)

    class Meta(object):
        app_label = 'fluff'
Ejemplo n.º 8
0
class ProjectIndicatorsCaseFluff(BaseM4ChangeCaseFluff):
    group_by = (
        "domain",
        fluff.AttributeGetter("mother_id",
                              getter_function=_get_form_mother_id),
    )

    location_id = fluff.FlatField(_get_form_location_id)
    women_registered_anc = project_indicators_report_calcs.AncRegistrationCalculator(
    )
    women_having_4_anc_visits = project_indicators_report_calcs.Anc4VisitsCalculator(
    )
    women_delivering_at_facility_cct = project_indicators_report_calcs.FacilityDeliveryCctCalculator(
    )
    women_delivering_within_6_weeks_attending_pnc = project_indicators_report_calcs.PncAttendanceWithin6WeeksCalculator(
    )
    number_of_free_sims_given = project_indicators_report_calcs.NumberOfFreeSimsGivenCalculator(
    )
    mno_mtn = project_indicators_report_calcs.MnoCalculator('mtn')
    mno_etisalat = project_indicators_report_calcs.MnoCalculator('etisalat')
    mno_glo = project_indicators_report_calcs.MnoCalculator('glo')
    mno_airtel = project_indicators_report_calcs.MnoCalculator('airtel')

    class Meta(object):
        app_label = 'm4change'
Ejemplo n.º 9
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.º 10
0
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()
Ejemplo n.º 11
0
class ProjectIndicatorsCaseFluff(BaseM4ChangeCaseFluff):
    group_by = (
        "domain",
        fluff.AttributeGetter("mother_id",
                              getter_function=_get_form_mother_id),
    )

    location_id = fluff.FlatField(_get_form_location_id)
    women_registered_anc = project_indicators_report_calcs.AncRegistrationCalculator(
    )
    women_having_4_anc_visits = project_indicators_report_calcs.Anc4VisitsCalculator(
    )
    women_delivering_at_facility_cct = project_indicators_report_calcs.FacilityDeliveryCctCalculator(
    )
    women_delivering_within_6_weeks_attending_pnc = project_indicators_report_calcs.PncAttendanceWithin6WeeksCalculator(
    )
Ejemplo n.º 12
0
class CouvertureFluff(fluff.IndicatorDocument):
    document_class = XFormInstance
    document_filter = FormPropertyFilter(xmlns=OPERATEUR_XMLNSES[0])

    domains = INTRAHEALTH_DOMAINS
    group_by = ('domain', fluff.AttributeGetter('location_id',
                                                get_location_id))
    save_direct_to_sql = True

    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)
    registered = report_calcs.PPSRegistered()
    planned = report_calcs.PPSPlaned()
Ejemplo n.º 13
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.º 14
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.º 15
0
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 case
    bp1_cash = case_calcs.BirthPreparedness(
        ['window_1_1', 'window_1_2', 'window_1_3'])
    bp2_cash = case_calcs.BirthPreparedness(
        ['window_2_1', 'window_2_2', 'window_2_3'])
    delivery = case_calcs.Delivery()
    child_followup = case_calcs.ChildFollowup()
    child_spacing = case_calcs.ChildSpacing()

    # per user
    service_forms = user_calcs.ServiceForms()
    growth_monitoring = user_calcs.GrowthMonitoring()
Ejemplo n.º 16
0
class CareSAFluff(fluff.IndicatorDocument):
    document_class = XFormInstance

    domains = ('care-ihapc-live', )
    group_by = (
        'domain',
        fluff.AttributeGetter('user_id', get_user_id),
        fluff.AttributeGetter('province', get_province),
        fluff.AttributeGetter('cbo', get_cbo),
        fluff.AttributeGetter('age_group', get_age_group),
        fluff.AttributeGetter('gender', get_gender),
    )

    # Report 1
    # Testing and Counseling

    #1a
    # tested
    hiv_counseling = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/testing_consent',
        property_value='counseling_testing',
    )

    #1b
    hiv_tested = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/hiv_tested',
        property_value='yes',
    )

    #1c
    # no results
    internal_hiv_pos_test = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/test_results',
        property_value='hiv_pos',
    )
    hiv_positive = xcalculators.FormANDCalculator(
        [hiv_tested, internal_hiv_pos_test])

    #1d
    new_hiv_tb_screen = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/test_results',
        operator=xcalculators.ANY,
    )

    #1e
    internal_tb_screening = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/tb_screening',
        operator=xcalculators.ANY,
    )
    internal_tested_before = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/tested_b4',
        property_value='yes',
    )
    hiv_known_screened = xcalculators.FormANDCalculator(
        [internal_tb_screening, internal_tested_before])

    #1f
    referred_tb_signs = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/refer_phcf_tb',
        property_value='yes',
    )

    #1g TODO NOT IN FORM

    #1h
    internal_refer_phcf = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/refer_phcf',
        property_value='yes',
    )
    #1ha
    internal_new_patient = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/newly_diagnosed',
        property_value='yes',
    )
    referred_for_cdf_new = xcalculators.FormANDCalculator(
        [internal_refer_phcf, internal_new_patient])
    #1hb
    internal_existing_patient = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/newly_diagnosed',
        property_value='no',
    )
    referred_for_cdf_existing = xcalculators.FormANDCalculator(
        [internal_refer_phcf, internal_existing_patient])

    #1i
    internal_new_cd4 = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/new_cd4',
        property_value='yes',
    )
    new_hiv_cd4_results = xcalculators.FormANDCalculator(
        [internal_new_cd4, internal_new_patient])

    #1k
    internal_refer_hbc = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/refer_hbc',
        property_value='yes',
    )
    internal_refer_iact = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/refer_iact',
        property_value='yes',
    )
    internal_care_referral = xcalculators.FormORCalculator(
        [internal_refer_hbc, internal_refer_iact])
    internal_test_results_yes = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/test_results',
        property_value='yes',
    )
    new_hiv_in_care_program = xcalculators.FormANDCalculator(
        [internal_care_referral, internal_test_results_yes])

    #1l
    individual_tests = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HCT_XMLNS,
        property_path='form/couple',
        property_value='single',
    )

    #1m
    # TODO ENABLE
    #couple_tests = xcalculators.FilteredFormPropertyCalculator(
    #xmlns=HCT_XMLNS,
    #indicator_calculator=xcalculators.IntegerPropertyReference('form/couple_number'),
    #)

    #2a
    deceased = xcalculators.FilteredFormPropertyCalculator(
        xmlns=PMM_XMLNS,
        property_path='form/why_close',
        property_value='deceased',
    )

    #2b TODO
    #lost_to_followup = xcalculators.FilteredFormPropertyCalculator(
    #xmlns=HBC_XMLNS,
    #property_path='form/visit_date',
    #property_value='90',
    #)

    #2c TODO

    #2d
    tb_treatment_completed = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/tb_treatment',
        property_value='completed_treatment',
    )

    #2e TODO

    #2f TODO

    #2g TODO

    #2h
    internal_on_ipt = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/on_ipt',
        property_value='yes',
    )
    new_hiv_starting_ipt = xcalculators.FormANDCalculator(
        [internal_new_patient, internal_on_ipt])

    #2i
    internal_on_bactrim = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/on_bactrim',
        property_value='yes',
    )
    new_hiv_starting_bactrim = xcalculators.FormANDCalculator(
        [internal_new_patient, internal_on_bactrim])

    #2k
    internal_on_arv = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/on_arv',
        property_value='yes',
    )
    internal_pre_art = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/pre_art',
        property_value='yes',
    )
    internal_hiv_care = xcalculators.FormORCalculator([
        internal_on_bactrim, internal_on_ipt, internal_pre_art, internal_on_arv
    ])
    internal_tb_re_screening = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        property_path='form/tb_re_screening',
        operator=xcalculators.ANY,
    )

    hiv_on_care_screened_for_tb = xcalculators.FormANDCalculator(
        [internal_hiv_care, internal_tb_re_screening])

    #2l
    family_screened = xcalculators.FilteredFormPropertyCalculator(
        xmlns=HBC_XMLNS,
        indicator_calculator=xcalculators.IntegerPropertyReference(
            'form/number_family', lambda x: x - 1),
    )

    #3a
    hiv_pos_enrolled = xcalculators.FilteredFormPropertyCalculator(
        xmlns=IACT_XMLNS,
        property_path='form/first_session',
        property_value='yes',
    )

    #3b
    hiv_pos_completed = xcalculators.FilteredFormPropertyCalculator(
        xmlns=IACT_XMLNS,
        property_path='form/last_session',
        property_value='confirm',
    )

    #3c
    hiv_pos_pipeline = xcalculators.FilteredFormPropertyCalculator(
        xmlns=IACT_XMLNS,
        property_path='form/session_no',
        property_value='session_5',
    )

    #3d TODO CASE

    #3f
    internal_iact_not_complete = xcalculators.FilteredFormPropertyCalculator(
        xmlns=IACT_XMLNS,
        property_path='form/last_session',
        property_value='not_complete',
    )
    iact_participant_ipt = xcalculators.FormANDCalculator(
        [internal_iact_not_complete, internal_on_ipt])

    #3g
    iact_participant_bactrim = xcalculators.FormANDCalculator(
        [internal_iact_not_complete, internal_on_bactrim])

    #3h
    iact_participant_art = xcalculators.FormANDCalculator(
        [internal_iact_not_complete, internal_pre_art])

    #3i
    iact_participant_arv = xcalculators.FormANDCalculator(
        [internal_iact_not_complete, internal_on_arv])

    #3j...n TODO

    class Meta:
        app_label = 'care_sa'
Ejemplo n.º 17
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.º 18
0
class MalariaConsortiumFluff(fluff.IndicatorDocument):
    document_class = XFormInstance

    domains = ('mc-inscale',)
    group_by = ('domain', fluff.AttributeGetter('user_id', get_user_id))

    document_filter = ANDFilter([
        NOTFilter(xcalculators.FormPropertyFilter(xmlns='http://openrosa.org/user-registration')),
        NOTFilter(xcalculators.FormPropertyFilter(xmlns='http://code.javarosa.org/devicereport')),
    ])

    # report 1a, district - monthly

    # home visits
    home_visits_adult_reg = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
    )
    home_visits_pregnant = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/pregnant',
        property_value='1',
    )
    home_visits_non_pregnant = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/pregnant',
        property_value='0',
    )
    home_visits_postpartem = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/post_partum',
        property_value='1',
    )
    home_visits_non_postpartem = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/post_partum',
        property_value='0',
    )
    home_visits_male_reg = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/sex',
        property_value='1',
    )
    home_visits_newborn_reg = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
    )
    home_visits_newborn_followup = _filtered_calc_alias(
        xmlns=NEWBORN_FOLLOWUP_XMLNS,
    )
    home_visits_newborn = _or_alias(
        [home_visits_newborn_reg, home_visits_newborn_followup]
    )
    home_visits_child_reg = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
    )
    home_visits_child_followup = _filtered_calc_alias(
        xmlns=CHILD_FOLLOWUP_XMLNS,
    )
    home_visits_children = _or_alias(
        [home_visits_child_reg, home_visits_child_followup]
    )
    home_visits_other_women = _and_alias(
        [home_visits_non_pregnant, home_visits_non_postpartem]
    )
    home_visits_adult_followup = _filtered_calc_alias(
        xmlns=ADULT_FOLLOWUP_XMLNS,
    )
    home_visits_adult = _or_alias(
        [home_visits_adult_reg, home_visits_adult_followup]
    )
    home_visits_followup = _or_alias(
        [home_visits_newborn_followup, home_visits_child_followup, home_visits_adult_followup]
    )
    home_visits_other = _or_alias(
        [home_visits_other_women, home_visits_male_reg, home_visits_adult_followup]
    )
    home_visits_total = _or_alias(
        [home_visits_pregnant, home_visits_postpartem, home_visits_newborn, home_visits_children, home_visits_other]
    )

    # rdt
    rdt_positive_children = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/consult/results_rdt',
        property_value='1',
    )
    rdt_positive_adults = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/rdt_result',
        property_value='1',
    )
    internal_rdt_negative_children = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/consult/results_rdt',
        property_value=set(['2', '3']),
        operator=xcalculators.IN,
    )
    internal_rdt_negative_adults = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/rdt_result',
        property_value=set(['2', '3']),
        operator=xcalculators.IN,
    )
    rdt_others = _or_alias(
         [internal_rdt_negative_adults, internal_rdt_negative_children]
    )
    rdt_total = _or_alias(
        [rdt_positive_children, rdt_positive_adults, rdt_others]
    )

    # diagnosed cases
    diagnosed_malaria_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='1',
        operator=xcalculators.IN_MULTISELECT,
    )
    diagnosed_malaria_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='1',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_diagnosed_diarrhea_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='2',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_diagnosed_diarrhea_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='2',
        operator=xcalculators.IN_MULTISELECT,
    )
    diagnosed_diarrhea = _or_alias(
         [internal_diagnosed_diarrhea_child, internal_diagnosed_diarrhea_adult]
    )
    # ari = acute resperatory infection
    internal_diagnosed_ari_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='3',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_diagnosed_ari_adult  = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/diagnosis_given',
        property_value='pneumonia',
        operator=xcalculators.IN_MULTISELECT,
    )
    diagnosed_ari = _or_alias(
         [internal_diagnosed_ari_child, internal_diagnosed_ari_adult]
    )
    diagnosed_total = _or_alias(
        [diagnosed_malaria_child, diagnosed_malaria_adult, diagnosed_diarrhea, diagnosed_ari]
    )

    # treated cases
    internal_treated_malaria_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value=set(['4', '5', '7', '8', '9', '10', '11']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_malaria_child = _and_alias(
        [diagnosed_malaria_child, internal_treated_malaria_child]
    )
    internal_treated_malaria_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value=set(['4', '5', '7', '8', '9', '10', '11']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_malaria_adult = _and_alias(
        [diagnosed_malaria_adult, internal_treated_malaria_adult]
    )
    treated_malaria = _or_alias(
         [internal_diagnosed_and_treated_malaria_child, internal_diagnosed_and_treated_malaria_adult]
    )
    internal_treated_diarrhea_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value='3',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_diarrhea_child = _and_alias(
         [internal_diagnosed_diarrhea_child, internal_treated_diarrhea_child]
    )
    internal_treated_diarrhea_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value=set(['3', '6']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_diarrhea_adult = _and_alias(
         [internal_diagnosed_diarrhea_adult, internal_treated_diarrhea_adult]
    )
    treated_diarrhea = _or_alias(
         [internal_diagnosed_and_treated_diarrhea_child, internal_diagnosed_and_treated_diarrhea_adult]
    )
    internal_treated_ari_child= _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value=set(['1', '2']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_ari_child = _and_alias(
         [internal_diagnosed_ari_child, internal_treated_ari_child]
    )
    internal_treated_ari_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/treatment_given',
        property_value=set(['1', '2']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_diagnosed_and_treated_ari_adult = _and_alias(
         [internal_diagnosed_ari_adult, internal_treated_ari_adult]
    )
    treated_ari = _or_alias(
        [internal_diagnosed_and_treated_ari_child, internal_diagnosed_and_treated_ari_adult]
    )
    treated_total = _or_alias(
        [treated_malaria, treated_diarrhea, treated_ari]
    )

    # transfers
    internal_transfer_malnutrition_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='5',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_malnutrition_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='5',
        operator=xcalculators.IN_MULTISELECT,
    )
    transfer_malnutrition = _or_alias(
        [internal_transfer_malnutrition_child, internal_transfer_malnutrition_adult]
    )
    internal_transfer_incomplete_vaccination_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='3',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_incomplete_vaccination_newborn = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='3',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_incomplete_vaccination_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='3',
        operator=xcalculators.IN_MULTISELECT,
    )
    transfer_incomplete_vaccination = _or_alias([
        internal_transfer_incomplete_vaccination_child,
        internal_transfer_incomplete_vaccination_newborn,
        internal_transfer_incomplete_vaccination_adult,
    ])
    internal_transfer_danger_signs_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='1',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_danger_signs_newborn = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='1',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_danger_signs_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='1',
        operator=xcalculators.IN_MULTISELECT,
    )
    transfer_danger_signs = _or_alias([
        internal_transfer_danger_signs_child,
        internal_transfer_danger_signs_newborn,
        internal_transfer_danger_signs_adult,
    ])
    transfer_prenatal_consult =  _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='6',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_missing_malaria_meds_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='7',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_transfer_missing_malaria_meds_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='7',
        operator=xcalculators.IN_MULTISELECT,
    )
    transfer_missing_malaria_meds = _or_alias([
        internal_transfer_missing_malaria_meds_child,
        internal_transfer_missing_malaria_meds_adult,
    ])
    internal_transfer_other_child = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value=set(['0', '6']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_transfer_other_newborn = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value=set(['0', '2', '4']),
        operator=xcalculators.ANY_IN_MULTISELECT,
    )
    internal_transfer_other_adult = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='0',
        operator=xcalculators.IN_MULTISELECT,
    )
    transfer_other = _or_alias([
        internal_transfer_other_child,
        internal_transfer_other_newborn,
        internal_transfer_other_adult,
    ])
    transfer_total = _or_alias([
        transfer_malnutrition,
        transfer_incomplete_vaccination,
        transfer_danger_signs,
        transfer_prenatal_consult,
        transfer_missing_malaria_meds,
        transfer_other,
    ])

    # deaths
    deaths_newborn = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/deaths/deaths_newborns'),
    )
    deaths_children = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/deaths/deaths_children'),
    )
    deaths_mothers = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/deaths/deaths_mothers'),
    )
    deaths_other = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/deaths/deaths_others'),
    )
    deaths_total = xcalculators.FormSUMCalculator([
        deaths_newborn, deaths_children, deaths_mothers, deaths_other
    ])
    heath_ed_talks = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/he/he_number'),
    )
    heath_ed_participants = _filtered_calc_alias(
        xmlns=WEEKLY_SUMMARY_XMLNS,
        indicator_calculator=IntegerPropertyReference('form/he/he_number_participants'),
    )

    # validation of diagnosis and treatment
    internal_child_has_pneumonia = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/has_pneumonia',
        property_value='yes',
    )
    internal_child_diagnosed_pneumonia = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/pneumonia_ds',
        property_value='yes',
    )
    internal_child_given_correct_pneumonia_treatment_1 = _and_alias([
         internal_child_has_pneumonia, internal_treated_ari_child
    ])
    internal_child_given_correct_pneumonia_treatment_2 = _and_alias([
         internal_child_diagnosed_pneumonia, internal_treated_ari_child
    ])

    patients_given_pneumonia_meds_denom = _or_alias([
        internal_child_has_pneumonia,
        internal_child_diagnosed_pneumonia,
        internal_diagnosed_ari_adult,
    ])
    patients_given_pneumonia_meds_num = _or_alias([
        internal_child_given_correct_pneumonia_treatment_1,
        internal_child_given_correct_pneumonia_treatment_2,
        internal_diagnosed_and_treated_ari_adult,
    ])

    internal_child_has_diarrhoea_ds = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/diarrhoea_ds',
        property_value='yes',
    )
    internal_child_has_diarrhoea_symptom = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/non_severe_symptoms/diarrhoea',
        property_value='1',
    )
    internal_child_has_diarrhoea = _or_alias([
        internal_child_has_diarrhoea_ds,
        internal_child_has_diarrhoea_symptom,
    ])
    internal_child_given_correct_diarrhoea_treatment = _and_alias([
        internal_child_has_diarrhoea,
        internal_treated_diarrhea_child,
    ])
    patients_given_diarrhoea_meds_denom = _or_alias([
        internal_child_has_diarrhoea,
        internal_diagnosed_diarrhea_adult,
    ])
    patients_given_diarrhoea_meds_num = _or_alias([
        internal_child_given_correct_diarrhoea_treatment,
        internal_diagnosed_and_treated_diarrhea_adult,
    ])

    internal_child_has_malaria = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/has_malaria',
        property_value='yes',
    )
    internal_child_given_correct_malaria_treatment = _and_alias([
        internal_child_has_malaria,
        internal_treated_malaria_child,
    ])
    patients_given_malaria_meds_denom = _or_alias([
        internal_child_has_malaria,
        diagnosed_malaria_adult,
    ])
    patients_given_malaria_meds_num = _or_alias([
        internal_child_given_correct_malaria_treatment,
        internal_diagnosed_and_treated_malaria_adult,
    ])

    # referrals
    internal_newborn_referral_needed = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/referral_needed',
        property_value='yes',
    )
    internal_newborn_referral_given = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/referral_given',
        property_value='yes',
    )
    internal_newborn_referred_correctly = _and_alias([
        internal_newborn_referral_needed,
        internal_newborn_referral_given
    ])
    internal_child_referral_needed = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/referral_needed',
        property_value='yes',
    )
    internal_child_referral_given = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given',
        property_value='1',
    )
    internal_child_referred_correctly = _and_alias([
        internal_child_referral_needed,
        internal_child_referral_given
    ])
    internal_adult_referral_needed = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/preg_danger_signs/treatment_preg_ds',
        property_value='OK',
    )
    internal_adult_referral_given = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given',
        property_value='1',
    )
    internal_adult_referred_correctly = _and_alias([
        internal_adult_referral_needed,
        internal_adult_referral_given
    ])
    patients_correctly_referred_denom = _or_alias([
        internal_newborn_referral_needed,
        internal_child_referral_needed,
        internal_adult_referral_needed,
    ])
    patients_correctly_referred_num = _or_alias([
        internal_newborn_referred_correctly,
        internal_child_referred_correctly,
        internal_adult_referred_correctly,
    ])

    cases_rdt_not_done = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/consult/results_rdt',
        property_value='0',
    )

    # danger signs not referred
    internal_newborn_has_danger_sign = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/has_danger_sign',
        property_value='yes',
    )
    internal_newborn_referral_not_reported = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_reported',
        property_value='0',
    )
    internal_newborn_referral_reported = _filtered_calc_alias(
        xmlns=NEWBORN_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_reported',
        property_value='1',
    )
    internal_newborn_danger_sign_handled_wrong = _and_alias([
        internal_newborn_has_danger_sign,
        internal_newborn_referral_not_reported,
    ])
    internal_child_has_danger_sign = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/has_danger_sign',
        property_value='yes',
    )
    internal_child_referral_not_given = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given',
        property_value='0',
    )
    internal_child_danger_sign_handled_wrong = _and_alias([
        internal_child_has_danger_sign,
        internal_child_referral_not_given,
    ])
    internal_adult_referral_not_given = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given',
        property_value='0',
    )
    internal_adult_danger_sign_handled_wrong = _and_alias([
        internal_adult_referral_needed,
        internal_adult_referral_not_given,
    ])
    cases_danger_signs_not_referred = _or_alias([
        internal_newborn_danger_sign_handled_wrong,
        internal_child_danger_sign_handled_wrong,
        internal_adult_danger_sign_handled_wrong,
    ])

    # missing malaria meds
    internal_child_no_malaria_meds = _filtered_calc_alias(
        xmlns=CHILD_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='7',
        operator=xcalculators.IN_MULTISELECT,
    )
    internal_adult_no_malaria_meds = _filtered_calc_alias(
        xmlns=ADULT_REGISTRATION_XMLNS,
        property_path='form/self_report/referral_given_reason',
        property_value='7',
        operator=xcalculators.IN_MULTISELECT,
    )
    cases_no_malaria_meds = _or_alias([
        internal_child_no_malaria_meds,
        internal_adult_no_malaria_meds,
    ])
    cases_transferred = _or_alias([
        internal_newborn_referral_reported,
        internal_child_referral_given,
        internal_adult_referral_given,
    ])


    class Meta:
        app_label = 'mc'