def _get_rowval(cls, report_slug, row): # convert the row to a report display value col_slug = row["key"][3] return NumericalDisplayValue( row["value"], col_slug, const.is_hidden(report_slug, col_slug), const.get_display_name(report_slug, col_slug), const.get_description(report_slug, col_slug), )
def pi_details(request): year = int(request.GET["year"]) month = int(request.GET["month"]) clinic = request.GET["clinic"] report_slug = request.GET["report"] col_slug = request.GET["col"] results = get_db().view(const.get_view_name(report_slug), reduce=False, key=[year, month -1, clinic, col_slug], include_docs=True) forms = [] for row in results: num, denom = row["value"] # only count forms for now, and make sure they have a patient id # and contributed to the report denominator if row["doc"]["doc_type"] == "CXFormInstance" and denom > 0: form = CXFormInstance.wrap(row["doc"]) try: form.patient_id = form.xpath("case/patient_id") form.bhoma_patient_id = CPatient.get(form.patient_id).formatted_id except ResourceNotFound: form.patient = form.patient_id = form.bhoma_patient_id = None form.num = num form.denom = denom form.good = num == denom forms.append(form) elif row["doc"]["doc_type"] == "PregnancyReportRecord" and denom > 0: # for the pregnancy PI force the aggregated pregnancy docs # to look like forms preg = PregnancyReportRecord.wrap(row["doc"]) try: preg.bhoma_patient_id = CPatient.get(preg.patient_id).formatted_id except ResourceNotFound: form.patient = form.patient_id = form.bhoma_patient_id = None preg.num = num preg.denom = denom preg.good = num == denom preg.encounter_date = preg.first_visit_date forms.append(preg) title = "PI Details - %s: %s (%s, %s)" % (const.get_name(report_slug), const.get_display_name(report_slug, col_slug), datetime(year, month, 1).strftime("%B %Y"), clinic_display_name(clinic)) return render_to_response(request, "reports/pi_details.html", {"report": {"name": title}, "forms": forms})
def disease_details(request): year = int(request.GET["year"]) month = int(request.GET["month"]) clinic = request.GET["clinic"] report_slug = request.GET["report"] col_slug = request.GET["col"] results = get_db().view(const.get_view_name(report_slug), reduce=True, startkey=[year, month -1, clinic, col_slug], endkey=[year, month -1, clinic, col_slug, {}], group=True, group_level=5) results_dict = dict([(row["key"][4], row["value"]) for row in results]) title = "Clinic: %s, Category: %s, %s" % \ (clinic_display_name(clinic), const.get_display_name(report_slug, col_slug), datetime(year, month, 1).strftime("%B, %Y")) return render_to_response(request, "reports/disease_details.html", {"report": {"name": title}, "values": results_dict})