Beispiel #1
0
    def testNVP(self):

        # Not testing positive
        p = random_person()
        p.save()
        post_and_process_xform("preg_no_hiv_test_1.xml", p)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p.get_id, include_docs=True).one()
        self.assertEqual(False, pregnancy.got_nvp_when_tested_positive)
        
        # Test positive subsequent visit
        post_and_process_xform("preg_hiv_pos_2.xml", p)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p.get_id, include_docs=True).one()
        self.assertEqual(True, pregnancy.got_nvp_when_tested_positive)
        
        p2 = random_person()
        p2.save()
        # Testing positive but already on Haart
        post_and_process_xform("preg_hiv_pos_1.xml", p2)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p2.get_id, include_docs=True).one()
        self.assertEqual(False, pregnancy.got_nvp_when_tested_positive)
Beispiel #2
0
def update_pregnancy_report_data(sender, patient_id, **kwargs):
    """
    Update pregnancies of a patient.
    """
    from bhoma.apps.reports.calc.pregnancy import PregnancyReportData
    from bhoma.apps.reports.models import PregnancyReportRecord
    from bhoma.apps.patient.models import CPatient
    
    patient = CPatient.get(patient_id)
    # manually remove old pregnancies, since all pregnancy data is dynamically generated
    for old_preg in PregnancyReportRecord.view("reports/pregnancies_for_patient", key=patient_id, include_docs=True).all():
        old_preg.delete() 
    for preg in patient.pregnancies:
        preg_report_data = PregnancyReportData(patient, preg)
        couch_pregnancy = preg_report_data.to_couch_object()
        couch_pregnancy.save()
Beispiel #3
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})
Beispiel #4
0
 def _latest_pregnancy():
     return PregnancyReportRecord.view("reports/pregnancies_for_patient", 
                                        key=updated_patient.get_id, 
                                        include_docs=True).one()