Skip to content

Commit

Permalink
chore(release): API rendering changes & attribute hotfix (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
ieuans authored Nov 7, 2023
1 parent f53ce1b commit fd29b05
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 51 deletions.
9 changes: 6 additions & 3 deletions CodeListLibrary_project/clinicalcode/api/views/Concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ def get_concept_detail(request, concept_id, version_id=None, export_codes=False)
incl_attributes=True
)
for code in concept_codes:
code['attributes'] = dict(zip(
historical_concept.code_attribute_header, code['attributes']
))
attributes = code.get('attributes')
headers = historical_concept.code_attribute_header
if attributes is not None and headers is not None:
code['attributes'] = dict(zip(
headers, attributes
))

return Response(
data=concept_codes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework import status
from django.db.models.functions import JSONObject
from django.db.models import ForeignKey, F
from rest_framework.renderers import JSONRenderer

from ..models.GenericEntity import GenericEntity
from ..models.Template import Template
Expand All @@ -16,6 +17,11 @@
from . import gen_utils
from . import constants

""" REST renderer """
class PrettyJsonRenderer(JSONRenderer):
def get_indent(self, accepted_media_type, renderer_context):
return 2

""" Parameter validation """

def is_malformed_entity_id(primary_key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,12 @@ def get_concept_component_details(concept_id, concept_history_id, aggregate_code
codes = list(codes)
if format_for_api:
for code in codes:
code['attributes'] = dict(zip(
historical_concept.code_attribute_header, code['attributes']
))
attributes = code.get('attributes')
headers = historical_concept.code_attribute_header
if attributes is not None and headers is not None:
code['attributes'] = dict(zip(
headers, attributes
))

# Append codes to component if required
if include_codes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ def validate_concept_form(form, errors):
component_code.get('attributes'), 'string_array'
)
if isinstance(code_attributes, list):
if len(set(code_attributes)) != len(code_attributes):
errors.append(f'Invalid concept with ID {concept_id} - attribute headers must be unique.')
return None

code_attributes = code_attributes[:len(attribute_headers)]
code['attributes'] = code_attributes

Expand Down
3 changes: 1 addition & 2 deletions CodeListLibrary_project/cll/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ def get_env_value(env_variable, cast=None):

if not BROWSABLEAPI:
REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] = (
'rest_framework.renderers.JSONRenderer',
'rest_framework_xml.renderers.XMLRenderer',
'clinicalcode.entity_utils.api_utils.PrettyJsonRenderer',
)

#==============================================================================#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@
JSON
</a>
</li>
<li aria-label="Export phenotype as XML" role="button" tabindex="0">
<a {% if user_can_export %}
href="{% url 'api:get_generic_entity_detail_by_version' entity.id entity.history_id %}?format=xml"
target=_blank
{% endif %}>
XML
</a>
</li>
</ul>
</label>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ <h3 class="paneltitle" id="API_Header" style="margin-top:20px; margin-bottom:20p
<th>API</th>
</tr>

<tr>
<td>XML</td>
<td>
{% if user.is_authenticated %}
<a href="{% url 'api:get_generic_entity_detail_by_version' entity.id entity.history_id %}?format=xml"
target=_blank>
site_root{% url 'api:get_generic_entity_detail_by_version' entity.id entity.history_id %}?format=xml
</a>
{% else %}
<a href="{% url 'api:get_generic_entity_detail_by_version' entity.id entity.history_id %}?format=xml"
target=_blank>
site_root{% url 'api:get_generic_entity_detail_by_version' entity.id entity.history_id %}?format=xml
</a>
{% endif %}
</td>
</tr>

<tr>
<td>JSON</td>
<td>
Expand Down Expand Up @@ -118,16 +101,6 @@ <h3 class="paneltitle" id="API_Header" style="margin-top:20px; margin-bottom:20p
<th>Format</th>
<th>API</th>
</tr>

<tr>
<td>XML</td>
<td>
<a href="{% url 'api:get_generic_entity_field_by_version' entity.id entity.history_id 'codes' %}?format=xml"
target=_blank>
site_root{% url 'api:get_generic_entity_field_by_version' entity.id entity.history_id 'codes' %}?format=xml
</a>
</td>
</tr>

<tr>
<td>JSON</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
JSON
</a>
</li>
<li aria-label="Export code list as XML" role="button" tabindex="0">
<a {% if user_can_export %}
href="{% url 'api:get_generic_entity_field_by_version' entity.id entity.history_id 'codes' %}?format=xml"
target=_blank {% endif %}
>
XML
</a>
</li>
</ul>

</label>
Expand Down

0 comments on commit fd29b05

Please sign in to comment.