From f2af0c98097ee58109b47bec65c05b6c3328365e Mon Sep 17 00:00:00 2001 From: Arman Jahanpour <77515879+rmanaem@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:12:34 -0500 Subject: [PATCH] [MNT] Removed `session_file_path` from aggregate results (#214) * Removed `session_file_path` from result on aggregate mode * Updated `test_data` fixture * Revert "Updated `test_data` fixture" This reverts commit e30103f87ec6401f50d911a979f7032f8228a121. * Updated `test_data` fixture * Updated `CohortQueryResponse` model to accept string values for `subject_data` field * Updated `get` function --- app/api/crud.py | 5 +---- app/api/models.py | 4 ++-- app/api/utility.py | 4 ++-- tests/conftest.py | 26 ++------------------------ 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/app/api/crud.py b/app/api/crud.py index 45dadbc..9441668 100644 --- a/app/api/crud.py +++ b/app/api/crud.py @@ -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) diff --git a/app/api/models.py b/app/api/models.py index 6e65618..a52d850 100644 --- a/app/api/models.py +++ b/app/api/models.py @@ -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 @@ -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 diff --git a/app/api/utility.py b/app/api/utility.py index fedb6c9..0d3009b 100644 --- a/app/api/utility.py +++ b/app/api/utility.py @@ -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]) diff --git a/tests/conftest.py b/tests/conftest.py index 6a4c2d3..f846077 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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", @@ -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",