Exemplo n.º 1
0
def single_patient(request, patient_id):
    patient = loader.get_patient(patient_id)
    xforms = CXFormInstance.view("patient/xforms", key=patient.get_id, include_docs=True)
    encounter_types = get_encounters(patient)
    options = TouchscreenOptions.default()
    # TODO: are we upset about how this breaks MVC?
    options.nextbutton.show  = False
    options.backbutton = ButtonOptions(text="BACK", 
                                       link=reverse("patient_select"))
    
    encounters = sorted(patient.encounters, key=lambda encounter: encounter.visit_date, reverse=True)
    # TODO: figure out a way to do this more centrally
    # Inject cases into encounters so we can show them linked in the view
    for encounter in patient.encounters:
        if encounter.get_xform():
            encounter.dynamic_data["classification"] = get_classification(encounter.get_xform().namespace)
            encounter.dynamic_data["cases"] = []
            for case in patient.cases:
                if case.encounter_id == encounter.get_id:
                    encounter.dynamic_data["cases"].append(case)
        
    
    return render_to_response(request, "patient/single_patient_touchscreen.html", 
                              {"patient": patient,
                               "encounters": encounters,
                               "xforms": xforms,
                               "encounter_types": encounter_types,
                               "options": options })
Exemplo n.º 2
0
 def wrapped_view(request, *args, **kwargs):
     site = get_current_site()
     if site.type.slug in aggregation_levels:
         return view_func(request, *args, **kwargs)
     else:
         return render_to_response("bad_permissions.html", {"options": TouchscreenOptions.default()},
                                   context_instance = RequestContext(request))
Exemplo n.º 3
0
def not_found(request, template_name='404.html'):
    """
    404 error handler.
    """
    t = loader.get_template(template_name) 
    return HttpResponseServerError(t.render(RequestContext(request, 
                                                           {'STATIC_URL': settings.STATIC_URL,
                                                            "options": TouchscreenOptions.default()})))
Exemplo n.º 4
0
def server_error(request, template_name='500.html'):
    """
    500 error handler.
    """
    # hat tip: http://www.arthurkoziel.com/2009/01/15/passing-mediaurl-djangos-500-error-view/
    t = loader.get_template(template_name) 
    return HttpResponseServerError(t.render(RequestContext(request, 
                                                           {'STATIC_URL': settings.STATIC_URL,
                                                            "options": TouchscreenOptions.default()})))
Exemplo n.º 5
0
def single_encounter(request, patient_id, encounter_id):
    patient = loader.get_patient(patient_id)
    encounters = [enc for enc in patient.encounters if enc.get_id == encounter_id]
    if not encounters:
        raise Exception("No matching encounter for id %s in patient %s" % (encounter_id, patient_id))
    encounter = encounters[0]
    return render_to_response(request, "encounter/single_encounter.html", 
                              {"patient": patient,
                               "encounter": encounter,
                               "options": TouchscreenOptions.default()})
Exemplo n.º 6
0
def clinic_report(request, view_name):
    url = reverse(view_name)
    view, args, kwargs = resolve(url)
    options = TouchscreenOptions.default()
    options.header = view.__doc__
    options.backbutton = ButtonOptions(show=True, link=reverse("report_list"), text="BACK")

    return render_to_response(request, "reports/clinic_report_wrapper.html", 
                              {"options": options,
                               "url": url})
Exemplo n.º 7
0
def patient_case(request, patient_id, case_id):
    pat = CPatient.get(patient_id)
    found_case = None
    for case in pat.cases:
        if case.get_id == case_id:
            found_case = case
            break
    return render_to_response(request, "case/single_case.html", 
                              {"patient": pat,
                               "case": found_case,
                               "options": TouchscreenOptions.default()})
Exemplo n.º 8
0
def test(request):
    dynamic = string_to_boolean(request.GET["dynamic"]) if "dynamic" in request.GET else True
    template = request.GET["template"] if "template" in request.GET \
                                       else "touchscreen/example-inner.html"
    header = request.GET["header"] if "header" in request.GET \
                                   else "Hello World!"
    pat_id = request.GET["id"] if "id" in request.GET \
                               else "000000000001" 
    try:
        patient = loader.get_patient(pat_id)
    except Exception:
        patient = None
    if dynamic:
        return render_to_response(request, "touchscreen/wrapper-dynamic.html", 
                                  {"header": header,
                                   "template": template,
                                   "patient": patient,
                                   "options": TouchscreenOptions.default()})
    else:
        return render_to_response(request, template, 
                              {"patient": patient,
                               "options": TouchscreenOptions.default()})
Exemplo n.º 9
0
def new_user(request):
    if request.method == "POST":

        data = json.loads(request.POST.get('result'))
        if not data:
            return HttpResponseRedirect(reverse('bhoma_admin'))

        user = User()
        # HACK: all usernames and passwords are lowercased going into the db
        user.username = data.get("username").lower()
        user.set_password(data.get("password").lower())
        user.first_name = data.get("fname")
        user.last_name  = data.get("lname")
        user.email = ""
        user.is_staff = False # Can't log in to admin site
        user.is_active = True # Activated upon receipt of confirmation
        user.is_superuser = False # Certainly not
        user.last_login =  datetime(1970,1,1)
        user.date_joined = datetime.utcnow()
        user.save()
        # have to have an object before you're allowed to edit M2M fields
        # so do groups/roles last
        role = data.get("role")
        if role:
            try:
                user.groups = [Group.objects.get(name=role)]
            except Group.DoesNotExist:
                logging.error("Unable to give role %s to %s -- permissions may " 
                              "not work.  Did you forget to run syncdb recently?")
        return render_to_response(request, "auth/user_reg_complete.html", 
                                  {"new_user": user,
                                   "options": TouchscreenOptions.admin() }) 
                                  
    return render_to_response(request, "bhoma_touchscreen.html", 
                              {'form': {'name':  'add user', 
                                        'wfobj': 'wfNewUser'}, 
                               'mode':  'workflow', 
                               'dynamic_scripts': ["%swebapp/javascripts/user_reg.js" %\
                                                   settings.STATIC_URL,] })
Exemplo n.º 10
0
def delete_user(request):
    if request.method == "POST":

        data = json.loads(request.POST.get('result'))
        if not data:
            return HttpResponseRedirect(reverse('bhoma_admin'))

        if string_to_boolean(data.get("confirm")):
            user = User.objects.get(username=data.get("username"))
            if request.user == user:
                return render_to_response(request, "touchscreen/error.html", 
                    {"error_text": "You can't delete the currently logged in user account. "
                     "Please logout and log in as a different user",
                     "options": TouchscreenOptions.admin()})
            else:
                user.delete()
        return HttpResponseRedirect(reverse("bhoma_admin"))
                                  
    return render_to_response(request, "bhoma_touchscreen.html", 
                              {'form': {'name':  'delete user', 
                                        'wfobj': 'wfDeleteUser'}, 
                               'mode':  'workflow', 
                               'dynamic_scripts': ["%swebapp/javascripts/user_del.js" % \
                                                   settings.STATIC_URL,] })
Exemplo n.º 11
0
def clinic_landing_page(req):
    return render_to_response(req, "clinic_landing_page.html",
                              {"options": TouchscreenOptions.default(),
                               "can_power_down_server": settings.BHOMA_CAN_POWER_DOWN_SERVER})
Exemplo n.º 12
0
def report_list(request):
    template = "reports/report_list_ts.html" if is_clinic() else "reports/report_list.html"
    return render_to_response(request, template, {"options": TouchscreenOptions.default()})