Skip to content

Commit

Permalink
adapter.cases accepts an array of collaborators or just one
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch committed Mar 25, 2019
1 parent ddbd84e commit caa8b8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 9 additions & 6 deletions scout/adapter/mongo/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
class CaseHandler(object):
"""Part of the pymongo adapter that handles cases and institutes"""

def cases(self, owner=None, collaborator=None, query=None, skip_assigned=False,
def cases(self, owner=None, collaborators=None, query=None, skip_assigned=False,
has_causatives=False, reruns=False, finished=False,
research_requested=False, is_research=False, status=None,
phenotype_terms=False, pinned=False, cohort=False, name_query=None,
yield_query=False):
"""Fetches all cases from the backend.
Args:
collaborator(str): If collaborator should be considered
collaborator(str or list): If collaborator(s) should be considered
owner(str): Query cases for specified case owner only
query(dict): If a specific query is used
skip_assigned(bool)
Expand All @@ -53,9 +53,12 @@ def cases(self, owner=None, collaborator=None, query=None, skip_assigned=False,
LOG.debug("Fetch all cases")
query = query or {}

if collaborator:
LOG.debug("Use collaborator {0}".format(collaborator))
query['collaborators'] = collaborator
if collaborators:
LOG.debug("Use collaborators {0}".format(collaborators))
if isinstance(collaborators, str):
query['collaborators'] = collaborators
elif isinstance(collaborators, list):
query['collaborators'] = {'$in' : collaborators}

if owner:
LOG.debug("Use owner {0}".format(owner))
Expand Down Expand Up @@ -321,7 +324,7 @@ def load_case(self, config_data, update=False):
category=category,
rank_threshold=case_obj.get('rank_score_threshold', 0),
)

except (IntegrityError, ValueError, ConfigError, KeyError) as error:
LOG.warning(error)

Expand Down
10 changes: 7 additions & 3 deletions scout/server/blueprints/cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
def index():
"""Display a list of all user institutes."""
institute_objs = user_institutes(store, current_user)
institutes_count = ((institute_obj, store.cases(collaborator=institute_obj['_id']).count())
institutes_count = ((institute_obj, store.cases(collaborators=institute_obj['_id']).count())
for institute_obj in institute_objs if institute_obj)
return dict(institutes=institutes_count)

Expand All @@ -43,16 +43,20 @@ def index():
@templated('cases/cases.html')
def cases(institute_id):
"""Display a list of cases for an institute."""
query = request.args.get('query')
institute_obj = institute_and_case(store, institute_id)

query = request.args.get('query')
collaborators = []
user_institute_objs = user_institutes(store, current_user)
for user_institute in user_institute_objs:
collaborators.append(user_institute['_id'])

limit = 100
if request.args.get('limit'):
limit = int(request.args.get('limit'))

skip_assigned = request.args.get('skip_assigned')
all_cases = store.cases(institute_id, collaborator=institute_obj['_id'],
all_cases = store.cases(institute_id, collaborators=collaborators,
name_query=query, skip_assigned=skip_assigned)
data = controllers.cases(store, all_cases, limit)

Expand Down

0 comments on commit caa8b8d

Please sign in to comment.