def post(self, request, *args, **kwargs): form = SearchForm(request) data = [ get_per_cds_statistics( kwargs["pk"], request.POST.get("start_date"), request.POST.get("end_date"), ) ] statistics = PatientsTable(data) RequestConfig(request).configure(statistics) request.session["sstart_date"] = request.POST.get("start_date") request.session["eend_date"] = request.POST.get("end_date") return render( request, "surveillance_cholera/cds_detail.html", { "form": form, "statistics": statistics, "object": CDS.objects.get(pk=kwargs["pk"]), "start_date": request.POST.get("start_date"), "end_date": request.POST.get("end_date"), }, )
def get_context_data(self, **kwargs): context = super(DistrictDetailView, self).get_context_data(**kwargs) district_id = self.kwargs["pk"] data = None if "sstart_date" in self.request.session: data = get_district_data( district_id, start_date=self.request.session["sstart_date"], end_date=self.request.session["eend_date"], ) context["start_date"] = self.request.session["sstart_date"] context["end_date"] = self.request.session["eend_date"] else: data = get_district_data(district_id) statistics = PatientsTable(data) RequestConfig(self.request).configure(statistics) context["statistics"] = statistics context["form"] = SearchForm() return context
def post(self, request, *args, **kwargs): form = SearchForm(request) data = get_province_data(kwargs["pk"], request.POST.get("start_date"), request.POST.get("end_date")) statistics = Patients2Table(data) RequestConfig(request, paginate={ "per_page": 1000 }).configure(statistics) request.session["sstart_date"] = request.POST.get("start_date") request.session["eend_date"] = request.POST.get("end_date") return render( request, "surveillance_cholera/province_detail.html", { "form": form, "statistics": statistics, "object": Province.objects.get(pk=kwargs["pk"]), "start_date": request.POST.get("start_date"), "end_date": request.POST.get("end_date"), }, )
def get_context_data(self, **kwargs): context = super(ProvinceDetailView, self).get_context_data(**kwargs) province_id = self.kwargs["pk"] data = None # import ipdb; ipdb.set_trace() if "sstart_date" in self.request.session: data = get_province_data( province_id, start_date=self.request.session["sstart_date"], end_date=self.request.session["eend_date"], ) context["start_date"] = self.request.session["sstart_date"] context["end_date"] = self.request.session["eend_date"] else: data = get_province_data(province_id) statistics = Patients2Table(data) RequestConfig(self.request, paginate={ "per_page": 1000 }).configure(statistics) context["statistics"] = statistics context["form"] = SearchForm() return context
def get_statistics(request): form = SearchForm(request) userprofile = UserProfile.objects.get(user=request.user) all_patients = get_all_patients(level=userprofile.level, moh_facility=userprofile.moh_facility) if request.method == "POST": if request.POST.get("patient") != "": all_patients = all_patients.filter( patient_id__icontains=request.POST.get("patient")) start_date = request.POST.get("start_date") end_date = request.POST.get("end_date") if not request.POST.get("start_date"): start_date = u"01/01/2015" if not request.POST.get("end_date"): end_date = datetime.date.today().strftime("%d/%m/%Y") if request.POST.get("province") != "": if request.POST.get("districts") != "": if request.POST.get("cds") != "": results = PatientTable( all_patients.filter( cds=request.POST.get("cds"), date_entry__range=[ format_to_time(start_date), format_to_time(end_date), ], )) RequestConfig(request, paginate={ "per_page": 25 }).configure(results) return render(request, "statistics.html", { "form": form, "results": results }) results = PatientTable( all_patients.filter( cds__district__id=request.POST.get("districts"), date_entry__range=[ format_to_time(start_date), format_to_time(end_date), ], )) RequestConfig(request, paginate={ "per_page": 25 }).configure(results) return render(request, "statistics.html", { "form": form, "results": results }) results = PatientTable( all_patients.filter( cds__district__province__id=request.POST.get("province"), date_entry__range=[ format_to_time(start_date), format_to_time(end_date), ], )) RequestConfig(request, paginate={ "per_page": 25 }).configure(results) return render(request, "statistics.html", { "form": form, "results": results }) results = PatientTable( all_patients.filter(date_entry__range=[ format_to_time(start_date), format_to_time(end_date) ])) RequestConfig(request, paginate={"per_page": 25}).configure(results) return render(request, "statistics.html", { "form": form, "results": results }) results = PatientTable(all_patients) RequestConfig(request, paginate={"per_page": 25}).configure(results) return render(request, "statistics.html", { "form": form, "results": results })
def search_form(request): if request.user.is_authenticated: return {"search_form": SearchForm(request)}