Ejemplo n.º 1
0
def patient_lookup(request):
    """ Handles patient lookup and order creation """

    # Grab a data object from our DateWidget
    dob = datetime.datetime.strptime(request.POST['birth_date'],
                                     '%m/%d/%Y').date()

    if dob > datetime.date.today():
        messages = {
            'headline1': 'Birth date must be in the past',
            'headline2': 'Please try again.',
            'headline3': f""
        }
        return show_message(request, messages)

    # Grab a list of patients with that DOB from DB
    patient_list = Patient.objects.filter(birth_date=dob)

    # Prepare empty lookup form
    new_form = PatientLookupForm(initial={'birth_date': dob})

    # prepare context for our page and then render it
    context = {
        'patient_list': patient_list,
        'date_selected': dob.strftime('%m/%d/%Y'),
        'new_patient_form': PatientInfoForm(),
        'patient_lookup': new_form,
    }
    return render(request, 'patient_lookup.html', context)
Ejemplo n.º 2
0
def index(request):
    """ Displays dashboard tables, depending on group membership of logged in user. """

    # Determine if current user can see all sections
    see_all = is_in_group(request.user, "Administrators")

    # Set up empty context to pass to template
    context = {}

    # Check if administrator or physician
    if see_all or is_in_group(request.user, "Physicians"):
        # Grab active orders and completed orders from database
        active_orders = Order.objects.filter(level_id__lt=4)
        complete_orders = Order.objects.filter(level_id=4)

        # If we are not an administrator, limit active and complete orders to
        # the logged in users' patients.
        if not see_all:
            active_orders = active_orders.filter(patient__doctor=request.user)
            complete_orders = complete_orders.filter(
                patient__doctor=request.user)

        # Add the orders we grabbed to our template context
        context['active_orders'] = active_orders
        context['complete_orders'] = complete_orders

        # Add the patient lookup form to our context
        context['patient_lookup'] = PatientLookupForm()

    # Check if administrator or receptionist
    if see_all or is_in_group(request.user, "Receptionists"):
        # Find today's appts. To filter by today's appointments, we find the datetime for today at midnight,
        # and today at 11:59 PM. We then find all appts between those two ranges. Then we add it to the context.
        today_min = datetime.datetime.combine(datetime.date.today(),
                                              datetime.time.min)
        today_max = datetime.datetime.combine(datetime.date.today(),
                                              datetime.time.max)
        context['todays_orders'] = Order.objects.filter(
            level_id=1, appointment__range=(today_min, today_max))

        # Find unscheduled appointments
        context['unsched_orders'] = Order.objects.filter(
            level_id=1, appointment__isnull=True)

    # Check if administrator or technician
    if see_all or is_in_group(request.user, "Technicians"):
        # Pass into context all checked in orders for any team where the logged in user is a technician.
        context['checked_in_orders'] = Order.objects.filter(
            level_id=2, team__technicians=request.user)

    if see_all or is_in_group(request.user, "Radiologists"):
        # Pass into context all imaging complete orders for teams where logged in user is a radiologist.
        context['radiologist_orders'] = Order.objects.filter(
            level_id=3, team__radiologists=request.user)

    # Render the dashoboard with any context we've passed in.
    return render(request, 'index.html', context)
Ejemplo n.º 3
0
def index(request):
    """ Displays dashboard tables, depending on group membership of logged in user. """

    # Determine if current user can see all sections
    see_all = is_in_group(request.user, "Administrators")

    # Set up empty context to pass to template
    context = {}

    # Check if administrator or physician
    if see_all or is_in_group(request.user, "Physicians"):
        # Grab active orders and completed orders from database
        active_orders = Order.objects.filter(level_id__lt=4)
        complete_orders = Order.objects.filter(level_id=4)

        # If we are not an administrator, limit active and complete orders to
        # the logged in users' patients.
        if not see_all:
            active_orders = active_orders.filter(patient__doctor=request.user)
            complete_orders = complete_orders.filter(
                patient__doctor=request.user)

        # Add the orders we grabbed to our template context
        context['active_orders'] = active_orders
        context['complete_orders'] = complete_orders

        # Add the patient lookup form to our context
        context['patient_lookup'] = PatientLookupForm()

    # Check if administrator or receptionist
    if see_all or is_in_group(request.user, "Receptionists"):
        # Find today's appts. To filter by today's appointments, we find the datetime for today at midnight,
        # and today at 11:59 PM. We then find all appts between those two ranges. Then we add it to the context.
        today_min = datetime.datetime.combine(datetime.date.today(),
                                              datetime.time.min)
        today_max = datetime.datetime.combine(datetime.date.today(),
                                              datetime.time.max)
        context['todays_orders'] = Order.objects.filter(
            level_id=1, appointment__range=(today_min, today_max))

        # Find unscheduled appointments
        context['unsched_orders'] = Order.objects.filter(
            level_id=1, appointment__isnull=True)

    # Check if administrator or technician
    if see_all or is_in_group(request.user, "Technicians"):
        # Pass into context all checked in orders for any team where the logged in user is a technician.
        context['checked_in_orders'] = Order.objects.filter(
            level_id=2, team__technicians=request.user)

    if see_all or is_in_group(request.user, "Radiologists"):
        # Pass into context all imaging complete orders for teams where logged in user is a radiologist.
        context['radiologist_orders'] = Order.objects.filter(
            level_id=3, team__radiologists=request.user)

    if is_in_group(request.user, "Patient"):
        # Grab patient from the database
        patient_rec = Patient.objects.get(pk=request.user.user_obj.pk)
        # Set up variables for our template and render it
        context['user'] = request.user
        context['patient_info'] = patient_rec
        context['active_orders'] = patient_rec.orders.filter(level_id__lt=4)
        context['complete_orders'] = patient_rec.orders.filter(
            level_id__gte=4).order_by('-added_on')
        context['order_id'] = list(context['complete_orders'])[0].pk

        new_form = SurveyForm(data=request.POST)
        context['new_survey_form'] = new_form
        # Determine if a survey was just submitted, and only allow the notification to show once
        if 'just_submitted' in request.session:
            if request.session['just_submitted'] >= 1:
                del request.session['just_submitted']
            elif request.session['just_submitted'] < 0:
                request.session['just_submitted'] = 0
            else:
                request.session['just_submitted'] = request.session.get(
                    'just_submitted') + 1

    # Render the dashoboard with any context we've passed in.
    return render(request, 'index.html', context)