Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOWED_METHODS = ["GET"]

CSRF_COOKIE_SECURE = config("DJANGO_CSRF_COOKIE_SECURE", cast=bool, default=False) # Only if using HTTPS
CSRF_COOKIE_HTTPONLY = config("DJANGO_CSRF_COOKIE_HTTPONLY", cast=bool, default=False) # Must be False for JavaScript access
CSRF_COOKIE_SECURE = config(
"DJANGO_CSRF_COOKIE_SECURE", cast=bool, default=False
) # Only if using HTTPS
CSRF_COOKIE_HTTPONLY = config(
"DJANGO_CSRF_COOKIE_HTTPONLY", cast=bool, default=False
) # Must be False for JavaScript access
CSRF_COOKIE_SAMESITE = config("DJANGO_CSRF_COOKIE_SAMESITE", default="Lax") # or 'Strict' or 'None'
CSRF_TRUSTED_ORIGINS = config("DJANGO_CSRF_TRUSTED_DOMAINS", default="").split(",") # Add your domains
CSRF_TRUSTED_ORIGINS = config("DJANGO_CSRF_TRUSTED_DOMAINS", default="").split(
","
) # Add your domains

if DEBUG:
# in development, allow the frontend app to POST forms to the backend
Expand Down Expand Up @@ -226,6 +232,7 @@
"rest_framework.authentication.SessionAuthentication",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
}

SPECTACULAR_SETTINGS = {
Expand Down Expand Up @@ -322,11 +329,7 @@
"handlers": ["console"],
"level": LOG_LEVEL,
},
'django.security.csrf': {
'handlers': ['console'],
'level': LOG_LEVEL,
'propagate': False
},
"django.security.csrf": {"handlers": ["console"], "level": LOG_LEVEL, "propagate": False},
},
}

Expand Down
2 changes: 1 addition & 1 deletion backend/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# See app/tests/test_routing.py for validation tests to ensure that changes
# inside npdfhir.urls don't break our routing configuration.
path("fhir/", include("npdfhir.urls")),
path("fhir", npdfhir_router.get_api_root_view, name="api-root"),
path("fhir", npdfhir_router.get_api_root_view(), name="api-root"),
path("admin/", admin.site.urls),
# everything else goes to provider_directory
path("", include("provider_directory.urls")),
Expand Down
4 changes: 2 additions & 2 deletions backend/npdfhir/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ class CapabilityStatementSerializer(serializers.Serializer):
Serializer for FHIR CapablityStatement resource
"""

def to_representation(self, instance):
def to_representation(self):
request = self.context.get("request")
baseURL = request.build_absolute_uri("/fhir")
metadataURL = request.build_absolute_uri(reverse("fhir-metadata"))
schemaData = get_schema_data(request, "schema")
schemaData = get_schema_data(request)

capability_statement = CapabilityStatement(
url=metadataURL,
Expand Down
8 changes: 8 additions & 0 deletions backend/npdfhir/tests/test_basic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ def test_health_view(self):
res_obj = response.json()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(res_obj["status"], "healthy")

def test_fhir_endpoint_list_without_slash(self):
response = self.client.get("/fhir")
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_fhir_endpoint_list_with_slash(self):
response = self.client.get("/fhir/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
2 changes: 1 addition & 1 deletion backend/npdfhir/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
re_path("docs/redoc/?", SpectacularRedocView.as_view(url_name="schema"), name="schema-redoc"),
re_path("docs/?", SpectacularSwaggerView.as_view(url_name="schema"), name="schema-swagger-ui"),
path("healthCheck", views.health, name="healthCheck"),
path("metadata", views.FHIRCapabilityStatementView.as_view(), name="fhir-metadata"),
path("metadata/?", views.FHIRCapabilityStatementView.as_view(), name="fhir-metadata"),
# Router URLs
# everything else is passed to the rest_framework router to manage
path("", include(router.urls), name="index"),
Expand Down
18 changes: 8 additions & 10 deletions backend/npdfhir/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import reverse
from fhir.resources.R4B.address import Address
from fhir.resources.R4B.reference import Reference
from rest_framework.test import APIClient
from drf_spectacular.views import SpectacularJSONAPIView


def SmartyStreetstoFHIR(address):
Expand All @@ -17,15 +17,13 @@ def SmartyStreetstoFHIR(address):
)


def get_schema_data(request, url_name, additional_args=None):
client = APIClient()
if request.user:
# reuse the authenticated user from the active request to make the
# internal request to retrieve the current schema
client.force_authenticate(user=request.user)
schema_url = reverse(url_name, kwargs=additional_args)
response = client.get(schema_url)
return response.data
def get_schema_data(request):
schema_view = SpectacularJSONAPIView.as_view()
response = schema_view(request._request)
# The response contains the schema data in its .data attribute
schema_data = response.data

return schema_data


def genReference(url_name, identifier, request):
Expand Down
9 changes: 6 additions & 3 deletions backend/npdfhir/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,10 @@ def get(self, request):
"""
Query metadata about this FHIR instance, represented as FHIR CapabilityStatement resource
"""
serializer = CapabilityStatementSerializer(context={"request": request})
response = serializer.to_representation(None)
serialized_capability_statement = CapabilityStatementSerializer(
context={"request": request}
)

response = Response(serialized_capability_statement.to_representation())

return Response(response)
return response