예제 #1
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)
예제 #2
0
def unfpa_monthly_product_stockouts(message, args, sub_cmd, **kwargs):
    """  Incomming:
            fnuap mps family_planning delivery_services male_condom
            female_condom oral_pills injectable iud implants
            female_sterilization male_sterilization
            amoxicillin_ij amoxicillin_cap_gel
            amoxicillin_suspension azithromycine_tab
            azithromycine_suspension benzathine_penicillin cefexime
            clotrimazole ergometrine_tab ergometrine_vials iron
            folate iron_folate magnesium_sulfate metronidazole
            oxytocine ceftriaxone_500 ceftriaxone_1000 comment
        example:
           'fnuap mps 2012 05 wolo 0 0 20 - - - - - 0 0 - - - - - - - - - - - -
             - - - - - - -'
        Outgoing:
            [SUCCES] Le rapport de name a ete enregistre.
            or [ERREUR] message """

    try:
        # -1 represente le non disponible
        args = args.replace("-", "-1")
        reporting_year, reporting_month, location_of_sdp, family_planning, \
        delivery_services, male_condom, female_condom,\
        oral_pills, injectable, iud, implants, female_sterilization, \
        male_sterilization, amoxicillin_ij, amoxicillin_cap_gel, \
        amoxicillin_suspension, azithromycine_tab, azithromycine_suspension, \
        benzathine_penicillin, cefexime, clotrimazole, ergometrine_tab, \
        ergometrine_vials, iron, folate, iron_folate, magnesium_sulfate, \
        metronidazole, oxytocine, ceftriaxone_500, ceftriaxone_1000, \
        comment = args.split()
    except:
        return resp_error(message, u"le rapport")

    try:
        period = MonthPeriod.find_create_from(year=int(reporting_year),
                                              month=int(reporting_month))
    except:
        message.respond(u"La periode (%s %s) n'est pas valide" %
                        (reporting_month, reporting_year))
        return True

    if period != current_period().previous():
        message.respond(u"La periode (%s %s) n'est pas valide, "
                        u"elle doit etre %s" % (reporting_month,
                                                reporting_year,
                                                current_period().previous()))
        return True

    # Entity code
    try:
        entity = Entity.objects.get(slug=location_of_sdp)
    except Entity.DoesNotExist:
        message.respond(u"Le code %s n'existe pas" % location_of_sdp)
        return True

    def check_int(val):
        try:
            return int(val)
        except:
            return -1

    try:
        comment = comment.replace(u"_", u" ")
    except:
        comment = u""

    contact = contact_for(message.identity)

    report = RHCommoditiesReport()

    if contact:
        report.created_by = contact
    else:
        return resp_error_provider(message)

    report.type = 0
    report.period = period
    report.entity = entity
    report.family_planning = check_int(family_planning)
    report.delivery_services = check_int(delivery_services)
    report.male_condom = check_int(male_condom)
    report.female_condom = check_int(female_condom)
    report.oral_pills = check_int(oral_pills)
    report.injectable = check_int(injectable)
    report.iud = check_int(iud)
    report.implants = check_int(implants)
    report.female_sterilization = YESNOAVAIL.get(female_sterilization,
                                    RHCommoditiesReport.SUPPLIES_NOT_PROVIDED)
    report.male_sterilization = YESNOAVAIL.get(male_sterilization,
                                    RHCommoditiesReport.SUPPLIES_NOT_PROVIDED)
    report.amoxicillin_ij = check_int(amoxicillin_ij)
    report.amoxicillin_cap_gel = check_int(amoxicillin_cap_gel)
    report.amoxicillin_suspension = check_int(amoxicillin_suspension)
    report.azithromycine_tab = check_int(azithromycine_tab)
    report.azithromycine_suspension = check_int(azithromycine_suspension)
    report.benzathine_penicillin = check_int(benzathine_penicillin)
    report.cefexime = check_int(cefexime)
    report.clotrimazole = check_int(clotrimazole)
    report.ergometrine_tab = check_int(ergometrine_tab)
    report.ergometrine_vials = check_int(ergometrine_vials)
    report.iron = check_int(iron)
    report.folate = check_int(folate)
    report.iron_folate = check_int(iron_folate)
    report.magnesium_sulfate = check_int(magnesium_sulfate)
    report.metronidazole = check_int(metronidazole)
    report.oxytocine = check_int(oxytocine)

    report.ceftriaxone_500 = check_int(ceftriaxone_500)
    report.ceftriaxone_1000 = check_int(ceftriaxone_1000)
    report.comment = check_int(comment)
    report._status = report.STATUS_VALIDATED

    try:
        report.save()
        message.respond(u"[SUCCES] Le rapport de %(cscom)s pour %(period)s "
                        u"a ete enregistre. "
                        u"Le No de recu est #%(receipt)s."
                        % {'cscom': report.entity.display_full_name(),
                           'period': report.period,
                           'receipt': report.receipt})
    except IntegrityError:
        message.respond(u"[ERREUR] il ya deja un rapport pour cette periode")
    except:
        message.respond(u"[ERREUR] Le rapport n est pas enregiste")

    return True
예제 #3
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)