1- from rest_framework import viewsets , permissions
2- from rest_framework .response import Response
3-
4- from apps .fhir .bluebutton .views .generic import FhirDataView
1+ from apps .fhir .bluebutton .views .viewsets_base import ResourceViewSet
52from apps .fhir .bluebutton .views .search import HasSearchScope , SearchView
63from apps .authorization .permissions import DataAccessGrantPermission
74from apps .capabilities .permissions import TokenHasProtectedCapability
118 ResourcePermission ,
129 ApplicationActivePermission ,
1310)
11+ from rest_framework import permissions
1412
1513
16- class PatientViewSet (FhirDataView , viewsets . ViewSet ):
14+ class PatientViewSet (ResourceViewSet ):
1715 """Patient django-rest-framework ViewSet experiment
1816
1917 Args:
@@ -24,51 +22,31 @@ class PatientViewSet(FhirDataView, viewsets.ViewSet):
2422 version = 1
2523 resource_type = 'Patient'
2624
27- QUERY_TRANSFORMS = getattr (SearchView , 'QUERY_TRANSFORMS' , {})
28- QUERY_SCHEMA = {** getattr (SearchView , 'QUERY_SCHEMA' , {}), '_id' : str , 'identifier' : str }
29-
30- required_scopes = ['patient/Patient.read' , 'patient/Patient.rs' , 'patient/Patient.s' ]
31-
32- def __init__ (self , version = 1 , ** kwargs ):
33- super ().__init__ (version )
25+ # TODO - I don't love the separation here, could be indicative that we don't want to move to resource based ViewSets, or that
26+ # we need a better base class, or these differences should be defined in PatientViewSet.
27+ SEARCH_QUERY_TRANSFORMS = getattr (SearchView , 'QUERY_TRANSFORMS' , {})
28+ SEARCH_QUERY_SCHEMA = {** getattr (SearchView , 'QUERY_SCHEMA' , {}), '_id' : str , 'identifier' : str }
3429
35- def initial (self , request , * args , ** kwargs ):
36- return super ().initial (request , self .resource_type , * args , ** kwargs )
30+ SEARCH_PERMISSION_CLASSES = (
31+ permissions .IsAuthenticated ,
32+ ApplicationActivePermission ,
33+ ResourcePermission ,
34+ SearchCrosswalkPermission ,
35+ DataAccessGrantPermission ,
36+ TokenHasProtectedCapability ,
37+ HasSearchScope ,
38+ )
3739
38- def get_permissions (self ):
39- action = getattr (self , 'action' , None )
40- if action == 'list' :
41- perm_classes = [
42- permissions .IsAuthenticated ,
43- ApplicationActivePermission ,
44- ResourcePermission ,
45- SearchCrosswalkPermission ,
46- DataAccessGrantPermission ,
47- TokenHasProtectedCapability ,
48- HasSearchScope ,
49- ]
50- else :
51- perm_classes = [
52- permissions .IsAuthenticated ,
53- ApplicationActivePermission ,
54- ResourcePermission ,
55- ReadCrosswalkPermission ,
56- DataAccessGrantPermission ,
57- TokenHasProtectedCapability ,
58- ]
59- return [p () for p in perm_classes ]
60-
61- def list (self , request , * args , ** kwargs ):
62- '''Equivalent to get()/search in FhirDataView'''
63- out = self .fetch_data (request , self .resource_type , * args , ** kwargs )
64- return Response (out )
40+ READ_PERMISSION_CLASSES = (
41+ permissions .IsAuthenticated ,
42+ ApplicationActivePermission ,
43+ ResourcePermission ,
44+ ReadCrosswalkPermission ,
45+ DataAccessGrantPermission ,
46+ TokenHasProtectedCapability ,
47+ )
6548
66- def retrieve (self , request , resource_id = None , * args , ** kwargs ):
67- out = self .fetch_data (request , self .resource_type , resource_id = resource_id , * args , ** kwargs )
68- return Response (out )
69-
70- def build_parameters (self , request ):
71- return {'_format' : 'application/json+fhir' }
49+ required_scopes = ['patient/Patient.read' , 'patient/Patient.rs' , 'patient/Patient.s' ]
7250
7351 def build_url (self , fhir_settings , resource_type , resource_id = None , * args , ** kwargs ):
7452 if fhir_settings .fhir_url .endswith ('v1/fhir/' ):
0 commit comments