Skip to content

Commit

Permalink
[MNT] Removed session_file_path from aggregate results (#214)
Browse files Browse the repository at this point in the history
* Removed `session_file_path` from result on aggregate mode

* Updated `test_data` fixture

* Revert "Updated `test_data` fixture"

This reverts commit e30103f.

* Updated `test_data` fixture

* Updated `CohortQueryResponse` model to accept string values for `subject_data` field

* Updated `get` function
  • Loading branch information
rmanaem authored Nov 7, 2023
1 parent 47d3b7e commit f2af0c9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
5 changes: 1 addition & 4 deletions app/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ async def get(
by=dataset_cols
):
if util.RETURN_AGG.val:
subject_data = list(
{"session_file_path": file_path}
for file_path in group["session_file_path"].dropna()
)
subject_data = "protected"
else:
subject_data = (
group.drop(dataset_cols, axis=1)
Expand Down
4 changes: 2 additions & 2 deletions app/api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Data models."""

from enum import Enum
from typing import Optional
from typing import Optional, Union

from fastapi import Query
from fastapi.exceptions import HTTPException
Expand Down Expand Up @@ -60,7 +60,7 @@ class CohortQueryResponse(BaseModel):
dataset_portal_uri: Optional[str]
records_protected: bool
num_matching_subjects: int
subject_data: list[dict]
subject_data: Union[list[dict], str]
image_modals: list


Expand Down
4 changes: 2 additions & 2 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ def create_query(
# wrap query in an aggregating statement so data returned from graph include only attributes needed for dataset-level aggregate metadata.
if return_agg:
query_string = f"""
SELECT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?session_file_path ?image_modal WHERE {{\n
SELECT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal WHERE {{\n
{query_string}
\n}} GROUP BY ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?session_file_path ?image_modal
\n}} GROUP BY ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal
"""

return "\n".join([create_context(), query_string])
Expand Down
26 changes: 2 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ def test_data():
"dataset_portal_uri": "https://rpq-qpn.ca/en/researchers-section/databases/",
"num_matching_subjects": 5,
"records_protected": True,
"subject_data": [
{"session_file_path": "/my/happy/path/sub-0051/to/session-01"},
{"session_file_path": "/my/happy/path/sub-0653/to/session-01"},
{"session_file_path": "/my/happy/path/sub-1063/to/session-01"},
{"session_file_path": "/my/happy/path/sub-1113/to/session-01"},
{"session_file_path": "/my/happy/path/sub-1170/to/session-01"},
],
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#T2Weighted",
Expand All @@ -38,23 +32,7 @@ def test_data():
"dataset_portal_uri": "https://www.ppmi-info.org/access-data-specimens/download-data",
"num_matching_subjects": 3,
"records_protected": True,
"subject_data": [
{
"session_file_path": "/my/happy/path/sub-719238/to/session-01"
},
{
"session_file_path": "/my/happy/path/sub-719341/to/session-01"
},
{
"session_file_path": "/my/happy/path/sub-719369/to/session-01"
},
{
"session_file_path": "/my/happy/path/sub-719238/to/session-02"
},
{
"session_file_path": "/my/happy/path/sub-719341/to/session-02"
},
],
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#FlowWeighted",
"http://purl.org/nidash/nidm#T1Weighted",
Expand Down

0 comments on commit f2af0c9

Please sign in to comment.