1
|
# -*- coding: utf-8 -*-
|
2
|
|
3
|
from django.db import models
|
4
|
|
5
|
from calebasse.agenda.models import Event, EventType
|
6
|
from calebasse.agenda.managers import EventManager
|
7
|
|
8
|
class Act(models.Model):
|
9
|
act_type = models.ForeignKey('ressources.ActType',
|
10
|
verbose_name=u'Type d\'acte')
|
11
|
validated = models.BooleanField(blank=True,
|
12
|
verbose_name=u'Validé')
|
13
|
date = models.DateTimeField()
|
14
|
patient = models.ForeignKey('dossiers.PatientRecord')
|
15
|
transport_company = models.ForeignKey('ressources.TransportCompany',
|
16
|
blank=True,
|
17
|
null=True,
|
18
|
verbose_name=u'Compagnie de transport')
|
19
|
transport_type = models.ForeignKey('ressources.TransportType',
|
20
|
blank=True,
|
21
|
null=True,
|
22
|
verbose_name=u'Type de transport')
|
23
|
doctors = models.ManyToManyField('personnes.Worker',
|
24
|
limit_choices_to={'type__intervene': True },
|
25
|
verbose_name=u'Thérapeutes')
|
26
|
|
27
|
def __unicode__(self):
|
28
|
return '{0} le {1} pour {2} avec {3}'.format(
|
29
|
self.act_type, self.date, self.patient,
|
30
|
', '.join(map(unicode, self.doctors.all())))
|
31
|
|
32
|
def __repr__(self):
|
33
|
return '<%s %r %r>' % (self.__class__.__name__, unicode(self), self.id)
|
34
|
|
35
|
|
36
|
class Meta:
|
37
|
verbose_name = u"Acte"
|
38
|
verbose_name_plural = u"Actes"
|
39
|
ordering = ['-date', 'patient']
|
40
|
|
41
|
|
42
|
class EventActManager(EventManager):
|
43
|
|
44
|
def create_patient_appointment(self, title, patient, participants, act_type,
|
45
|
service, start_datetime, end_datetime, description='', room=None,
|
46
|
note=None, **rrule_params):
|
47
|
"""
|
48
|
This method allow you to create a new patient appointment quickly
|
49
|
|
50
|
Args:
|
51
|
title: patient appointment title (str)
|
52
|
patient: Patient object
|
53
|
participants: List of CalebasseUser (therapists)
|
54
|
act_type: ActType object
|
55
|
service: Service object. Use session service by defaut
|
56
|
start_datetime: datetime with the start date and time
|
57
|
end_datetime: datetime with the end date and time
|
58
|
freq, count, until, byweekday, rrule_params:
|
59
|
follow the ``dateutils`` API (see http://labix.org/python-dateutil)
|
60
|
|
61
|
Example:
|
62
|
Look at calebasse.agenda.tests.EventTest (test_create_appointments method)
|
63
|
"""
|
64
|
|
65
|
event_type, created = EventType.objects.get_or_create(
|
66
|
label="patient_appointment"
|
67
|
)
|
68
|
|
69
|
act_event = EventAct.objects.create(
|
70
|
title=title,
|
71
|
event_type=event_type,
|
72
|
patient=patient,
|
73
|
act_type=act_type,
|
74
|
date=start_datetime.date(),
|
75
|
)
|
76
|
|
77
|
return self._set_event(act_event, participants, description,
|
78
|
services = [service], start_datetime = start_datetime, end_datetime = end_datetime,
|
79
|
room = room, note = note, **rrule_params)
|
80
|
|
81
|
|
82
|
class EventAct(Act, Event):
|
83
|
objects = EventActManager()
|
84
|
|
85
|
VALIDATION_CODE_CHOICES = (
|
86
|
('absent', u'Absent'),
|
87
|
('present', u'Présent'),
|
88
|
)
|
89
|
attendance = models.CharField(max_length=16,
|
90
|
choices=VALIDATION_CODE_CHOICES,
|
91
|
default='absent',
|
92
|
verbose_name=u'Présence')
|
93
|
convocation_sent = models.BooleanField(blank=True,
|
94
|
verbose_name=u'Convoqué')
|
95
|
|