Revision 76974b6f
Added by Benjamin Dauvergne almost 12 years ago
calebasse/dossiers/views.py | ||
---|---|---|
15 | 15 |
from calebasse import cbv |
16 | 16 |
from calebasse.doc_templates import make_doc_from_template |
17 | 17 |
from calebasse.dossiers import forms |
18 |
from calebasse.agenda.models import Occurrence |
|
18 |
from calebasse.agenda.models import Event, EventWithAct |
|
19 |
from calebasse.actes.models import Act |
|
19 | 20 |
from calebasse.agenda.appointments import Appointment |
20 | 21 |
from calebasse.dossiers.models import (PatientRecord, PatientContact, |
21 | 22 |
PatientAddress, Status, FileState, create_patient, CmppHealthCareTreatment, |
... | ... | |
27 | 28 |
|
28 | 29 |
def get_next_rdv(patient_record): |
29 | 30 |
next_rdv = {} |
30 |
occurrence = Occurrence.objects.next_appoinment(patient_record)
|
|
31 |
if occurrence:
|
|
32 |
next_rdv['start_datetime'] = occurrence.start_time
|
|
33 |
next_rdv['participants'] = occurrence.event.participants.all()
|
|
34 |
next_rdv['act_type'] = occurrence.event.eventact.act_type
|
|
31 |
event = Event.objects.next_appointment(patient_record)
|
|
32 |
if event:
|
|
33 |
next_rdv['start_datetime'] = event.start_time
|
|
34 |
next_rdv['participants'] = event.participants.all() |
|
35 |
next_rdv['act_type'] = event.eventact.act_type |
|
35 | 36 |
return next_rdv |
36 | 37 |
|
37 | 38 |
def get_last_rdv(patient_record): |
38 | 39 |
last_rdv = {} |
39 |
occurrence = Occurrence.objects.last_appoinment(patient_record)
|
|
40 |
if occurrence:
|
|
41 |
last_rdv['start_datetime'] = occurrence.start_time
|
|
42 |
last_rdv['participants'] = occurrence.event.participants.all()
|
|
43 |
last_rdv['act_type'] = occurrence.event.eventact.act_type
|
|
40 |
event = Event.objects.last_appointment(patient_record)
|
|
41 |
if event:
|
|
42 |
last_rdv['start_datetime'] = event.start_time
|
|
43 |
last_rdv['participants'] = event.participants.all() |
|
44 |
last_rdv['act_type'] = event.eventact.act_type |
|
44 | 45 |
return last_rdv |
45 | 46 |
|
46 | 47 |
class NewPatientRecordView(cbv.FormView, cbv.ServiceViewMixin): |
... | ... | |
254 | 255 |
ctx['service_id'] = self.service.id |
255 | 256 |
ctx['states'] = FileState.objects.filter(patient=self.object).filter(status__services=self.service) |
256 | 257 |
ctx['next_rdvs'] = [] |
257 |
for rdv in Occurrence.objects.next_appoinments(ctx['object']):
|
|
258 |
state = rdv.event.eventact.get_state()
|
|
258 |
for act in Act.objects.next_acts(ctx['object']).select_related():
|
|
259 |
state = act.get_state() |
|
259 | 260 |
if not state.previous_state: |
260 | 261 |
state = None |
261 |
ctx['next_rdvs'].append((rdv, state))
|
|
262 |
ctx['next_rdvs'].append((act.parent_event, state))
|
|
262 | 263 |
ctx['last_rdvs'] = [] |
263 |
for rdv in Occurrence.objects.last_appoinments(ctx['object']):
|
|
264 |
state = rdv.event.eventact.get_state()
|
|
264 |
for act in Act.objects.last_acts(ctx['object']):
|
|
265 |
state = act.get_state() |
|
265 | 266 |
if not state.previous_state: |
266 | 267 |
state = None |
267 |
ctx['last_rdvs'].append((rdv, state))
|
|
268 |
ctx['last_rdvs'].append((act.parent_event, state))
|
|
268 | 269 |
ctx['status'] = [] |
269 | 270 |
if ctx['object'].service.name == "CMPP": |
270 | 271 |
if ctx['object'].last_state.status.type == "ACCUEIL": |
... | ... | |
577 | 578 |
ctx['object'] = PatientRecord.objects.get(id=self.kwargs['patientrecord_id']) |
578 | 579 |
ctx['service_id'] = self.service.id |
579 | 580 |
if self.request.GET.get('event-id'): |
581 |
date = self.request.GET.get('date') |
|
582 |
date = datetime.strptime(date, '%Y-%m-%d').date() |
|
580 | 583 |
appointment = Appointment() |
581 |
occurrence = Occurrence.objects.get(id=self.request.GET.get('event-id')) |
|
582 |
appointment.init_from_occurrence(occurrence, self.service) |
|
584 |
event = Event.objects.get(id=self.request.GET.get('event-id')) |
|
585 |
event = event.today_occurence(date) |
|
586 |
appointment.init_from_event(event, self.service) |
|
583 | 587 |
ctx['appointment'] = appointment |
584 | 588 |
return ctx |
585 | 589 |
|
... | ... | |
632 | 636 |
else: |
633 | 637 |
qs = qs.filter(last_state__status__type__in='') |
634 | 638 |
|
635 |
qs_events = Occurrence.objects.select_related('event') |
|
636 | 639 |
try: |
637 | 640 |
date_actes_start = datetime.strptime(form.data['date_actes_start'], "%d/%m/%Y") |
638 |
qs_events = qs_events.filter(models.Q(start_time__gte=date_actes_start))
|
|
641 |
qs = qs.filter(act_set__date__gte=date_actes_start.date())
|
|
639 | 642 |
except (ValueError, KeyError): |
640 |
date_actes_start = None
|
|
643 |
pass
|
|
641 | 644 |
try: |
642 | 645 |
date_actes_end = datetime.strptime(form.data['date_actes_end'], "%d/%m/%Y") |
643 |
qs_events = qs_events.filter(models.Q(end_time__lte=date_actes_end))
|
|
646 |
qs = qs.filter(act_set__date__lte=date_actes_end.date())
|
|
644 | 647 |
except (ValueError, KeyError): |
645 |
date_actes_end = None |
|
646 |
|
|
647 |
if date_actes_start or date_actes_end: |
|
648 |
qs = qs.filter(id__in=[x.event.eventact.patient.id for x in qs_events]) |
|
649 |
|
|
648 |
pass |
|
650 | 649 |
qs = qs.filter(service=self.service).order_by('last_name') |
651 | 650 |
return qs |
652 | 651 |
|
Also available in: Unified diff
agenda/actes/dossiers: move Occurence fields into Event, add recurring events support