예제 #1
0
def new_patient(request):
    """ Handles creation of a new patient """

    # if not post request, redirect to 404
    if not request.method == 'POST':
        raise Http404

    # set up new patient request form with POST data
    new_form = PatientInfoForm(data=request.POST)

    # Check if form is valid. If so, assign doctor and save, the redir to a new order. Otherwise, show error.
    if new_form.is_valid():
        new_patient = new_form.save()

        new_patient.doctor_id = request.user.pk
        new_patient.save()

        return redirect('new_order', pat_id=new_patient.pk)

    else:
        context = {
            'patient_list': None,
            'date_selected': None,
            'new_patient_form': new_form,
            'show_modal': True,
        }
        return render(request, 'patient_lookup.html', context)
예제 #2
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)
예제 #3
0
def new_patient(request):
    """ Handles creation of a new patient """

    # if not post request, redirect to 404
    if not request.method == 'POST':
        raise Http404

    # set up new patient request form with POST data
    new_form = PatientInfoForm(data=request.POST)

    # Check if form is valid. If so, assign doctor and save, the redir to a new order. Otherwise, show error.
    if new_form.is_valid():
        new_patient = new_form.save()
        new_patient.doctor_id = request.user.pk
        
    new_patient.save()
        return redirect('new_order', pat_id=new_patient.pk)
예제 #4
0
def new_patient(request):
    """ Handles creation of a new patient """

    # if not post request, redirect to 404
    if not request.method == 'POST':
        raise Http404

    # set up new patient request form with POST data
    new_form = PatientInfoForm(data=request.POST)

    # Check if form is valid. If so, assign doctor and save, the redir to a new order. Otherwise, show error.
    if new_form.is_valid():
        new_patient = new_form.save(commit=False)
        new_patient.set_password(new_form.cleaned_data['password'])

        new_user = User.objects.create_user(
            username=new_form.cleaned_data['email_info'],
            email=new_form.cleaned_data['email_info'],
            password=new_form.cleaned_data['password'])

        new_user.first_name = new_form.cleaned_data['first_name']
        new_user.last_name = new_form.cleaned_data['last_name']
        new_user.save()

        new_patient.user = new_user
        new_patient.save()

        patient_group = Group.objects.get(name="Patient")
        patient_group.user_set.add(new_patient.user)

        new_patient.doctor_id = request.user.pk
        new_patient.save()

        return redirect('new_order', pat_id=new_patient.pk)

    else:
        context = {
            'patient_list': None,
            'date_selected': None,
            'new_patient_form': new_form,
            'show_modal': True,
        }
        return render(request, 'patient_lookup.html', context)
예제 #5
0
def patient(request, pat_id=None):
    """ Displays the patient info and orders """

    # Grab patient from the database
    patient_rec = Patient.objects.get(pk=pat_id)

    # Check if it is a post request. If so, build our form with the post data.
    if request.method == 'POST':
        form = PatientInfoForm(data=request.POST, instance=patient_rec)

        # Ensure form is valid. If so, save. If not, show error.
        if form.is_valid():
            form.save()
        else:
            messages = {
                'headline1': 'Invalid Form',
                'headline2': 'Please try again.',
                'headline3': f"{form.errors}"
            }
            return show_message(request, messages)

    # Set up variables for our template and render it
    context = {
        'patient_info': patient_rec,
        'form': PatientInfoForm(instance=patient_rec),
        'active_orders': patient_rec.orders.filter(level_id__lt=4),
        'complete_orders': patient_rec.orders.filter(level_id__gte=4),
    }
    return render(request, 'patient.html', context)