Exemple #1
0
def single_chw_summary(request):
    """Report for a single CHW""" 
    chw_id = request.GET.get("chw", None)
    chws = CommunityHealthWorker.view("chw/by_clinic", include_docs=True)
    main_chw = CommunityHealthWorker.get(chw_id) if chw_id else None
    
    punchcard_url = ""
    if main_chw:
        punchcard_url = get_punchcard_url(get_data(main_chw.current_clinic_id, chw_id), width=910)
        # patch on extra data for display
        main_chw.last_submission = get_last_submission_date(main_chw.get_id)    
        main_chw.first_submission = get_first_submission_date(main_chw.get_id)    
        main_chw.forms_submitted = get_forms_submitted(main_chw.get_id)    
        forms_breakdown = get_submission_breakdown(main_chw.get_id)
        main_chw.hh_surveys = forms_breakdown[config.CHW_HOUSEHOLD_SURVEY_NAMESPACE]
        main_chw.fus = forms_breakdown[config.CHW_FOLLOWUP_NAMESPACE]
        main_chw.refs = forms_breakdown[config.CHW_REFERRAL_NAMESPACE]
        main_chw.monthly_surveys = forms_breakdown[config.CHW_MONTHLY_SURVEY_NAMESPACE]
        
        # recent monthly surveys
        main_chw.recent_surveys = get_recent_forms(main_chw.get_id, config.CHW_MONTHLY_SURVEY_NAMESPACE)
        
        if not request.datespan.is_valid():
            messages.error(request, request.datespan.get_validation_reason())
            messages.warning(request, "Performance Indicators are not displayed. Please fix the other errors")
            report = {"name": "Partial CHW Summary for %s" % main_chw.formatted_name}
        else:
            report = get_chw_pi_report(main_chw, request.datespan.startdate, request.datespan.enddate)
    else:        
        report = {"name": "CHW Summary"}
    fake_hh_data = []
    now = datetime.now()
    for i in range(3):
        year, month = add_months(now.year, now.month, -i)
        fake_hh_data.append(["%s %s" % (year, month), 100, 200, "25%", "13%"])
        
    return render_to_response(request, "reports/chw_summary.html", 
                              {"report": report,
                               "chw_id": chw_id,
                               "main_chw":    main_chw,
                               "chws":   chws,
                               "punchcard_url":    punchcard_url,
                               "show_dates": False,
                               "hh_data": fake_hh_data, # TODO
                               "fu_data": fake_hh_data, # TODO
                               "ref_data": fake_hh_data # TODO
                               })
Exemple #2
0
def punchcard(request):
    # todo    
    clinic_id = request.GET.get("clinic", None)
    user_id = request.GET.get("user", None)
    url = None
    user_data = {}
    name = "Punchcard Report"
    if clinic_id:
        url = get_punchcard_url(get_data(clinic_id, user_id))
        user_data = get_users(clinic_id)
        if user_id:
            selected_user = [user for user, _ in user_data if user["_id"] == user_id][0]
            name = "Punchcard Report for %s at %s" % (render_user_inline(selected_user), clinic_display_name(clinic_id)) 
        else:
            name = "Punchcard Report for %s (%s)" % (clinic_display_name(clinic_id), clinic_id)  
    clinic_data = get_clinics()
    return render_to_response(request, "reports/punchcard.html", 
                              {"report": {"name": name},
                               "chart_url": url, 
                               "clinic_data": clinic_data,
                               "user_data": user_data,
                               "clinic_id": clinic_id,
                               "user_id": user_id})