コード例 #1
0
ファイル: views.py プロジェクト: dimagi/bhoma
def disease_aggregates(request):
    """
    Disease Aggregates Report
    """
    if not request.datespan.is_valid():
        messages.error(request, request.datespan.get_validation_reason())
        return render_to_response(request, "reports/pi_report.html",
                              {"show_dates": True, "report": None})
                               
                                   
    clinic_id = request.GET.get("clinic", None)
    slug = "disease_aggregate"
    results = _pi_results(slug, request.datespan.startdate, request.datespan.enddate,
                          clinic_id)
    
    main_clinic = Location.objects.get(slug=clinic_id) if clinic_id else None
    report = AggregateReport.from_view_results(slug, results)
    
    return render_to_response(request, "reports/pi_report.html",
                              {"show_dates": False, 
                               "hide_districts": True, 
                               "main_clinic": main_clinic,
                               "clinics": clinics_for_view(),
                               "districts": districts_for_view(),
                               "view_slug": slug,
                               "report": report})
コード例 #2
0
ファイル: views.py プロジェクト: dimagi/bhoma
def mortality_register(request):
    if not request.datespan.is_valid():
        messages.error(request, request.datespan.get_validation_reason())
        return render_to_response(request, "reports/mortality_register.html", 
                                  {"show_dates": True, "report": None})
    
    clinic_id = request.GET.get("clinic", None)
    main_clinic = Location.objects.get(slug=clinic_id) if clinic_id else None
    cause_of_death_report = MortalityReport()
    place_of_death_report = MortalityReport()
    global_map = defaultdict(lambda: 0)
    global_display = CauseOfDeathDisplay("Total", AGGREGATE_OPTIONS)
    hhs = 0
    if main_clinic:
        startkey = [clinic_id, request.datespan.startdate.year, request.datespan.startdate.month - 1]
        endkey = [clinic_id, request.datespan.enddate.year, request.datespan.enddate.month - 1, {}]
        results = get_db().view("centralreports/nhc_mortality_report", group=True, group_level=7,
                                startkey=startkey, endkey=endkey).all()
        for row in results:
            # key: ["5010", 2010,8,"adult","f","cause","heart_problem"]
            clinic_id_back, year, jsmonth, agegroup, gender, type, val = row["key"]
            count = row["value"]
            group = MortalityGroup(main_clinic, agegroup, gender)
            if type == "global":
                global_map[val] = count
            if type == "cause":
                cause_of_death_report.add_data(group, val, count)
            elif type == "place":
                place_of_death_report.add_data(group, val, count)
        if "num_households" in global_map:
            hhs = global_map.pop("num_households")
        global_display.add_data(global_map)
    
    return render_to_response(request, "reports/mortality_register.html", 
                              {"show_dates": True, "cause_report": cause_of_death_report,
                               "place_report": place_of_death_report,
                               "districts": districts_for_view(), 
                               "clinics": clinics_for_view(), 
                               "global_display": global_display,
                               "hhs": hhs,
                               "main_clinic": main_clinic,
                               })
コード例 #3
0
ファイル: views.py プロジェクト: dimagi/bhoma
def _pi_report(request, view_slug):
    """
    Generic report engine for the performance indicator reports
    """
    if not request.datespan.is_valid():
        messages.error(request, request.datespan.get_validation_reason())
        return render_to_response(request, "reports/pi_report.html",
                              {"show_dates": True, "report": None})
                               
                                   
    clinic_id = request.GET.get("clinic", None)
    results = _pi_results(view_slug, request.datespan.startdate, request.datespan.enddate,
                          clinic_id) 
    report = PIReport.from_view_results(view_slug, results)
    
    main_clinic = Location.objects.get(slug=clinic_id) if clinic_id else None
    return render_to_response(request, "reports/pi_report.html",
                              {"show_dates": False, 
                               "hide_districts": True, 
                               "main_clinic": main_clinic,
                               "clinics": clinics_for_view(),
                               "districts": districts_for_view(),
                               "view_slug": view_slug,
                               "report": report})