def measles(request, object_id=None, per_page="0", rformat="pdf"): '''List of Cases/Children Eligible for measles not yet vaccinated''' pdfrpt = PDFReport() pdfrpt.setLandscape(False) #pdfrpt.setTitle("RapidResponse MVP Kenya: Cases Reports by CHW") pdfrpt.setTitle(_("Measles Campaign")) if object_id is None: if request.POST and request.POST['zone']: reporters = Case.objects.filter(location=request.POST['zone']).\ values('reporter', 'location').distinct() per_page = "1" else: reporters = Reporter.objects.order_by("location").all() for reporter in reporters: queryset, fields = ReportAllPatients.measles_by_provider(reporter) if queryset: title = reporter.location.name + ": " + \ reporter.full_name() + \ " (sms format: `MEASLES +PID +PID +PID`)" pdfrpt.setTableData(queryset, fields, title) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/report_per_page") else: if request.POST and request.POST['provider']: object_id = request.POST['provider'] reporter = Reporter.objects.get(id=object_id) queryset, fields = ReportAllPatients.measles_by_provider(reporter) if queryset: title = reporter.full_name() + \ " (sms format: `MEASLES +PID +PID +PID`)" if rformat == "csv" or (request.POST \ and request.POST["format"].lower() == "csv"): file_name = reporter.full_name() + ".csv" file_name = file_name.replace(" ", "_").replace("'", "") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, title) return pdfrpt.render()
def commands_pdf(request): '''List of supported commands and their format''' pdfrpt = PDFReport() pdfrpt.setLandscape(True) pdfrpt.setNumOfColumns(2) pdfrpt.setFilename("shortlist") header("Malnutrition Monitoring Report") p("MUAC +PatientID MUACMeasurement Edema (E/N) Symptoms") pre("Example: MUAC +1410 105 E V D Or MUAC +1385 140 n") header("Malaria Rapid Diagnostic Test Reports (MRDT)") p("MRDT +PatientID RDTResult (Y/N) BedNet (Y/N) Symtoms") pre("Example: MRDT +28 Y N D CV") pre('''\ Code | Symptom | Danger Sign ============================================= CG | Coughing | D | Diarrhea | CMAM A | Appetite Loss | CMAM F | Fever | CMAM V | Vomiting | CMAM, RDT NR | Nonresponsive | CMAM, RDT UF | Unable to Feed | CMAM, RDT B | Breathing Difficulty | RDT CV | Convulsions/Fits | RDT CF | Confusion | RDT ============================================== ''') header("Death Report") p("DEATH LAST FIRST GENDER AGE DateOfDeath (DDMMYY) CauseOfDeath "\ "Location Description") pre("Example: DEATH RUTH BABE M 50m 041055 S H Sudden heart attack") header("Child Death Report") p("CDEATH +ID DateOfDeath(DDMMYY) Cause Location Description") pre("Example: CDEATH +782 101109 I C severe case of pneumonia") pre('''\ CauseOfDeath - Likely causes of death =========================== P | Pregnancy related B | Child Birth A | Accident I | Illness S | Sudden Death =========================== ''') pre('''\ Location - where the death occurred =================================================== H | Home C | Health Facility T | Transport - On route to Clinic/Hospital =================================================== ''') header("Birth Report") p("BIRTH Last First Gender(M/F) DOB (DDMMYY) WEIGHT Location "\ "Guardian Complications") pre("BIRTH Onyango James M 051009 4.5 C Anyango No Complications") header("Inactive Cases") p("INACTIVE +PID ReasonOfInactivity") pre(" INACTIVE +23423 immigrated to another town(Siaya)") header("Activate Inactive Cases") p("ACTIVATE +PID ReasonForActivating") pre(" ACTIVATE +23423 came back from Nairobi") pdfrpt.setElements(Elements) return pdfrpt.render()
def malnutrition_screening(request, object_id=None, per_page="0", \ rformat="pdf"): ''' Malnutrition Screening Form Originally for SN CC ''' pdfrpt = [] pdfrpt = PDFReport() #fourteen_days = timedelta(days=30) today = datetime.now() #duration_start = day_start(today - fourteen_days) #duration_end = today pdfrpt.setTitle("%(app_name)s: Formulaire de Depistage" % \ {'app_name': Cfg.get("app_name")}) #pdfrpt.setRowsPerPage(66) pdfrpt.setNumOfColumns(1) pdfrpt.setLandscape(True) pdfrpt.setFontSize(10) if object_id is None and not request.POST: sites = Location.objects.filter(type__name="Site") for site in sites: queryset, fields = \ ReportAllPatients.malnutrition_screening_info(site) subtitle = _("%(site_name)s: Registre des Enfants pour: " % \ {'site_name': site.name}) pdfrpt.setTableData(queryset, fields, subtitle, \ [0.4 * inch, 1.5 * inch, 0.4 * inch, 0.5 * inch, \ 0.5 * inch, 1.0 * inch, 0.9 * inch, 1.0 * inch, \ 0.7 * inch, 0.7 * inch, 0.7 * inch, 0.7 * inch, \ 0.8 * inch, 1.0 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/malnutrition_at_risk") else: if request.POST['zone']: site_id = request.POST['zone'] site = Location.objects.get(id=site_id) queryset, fields = \ ReportAllPatients.malnutrition_screening_info(site) subtitle = _("Registre des Enfants pour: %(site_name)s" % \ {'site_name': site.name}) # no nom sex dob age mere sms numero pb poids oedems # ddepistage consulter pdfrpt.setTableData(queryset, fields, subtitle, \ [0.4 * inch, 1.5 * inch, 0.4 * inch, 0.5 * inch, \ 0.5 * inch, 1.0 * inch, 0.9 * inch, 1.0 * inch, \ 0.7 * inch, 0.7 * inch, 0.7 * inch, 0.7 * inch, \ 0.8 * inch, 1.0 * inch]) filename = "/tmp/formulaire_de_depistage" + \ datetime.today().strftime("%Y_%m_%d_%H_%M_%S") pdfrpt.setFilename(filename) return pdfrpt.render()
def malaria(request, object_id=None, per_page="0", rformat="pdf"): ''' List Positive RDT Test Cases per clinic ''' pdfrpt = PDFReport() fourteen_days = timedelta(days=14) today = datetime.now() duration_start = day_start(today - fourteen_days) duration_end = today pdfrpt.setTitle(_("%(app_name)s: Positive RDT Cases from "\ "%(start_date)s to %(end_date)s" % \ {'start_date': duration_start.date(), \ 'end_date': duration_end.date(), 'app_name': Cfg.get("app_name")})) pdfrpt.setRowsPerPage(66) if object_id is None and not request.POST: clinics = Location.objects.filter(type__name="Clinic") for clinic in clinics: queryset, fields = \ ReportAllPatients.malaria_at_risk(duration_start, \ duration_end, clinic) c = clinic subtitle = _("%(clinic)s: Positive RDT Cases from "\ "%(start_date)s to %(end_date)s" % {'clinic': c.name, \ 'start_date': duration_start.date(), \ 'end_date': duration_end.date()}) pdfrpt.setTableData(queryset, fields, subtitle, \ [0.3 * inch, 0.4 * inch, 1 * inch, 0.4 * inch, \ .4 * inch, .4 * inch, 0.5 * inch, .8 * inch, \ .4 * inch, 1 * inch, 1 * inch, 1.4 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/malaria_cases") else: if request.POST['clinic']: object_id = request.POST['clinic'] object_id = Location.objects.get(id=object_id) queryset, fields = \ ReportAllPatients.malaria_at_risk(duration_start, \ duration_end, object_id) subtitle = _("%(clinic)s: Positive RDT Cases from "\ "%(start_date)s to %(end_date)s" % {'clinic': object_id.name, \ 'start_date': duration_start.date(), \ 'end_date': duration_end.date()}) pdfrpt.setTableData(queryset, fields, subtitle, \ [0.3 * inch, 0.4 * inch, 1 * inch, 0.4 * inch, \ .4 * inch, .4 * inch, 0.5 * inch, .8 * inch, \ .4 * inch, 1 * inch, 1 * inch, 1.4 * inch]) pdfrpt.setFilename("/tmp/malaria_cases") return pdfrpt.render()
def dead_cases_report(request, rformat="pdf"): '''List of Cases/Patient per CHW''' today = datetime.now().strftime("%d %B,%Y") pdfrpt = PDFReport() pdfrpt.setLandscape(True) title = _("%(app_name)s: Dead Cases report as of %(date)s" % \ {'app_name': Cfg.get("app_name"), 'date': today}) pdfrpt.setTitle(title) pdfrpt.setNumOfColumns(1) queryset, fields = \ ReportAllPatients.death_report_by_provider() if queryset: pdfrpt.setTableData(queryset, fields, title, \ [0.3 * inch, 0.4 * inch, 1 * inch, 0.4 * inch, \ 0.5 * inch, 0.8 * inch, 0.5 * inch, 1 * inch, \ 0.6 * inch, 1.4 * inch, 1.5 * inch, 1 * inch, \ 1.3 * inch, 1.2 * inch]) pdfrpt.setFilename("/tmp/deathreport_") return pdfrpt.render()
def patients_by_age(request, object_id=None, per_page="0", rformat="pdf"): ''' Children Screening per age for SN CC ''' pdfrpt = PDFReport() #pdfrpt.setTitle(_("ChildCount Senegal: Listing Enfant par Age")) pdfrpt.setTitle(_(Cfg.get("app_name") + \ ": Listing Enfant par Age" )) #pdfrpt.setRowsPerPage(66) pdfrpt.setNumOfColumns(1) pdfrpt.setLandscape(True) pdfrpt.setFontSize(10) if object_id is None and not request.POST: age_mois = 0 cases = Case.objects.order_by("location").distinct() queryset, fields = ReportAllPatients.by_age(age_mois, cases) subtitle = _("Registre des Enfants pour: ") #%(site.name) pdfrpt.setTableData(queryset, fields, subtitle, \ [0.2 * inch, 1.5 * inch, 0.5 * inch, 0.7 * inch, \ 0.5 * inch, 1.5 * inch,1.0 * inch, 0.5 * inch, 0.7 * inch, \ 0.5 * inch, 0.5 * inch, 0.7 * inch, 1.5 * inch, \ 1 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/Listing_Enfant") else: cases = Case.objects.order_by("location").distinct() if request.POST['age']: age_mois = int(request.POST['age']) str_age = request.POST['age'] queryset, fields = ReportAllPatients.by_age(age_mois, cases) subtitle = _("Registre des Enfants de : %(age)s mois" % \ {'age': str_age}) # no nom sex dob age mere sms numero pb poids oedems #depistage consulter pdfrpt.setTableData(queryset, fields, subtitle, \ [0.2 * inch, 1.5 * inch, 0.5 * inch, 0.7 * inch, \ 0.5 * inch, 1.5 * inch,1.0 * inch, 0.5 * inch, 0.7 * inch, \ 0.5 * inch, 0.5 * inch, 0.7 * inch, 1.5 * inch, \ 1 * inch]) filename = "/tmp/Listing_Enfant_" + \ datetime.today().strftime("%Y_%m_%d_%H_%M_%S") pdfrpt.setFilename(filename) return pdfrpt.render()
def vitamines_summary(request, object_id=None, per_page="0", \ rformat="pdf", d="30"): '''A summary of vitamines A report per Site - pdf formart''' pdfrpt = PDFReport() d = int(d) pdfrpt.enableFooter(True) thirty_days = timedelta(days=d) ninty_days = timedelta(days=90) today = date.today() duration_start = today - thirty_days muac_duration_start = today - ninty_days duration_end = today pdfrpt.setTitle(_("Vitamines Campaign Summary")) if object_id is None: clinics = Location.objects.filter(type__name="Site") for clinic in clinics: queryset, fields = ReportCHWStatus.\ vitamines_summary(duration_start, duration_end, \ muac_duration_start, clinic) pdfrpt.setTableData(queryset, fields, clinic,\ [1.0* inch, 1.0 * inch, 1.0 * inch, 1.0 * inch, \ 1.0 * inch, 1.5 * inch, 1.0 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/vitamines_per_page") else: if request.POST['site']: object_id = request.POST['site'] clinic = Location.objects.get(id=object_id) queryset, fields = ReportCHWStatus.\ vitamines_summary(duration_start, duration_end, \ muac_duration_start, clinic) if rformat == "csv" or (request.POST \ and request.POST["format"].lower() == "csv"): file_name = clinic.name + ".csv" file_name = file_name.replace(" ", "_").replace("'", "") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, clinic,\ [1.0* inch, 1.0 * inch, 1.0 * inch, 1.0 * inch, \ 1.0 * inch, 1.5 * inch, 1.0 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/vitamines_per_page") return pdfrpt.render()
def patients_by_chw(request, object_id=None, per_page="0", rformat="pdf"): '''List of Cases/Patient per CHW''' today = datetime.now().strftime("%d %B,%Y") pdfrpt = PDFReport() pdfrpt.setLandscape(True) pdfrpt.setPrintOnBothSides(True) pdfrpt.setTitle(_("%(app_name)s: Cases Reports by CHW as of %(date)s") % {'date': today,'app_name':Cfg.get("app_name")}) pdfrpt.setNumOfColumns(2) #pdfrpt.setRowsPerPage(88) if object_id is None: if request.POST and request.POST['zone']: # providers = Case.objects.filter(location=request.POST['zone']).\ # values('reporter', 'location').distinct() providers = Reporter.objects.filter(location=request.POST['zone']) #per_page = "1" else: providers = Reporter.objects.all() # providers = Case.objects.order_by("location").\ # values('reporter', 'location').distinct() for reporter in providers: queryset, fields = ReportAllPatients.by_provider(reporter) if queryset: cinfo = {'loc': reporter.location, 'lname': reporter.last_name, 'fname': reporter.first_name, 'date': today} c = _("%(loc)s: %(lname)s %(fname)s: %(date)s" % cinfo) pdfrpt.setTableData(queryset, fields, c, \ [0.3 * inch, 0.4 * inch, 1 * inch, 0.4 * inch, \ 0.3 * inch, 0.8 * inch, 0.5 * inch, 1 * inch, \ 0.8 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/report_per_page") else: if request.POST and request.POST['provider']: object_id = request.POST['provider'] reporter = Reporter.objects.get(id=object_id) queryset, fields = ReportAllPatients.by_provider(reporter) if queryset: cinfo = {'loc': reporter.location, 'lname': reporter.last_name, 'fname': reporter.first_name, 'date': today} c = _("%(loc)s: %(lname)s %(fname)s: %(date)s" % cinfo) if rformat == "csv" or (request.POST \ and request.POST["format"].lower() == "csv"): file_name = reporter.last_name + ".csv" file_name = file_name.replace(" ", "_").replace("'", "") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, c, \ [0.3 * inch, 0.4 * inch, 1 * inch, 0.4 * inch, \ 0.3 * inch, 0.4 * inch, 0.5 * inch, 1 * inch, \ 1 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/report_per_page") return pdfrpt.render()
def muac_summary(request, object_id=None, per_page="0", rformat="pdf", d="30"): '''A pdf report of chw perfomance within the last 30 days''' pdfrpt = PDFReport() d = int(d) pdfrpt.enableFooter(True) thirty_days = timedelta(days=d) today = date.today() duration_start = today - thirty_days duration_start = duration_start.replace(day=1) duration_end = today duration_str = _("CMAM Summary from %(start_date)s to %(end_date)s") % \ {'start_date': duration_start.strftime("%d %B, %Y"), \ 'end_date': today.strftime("%d %B, %Y")} pdfrpt.setTitle(Cfg.get("app_name") + _(": CMAM Summary from %(start_date)s to %(end_date)s") % \ {'start_date': duration_start, 'end_date': duration_end}) if object_id is None: clinics = Location.objects.filter(type__name="Clinic") for clinic in clinics: queryset, fields = ReportCHWStatus.muac_summary(duration_start, \ duration_end, clinic) title = "%s : %s" % (clinic.name, duration_str) pdfrpt.setTableData(queryset, fields, title, \ [0.3 * inch, 1 * inch, 0.8 * inch, 0.8 * inch, \ .8 * inch, .8 * inch, 0.8 * inch, 1 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/report_per_page") else: if request.POST['clinic']: object_id = request.POST['clinic'] object_id = Location.objects.get(id=object_id) queryset, fields = ReportCHWStatus.muac_summary(duration_start, \ duration_end, object_id) c = object_id if rformat == "csv" or (request.POST and \ request.POST["format"].lower() == "csv"): file_name = c.name + ".csv" file_name = file_name.replace(" ", "_").replace("'", "") return handle_csv(request, queryset, fields, file_name) title = "%s : %s" % (c.name, duration_str) pdfrpt.setTableData(queryset, fields, title) return pdfrpt.render()
def last_30_days(request, object_id=None, per_page="0", rformat="pdf", d="30"): '''A pdf report of chw perfomance within the last 30 days''' pdfrpt = PDFReport() pdfrpt.enableFooter(True) d = int(d) thirty_days = timedelta(days=d) ninty_days = timedelta(days=90) today = date.today() duration_start = today - thirty_days muac_duration_start = today - ninty_days duration_end = today pdfrpt.setTitle(_(Cfg.get("app_name") + ": CHW 30 Day Performance Report,"\ " from %(start_date)s " \ "to %(end_date)s" % ({'start_date': duration_start, \ 'end_date': duration_end}))) title = _("CHW 30 Day Performance Report, from %(start_date)s " \ "to %(end_date)s" % {'start_date': duration_start, \ 'end_date': duration_end}) if object_id is None: clinics = Location.objects.filter(type__name="Clinic") for clinic in clinics: queryset, fields = ReportCHWStatus.\ get_providers_by_clinic(duration_start, duration_end, \ muac_duration_start, clinic) stitle = "%s: %s" % (clinic.name, title) pdfrpt.setTableData(queryset, fields, stitle, \ [0.3 * inch, 1 * inch, 0.8 * inch, 0.8 * inch, .8 * inch, \ .8 * inch, 0.8 * inch, 1 * inch, 1 * inch, 1 * inch]) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("/tmp/report_per_page") else: if request.POST['clinic']: object_id = request.POST['clinic'] object_id = Location.objects.get(id=object_id) queryset, fields = ReportCHWStatus.\ get_providers_by_clinic(duration_start, duration_end, \ muac_duration_start, object_id) stitle = "%s: %s" % (object_id.name, title) if rformat == "csv" or (request.POST \ and request.POST["format"].lower() == "csv"): file_name = object_id.name + ".csv" file_name = file_name.replace(" ", "_").replace("'", "") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, stitle) return pdfrpt.render()
def trend(request, object_id=None, per_page="0", rformat="pdf"): pdfrpt = PDFReport() pdfrpt.setLandscape(False) pdfrpt.setTitle("RapidResponse MVP Kenya: Malnutrition Trend by Case Report") if object_id is None: queryset, fields = ReportAllPatients.malnut_trend_by_provider() if queryset: pdfrpt.setTableData(queryset, fields, "") if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("report_per_page") else: if request.POST and request.POST['provider']: object_id = request.POST['provider'] queryset, fields = ReportAllPatients.malnut_trend_by_provider(object_id) if queryset: c = Provider.objects.get(id=object_id) if rformat == "csv" or (request.POST and request.POST["format"].lower() == "csv"): file_name = c.get_name_display() + ".csv" file_name = file_name.replace(" ","_").replace("'","") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, c.get_name_display()) return pdfrpt.render()
def malaria(request, object_id=None, per_page="0", rformat="pdf"): pdfrpt = PDFReport() pdfrpt.setLandscape(True) #pdfrpt.setTitle("RapidResponse MVP Kenya: Cases Reports by CHW") pdfrpt.setTitle("RapidResponse MVP Kenya: Malaria Report") if object_id is None: if request.POST and request.POST['zone']: providers = Case.objects.filter(zone=request.POST['zone']).values('provider', 'zone__name').distinct() per_page = "1" else: providers = Case.objects.order_by("zone").values('provider', 'zone__name').distinct() #for provider in providers: queryset, fields = ReportAllPatients.malaria_by_provider() if queryset: pdfrpt.setTableData(queryset, fields, "") if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("report_per_page") else: if request.POST and request.POST['provider']: object_id = request.POST['provider'] queryset, fields = ReportAllPatients.malaria_by_provider(object_id) if queryset: c = Provider.objects.get(id=object_id) if rformat == "csv" or (request.POST and request.POST["format"].lower() == "csv"): file_name = c.get_name_display() + ".csv" file_name = file_name.replace(" ","_").replace("'","") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, c.get_name_display()) return pdfrpt.render()
def measles_summary(request, object_id=None, per_page="0", rformat="pdf", d="30"): pdfrpt = PDFReport() d = int(d) pdfrpt.enableFooter(True) thirty_days = timedelta(days=d) ninty_days = timedelta(days=90) today = date.today() duration_start = today - thirty_days muac_duration_start = today - ninty_days duration_end = today #pdfrpt.setTitle("RapidResponse MVP Kenya: CHW 30 Day Performance Report, from %s to %s"%(duration_start, duration_end)) pdfrpt.setTitle("Measles Campaign Summary") if object_id is None: clinics = Provider.objects.values('clinic').filter(role=1).distinct() for clinic in clinics: queryset, fields = ReportCHWStatus.measles_summary(duration_start, duration_end, muac_duration_start, clinic["clinic"]) c = Facility.objects.filter(id=clinic["clinic"])[0] pdfrpt.setTableData(queryset, fields, c.name) if (int(per_page) == 1) is True: pdfrpt.setPageBreak() pdfrpt.setFilename("report_per_page") else: if request.POST['clinic']: object_id = request.POST['clinic'] queryset, fields = ReportCHWStatus.measles_summary(duration_start, duration_end, muac_duration_start, object_id) c = Facility.objects.filter(id=object_id)[0] if rformat == "csv" or (request.POST and request.POST["format"].lower() == "csv"): file_name = c.name + ".csv" file_name = file_name.replace(" ","_").replace("'","") return handle_csv(request, queryset, fields, file_name) pdfrpt.setTableData(queryset, fields, c.name) return pdfrpt.render()