Exemplo n.º 1
0
def report_chooser(request, report_type, period_type,
                   period_str=None, export=False):

    if not report_type in ('children', 'maternal', 'commodities'):
        raise Http404(u"Invalid report type")

    if (not period_type in ('monthly', 'annual', 'quarterly', 'weekly')
        or (report_type == 'commodities' and period_type == 'weekly')):
        raise Http404(u"Invalid period type")

    # web views and export views are named the same.
    # difference is the _export suffix.
    func_suffix = '_export' if export else ''

    try:
        view = import_path('unfpa_web.views.%(report_type)s.'
                           '%(period_type)s_%(report_type)s%(suffix)s'
                           % {'report_type': report_type,
                              'period_type': period_type,
                              'suffix': func_suffix})
    except:
        raise Http404(u"Incorrect URL.")

    try:
        if '-' in period_str:
            indice, year = period_str.split('-')
            indice = int(indice)
            year = int(year)
        else:
            indice = None
            year = int(period_str)
    except:
        raise Http404(u"Incorrect period.")

    if period_type == 'weekly':
        period = WeekPeriod.find_create_by_weeknum(year, indice)
    elif period_type == 'monthly':
        period = MonthPeriod.find_create_from(year, month=indice)
    elif period_type == 'quarterly':
        period = QuarterPeriod.find_create_by_quarter(year, indice)
    elif period_type == 'annual':
        period = YearPeriod.find_create_from(year)
    else:
        # default period is current Month
        period = MonthPeriod.find_create_by_date(date.today())

    return view(request, period)
Exemplo n.º 2
0
def unfpa_epidemiology(message, args, sub_cmd, **kwargs):
    """  Incomming:
            fnuap profile year number_week code_reporting_location

        example:
           'fnuap epid e 2012 1 v01619 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11'

        Outgoing:
            [SUCCES] Le rapport de name a ete enregistre.
            or [ERREUR] message """

    # def comparecasedeath(case, death):
    #     if case < death:
    #         message.respond(u"le cas de decès (%s) ne peut pas etre supeieur"
    #                         u" au cas d'epidemie (%s)" %
    #                         (death, case))
    #         return True
    #     return False

    try:
        profile, reporting_year, reporting_week, reporting_location, \
        acute_flaccid_paralysis_case, acute_flaccid_paralysis_death, \
        influenza_a_h1n1_case, influenza_a_h1n1_death, cholera_case, \
        cholera_death, red_diarrhea_case, red_diarrhea_death, measles_case, \
        measles_death, yellow_fever_case, yellow_fever_death, \
        neonatal_tetanus_case, neonatal_tetanus_death, meningitis_case, \
        meningitis_death, rabies_case, rabies_death, \
        acute_measles_diarrhea_case, acute_measles_diarrhea_death, \
        other_notifiable_disease_case, \
        other_notifiable_disease_death = args.split()
    except:
        return resp_error(message, u"l'enregistrement de la naissance.")

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

    try:
        period = WeekPeriod.find_create_by_weeknum(int(reporting_year),
                                    int(reporting_week))
    except:
        message.respond(u"La periode (%s %s) n'est pas valide" %
                        (reporting_week, reporting_year))
        return True

    # liste = args.split()[4:]

    # comp = 0
    # for u in range(0, len(liste) / 2):
    #     print liste[comp], "?",  liste[comp + 1]
    #     if liste[comp] < liste[comp + 1]:
    #         print liste[comp], "<",  liste[comp + 1]
    #     else:
    #         print "cool"
    #     comp += 2

    # print acute_flaccid_paralysis_case, acute_flaccid_paralysis_death

    # comparecasedeath(acute_flaccid_paralysis_case,
    #                  acute_flaccid_paralysis_death)
    # comparecasedeath(influenza_a_h1n1_case, influenza_a_h1n1_death)
    # comparecasedeath(cholera_case, cholera_death)
    # comparecasedeath(red_diarrhea_case, red_diarrhea_death)
    # comparecasedeath(measles_case, measles_death)
    # comparecasedeath(yellow_fever_case, yellow_fever_death)
    # comparecasedeath(neonatal_tetanus_case, neonatal_tetanus_death)
    # comparecasedeath(meningitis_case, meningitis_death)
    # comparecasedeath(rabies_case, rabies_death)
    # comparecasedeath(acute_measles_diarrhea_case, acute_measles_diarrhea_death)
    # comparecasedeath(other_notifiable_disease_case,
    #                  other_notifiable_disease_death)

    try:
        EpidemiologyReport.objects.get(entity=entity, period=period)
        message.respond(u"Il existe un rapport pour cette periode (%s %s) " %
                        (reporting_week, reporting_year))
        return True
    except:
        pass

    report = EpidemiologyReport()
    report.type = 0
    report.period = period

    report.entity = entity
    report.acute_flaccid_paralysis_case = acute_flaccid_paralysis_case
    report.acute_flaccid_paralysis_death = acute_flaccid_paralysis_death
    report.influenza_a_h1n1_case = influenza_a_h1n1_case
    report.influenza_a_h1n1_death = influenza_a_h1n1_death
    report.cholera_case = cholera_case
    report.cholera_death = cholera_death
    report.red_diarrhea_case = red_diarrhea_case
    report.red_diarrhea_death = red_diarrhea_death
    report.measles_case = measles_case
    report.measles_death = measles_death
    report.yellow_fever_case = yellow_fever_case
    report.yellow_fever_death = yellow_fever_death
    report.neonatal_tetanus_case = neonatal_tetanus_case
    report.neonatal_tetanus_death = neonatal_tetanus_death
    report.meningitis_case = meningitis_case
    report.meningitis_death = meningitis_death
    report.rabies_case = rabies_case
    report.rabies_death = rabies_death
    report.acute_measles_diarrhea_case = acute_measles_diarrhea_case
    report.acute_measles_diarrhea_death = acute_measles_diarrhea_death
    report.other_notifiable_disease_case = other_notifiable_disease_case
    report.other_notifiable_disease_death = other_notifiable_disease_death

    contact = contact_for(message.identity)

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

    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