Skip to content

Commit 3e85c02

Browse files
modifying protected capability statements and permission checking
1 parent b347722 commit 3e85c02

File tree

10 files changed

+28
-12
lines changed

10 files changed

+28
-12
lines changed

apps/authorization/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DataAccessGrantPermission(permissions.BasePermission):
99
"""
1010
Permission check for a Grant related to the token used.
1111
"""
12-
def has_permission(self, request, view):
12+
def has_permission(self, request, view) -> bool: # type: ignore
1313
dag = None
1414
try:
1515
dag = DataAccessGrant.objects.get(

apps/capabilities/management/commands/create_blue_button_scopes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,20 @@ def create_coverage_read_search_capability(group,
260260
protected_resources=json.dumps(pr, indent=4))
261261
return c
262262

263+
def create_insurance_card_capability(group, fhir_prefix, title="Digital Insurance Card access."):
264+
c = None
265+
description = "Digital Insurance Card"
266+
# TODO - this is not a real FHIR resource or scope, decision on how we want ot handle this
267+
smart_scope_string = "patient/DigitalInsuranceCard.read"
268+
pr = []
269+
pr.append(["GET", "%sDigitalInsuranceCard[/]?$" % fhir_prefix])
270+
if not ProtectedCapability.objects.filter(slug=smart_scope_string).exists():
271+
c = ProtectedCapability.objects.create(group=group,
272+
title=title,
273+
description=description,
274+
slug=smart_scope_string,
275+
protected_resources=json.dumps(pr, indent=4))
276+
return c
263277

264278
def create_launch_capability(group, fhir_prefix, title="Patient launch context."):
265279

@@ -296,5 +310,6 @@ def handle(self, *args, **options):
296310
create_coverage_read_capability(g, fhir_prefix)
297311
create_coverage_search_capability(g, fhir_prefix)
298312
create_coverage_read_search_capability(g, fhir_prefix)
313+
create_insurance_card_capability(g, fhir_prefix)
299314
create_launch_capability(g, fhir_prefix)
300315
create_openid_capability(g)

apps/capabilities/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BBCapabilitiesPermissionTokenScopeMissingException(APIException):
1616

1717
class TokenHasProtectedCapability(permissions.BasePermission):
1818

19-
def has_permission(self, request, view):
19+
def has_permission(self, request, view) -> bool: # type: ignore
2020
token = request.auth
2121
access_token_query_param = request.GET.get("access_token", None)
2222

apps/fhir/bluebutton/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ALLOWED_RESOURCE_TYPES = ['Patient', 'Coverage', 'ExplanationOfBenefit']
1+
ALLOWED_RESOURCE_TYPES = ['Patient', 'Coverage', 'ExplanationOfBenefit', 'Bundle']
22
DEFAULT_PAGE_SIZE = 10
33
MAX_PAGE_SIZE = 50

apps/fhir/bluebutton/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def has_object_permission(self, request, view, obj):
7272

7373

7474
class SearchCrosswalkPermission(HasCrosswalk):
75-
def has_object_permission(self, request, view, obj): # type: ignore
75+
def has_object_permission(self, request, view, obj) -> bool: # type: ignore
7676
if view.version in Versions.supported_versions():
7777
patient_id = request.crosswalk.fhir_id(view.version)
7878
else:

apps/fhir/bluebutton/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ def notNone(value=None, default=None):
323323

324324
def FhirServerAuth() -> dict:
325325
"""Helper class to modify cert paths if client_auth is true
326-
TODO - this can probably be refactored or removed, rolled into the FHIRServerSettings class
326+
TODO - this can probably be refactored or removed, rolled into the FHIRServerSettings class, all it does is a conditional
327+
settings check
327328
328329
Returns:
329330
dict: A dictionary with the following:

apps/fhir/bluebutton/v3/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
),
5555
# C4DIC
5656
# Digital Insurance Card ViewSet
57+
# TODO - Change the URI for this endpoint when we finalize
5758
re_path(
5859
r'DigitalInsuranceCard[/]?',
5960
waffle_switch('v3_endpoints')(DigitalInsuranceCardViewSet.as_view({'get': 'list'}, version=3)),

apps/fhir/bluebutton/views/insurancecard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def build_parameters(self, request):
4848
'_format': 'application/json+fhir'
4949
}
5050

51-
def build_url(self, fhir_settings, resource_type, resource_id, **kwargs): # type: ignore
51+
def build_url(self, fhir_settings, resource_type, resource_id=None, *args, **kwargs):
5252
if fhir_settings.fhir_url.endswith('v1/fhir/'):
5353
# only if called by tests
54-
return '{}{}/{}/'.format(fhir_settings.fhir_url, resource_type, resource_id)
54+
return f"{fhir_settings.fhir_url}{resource_type}/"
5555
else:
56-
if self.version == 3 and fhir_settings.fhir_url_v3:
56+
if self.version == 3 and getattr(fhir_settings, 'fhir_url_v3', None):
5757
fhir_url = fhir_settings.fhir_url_v3
5858
else:
5959
fhir_url = fhir_settings.fhir_url
60-
return f'{fhir_url}/v{self.version}/fhir/{resource_type}/{resource_id}/'
60+
return f"{fhir_url}/v{self.version}/fhir/Patient/{resource_id}/$generate-insurance-card"

apps/fhir/bluebutton/views/insurancecard_viewset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,4 @@ def build_url(self, fhir_settings, resource_type, resource_id=None, *args, **kwa
6767
fhir_url = fhir_settings.fhir_url_v3
6868
else:
6969
fhir_url = fhir_settings.fhir_url
70-
71-
return f"{fhir_url}/v{self.version}/fhir/{resource_type}/"
70+
return f"{fhir_url}/v{self.version}/fhir/Patient/{resource_id}/$generate-insurance-card"

apps/fhir/bluebutton/views/patient_viewset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_permissions(self):
5959
return [p() for p in perm_classes]
6060

6161
def list(self, request, *args, **kwargs):
62-
'''Equivalent to get() in FhirDataView'''
62+
'''Equivalent to get()/search in FhirDataView'''
6363
out = self.fetch_data(request, self.resource_type, *args, **kwargs)
6464
return Response(out)
6565

0 commit comments

Comments
 (0)