Exemplo n.º 1
0
def pregnancy(request):
    context = {'category': 'credos', 'subcategory': 'pregnancy'}

    periods = all_periods(MonthPeriod)

    indicators = []

    evol_data = {'fe': {'label': u"Total femmes enceintes", 'values': {}},
                 'ae': {'label': u"Accouchement enregistrés", 'values': {}},
                 'gi': {'label': u"Grossesses interrompues", 'values': {}},
                 'av': {'label': u"Grossesses avec enfants vivants",
                        'values': {}},
                 'mn': {'label': u"Grossesses avec morts nées", 'values': {}}}

    for month in periods:
        indicator = sum_month(month)
        indicators.append(indicator)
        indicator['rate_fe'] = rate_cal(indicator['fe'], indicator['fe'])
        indicator['rate_ae'] = rate_cal(indicator['ae'], indicator['fe'])
        indicator['rate_gi'] = rate_cal(indicator['gi'], indicator['fe'])
        indicator['rate_av'] = rate_cal(indicator['av'], indicator['fe'])
        indicator['rate_mn'] = rate_cal(indicator['mn'], indicator['fe'])
        evol_data['fe']['values'][month.pid] = {'value': indicator['fe']}
        evol_data['ae']['values'][month.pid] = {'value': indicator['ae']}
        evol_data['gi']['values'][month.pid] = {'value': indicator['gi']}
        evol_data['av']['values'][month.pid] = {'value': indicator['av']}
        evol_data['mn']['values'][month.pid] = {'value': indicator['mn']}

    context.update({'indicators': indicators, 'evol_data': evol_data.items(),
                                                         'periods': periods})

    return render(request, 'pregnancy.html', context)
