Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1867 | Brief response with checksums only f…
Browse files Browse the repository at this point in the history
…or concepts and mappings | allowing max limit of 20000
  • Loading branch information
snyaggarwal committed Nov 29, 2024
1 parent 0f01ea9 commit f284536
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
VERBOSE_PARAM = 'verbose'
RAW_PARAM = 'raw'
BRIEF_PARAM = 'brief'
CHECKSUMS_PARAM = 'checksums'
UPDATED_SINCE_PARAM = 'updatedSince'
UPDATED_BY_USERNAME_PARAM = 'updatedBy'
LAST_LOGIN_SINCE_PARAM = 'lastLoginSince'
Expand Down
7 changes: 6 additions & 1 deletion core/common/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ def list(self, request, *args, **kwargs): # pylint:disable=too-many-locals
headers = {}
results = sorted_list
paginator = None

if not compress:
if not self.limit or int(self.limit) == 0 or int(self.limit) > 1000:
self.limit = LIST_DEFAULT_LIMIT
if self.is_brief() and self.is_checksums() and self.kwargs.get('source') and get(
self, 'model.__name__') in ['Concept', 'Mapping']:
self.limit = 20000 # for checksums
else:
self.limit = LIST_DEFAULT_LIMIT
paginator = CustomPaginator(
request=request, queryset=sorted_list, page_size=self.limit, total_count=self.total_count,
is_sliced=self.should_perform_es_search(), max_score=get(self, '_max_score'),
Expand Down
5 changes: 4 additions & 1 deletion core/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
LIMIT_PARAM, NOT_FOUND, MUST_SPECIFY_EXTRA_PARAM_IN_BODY, INCLUDE_RETIRED_PARAM, VERBOSE_PARAM, HEAD, LATEST, \
BRIEF_PARAM, ES_REQUEST_TIMEOUT, INCLUDE_INACTIVE, FHIR_LIMIT_PARAM, RAW_PARAM, SEARCH_MAP_CODES_PARAM, \
INCLUDE_SEARCH_META_PARAM, EXCLUDE_FUZZY_SEARCH_PARAM, EXCLUDE_WILDCARD_SEARCH_PARAM, UPDATED_BY_USERNAME_PARAM, \
CANONICAL_URL_REQUEST_PARAM
CANONICAL_URL_REQUEST_PARAM, CHECKSUMS_PARAM
from core.common.exceptions import Http400
from core.common.mixins import PathWalkerMixin
from core.common.search import CustomESSearch
Expand Down Expand Up @@ -97,6 +97,9 @@ def is_raw(self):
def is_brief(self):
return self.request.query_params.get(BRIEF_PARAM, False) in TRUTHY

def is_checksums(self):
return self.request.query_params.get(CHECKSUMS_PARAM, False) in TRUTHY

def is_hard_delete_requested(self):
return self.request.query_params.get('hardDelete', None) in TRUTHY

Expand Down
10 changes: 10 additions & 0 deletions core/concepts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ class Meta:
fields = ConceptAbstractSerializer.Meta.fields + ('id', 'type', 'url', 'version_url', 'retired')


class ConceptChecksumSerializer(AbstractResourceSerializer):
id = EncodedDecodedCharField(source='mnemonic', read_only=True)
type = CharField(source='resource_type', read_only=True)
url = CharField(source='uri', read_only=True)

class Meta:
model = Concept
fields = AbstractResourceSerializer.Meta.fields + ('id', 'type', 'url', 'checksums')


class ConceptCascadeMinimalSerializer(ConceptMinimalSerializer):
class Meta:
model = Concept
Expand Down
4 changes: 3 additions & 1 deletion core/concepts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ConceptDetailSerializer, ConceptListSerializer, ConceptDescriptionSerializer, ConceptNameSerializer,
ConceptVersionDetailSerializer,
ConceptVersionListSerializer, ConceptSummarySerializer, ConceptMinimalSerializer,
ConceptChildrenSerializer, ConceptParentsSerializer, ConceptLookupListSerializer)
ConceptChildrenSerializer, ConceptParentsSerializer, ConceptLookupListSerializer, ConceptChecksumSerializer)
from core.mappings.serializers import MappingListSerializer
from core.tasks.models import Task

Expand Down Expand Up @@ -141,6 +141,8 @@ def get_serializer_class(self):
is_get = method == 'GET'

if is_get and self.is_brief():
if self.is_checksums():
return ConceptChecksumSerializer
return ConceptMinimalSerializer
if (is_get and self.is_verbose()) or method == 'POST':
return ConceptDetailSerializer
Expand Down
12 changes: 12 additions & 0 deletions core/mappings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class MappingChecksumSerializer(AbstractResourceSerializer):
id = CharField(source='mnemonic', read_only=True)
type = CharField(source='resource_type', read_only=True)
url = CharField(source='uri', read_only=True)

class Meta:
model = Mapping
fields = AbstractResourceSerializer.Meta.fields + (
'checksums', 'from_concept_url', 'to_concept_url', 'id', 'type', 'url', 'map_type'
)


class MappingMinimalSerializer(AbstractMappingSerializer):
id = CharField(source='mnemonic', read_only=True)
type = CharField(source='resource_type', read_only=True)
Expand Down
4 changes: 3 additions & 1 deletion core/mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from core.mappings.models import Mapping
from core.mappings.search import MappingFacetedSearch
from core.mappings.serializers import MappingDetailSerializer, MappingListSerializer, MappingVersionListSerializer, \
MappingVersionDetailSerializer, MappingMinimalSerializer
MappingVersionDetailSerializer, MappingMinimalSerializer, MappingChecksumSerializer


class MappingBaseView(SourceChildCommonBaseView):
Expand Down Expand Up @@ -55,6 +55,8 @@ def get_serializer_class(self):
method = self.request.method
is_get = method == 'GET'
if is_get and self.is_brief():
if self.is_checksums():
return MappingChecksumSerializer
return MappingMinimalSerializer

if (is_get and self.is_verbose()) or method == 'POST':
Expand Down

0 comments on commit f284536

Please sign in to comment.