From 3725059d0666c91fd7f58c513bc1200d290e583e Mon Sep 17 00:00:00 2001 From: "piotr.atyjaszyk" <piotrmk1@gmail.com> Date: Wed, 1 Feb 2017 15:28:23 +0100 Subject: [PATCH] Assignments to plan will now pop-up --- smash/web/models.py | 12 +++++++++- smash/web/templates/assignments/index.html | 4 ++-- smash/web/views.py | 27 +++++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/smash/web/models.py b/smash/web/models.py index 5feb23ac..0ee99a4f 100644 --- a/smash/web/models.py +++ b/smash/web/models.py @@ -216,6 +216,16 @@ class AppointmentType (models.Model): rest_time = models.IntegerField( verbose_name='Suggested rest time' ) + REQ_ROLE_CHOICES = ( + ('DOCTOR', 'Doctor'), + ('NURSE', 'Nurse'), + ('PSYCHOLOGIST', 'Psychologist'), + ('ANY', 'Any') + ) + required_worker = models.CharField(max_length=20, choices=REQ_ROLE_CHOICES, + verbose_name='Type of worker required for assignment', + default='ANY' + ) def __str__(self): return self.apCode @@ -363,7 +373,7 @@ class Appointment(models.Model): ) datetime_when = models.DateTimeField( verbose_name='Appointment on', - null=True + null=True, blank=True ) length = models.IntegerField( verbose_name='Appointment length (in minutes)' diff --git a/smash/web/templates/assignments/index.html b/smash/web/templates/assignments/index.html index e7cf4ca2..d9b5f02c 100644 --- a/smash/web/templates/assignments/index.html +++ b/smash/web/templates/assignments/index.html @@ -33,7 +33,7 @@ <th>Subject name</th> <th>Full information</th> <th>Suggested date</th> - <th>Details</th> + <th>Plan/Modify</th> </tr> </thead> <tbody> @@ -47,7 +47,7 @@ {{ planned.datetime_when }} </td> <td> - <button type="button" class="btn btn-block btn-default">Details</button> + <button type="button" class="btn btn-block btn-default">Plan/Modify</button> </td> </tr> {% endfor %} diff --git a/smash/web/views.py b/smash/web/views.py index bb4b1a28..02b77e94 100644 --- a/smash/web/views.py +++ b/smash/web/views.py @@ -7,6 +7,7 @@ from .forms import * from .auth import * # Own wrapper for django logging in/out from django.forms import modelformset_factory from django.shortcuts import render +from django.db.models import Q import collections def index(request): @@ -227,8 +228,31 @@ def equipment_and_rooms(request): def mail_templates(request): return wrap_response(request, "mail_templates/index.html", {}) + +""" +#An initial draft of a function that was supposed to suggest date, room and worker for an assignment +def suggest_details(Appointment appoint): + + avaibleWorkers = Worker.objects.get() + if appoint.appointment_type__required_worker == 'DOCTOR': + avaibleWorkers.filter(role='DOCTOR') + elif appoint.appointment_type__required_worker == 'NURSE': + avaibleWorkers.filter(role__in=['DOCTOR','NURSE']) + elif appoint.appointment_type__required_worker == 'PSYCHOLOGIST': + avaibleWorkers.filter(role__in=['DOCTOR','PSYCHOLOGIST']) + + avaibleRooms = Room.objects.get + requireditems = appoint.appointment_type.required_equipment.filter(is_fixed=True) + reduce(operator.and_, (Q(equipment__contains=requireditems) for x in avaibleRooms)) + +""" + + + + def assignments(request): - planning_list = Appointment.objects.none() + futureDate = datetime.datetime.now()+datetime.timedelta(days=93) + planning_list = Appointment.objects.filter(datetime_when__isnull=True, visit__datetime_begin__lt = futureDate) approaching_list = Appointment.objects.filter(datetime_when__gt = datetime.datetime.now()) context = { @@ -246,6 +270,7 @@ def assignment_details(request, id): def assignment_add(request, id): if request.method == 'POST': form = AppointmentAddForm(request.POST, request.FILES) + form.fields['visit'].widget = forms.HiddenInput() if form.is_valid(): form.save() return redirect(visit_details, id=id) -- GitLab