Esempio n. 1
0
    def measles_mini_summary(cls):
        ps = []
        fields = []
        tcounter = 0
        teligible_cases = 0
        tvaccinated_cases = 0
        tclinic_cases = 0
        clinics = Facility.objects.all()
        for clinic in clinics:
            providers = Provider.list_by_clinic(clinic)
            p = {}
            eligible_cases = 0
            vaccinated_cases = 0
            clinic_cases = 0
            counter = 0
            p["clinic"] = clinic
            p["num_cases"] = 0
            p["eligible_cases"] = 0
            p["vaccinated_cases"] = 0
            for provider in providers:
                counter = counter + 1
                # p['counter'] = "%d"%counter
                cases = Case.list_e_4_measles(provider)
                eligible_cases += cases.count()
                clinic_cases = clinic_cases + Case.count_by_provider(provider)
                mcases = ReportMeasles.get_vaccinated(provider)
                # slow count
                slowcount = 0
                for case in cases:
                    if ReportMeasles.is_vaccinated(case):
                        slowcount += 1
                # vaccinated_cases += mcases.count()
                vaccinated_cases += slowcount

            # Summary
            p = {}
            p["clinic"] = clinic
            p["counter"] = ""
            p["num_cases"] = clinic_cases
            p["eligible_cases"] = eligible_cases
            p["vaccinated_cases"] = vaccinated_cases
            ps.append(p)

            tcounter += counter
            teligible_cases += eligible_cases
            tvaccinated_cases += vaccinated_cases
            tclinic_cases += clinic_cases
            # caseid +|Y lastname firstname | sex | dob/age | guardian | provider  | date
        p = {}
        p["clinic"] = "Total:"
        p["counter"] = ""
        p["num_cases"] = tclinic_cases
        p["eligible_cases"] = teligible_cases
        p["vaccinated_cases"] = tvaccinated_cases
        ps.append(p)
        return ps
Esempio n. 2
0
    def measles_summary(cls, duration_start, duration_end, muac_duration_start, clinic_id=None):
        ps = []
        fields = []
        counter = 0
        eligible_cases = 0
        vaccinated_cases = 0
        clinic_cases = 0
        if clinic_id is not None:
            providers = Provider.list_by_clinic(clinic_id)
            for provider in providers:
                p = {}
                counter = counter + 1
                p["counter"] = "%d" % counter
                p["provider"] = provider
                p["num_cases"] = Case.count_by_provider(provider)
                cases = Case.list_e_4_measles(provider)
                p["eligible_cases"] = cases.count()
                eligible_cases += p["eligible_cases"]
                clinic_cases = clinic_cases + p["num_cases"]
                # slow count
                slowcount = 0
                for case in cases:
                    if ReportMeasles.is_vaccinated(case):
                        slowcount += 1
                mcases = ReportMeasles.get_vaccinated(provider)
                # p['vaccinated_cases'] = mcases.count()
                p["vaccinated_cases"] = slowcount
                p["not_vaccinated_cases"] = p["eligible_cases"] - p["vaccinated_cases"]
                vaccinated_cases += p["vaccinated_cases"]
                p["sms_sent"] = int(round(float(float(p["vaccinated_cases"]) / float(p["eligible_cases"])) * 100, 0))

                ps.append(p)

            # ps = sorted(ps)
            # Summary
            p = {}
            p["counter"] = ""
            p["provider"] = "Summary"
            p["num_cases"] = clinic_cases
            p["eligible_cases"] = eligible_cases
            p["vaccinated_cases"] = vaccinated_cases
            p["not_vaccinated_cases"] = eligible_cases - vaccinated_cases
            sms_sent = int(round(float(float(vaccinated_cases) / float(eligible_cases)) * 100, 0))
            p["sms_sent"] = sms_sent
            ps.append(p)
            # caseid +|Y lastname firstname | sex | dob/age | guardian | provider  | date
            fields.append({"name": "#", "column": None, "bit": "{{ object.counter }}"})
            fields.append({"name": "PROVIDER", "column": None, "bit": "{{ object.provider }}"})
            fields.append({"name": "TOTAL CASES", "column": None, "bit": "{{ object.num_cases}}"})
            fields.append({"name": "# ELIGIBLE CASES", "column": None, "bit": "{{ object.eligible_cases}}"})
            fields.append({"name": "# VACCINATED", "column": None, "bit": "{{ object.vaccinated_cases }}"})
            fields.append({"name": "# NOT VACCINATED", "column": None, "bit": "{{ object.not_vaccinated_cases }}"})
            fields.append({"name": "%", "column": None, "bit": "{{ object.sms_sent }}%"})
            return ps, fields