Exemplo n.º 2
0
def excel_export(request):

    indicators = []
    periods = all_periods(MonthPeriod)
    evol_data = {'birth': {'label': u"Total naissance", 'values': {}},
                 'residence': {'label': u"Domicile", 'values': {}},
                 'center': {'label': u"Centre", 'values': {}},
                 'other': {'label': u"Ailleurs", 'values': {}},
                 'male': {'label': u"Sexe masculin", 'values': {}},
                 'female': {'label': u"Sexe feminin", 'values': {}},
                 'alive': {'label': u"Né vivant",
                        'values': {}},
                 'stillborn': {'label': u"Mort-né", 'values': {}}}
    for month in periods:
        indicator = sum_month(month)

        indicator['rate_birth'] = rate_cal(indicator['birth'],
                                           indicator['birth'])
        indicator['rate_residence'] = rate_cal(indicator['residence'],
                                           indicator['birth'])
        indicator['rate_center'] = rate_cal(indicator['center'],
                                           indicator['birth'])
        indicator['rate_other'] = rate_cal(indicator['other'],
                                           indicator['birth'])
        indicator['rate_male'] = rate_cal(indicator['male'],
                                           indicator['birth'])
        indicator['rate_female'] = rate_cal(indicator['female'],
                                           indicator['birth'])
        indicator['rate_alive'] = rate_cal(indicator['alive'],
                                           indicator['birth'])
        indicator['rate_stillborn'] = rate_cal(indicator['stillborn'],
                                           indicator['birth'])

        evol_data['birth']['values'][month.pid] = {'value': indicator['birth']}
        evol_data['residence']['values'][month.pid] = \
                                            {'value': indicator['residence']}
        evol_data['center']['values'][month.pid] = \
                                            {'value': indicator['center']}
        evol_data['other']['values'][month.pid] = \
                                            {'value': indicator['other']}
        evol_data['male']['values'][month.pid] = \
                                            {'value': indicator['male']}
        evol_data['female']['values'][month.pid] = \
                                            {'value': indicator['female']}
        evol_data['alive']['values'][month.pid] = \
                                            {'value': indicator['alive']}
        evol_data['stillborn']['values'][month.pid] = \
                                            {'value': indicator['stillborn']}
        indicators.append(indicator)

    file_name = 'Rapports mensuels de naissances.xls'

    file_content = birth_as_excel(indicators).getvalue()

    response = HttpResponse(file_content, \
                            content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename="%s"' % file_name
    response['Content-Length'] = len(file_content)

    return response
Exemplo n.º 3
0
def death(request):
    context = {'category': 'credos', 'subcategory': 'death'}

    indicators = []
    periods = all_periods(MonthPeriod)

    evol_data = {'ntd': {'label': u"Total décès", 'values': {}},
                 'dd': {'label': u"Domicile", 'values': {}},
                 'dc': {'label': u"Centre", 'values': {}},
                 'da': {'label': u"Ailleurs", 'values': {}},
                 'sm': {'label': u"Sexe masculin", 'values': {}},
                 'sf': {'label': u"Sexe feminin", 'values': {}}}

    for month in periods:
        indicator = sum_month(month)
        indicators.append(indicator)
        indicator['rate_ntd'] = rate_cal(indicator['ntd'], indicator['ntd'])
        indicator['rate_dd'] = rate_cal(indicator['dd'], indicator['ntd'])
        indicator['rate_dc'] = rate_cal(indicator['dc'], indicator['ntd'])
        indicator['rate_da'] = rate_cal(indicator['da'], indicator['ntd'])
        indicator['rate_sm'] = rate_cal(indicator['sm'], indicator['ntd'])
        indicator['rate_sf'] = rate_cal(indicator['sf'], indicator['ntd'])

        evol_data['ntd']['values'][month.pid] = {'value': indicator['ntd']}
        evol_data['dd']['values'][month.pid] = {'value': indicator['dd']}
        evol_data['dc']['values'][month.pid] = {'value': indicator['dc']}
        evol_data['da']['values'][month.pid] = {'value': indicator['da']}
        evol_data['sm']['values'][month.pid] = {'value': indicator['sm']}
        evol_data['sf']['values'][month.pid] = {'value': indicator['sf']}

    context.update({'indicators': indicators,
                    'evol_data': evol_data.items(),
                    'periods': periods})

    return render(request, 'death.html', context)
Exemplo n.º 4
0
def birth(request):
    context = {'category': 'credos', 'subcategory': 'birth'}

    indicators = []
    periods = all_periods(MonthPeriod)

    evol_data = {'birth': {'label': u"Total naissance", 'values': {}},
                 'residence': {'label': u"Domicile", 'values': {}},
                 'center': {'label': u"Centre", 'values': {}},
                 'other': {'label': u"Ailleurs", 'values': {}},
                 'male': {'label': u"Sexe masculin", 'values': {}},
                 'female': {'label': u"Sexe feminin", 'values': {}},
                 'alive': {'label': u"Né vivant",
                        'values': {}},
                 'stillborn': {'label': u"Mort-né", 'values': {}}}

    for month in periods:
        indicator = sum_month(month)

        indicator['rate_birth'] = rate_cal(indicator['birth'],
                                           indicator['birth'])
        indicator['rate_residence'] = rate_cal(indicator['residence'],
                                           indicator['birth'])
        indicator['rate_center'] = rate_cal(indicator['center'],
                                           indicator['birth'])
        indicator['rate_other'] = rate_cal(indicator['other'],
                                           indicator['birth'])
        indicator['rate_male'] = rate_cal(indicator['male'],
                                           indicator['birth'])
        indicator['rate_female'] = rate_cal(indicator['female'],
                                           indicator['birth'])
        indicator['rate_alive'] = rate_cal(indicator['alive'],
                                           indicator['birth'])
        indicator['rate_stillborn'] = rate_cal(indicator['stillborn'],
                                           indicator['birth'])

        evol_data['birth']['values'][month.pid] = {'value': indicator['birth']}
        evol_data['residence']['values'][month.pid] = \
                                            {'value': indicator['residence']}
        evol_data['center']['values'][month.pid] = \
                                            {'value': indicator['center']}
        evol_data['other']['values'][month.pid] = \
                                            {'value': indicator['other']}
        evol_data['male']['values'][month.pid] = \
                                            {'value': indicator['male']}
        evol_data['female']['values'][month.pid] = \
                                            {'value': indicator['female']}
        evol_data['alive']['values'][month.pid] = \
                                            {'value': indicator['alive']}
        evol_data['stillborn']['values'][month.pid] = \
                                            {'value': indicator['stillborn']}

        indicators.append(indicator)

    context.update({'indicators': indicators,
                    'evol_data': evol_data.items(),
                    'periods': periods})

    return render(request, 'birth.html', context)
Exemplo n.º 5
0
def excel_export(request):

    indicators = []
    periods = all_periods(MonthPeriod)

    evol_data = {'ntd': {'label': u"Total décès", 'values': {}},
                 'dd': {'label': u"Domicile", 'values': {}},
                 'dc': {'label': u"Centre", 'values': {}},
                 'da': {'label': u"Ailleurs", 'values': {}},
                 'sm': {'label': u"Sexe masculin", 'values': {}},
                 'sf': {'label': u"Sexe feminin", 'values': {}}}

    for month in periods:
        indicator = sum_month(month)
        indicators.append(indicator)
        indicator['rate_ntd'] = rate_cal(indicator['ntd'], indicator['ntd'])
        indicator['rate_dd'] = rate_cal(indicator['dd'], indicator['ntd'])
        indicator['rate_dc'] = rate_cal(indicator['dc'], indicator['ntd'])
        indicator['rate_da'] = rate_cal(indicator['da'], indicator['ntd'])
        indicator['rate_sm'] = rate_cal(indicator['sm'], indicator['ntd'])
        indicator['rate_sf'] = rate_cal(indicator['sf'], indicator['ntd'])

        evol_data['ntd']['values'][month.pid] = {'value': indicator['ntd']}
        evol_data['dd']['values'][month.pid] = {'value': indicator['dd']}
        evol_data['dc']['values'][month.pid] = {'value': indicator['dc']}
        evol_data['da']['values'][month.pid] = {'value': indicator['da']}
        evol_data['sm']['values'][month.pid] = {'value': indicator['sm']}
        evol_data['sf']['values'][month.pid] = {'value': indicator['sf']}

    file_content = death_as_excel(indicators).getvalue()

    file_name = 'Rapports mensuels de décès infantile.xls'

    response = HttpResponse(file_content, \
                            content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename="%s"' % file_name
    response['Content-Length'] = len(file_content)

    return response
Exemplo n.º 6
0
def excel_export(request):

    periods = all_periods(MonthPeriod)

    indicators = []

    evol_data = {'fe': {'label': u"Total femmes enceintes", 'values': {}},
                 'ae': {'label': u"Accouchement enregistrés", 'values': {}},
                 'gi': {'label': u"Grossesses interrompues", 'values': {}},
                 'av': {'label': u"Grossesses avec enfants vivants",
                        'values': {}},
                 'mn': {'label': u"Grossesses avec morts nées", 'values': {}}}

    for month in periods:
        indicator = sum_month(month)
        indicators.append(indicator)
        indicator['rate_fe'] = rate_cal(indicator['fe'], indicator['fe'])
        indicator['rate_ae'] = rate_cal(indicator['ae'], indicator['fe'])
        indicator['rate_gi'] = rate_cal(indicator['gi'], indicator['fe'])
        indicator['rate_av'] = rate_cal(indicator['av'], indicator['fe'])
        indicator['rate_mn'] = rate_cal(indicator['mn'], indicator['fe'])
        evol_data['fe']['values'][month.pid] = {'value': indicator['fe']}
        evol_data['ae']['values'][month.pid] = {'value': indicator['ae']}
        evol_data['gi']['values'][month.pid] = {'value': indicator['gi']}
        evol_data['av']['values'][month.pid] = {'value': indicator['av']}
        evol_data['mn']['values'][month.pid] = {'value': indicator['mn']}

    file_name = 'Rapports mensuels de grossesses.xls'

    file_content = pregnancy_as_excel(indicators).getvalue()

    response = HttpResponse(file_content, \
                            content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename="%s"' % file_name
    response['Content-Length'] = len(file_content)

    return response
Exemplo n.º 7
0
def credos_dashboard(request):
    context = {'category': 'credos', 'subcategory': 'credos_dashboard'}

    periods = list(all_periods(MonthPeriod))[-15:]

    period = current_period()

    all_credos_center = UEntity.objects.filter(is_credos=True).all().count()

    # nb de decés infantile
    total_children_death = ChildrenMortalityReport.objects \
                            .filter(source=ChildrenMortalityReport.CREDOS) \
                            .count()
    last_children_death = ChildrenMortalityReport.periods \
                                                 .within(period) \
                         .filter(source=ChildrenMortalityReport.CREDOS) \
                         .count()

    # nb de naissance
    total_birth = BirthReport.objects \
                         .filter(source=BirthReport.CREDOS) \
                         .count()
    last_birth = BirthReport.periods.within(period) \
                         .filter(source=BirthReport.CREDOS) \
                         .count()

    # nb de grossesse
    total_pregnancy = PregnancyReport.objects \
                         .filter(source=PregnancyReport.CREDOS) \
                         .count()
    last_pregnancy = PregnancyReport.periods \
                                    .within(period) \
                                    .filter(source=PregnancyReport.CREDOS) \
                                    .count()

    # message
    all_inbox_qs = Inbox.objects.filter(
                              Q(textdecoded__startswith=u"fnuap born") |
                              Q(textdecoded__startswith=u"fnuap gpw") |
                              Q(textdecoded__startswith=u"fnuap du5 c"))
    all_inbox = all_inbox_qs.count()
    all_sent_qs = SentItems.objects.filter(
                              Q(textdecoded__startswith=u"fnuap born") |
                              Q(textdecoded__startswith=u"fnuap gpw") |
                              Q(textdecoded__startswith=u"fnuap du5 c"))
    all_sent = all_sent_qs.count()
    last_inbox = all_inbox_qs \
                         .filter(receivingdatetime__gte=period.start_on,
                                 receivingdatetime__lte=period.end_on) \
                         .count()
    last_sent = all_sent_qs \
                         .filter(deliverydatetime__gte=period.start_on,
                                 deliverydatetime__lte=period.end_on) \
                         .count()

    evol_data = {'children': {'label': u"Décès", 'values': {}},
                 'pregnancy': {'label': u"Grossesses", 'values': {}},
                 'birth': {'label': u"Naissances", 'values': {}}}
    for period in periods:
        nb_children = ChildrenMortalityReport.periods.within(period) \
                                    .filter(source=PregnancyReport.CREDOS) \
                                    .count()
        nb_pregnancy = PregnancyReport.periods.within(period) \
                                    .filter(source=PregnancyReport.CREDOS) \
                                    .count()
        nb_birth = BirthReport.periods.within(period) \
                                    .filter(source=PregnancyReport.CREDOS) \
                                    .count()
        evol_data['children']['values'][period.pid] = {'value': nb_children}
        evol_data['pregnancy']['values'][period.pid] = {'value': nb_pregnancy}
        evol_data['birth']['values'][period.pid] = {'value': nb_birth}

    context.update({'period': period,
                    'all_credos_center': all_credos_center,
                    'all_inbox': all_inbox,
                    'all_sent': all_sent,
                    'last_sent': last_sent,
                    'last_inbox': last_inbox,
                    'total_birth': total_birth,
                    'last_birth': last_birth,
                    'total_pregnancy': total_pregnancy,
                    'last_pregnancy': last_pregnancy,
                    'total_children_death': total_children_death,
                    'last_children_death': last_children_death,
                    'periods': periods,
                    'evol_data': evol_data.items()})

    return render(request, 'credos_dashboard.html', context)
Exemplo n.º 8
0
def unfpa_dashboard(request):
    context = {'category': 'unfpa', 'subcategory': 'unfpa_dashboard'}

    periods = list(all_periods(MonthPeriod))[-15:]

    period = current_period()

    all_unfpa_center = UEntity.objects.filter(is_unfpa=True).all().count()

    all_inbox_qs = Inbox.objects.filter(
                              Q(textdecoded__startswith=u"fnuap dpw") |
                              Q(textdecoded__startswith=u"fnuap mps") |
                              Q(textdecoded__startswith=u"fnuap du5 f"))
    all_inbox = all_inbox_qs.count()
    all_sent_qs = SentItems.objects.filter(
                              Q(textdecoded__startswith=u"fnuap dpw") |
                              Q(textdecoded__startswith=u"fnuap mps") |
                              Q(textdecoded__startswith=u"fnuap du5 f"))
    all_sent = all_sent_qs.count()
    last_inbox = all_inbox_qs \
                         .filter(receivingdatetime__gte=period.start_on,
                                 receivingdatetime__lte=period.end_on) \
                         .count()
    last_sent = all_sent_qs \
                         .filter(deliverydatetime__gte=period.start_on,
                                 deliverydatetime__lte=period.end_on) \
                         .count()

    total_children_death = ChildrenMortalityReport.objects \
                                .filter(source=ChildrenMortalityReport.UNFPA) \
                                .count()
    last_children_death = ChildrenMortalityReport.periods \
                            .within(period) \
                            .filter(source=ChildrenMortalityReport.UNFPA) \
                            .count()
    total_maternal_death = MaternalMortalityReport.objects \
                            .filter(source=MaternalMortalityReport.UNFPA) \
                            .count()
    last_maternal_death = MaternalMortalityReport.periods.within(period) \
                            .filter(source=MaternalMortalityReport.UNFPA) \
                            .count()

    total_3methods_out = sum([1
                        for report
                        in RHCommoditiesReport.validated.all()
                        if report.fp_stockout_3methods()])

    last_3methods_out = sum([1
                        for report
                        in RHCommoditiesReport.validated.filter(period=period)
                        if report.fp_stockout_3methods()])

    context.update({'period': period,
                    'all_unfpa_center': all_unfpa_center,
                    'all_inbox': all_inbox,
                    'all_sent': all_sent,
                    'last_inbox': last_inbox,
                    'last_sent': last_sent,
                    'total_children_death': total_children_death,
                    'last_children_death': last_children_death,
                    'total_maternal_death': total_maternal_death,
                    'last_maternal_death': last_maternal_death,
                    'total_3methods_out': total_3methods_out,
                    'last_3methods_out': last_3methods_out})

    evol_data = {'children': {'label': u"Mortalité infantile", 'values': {}},
                 'maternal': {'label': u"Mortalité maternelle", 'values': {}}}

    for period in periods:
        nb_children = ChildrenMortalityReport.periods.within(period) \
                            .filter(source=ChildrenMortalityReport.UNFPA) \
                            .count()
        nb_maternal = MaternalMortalityReport.periods.within(period) \
                            .filter(source=MaternalMortalityReport.UNFPA) \
                            .count()
        evol_data['children']['values'][period.pid] = {'value': nb_children}
        evol_data['maternal']['values'][period.pid] = {'value': nb_maternal}

    context.update({'periods': periods,
                    'evol_data': evol_data.items()})

    return render(request, 'unfpa_dashboard.html', context)