Revision 76974b6f
Added by Benjamin Dauvergne almost 12 years ago
calebasse/actes/models.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 |
from datetime import date |
|
3 |
|
|
2 | 4 |
from django.db import models |
3 | 5 |
from django.contrib.auth.models import User |
4 | 6 |
|
... | ... | |
40 | 42 |
return VALIDATION_STATES[self.state_name] |
41 | 43 |
|
42 | 44 |
|
45 |
class ActManager(models.Manager): |
|
46 |
def create_act(self, author=None, **kwargs): |
|
47 |
act = self.create(**kwargs) |
|
48 |
ActValidationState.objects.create(act=act,state_name='NON_VALIDE', |
|
49 |
author=author, previous_state=None) |
|
50 |
return act |
|
51 |
|
|
52 |
def next_acts(self, patient_record, today=None): |
|
53 |
today = today or date.today() |
|
54 |
return self.filter(date__gte=today) \ |
|
55 |
.filter(patient=patient_record) \ |
|
56 |
.order_by('date') |
|
57 |
|
|
58 |
def last_acts(self, patient_record, today=None): |
|
59 |
today = today or date.today() |
|
60 |
return self.filter(date__lte=today) \ |
|
61 |
.filter(patient=patient_record) \ |
|
62 |
.order_by('-date') |
|
63 |
|
|
64 |
|
|
43 | 65 |
class Act(models.Model): |
66 |
objects = ActManager() |
|
67 |
|
|
44 | 68 |
patient = models.ForeignKey('dossiers.PatientRecord') |
45 |
date = models.DateTimeField() |
|
69 |
date = models.DateField() |
|
70 |
_duration = models.IntegerField(u'Durée en minutes', default=0) |
|
46 | 71 |
act_type = models.ForeignKey('ressources.ActType', |
47 | 72 |
verbose_name=u'Type d\'acte') |
48 | 73 |
validation_locked = models.BooleanField(default=False, |
... | ... | |
68 | 93 |
verbose_name=u'Intervenants') |
69 | 94 |
pause = models.BooleanField(default=False, |
70 | 95 |
verbose_name=u'Pause facturation') |
96 |
parent_event = models.ForeignKey('agenda.Event', |
|
97 |
verbose_name=u'Rendez-vous lié', |
|
98 |
blank=True, null=True) |
|
99 |
VALIDATION_CODE_CHOICES = ( |
|
100 |
('absent', u'Absent'), |
|
101 |
('present', u'Présent'), |
|
102 |
) |
|
103 |
attendance = models.CharField(max_length=16, |
|
104 |
choices=VALIDATION_CODE_CHOICES, |
|
105 |
default='absent', |
|
106 |
verbose_name=u'Présence') |
|
107 |
convocation_sent = models.BooleanField(blank=True, |
|
108 |
verbose_name=u'Convoqué') |
|
109 |
|
|
110 |
@property |
|
111 |
def event(self): |
|
112 |
if self.parent_event: |
|
113 |
return self.parent_event.today_occurence(self.date) |
|
114 |
return None |
|
115 |
|
|
116 |
@property |
|
117 |
def start_time(self): |
|
118 |
event = self.event |
|
119 |
if event: |
|
120 |
return event.start_datetime.timetz() |
|
121 |
return None |
|
71 | 122 |
|
72 | 123 |
def get_hc_tag(self): |
73 | 124 |
if self.healthcare: |
... | ... | |
155 | 206 |
if not hc: |
156 | 207 |
# On pourrait ici créer une prise en charge de diagnostic |
157 | 208 |
return (False, None) |
158 |
if self.date.date() < hc.start_date:
|
|
209 |
if self.date < hc.start_date: |
|
159 | 210 |
return (False, None) |
160 | 211 |
# Les acts facturés déja couvert par la prise en charge sont pointés |
161 | 212 |
# dans hc.act_set.all() |
... | ... | |
172 | 223 |
for a in acts_billable: |
173 | 224 |
if nb_acts_billed + count >= hc.get_act_number(): |
174 | 225 |
return (False, None) |
175 |
if a.date.date() >= hc.start_date:
|
|
226 |
if a.date >= hc.start_date: |
|
176 | 227 |
if a.id == self.id: |
177 | 228 |
return (True, hc) |
178 | 229 |
count = count + 1 |
... | ... | |
225 | 276 |
# return (True, hc) |
226 | 277 |
# count = count + 1 |
227 | 278 |
# return (False, None) |
228 |
# END Specific to cmpp healthcare |
|
279 |
# END Specific to cmpp healthcare |
|
280 |
|
|
281 |
def duration(self): |
|
282 |
'''Return a displayable duration for this field.''' |
|
283 |
hours, remainder = divmod(self._duration, 60) |
|
284 |
return '%02d:%02d' % (hours, remainder) |
|
229 | 285 |
|
230 | 286 |
def __unicode__(self): |
231 | 287 |
return u'{0} le {1} pour {2} avec {3}'.format( |
... | ... | |
285 | 341 |
end_datetime=end_datetime, |
286 | 342 |
room=room, note=note, **rrule_params) |
287 | 343 |
|
288 |
def modify_patient_appointment(self, creator, title, patient, participants, |
|
289 |
act_type, service, start_datetime, end_datetime, description='', |
|
290 |
room=None, note=None, **rrule_params): |
|
291 |
""" |
|
292 |
This method allow you to create a new patient appointment quickly |
|
293 |
|
|
294 |
Args: |
|
295 |
creator: author of the modification |
|
296 |
title: patient appointment title (str) |
|
297 |
patient: Patient object |
|
298 |
participants: List of CalebasseUser (therapists) |
|
299 |
act_type: ActType object |
|
300 |
service: Service object. Use session service by defaut |
|
301 |
start_datetime: datetime with the start date and time |
|
302 |
end_datetime: datetime with the end date and time |
|
303 |
description: description of the event |
|
304 |
room: room where the event will take place |
|
305 |
freq, count, until, byweekday, rrule_params: |
|
306 |
follow the ``dateutils`` API (see http://labix.org/python-dateutil) |
|
307 |
|
|
308 |
Example: |
|
309 |
Look at calebasse.agenda.tests.EventTest (test_create_appointments |
|
310 |
method) |
|
311 |
""" |
|
312 |
|
|
313 |
event_type, created = EventType.objects.get_or_create( |
|
314 |
label=u"Rendez-vous patient" |
|
315 |
) |
|
316 |
|
|
317 |
act_event = EventAct.objects.create( |
|
318 |
title=title, |
|
319 |
event_type=event_type, |
|
320 |
patient=patient, |
|
321 |
act_type=act_type, |
|
322 |
date=start_datetime, |
|
323 |
) |
|
324 |
act_event.doctors = participants |
|
325 |
ActValidationState(act=act_event, state_name=NON_VALIDE, |
|
326 |
author=creator, previous_state=None).save() |
|
327 |
|
|
328 |
return self._set_event(act_event, participants, description, |
|
329 |
services=[service], start_datetime=start_datetime, |
|
330 |
end_datetime=end_datetime, |
|
331 |
room=room, note=note, **rrule_params) |
|
332 |
|
|
333 |
class EventAct(Event, Act): |
|
334 |
objects = EventActManager() |
|
335 |
|
|
336 |
VALIDATION_CODE_CHOICES = ( |
|
337 |
('absent', u'Absent'), |
|
338 |
('present', u'Présent'), |
|
339 |
) |
|
340 |
attendance = models.CharField(max_length=16, |
|
341 |
choices=VALIDATION_CODE_CHOICES, |
|
342 |
default='absent', |
|
343 |
verbose_name=u'Présence') |
|
344 |
convocation_sent = models.BooleanField(blank=True, |
|
345 |
verbose_name=u'Convoqué') |
|
346 |
|
|
347 |
def __unicode__(self): |
|
348 |
return u'Rdv le {0} de {1} avec {2} pour {3}'.format( |
|
349 |
self.occurrence_set.all()[0].start_time, self.patient, |
|
350 |
', '.join(map(unicode, self.participants.all())), |
|
351 |
self.act_type) |
|
352 |
|
|
353 |
def __repr__(self): |
|
354 |
return (u'<%s %r %r>' % (self.__class__.__name__, unicode(self), |
|
355 |
self.id)).encode('utf-8') |
|
356 |
|
|
357 |
def start_time(self): |
|
358 |
return self.occurrence_set.all()[0].start_time |
|
359 |
|
|
360 |
def duration(self): |
|
361 |
o = self.occurrence_set.all()[0] |
|
362 |
td = o.end_time - o.start_time |
|
363 |
hours, remainder = divmod(td.seconds, 3600) |
|
364 |
minutes, remainder = divmod(remainder, 60) |
|
365 |
return '%02d:%02d' % (hours, minutes) |
|
366 |
|
|
367 |
class Meta: |
|
368 |
verbose_name = 'Rendez-vous patient' |
|
369 |
verbose_name_plural = 'Rendez-vous patient' |
|
370 |
ordering = ['-date', 'patient'] |
|
371 |
|
|
372 |
reversion.register(EventAct, follow=['act_ptr', 'event_ptr']) |
|
373 | 344 |
|
374 | 345 |
class ValidationMessage(ServiceLinkedAbstractModel): |
375 | 346 |
validation_date = models.DateTimeField() |
Also available in: Unified diff
agenda/actes/dossiers: move Occurence fields into Event, add recurring events support