Esempio n. 1
0
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})
Esempio n. 2
0
    def from_view_results(cls, report_slug, results):
        """
        Build a report display row from a couchdb view results object
        """

        # iterate through results, bucketing into groups
        all_data = {}
        for row in results:
            rowkey = cls._get_rowkey(row)
            if rowkey in all_data:
                all_data[rowkey].append(cls._get_rowval(report_slug, row))
            else:
                all_data[rowkey] = [cls._get_rowval(report_slug, row)]

        report_name = const.get_name(report_slug)
        all_rows = []
        for rowkey, vals in all_data.items():
            all_rows.append(cls.row_class(report_slug, report_name, cls._get_displaykeys(rowkey), vals))

        return cls(report_slug, all_rows)
Esempio n. 3
0
 def __init__(self, slug, rows):
     self.name = const.get_name(slug)
     self.rows = rows
     self.slug = slug