1
|
import datetime
|
2
|
|
3
|
from tastypie.authorization import Authorization
|
4
|
from tastypie.resources import ModelResource
|
5
|
from calebasse.actes.models import Act
|
6
|
from calebasse.agenda.models import Event
|
7
|
from calebasse.dossiers.models import PatientRecord, PatientAddress
|
8
|
|
9
|
|
10
|
class EventResource(ModelResource):
|
11
|
class Meta:
|
12
|
queryset = Event.objects.all()
|
13
|
resource_name = 'event'
|
14
|
authorization = Authorization()
|
15
|
|
16
|
def obj_get(self, bundle, **kwargs):
|
17
|
'''If a date parameter is passed, use it to specialize the Event
|
18
|
instance for this date.'''
|
19
|
request = bundle.request
|
20
|
date = None
|
21
|
if 'date' in request.GET:
|
22
|
date = request.GET['date']
|
23
|
date = datetime.datetime.strptime(date, '%Y-%m-%d').date()
|
24
|
obj = super(EventResource, self).obj_get(bundle, **kwargs)
|
25
|
if date:
|
26
|
obj = obj.today_occurrence(date)
|
27
|
return obj
|
28
|
|
29
|
class PatientRecordRessource(ModelResource):
|
30
|
class Meta:
|
31
|
queryset = PatientRecord.objects.all()
|
32
|
resource_name = 'patientrecord'
|
33
|
authorization = Authorization()
|
34
|
|
35
|
class PatientAddressRessource(ModelResource):
|
36
|
class Meta:
|
37
|
queryset = PatientAddress.objects.all()
|
38
|
resource_name = 'patientaddress'
|
39
|
authorization = Authorization()
|
40
|
|
41
|
class ActRessource(ModelResource):
|
42
|
class Meta:
|
43
|
queryset = Act.objects.all()
|
44
|
resource_name = 'act'
|
45
|
authorization = Authorization()
|
46
|
|
47
|
patientaddress_ressource = PatientAddressRessource()
|
48
|
event_resource = EventResource()
|
49
|
patientrecord_resource = PatientRecordRessource()
|
50
|
act_ressource = ActRessource()
|
51
|
|