Esempio n. 3
0
 def get_providers_by_clinic(cls, duration_start, duration_end, muac_duration_start, clinic_id=None):
     
 
     ps      = []
     fields  = []
     counter = 0
     clinic_cases = 0
     clinic_mrdt = 0
     clinic_muac = 0
     clinic_sent = 0
     clinic_processed = 0
     clinic_refused = 0
     
     if clinic_id is not None:
         providers = Provider.list_by_clinic(clinic_id)
         for provider in providers:
             p = {}
             counter = counter + 1
             p['counter'] = "%d"%counter
             p['provider'] = provider
             p['num_cases'] = Case.count_by_provider(provider)
             p_muac = ReportMalaria.count_by_provider(provider, duration_end, duration_start)
             p['num_malaria_reports'] = p_muac
             clinic_mrdt = clinic_mrdt + p_muac 
             num_cases = Case.count_by_provider(provider)
             clinic_cases = clinic_cases + num_cases
             num_muac = ReportMalnutrition.count_by_provider(provider, duration_end, muac_duration_start)
             clinic_muac = clinic_muac + num_muac
             if num_cases == 0:
                 muac_percentage = 0
             else:
                 muac_percentage  = round(float(float(num_muac)/float(num_cases))*100, 0)
             p['num_muac_reports'] = "%d %% (%s/%s)"%(muac_percentage, num_muac, num_cases)
             sms_sent = MessageLog.count_by_provider(provider, duration_end, duration_start)
             clinic_sent = clinic_sent + sms_sent
             p['sms_sent'] = sms_sent
             sms_processed = MessageLog.count_processed_by_provider(provider, duration_end, duration_start)
             clinic_processed = clinic_processed + sms_processed
             p['sms_processed'] = sms_processed
             sms_refused = MessageLog.count_refused_by_provider(provider, duration_end, duration_start)
             clinic_refused = clinic_refused + sms_refused
             p['sms_refused'] = sms_refused
             if p['sms_sent'] != 0:
                 p['sms_rate'] = int(float(float(p['sms_processed'])/float(p['sms_sent'])*100))
             else:
                 p['sms_rate'] = 0
             #p['sms_rate'] = "%s%%"%p['sms_rate']
             last_activity = MessageLog.days_since_last_activity(provider)
             if last_activity == "":
                 p['days_since_last_activity'] = "No Activity"
             else:
                 p['days_since_last_activity'] = "%s days ago"%last_activity
                                 
             ps.append(p)
         
         #ps = sorted(ps)
         # Summary    
         p = {}
         p['counter'] = ""
         p['provider'] = "Summary"
         p['num_cases'] = clinic_cases
         p['num_malaria_reports'] = clinic_mrdt
         num_cases = clinic_cases
         num_muac = clinic_muac
         if num_cases == 0:
             muac_percentage = 0
         else:
             muac_percentage  = round(float(float(num_muac)/float(num_cases))*100, 0)
         p['num_muac_reports'] = "%d %% (%s/%s)"%(muac_percentage, num_muac, num_cases)
         p['sms_sent'] = clinic_sent
         p['sms_processed'] = clinic_processed
         p['sms_refused'] = clinic_refused
         if p['sms_sent'] != 0:
             p['sms_rate'] = int(float(float(p['sms_processed'])/float(p['sms_sent'])*100))
         else:
             p['sms_rate'] = 0
         #p['sms_rate'] = "%s%%"%p['sms_rate']
         p['days_since_last_activity'] = "" 
                             
         ps.append(p)
                 # caseid +|Y lastname firstname | sex | dob/age | guardian | provider  | date
         fields.append({"name": '#', "column": None, "bit": "{{ object.counter }}" })
         fields.append({"name": 'PROVIDER', "column": None, "bit": "{{ object.provider }}" })
         fields.append({"name": 'NUMBER OF CASES', "column": None, "bit": "{{ object.num_cases}}" })
         fields.append({"name": 'MRDT', "column": None, "bit": "{{ object.num_malaria_reports }}" })
         fields.append({"name": 'MUAC', "column": None, "bit": "{{ object.num_muac_reports }}" })
         fields.append({"name": 'RATE', "column": None, "bit": "{{ object.sms_rate }}% ({{ object.sms_processed }}/{{ object.sms_sent }})" })
         fields.append({"name": 'LAST ACTVITY', "column": None, "bit": "{{ object.days_since_last_activity }}" })
         return ps, fields        
