def site(request, pk, template="weltel/site.html"): context = {} site = get_object_or_404(Site, id=pk) patients = Patient.objects.filter(site=site) nurses = Nurse.objects.filter(sites=site) context['site'] = site context['patients'] = paginated(request, patients) context['nurses'] = paginated(request, nurses) return render_to_response(request, template, context)
def index(req): template_name = 'masterindex.html' columns = (("resource", "Resource"), ("facility", "Facility"), ) sort_column, sort_descending = _get_sort_info(req, default_sort_column="resource", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = MasterIndex.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter( Q(resource__name__icontains=search_string) | Q(facility__name__icontains=search_string)) indexies = paginated(req, query) return render_to_response(req, template_name, {"columns": columns, "indexies": indexies, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string})
def index(req): template_name = "resources/index_flat.html" columns = ( ("date_added", "Date Added"), ("name", "Name"), ("code", "Code"), ("facility", "Facility"), ("status", "Status"), ) sort_column, sort_descending = _get_sort_info(req, default_sort_column="date_added", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = Resource.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter(Q(code__icontains=search_string) | Q(name__icontains=search_string)) resources = paginated(req, query) return render_to_response( req, template_name, { "columns": columns, "resources": resources, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string, }, )
def resource_history(req): """ display resources' history """ template_name = "resources/history.html" columns = (("date", "Date Of Request"), ("name", "Name"), ("code", "Code"), ("Facility", "Current Location")) # ("New", "Prev Location")) #previous location sort_column, sort_descending = _get_sort_info(req, default_sort_column="date", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = Resource.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter(Q(status__icontains=search_string) | Q(user__first_name__icontains=search_string)) history = paginated(req, query) return render_to_response( req, template_name, { "columns": columns, "history": history, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string, }, )
def index(req): template_name = "facilities/index_flat.html" columns = (("added_date", "Date Added"), ("name", "Name"), ("location", "Location"), ("description", "Description")) sort_column, sort_descending = _get_sort_info(req, default_sort_column="added_date", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = Facility.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter(Q(name__icontains=search_string)) # Q(location__icontains=search_string)) facilities = paginated(req, query) return render_to_response( req, template_name, { "columns": columns, "facilities": facilities, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string, }, )
def index(req): template_name="logger/index_flat.html" columns = (("date", "Date"), ("connection__identity", "From/To"), ("connection__backend", "Backend"), ("is_incoming", "Direction"), ("text", "Message")) sort_column, sort_descending = _get_sort_info(req, default_sort_column="date", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = Message.objects.select_related("connection", "connection__backend" ).order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter( Q(text__icontains=search_string) | Q(connection__identity__icontains=search_string)) messages = paginated(req, query) return render_to_response(req, template_name, {"columns": columns, "messages": messages, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string})
def index(request, template="weltel/index.html"): context = {} sites = Site.objects.all().order_by('name') start_of_week = datetime.now() # set to monday 00:00 start_of_week = start_of_week - timedelta(days=start_of_week.weekday(), hours=start_of_week.hour, minutes=start_of_week.minute) for site in sites: patients = Patient.objects.filter(site=site) site.patient_count = patients.count() site.nurse_count = Nurse.objects.filter(sites=site).count() sawa_patients = patients.filter(state__code=SAWA_CODE) shida_patients = patients.filter(state__code=SHIDA_CODE) site.sawa_count = sawa_patients.count() site.shida_count = shida_patients.count() sawa_patients_this_week = sawa_patients.filter(active=True).filter( subscribed=True) sawa_patients_this_week = sawa_patients_this_week.filter( eventlog__date__gte=start_of_week) site.sawa_count_this_week = sawa_patients_this_week.distinct().count() shida_patients_this_week = shida_patients.filter(active=True).filter( subscribed=True) shida_patients_this_week = shida_patients_this_week.filter( eventlog__date__gte=start_of_week) site.shida_count_this_week = shida_patients_this_week.distinct().count( ) context['sites'] = paginated(request, sites) #messages = EventLog.objects.select_related().order_by('-received') #context.update( format_events_in_context(request, context, messages) ) return render_to_response(request, template, context)
def index(request, template="weltel/index.html"): context = {} sites = Site.objects.all().order_by('name') start_of_week = datetime.now() # set to monday 00:00 start_of_week = start_of_week - timedelta(days=start_of_week.weekday(), hours=start_of_week.hour, minutes=start_of_week.minute) for site in sites: patients = Patient.objects.filter(site=site) site.patient_count = patients.count() site.nurse_count = Nurse.objects.filter(sites=site).count() sawa_patients = patients.filter(state__code=SAWA_CODE) shida_patients = patients.filter(state__code=SHIDA_CODE) site.sawa_count = sawa_patients.count() site.shida_count = shida_patients.count() sawa_patients_this_week = sawa_patients.filter(active=True).filter(subscribed=True) sawa_patients_this_week = sawa_patients_this_week.filter(eventlog__date__gte=start_of_week) site.sawa_count_this_week = sawa_patients_this_week.distinct().count() shida_patients_this_week = shida_patients.filter(active=True).filter(subscribed=True) shida_patients_this_week = shida_patients_this_week.filter(eventlog__date__gte=start_of_week) site.shida_count_this_week = shida_patients_this_week.distinct().count() context['sites'] = paginated(request, sites) #messages = EventLog.objects.select_related().order_by('-received') #context.update( format_events_in_context(request, context, messages) ) return render_to_response(request, template, context)
def index(req): # reporters = get_tester(req.user) template_name = "testers/index.html" columns = (("last_name", "Surname"), ("first_name", "Firstname"), ) sort_column, sort_descending = _get_sort_info(req, default_sort_column="last_name", default_sort_descending=False) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = Reporter.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter( Q(first_name__icontains=search_string) | Q(last_name__icontains=search_string)) reporters = paginated(req, query) # TODO: get the facility from the reporter profile # and make if sortable. profiles = ReporterProfile.objects.filter(domain=req.user.selected_domain) return render_to_response(req, template_name, {"columns": columns, "reporters": reporters, "profiles": profiles, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string})
def patient_messages(request, pk, template="weltel/patient.html"): patient = get_object_or_404(Patient, id=pk) context = {} context['patient'] = patient logs = get_messages_for_patient(patient) context['messages'] = paginated(request, logs) return render_to_response(request, template, context )
def index(req): columns = (("name", "Point Name"), ("wqmarea", "Area"), ) sort_column, sort_descending = _get_sort_info(req, default_sort_column="name", default_sort_descending=False) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = SamplingPoint.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: district = WqmAuthority.objects.get(id = search_string) query = query.filter( Q(wqmarea__wqmauthority__id=district.id )) search_string = district points = paginated(req, query) return render_to_response(req, "index.html", { "columns": columns, "points": points, "districts": WqmAuthority.objects.all(), "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string, })
def get(req): # pre-populate the "connections" field # with a connection object to convert into a # reporter, if provided in the query string connections = [] if "connection" in req.GET: connections.append( get_object_or_404( PersistantConnection, pk=req.GET["connection"])) reporters = get_tester(req.user) return render_to_response(req, "testers/testers.html", { # display paginated reporters in the left panel "reporters": paginated(req, reporters), # pre-populate connections "connections": connections, # list all groups + backends in the edit form "all_groups": ReporterGroup.objects.flatten(), "facilities": Facility.objects.filter(domain = req.user.selected_domain), "all_backends": PersistantBackend.objects.all() })
def index(req): template_name = "childhealth/index.html" surveyentries = SurveyEntry.objects.order_by("survey_date") all = [] [all.append(entry) for entry in surveyentries] # sort by date, descending all.sort(lambda x, y: cmp(y.survey_date, x.survey_date)) assessments = ass_dicts_for_display() # sort by date, descending assessments.sort(lambda x, y: cmp(y["date"], x["date"])) context = {} context["entries"] = paginated(req, all, per_page=50) context["assessments"] = paginated(req, assessments, per_page=50) return render_to_response(req, template_name, context)
def patient_messages(request, pk, template="weltel/patient.html"): patient = get_object_or_404(Patient, id=pk) context = {} context['patient'] = patient logs = get_messages_for_patient(patient) if logs: context['messages'] = paginated(request, logs) return render_to_response(request, template, context)
def patient(request, pk, template="weltel/patient.html"): patient = get_object_or_404(Patient, id=pk) context = {} context['patient'] = patient logs = get_history_for_patient(patient) context['history'] = paginated(request, logs) context['phone_numbers'] = [c.identity for c in patient.connections.all()] return render_to_response(request, template, context)
def patient(request, pk, template="weltel/patient.html"): patient = get_object_or_404(Patient, id=pk) context = {} context['patient'] = patient logs = get_history_for_patient(patient) context['history'] = paginated(request, logs) context['phone_numbers'] = [c.identity for c in patient.connections.all()] return render_to_response(request, template, context )
def index(request): template_name = "index.html" notifications = SmsNotification.objects.all().order_by("-authorised_personnel") return render_to_response( request, template_name, {"notifications": paginated(request, notifications, prefix="smsnotice")} )
def get(req): template_name = "facilities/index.html" facilities = Facility.objects.all().filter(domain=req.user.selected_domain) locations = Location.objects.all() return render_to_response( req, template_name, {"facilities": paginated(req, facilities, prefix="facility"), "locations": locations} )
def nurse(request, pk, template="weltel/nurse.html"): context = {} nurse = get_object_or_404(Nurse, id=pk) context['nurse'] = nurse logs = nurse.messages(order_by='-received') if logs: context['logs'] = paginated(request, logs) context['phone_numbers'] = [c.identity for c in nurse.connections.all()] return render_to_response(request, template, context)
def index(request, template="contacts/index.html"): context = {} contacts = Contact.objects.all() for contact in contacts: connections = ChannelConnection.objects.filter(contact=contact) if connections: contact.phone_number = connections[0].user_identifier context['contacts'] = paginated(request, contacts) return render_to_response(request, template, context)
def nurse(request, pk, template="weltel/nurse.html"): context = {} nurse = get_object_or_404(Nurse, id=pk) context['nurse'] = nurse logs = nurse.messages(order_by='-received') if logs: context['logs'] = paginated(request, logs) context['phone_numbers'] = [c.identity for c in nurse.connections.all()] return render_to_response(request, template, context )
def location_type(req, location_type_pk): loc_type = get_object_or_404( LocationType, pk=location_type_pk) return render_to_response(req, "locations/location-type.html", { "active_location_type_tab": loc_type.pk, "locations": paginated(req, loc_type.locations.all(), prefix="loc"), "location_type": loc_type })
def index(request, template="contacts/index.html"): context = {} contacts = Contact.objects.all() for contact in contacts: connections = PersistantConnection.objects.filter(reporter=contact.reporter) if connections: contact.phone_number = connections[0].identity context['contacts'] = paginated(request, contacts) return render_to_response(request, template, context)
def index(req, template_name="logger/index.html"): incoming = IncomingMessage.objects.order_by('received') outgoing = OutgoingMessage.objects.order_by('sent') all = [] [ all.append(msg) for msg in incoming ] [ all.append(msg) for msg in outgoing] # sort by date, descending all.sort(lambda x, y: cmp(y.date, x.date)) context = {} context['messages'] = paginated(req, all, per_page=50) return render_to_response(req, template_name, context )
def dataPaginatev2(req,value,kfilter={},paginate=True,*args,**kwargs): try: cmd = "%s.objects" % value.klass if len(kfilter) == 0: cmd = cmd+".all()" else: cmd = cmd+".filter(**%s)" % kfilter if value.exclude : cmd = cmd+".exclude(**%s)" % kwargs["exclude"] if value.filterorder : cmd = cmd+".order_by(\"%s\")" % value.filterorder data = eval(cmd) p = paginated(req,data) #THANKS ADAM FOR SUPPORTING AGGREGATION if paginate : return {"paginate":paginated(req,data,prefix="%d" % value.id),"cmd":cmd} else: return {"paginate":data,"cmd":cmd} except Exception,e: return "%s e %s" % (e,cmd)
def index(req): query = ReporterProfile.objects.filter(domain=req.user.selected_domain).order_by('reporter__first_name') search_string = req.REQUEST.get("q", "") if search_string == "": pass else: query = query.filter( Q(reporter__first_name__icontains = search_string ) | Q(reporter__last_name__icontains = search_string)) reporters = [] for rep in query: reporter = rep.reporter reporters.append(reporter) return render_to_response(req, "testers/index.html", { "reporters": paginated(req, reporters, prefix="rep"), "groups": paginated(req, ReporterGroup.objects.flatten(), prefix="grp"), "search_string" : search_string, })
def index(request): template_name = 'sindex.html' notifications = SmsNotification.objects.all().order_by("-authorised_sampler") points = SamplingPoint.objects.all().order_by("name") districts = WqmAuthority.objects.all() return render_to_response(request, template_name, { "notifications": paginated(request, notifications, prefix="smsnotice"), "points" : points, "districts": districts, })
def dataPaginate(req,value,*args,**kwargs): try: if value.params == "" or value.params == "0": #remove 0 temp f#$k up cmd = "%s.objects.all()" % (value.klass) else: cmd = "%s.objects.filter(%s)" % (value.klass,value.params) % kwargs if value.filterorder: cmd = "%s.order_by(\"%s\")" % (cmd,value.filterorder) data = eval(cmd) return {"paginate":paginated(req,data,prefix="%d" % value.id),"cmd":cmd} except Exception,e: return "%s" % e
def index(request, template="weltel/index.html"): context = {} sites = Site.objects.all() for site in sites: site.patient_count = Patient.objects.filter(site=site).count() site.nurse_count = Nurse.objects.filter(sites=site).count() site.sawa_count = Patient.objects.filter(site=site).filter(state__code=SAWA).count() site.shida_count = Patient.objects.filter(site=site).filter(state__code=SHIDA).count() site.other_count = Patient.objects.filter(site=site).filter(state__code=OTHER).count() context['sites'] = paginated(request, sites) #messages = EventLog.objects.select_related().order_by('-received') #context.update( format_events_in_context(request, context, messages) ) return render_to_response(request, template, context)
def bylocation(req,location): type_id = LocationType.objects.get(slug=location).id locations = Location.objects.filter(type=type_id).order_by("name") rapidsms_locations =[] other_locations = [] status_location = [l.location.id for l in LocationStatus.objects.all()] rapidsms_loctions = Location.objects.filter(type=type_id,id__in=status_location).order_by("name") other_locations = Location.objects.filter(type=type_id)#.exclude(id__in=status_location).order_by("name") header,data = statsoverview([l for l in locations]) #header,data = statsoverview(rapidsms) #replace with this title = "Data on a %s Level" % location locations = Location.objects.filter(type=type_id).order_by("name") return render_to_response(req, "infsss/locations.html", { "rapidsms_locations": paginated(req,rapidsms_locations,prefix="rapidsms"), "other_locations": paginated(req,other_locations,prefix="other"), "title": title, "header":header, "data": data })
def get(req): return render_to_response(req, "hq/reporter.html", { # display paginated reporters in the left panel "reporters": paginated(req, Reporter.objects.all()), # list all groups + backends in the edit form "all_groups": ReporterGroup.objects.flatten(), "all_backends": PersistantBackend.objects.all(), # split objects linked to the editing reporter into # their own vars, to avoid coding in the template "connections": rep.connections.all(), "groups": rep.groups.all(), "reporter": rep })
def get(req): template_name = "resources/index.html" resources = Resource.objects.all() categories = ResourceCategory.objects.all() facilities = Facility.objects.all().filter(domain=req.user.selected_domain) status = Status.objects.all() return render_to_response( req, template_name, { "resources": paginated(req, resources, prefix="resource"), "categories": categories, "facilities": facilities, "status": status, }, )
def patient_list(request): #handle submission for updating a patient (from /patient/xxx/) patient_id = None if request.method == 'POST' and 'patient_id' in request.POST: patient_id = request.POST['patient_id'] save_msg = None if patient_id != None: form = PatientForm( request.POST, instance=Registration.objects.get(patient_id=patient_id)) if form.is_valid(): form.save() save_msg = 'Successfully updated patient %s' % patient_id else: save_msg = 'Unable to update patient %s! %s' % (patient_id, form.errors) regs = Registration.objects.all().order_by('-registered_on') sentlog = SentNotif.objects.all() sent = {} for s in sentlog: patid = s.patient_id day = s.day if patid not in sent: sent[patid] = set() days = sent[patid] days.add(day) for r in regs: days = sent[r.patient_id] if r.patient_id in sent else set() dayslist = [] for i in config.notification_days: dayslist.append(i in days) r.notifications = dayslist r.post_op = (date.today() - r.registered_on).days return render_to_response( request, 'circumcision/overview.html', { 'days': config.notification_days, 'patients': paginated(request, regs), 'save_msg': save_msg })
def get(req): return render_to_response(req, "testers/testers.html", { # display paginated reporters in the left panel "reporters": paginated(req, Reporter.objects.all()), # list all groups + backends in the edit form "all_groups": ReporterGroup.objects.flatten(), "all_backends": PersistantBackend.objects.all(), # split objects linked to the editing reporter into # their own vars, to avoid coding in the template "connections": rep.connections.all(), "groups": rep.groups.all(), 'facilities': Facility.objects.filter(domain = req.user.selected_domain), 'reporter_profile': rep_profile, "reporter": rep })
def resource_requests(req): """ display resource supply requests from the user within the domain. """ # resource_req = ResourceSupplyRequest.objects.all() template_name = "resources/requests.html" columns = ( ("request_date", "Date Of Request"), ("user", "Requester"), ("resource", "Resource"), ("request_remarks", "Remarks"), ("status", "Status"), ) sort_column, sort_descending = _get_sort_info(req, default_sort_column="request_date", default_sort_descending=True) sort_desc_string = "-" if sort_descending else "" search_string = req.REQUEST.get("q", "") query = ResourceSupplyRequest.objects.order_by("%s%s" % (sort_desc_string, sort_column)) if search_string == "": query = query.all() else: query = query.filter( Q(status__icontains=search_string) | Q(user__first_name__icontains=search_string) | Q(resource__name__icontains=search_string) | Q(resource__code__icontains=search_string) | Q(user__last_name__icontains=search_string) ) resource_reqs = paginated(req, query) return render_to_response( req, template_name, { "columns": columns, "resource_reqs": resource_reqs, "sort_column": sort_column, "sort_descending": sort_descending, "search_string": search_string, }, )
def get(req, template_name="blaster/new.html", errors=None): filter_params = get_location_filter_params(req, "location__") messages = BlastableMessage.objects.all() # TODO: genericize this out to only depend on reporters # filter out those not matching the type. if "type" in req.GET: filter_type = req.GET["type"] else: filter_type = None reporters = Reporter.objects.filter(**filter_params) # loop through and set some attributes on the reporters so we # can display school specific information in the UI # TODO: this is horribly inefficient and could be optimized final_list = [] #for reporter in reporters: for reporter in []: if reporter.location: try: school = School.objects.get(id=reporter.location.id) reporter.school = school if filter_type: try: group = school.groups.get(type=filter_type) if reporter in group.reporters.all(): reporter.school_role = group.member_title else: # they aren't part of the group we're filtering # on so don't add them continue except SchoolGroup.DoesNotExist: # if the school doesn't have a group then # don't add them continue else: # see if they belong to any known groups, and if so # set those objects in the UI groups = reporter.groups.all() school_groups = [] for group in groups: try: school_groups.append( SchoolGroup.objects.get(id=group.id)) except SchoolGroup.DoesNotExist: # wasn't a school group, just ignore it pass reporter.school_groups = school_groups # list their roles reporter.school_role = ",".join( [grp.member_title() for grp in school_groups]) except School.DoesNotExist: reporter.school = None final_list.append(reporter) # sort by location, then role final_list.sort(lambda x, y: cmp("%s-%s" % ( x.location, x.school_role), "%s-%s" % (y.location, y.school_role))) # wow! what a complete contradiction of the entire point of the # locations app. no matter, it's just for the demo. r = LocationType.objects.get(name="Region") regions = r.locations.all().order_by("name") d = LocationType.objects.get(name="District") districts = d.locations.all().order_by("parent__id", "name") s = LocationType.objects.get(name="School") schools = s.locations.all().order_by("parent__id", "parent__parent__id", "name") def _with_role(reporter): """ Add a 'school_role' attribute (a comma-separated list of the 'member_title' method of each linked SchoolGroup object) to *reporter* and return it. This is horribly, horribly inefficient, but there isn't a more direct way of finding the SchoolGroup names of each reporter, since every single School has its own roles (??). """ groups = SchoolGroup.objects.filter(reporters=reporter) roles = ", ".join([g.member_title() for g in groups]) roles = re.sub(r"\s+(Member|Leader)", "", roles) reporter.school_role = roles return reporter #people = [ # _with_role(person) # for person in Reporter.objects.all()] all_people = Reporter.objects.all()[0:100] people = paginated(req, all_people, per_page=10, wrapper=_with_role) roles = [(key, vals[1]) for key, vals in SCHOOL_GROUP_TYPES.items()] return render_to_response( req, template_name, { "messages": messages, "reporters": final_list, "errors": errors, "regions": regions, "districts": districts, "schools": schools, "people": people, "roles": roles })
def index(request, template="scheduler/index.html"): context = {} schedules = EventSchedule.objects.all() context['schedules'] = paginated(request, schedules) return render_to_response(request, template, context)