Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1761 | fixing middleware and pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed May 1, 2024
1 parent ac3cfae commit f8e8464
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/common/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def render(self, data, accepted_media_type=None, renderer_context=None):


class FhirRenderer(JSONRenderer):
media_type = 'application/fhir+json'
media_type = 'application/fhir+json'
20 changes: 10 additions & 10 deletions core/middlewares/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time

import requests
from django.http import HttpResponseNotFound, HttpRequest, HttpResponse
from django.http import HttpResponseNotFound, HttpResponse
from request_logging.middleware import LoggingMiddleware

from core.common.constants import VERSION_HEADER, REQUEST_USER_HEADER, RESPONSE_TIME_HEADER, REQUEST_URL_HEADER, \
Expand Down Expand Up @@ -107,26 +107,26 @@ def __call__(self, request):
elif is_fhir_resource:
return HttpResponseNotFound()

if settings.FHIR_VALIDATOR_URL and ('/CodeSystem/' in absolute_uri or '/ValueSet/' in absolute_uri or
'/ConceptMap' in absolute_uri):
accept_content_type = request.headers.get('Accept')
content_type = request.headers.get('Content-Type')
if settings.FHIR_VALIDATOR_URL and (
'/CodeSystem/' in absolute_uri or '/ValueSet/' in absolute_uri or '/ConceptMap' in absolute_uri):
accept_content_type = request.headers.get('Accept', '')
content_type = request.headers.get('Content-Type', '')

if content_type.startswith('application/xml') or content_type.startswith('application/fhir+xml'):
request.META['CONTENT_TYPE'] = "application/json"
if request.method == 'POST' or request.method == 'PUT':
if request.method in ['POST', 'PUT']:
json_request = requests.post(settings.FHIR_VALIDATOR_URL +
'/convert?version=4.0&type=xml&toType=json', data=request.body)
request._body = json_request

if accept_content_type.startswith('application/xml') or \
accept_content_type.startswith('application/fhir+xml'):
if accept_content_type.startswith(
'application/xml') or accept_content_type.startswith('application/fhir+xml'):
request.META['HTTP_ACCEPT'] = "application/json"

response = self.get_response(request)

if accept_content_type.startswith('application/xml') or \
accept_content_type.startswith('application/fhir+xml'):
if accept_content_type.startswith(
'application/xml') or accept_content_type.startswith('application/fhir+xml'):
xml_response = requests.post(settings.FHIR_VALIDATOR_URL + '/convert?version=4.0&type=json&toType=xml',
data=response.content)
response = HttpResponse(xml_response, content_type=accept_content_type)
Expand Down

0 comments on commit f8e8464

Please sign in to comment.