Exemple #1
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)
    ])
Exemple #2
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)
        ])
Exemple #3
0
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')),
        xcalculators.CustomFilter(lambda f: f.gender in ['male', 'female']),
        xcalculators.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'
Exemple #4
0
def filter_service(service):
    return xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS,
                                    operator=IN_MULTISELECT,
                                    property_path='form/immediate_services',
                                    property_value=service)
Exemple #5
0
def filter_action(action):
    return xcalc.FormPropertyFilter(
        xmlns=REPORT_INCIDENT_XMLNS,
        property_path='form/actions_to_resolve_case',
        property_value=action)
Exemple #6
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'
Exemple #7
0
def filter_abuse(category):
    return xcalc.FormPropertyFilter(xmlns=REPORT_INCIDENT_XMLNS,
                                    operator=IN_MULTISELECT,
                                    property_path='form/abuse_category',
                                    property_value=category)
Exemple #8
0
def filter_immediate_referral_org(org):
    return xcalc.FormPropertyFilter(
        xmlns=REPORT_INCIDENT_XMLNS,
        operator=IN_MULTISELECT,
        property_path='form/immediate_referral_organisation',
        property_value=org)
Exemple #9
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'