Esempio n. 4
0
    def measles_by_provider(cls, provider_id=None):
        qs = []
        fields = []
        counter = 0
        if provider_id is not None:
            provider = Provider.objects.get(id=provider_id)
            cases = Case.list_e_4_measles(provider)

            for case in cases:
                q = {}
                q["case"] = case
                counter = counter + 1
                q["counter"] = "%d" % counter
                try:
                    muacc = ReportMalnutrition.objects.filter(case=case).latest()
                    # q['malnut'] = u"%(diag)s on %(date)s" % {'diag': muacc.diagnosis_msg(), 'date': muacc.entered_at.strftime("%Y-%m-%d")}
                    q["malnut_muac"] = "%s (%smm)" % (muacc.get_status_display(), muacc.muac)
                    q["malnut_symptoms"] = muacc.symptoms()
                    q["malnut_days_since_last_update"] = muacc.days_since_last_activity()
                except ObjectDoesNotExist:
                    q["malnut_muac"] = ""
                    q["malnut_symptoms"] = ""
                    q["malnut_days_since_last_update"] = ""
                try:
                    orsc = ReportDiarrhea.objects.filter(case=case).latest()
                    q["diarrhea"] = u"%(diag)s on %(date)s" % {
                        "diag": orsc.diagnosis_msg(),
                        "date": orsc.entered_at.strftime("%Y-%m-%d"),
                    }
                except ObjectDoesNotExist:
                    q["diarrhea"] = None

                try:
                    twoweeksago = date.today() - timedelta(14)
                    mrdtc = ReportMalaria.objects.filter(case=case, entered_at__gte=twoweeksago).latest()
                    mrdtcd = mrdtc.get_dictionary()
                    # q['malaria'] = u"result:%(res)s bednet:%(bed)s obs:%(obs)s on %(date)s" % {'res': mrdtcd['result_text'], 'bed': mrdtcd['bednet_text'], 'obs': mrdtcd['observed'], 'date': mrdtc.entered_at.strftime("%Y-%m-%d")}
                    q["malaria_result"] = mrdtc.results_for_malaria_result()
                    q["malaria_bednet"] = mrdtc.results_for_malaria_bednet()
                except ObjectDoesNotExist:
                    q["malaria_result"] = ""
                    q["malaria_bednet"] = ""

                num_of_malaria_cases = ReportMalaria.num_reports_by_case(case)
                if num_of_malaria_cases is not None and num_of_malaria_cases > 1:
                    q["malaria_result"] = q["malaria_result"] + "(%sX)" % num_of_malaria_cases
                    last_mrdt = ReportMalaria.days_since_last_mrdt(case)
                    if last_mrdt is not "" and last_mrdt < 15:
                        q["malaria_result"] = q["malaria_result"] + " %s days ago" % last_mrdt

                try:
                    dc = ReportDiagnosis.objects.filter(case=case).latest("entered_at")
                    dcd = dc.get_dictionary()
                    q["diagnosis"] = u"diag:%(diag)s labs:%(lab)s on %(date)s" % {
                        "diag": dcd["diagnosis"],
                        "lab": dcd["labs_text"],
                        "date": dc.entered_at.strftime("%Y-%m-%d"),
                    }
                except ObjectDoesNotExist:
                    q["diagnosis"] = None

                q["vaccinated"] = ReportMeasles.is_vaccinated(case)
                if q["vaccinated"]:
                    q["sent"] = u"Yes"
                    q["vaccinated"] = u"Yes"
                else:
                    q["vaccinated"] = u"No"
                    q["sent"] = u"No"
                    qs.append(q)

            # caseid +|Y lastname firstname | sex | dob/age | guardian | provider  | date
            fields.append({"name": "#", "column": None, "bit": "{{ object.case.zone }}"})
            fields.append({"name": "PID#", "column": None, "bit": "{{ object.case.ref_id }}"})
            fields.append(
                {"name": "NAME", "column": None, "bit": "{{ object.case.last_name }} {{ object.case.first_name }}"}
            )
            fields.append({"name": "SEX", "column": None, "bit": "{{ object.case.gender }}"})
            fields.append({"name": "AGE", "column": None, "bit": "{{ object.case.age }}"})
            fields.append({"name": "VACCINATED?", "column": None, "bit": "{{ object.vaccinated }}"})
            fields.append({"name": "SENT?", "column": None, "bit": "{{ object.sent }}"})

            return qs, fields
