Project

General

Profile

Download (3.84 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / actes / models.py @ 74ba9776

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
        act_event.doctors = participants
77

    
78
        return self._set_event(act_event, participants, description,
79
                services = [service], start_datetime = start_datetime, end_datetime = end_datetime,
80
                room = room, note = note, **rrule_params)
81

    
82

    
83
class EventAct(Act, Event):
84
    objects = EventActManager()
85

    
86
    VALIDATION_CODE_CHOICES = (
87
            ('absent', u'Absent'),
88
            ('present', u'Présent'),
89
            )
90
    attendance = models.CharField(max_length=16,
91
            choices=VALIDATION_CODE_CHOICES,
92
            default='absent',
93
            verbose_name=u'Présence')
94
    convocation_sent = models.BooleanField(blank=True,
95
            verbose_name=u'Convoqué')
96

    
97
    def __unicode__(self):
98
        return 'Rdv le {0} de {1} avec {2} pour {3}'.format(
99
                self.occurrence_set.all()[0].start_time, self.patient,
100
                ', '.join(map(unicode, self.participants.all())), self.act_type)
101

    
102
    def __repr__(self):
103
        return '<%s %r %r>' % (self.__class__.__name__, unicode(self), self.id)
104

    
105
    class Meta:
106
        verbose_name = 'Rendez-vous patient'
107
        verbose_name_plural = 'Rendez-vous patient'
108
        ordering = ['-date', 'patient']
(4-4/7)