Esempio n. 5
0
 def report_birth(self, message, last, first, gender, dob, weight,where, guardian, complications=""):
     if len(dob) != 6:
         # There have been cases where a date like 30903 have been sent and
         # when saved it gives some date that is way off
         raise HandlerFailed(_("Date must be in the format ddmmyy: %s") % dob)
     else:
         dob = re.sub(r'\D', '', dob)
         try:
             dob = time.strptime(dob, "%d%m%y")
         except ValueError:
             try:
                 dob = time.strptime(dob, "%d%m%Y")
             except ValueError:
                 raise HandlerFailed(_("Couldn't understand date: %s") % dob)
         dob = datetime.date(*dob[:3])        
     reporter = message.persistant_connection.reporter
     location = None
     if not location:
         if reporter.location:
             location = reporter.location
     
     info = {
         "first_name" : first.title(),
         "last_name"  : last.title(),
         "gender"     : gender.upper(),
         "dob"        : dob,
         "guardian"   : guardian.title(),
         "mobile"     : "",
         "reporter"   : reporter,
         "location"       : location
     }
     
     abirth = ReportBirth(where=where.upper())
     #Perform Location checks
     if abirth.get_where() is None:
         raise HandlerFailed(_("Location `%s` is not known. Please try again with a known location") % where)
     
     iscase = Case.objects.filter(first_name=info['first_name'], last_name=info['last_name'], reporter=info['reporter'], dob=info['dob'])
     if iscase:
         info["PID"] = iscase[0].ref_id
         self.info(iscase[0].id)
         self.info(info)
         #message.respond(_(
         #"%(last_name)s, %(first_name)s (+%(PID)s) has already been registered by %(provider)s.") % info)
         # TODO: log this message
         case = iscase[0]
     else:
         case = Case(**info)
         case.save()
         log(case, "patient_created")
     
     info.update({
         "id": case.ref_id,
         "last_name": last.upper(),
         "age": case.age(),
         "dob": dob.strftime("%d/%m/%y")
     })
     
     info2 = {
         "case":case,
         "weight": weight,
         "where": where,
         "reporter": reporter,
         "complications": complications
     }
     
     #check if birth has already been reported
     rbirth = ReportBirth.objects.filter(case=case)
     
     if rbirth:
         raise HandlerFailed(_(
         "The birth of %(last_name)s, %(first_name)s (+%(PID)s) has already been reported by %(reporter)s.") % info)
         
     
     abirth = ReportBirth(**info2)
     abirth.save()
     
     info.update({"where":abirth.get_where()})
     
     message.respond(_(
         "Birth +%(id)s: %(last_name)s, %(first_name)s %(gender)s/%(dob)s " +
         "(%(guardian)s) %(location)s at %(where)s") % info)
     
     
     return True