diff --git a/app/api/utility.py b/app/api/utility.py index 9280fc5..1f39193 100644 --- a/app/api/utility.py +++ b/app/api/utility.py @@ -206,28 +206,14 @@ def create_query( nb:hasLabel ?session_id. OPTIONAL {{ ?session nb:hasAcquisition/nb:hasContrastType ?image_modal. - OPTIONAL {{ - ?session nb:hasFilePath ?session_file_path. - }} - }} - OPTIONAL {{ - ?dataset_uuid nb:hasPortalURI ?dataset_portal_uri. - }} - OPTIONAL {{ - ?session nb:hasAge ?age. - }} - OPTIONAL {{ - ?session nb:hasSex ?sex. - }} - OPTIONAL {{ - ?session nb:hasDiagnosis ?diagnosis. - }} - OPTIONAL {{ - ?session nb:isSubjectGroup ?subject_group. - }} - OPTIONAL {{ - ?session nb:hasAssessment ?assessment. + OPTIONAL {{?session nb:hasFilePath ?session_file_path.}} }} + OPTIONAL {{?dataset_uuid nb:hasPortalURI ?dataset_portal_uri.}} + OPTIONAL {{?session nb:hasAge ?age.}} + OPTIONAL {{?session nb:hasSex ?sex.}} + OPTIONAL {{?session nb:hasDiagnosis ?diagnosis.}} + OPTIONAL {{?session nb:isSubjectGroup ?subject_group.}} + OPTIONAL {{?session nb:hasAssessment ?assessment.}} {{ SELECT ?subject (count(distinct ?phenotypic_session) as ?num_matching_phenotypic_sessions) WHERE {{ @@ -235,21 +221,12 @@ def create_query( OPTIONAL {{ ?subject nb:hasSession ?phenotypic_session. ?phenotypic_session a nb:PhenotypicSession. - OPTIONAL {{ - ?phenotypic_session nb:hasAge ?age. - }} - OPTIONAL {{ - ?phenotypic_session nb:hasSex ?sex. - }} - OPTIONAL {{ - ?phenoypic_session nb:hasDiagnosis ?diagnosis. - }} - OPTIONAL {{ - ?phenotypic_session nb:isSubjectGroup ?subject_group. - }} - OPTIONAL {{ - ?phenotypic_session nb:hasAssessment ?assessment. - }} + + OPTIONAL {{?phenotypic_session nb:hasAge ?age.}} + OPTIONAL {{?phenotypic_session nb:hasSex ?sex.}} + OPTIONAL {{?phenotypic_session nb:hasDiagnosis ?diagnosis.}} + OPTIONAL {{?phenotypic_session nb:isSubjectGroup ?subject_group.}} + OPTIONAL {{?phenotypic_session nb:hasAssessment ?assessment.}} }} {phenotypic_session_level_filters} }} GROUP BY ?subject @@ -260,7 +237,8 @@ def create_query( ?subject a nb:Subject. OPTIONAL {{ ?subject nb:hasSession ?imaging_session. - ?imaging_session nb:hasAcquisition/nb:hasContrastType ?image_modal. + ?imaging_session a nb:ImagingSession; + nb:hasAcquisition/nb:hasContrastType ?image_modal. }} {imaging_session_level_filters} }} GROUP BY ?subject diff --git a/docs/default_neurobagel_query.rq b/docs/default_neurobagel_query.rq index 3d48d11..c4dc71c 100644 --- a/docs/default_neurobagel_query.rq +++ b/docs/default_neurobagel_query.rq @@ -18,28 +18,14 @@ WHERE { nb:hasLabel ?session_id. OPTIONAL { ?session nb:hasAcquisition/nb:hasContrastType ?image_modal. - OPTIONAL { - ?session nb:hasFilePath ?session_file_path. - } - } - OPTIONAL { - ?dataset_uuid nb:hasPortalURI ?dataset_portal_uri. - } - OPTIONAL { - ?session nb:hasAge ?age. - } - OPTIONAL { - ?session nb:hasSex ?sex. - } - OPTIONAL { - ?session nb:hasDiagnosis ?diagnosis. - } - OPTIONAL { - ?session nb:isSubjectGroup ?subject_group. - } - OPTIONAL { - ?session nb:hasAssessment ?assessment. - } + OPTIONAL {?session nb:hasFilePath ?session_file_path.} + } + OPTIONAL {?dataset_uuid nb:hasPortalURI ?dataset_portal_uri.} + OPTIONAL {?session nb:hasAge ?age.} + OPTIONAL {?session nb:hasSex ?sex.} + OPTIONAL {?session nb:hasDiagnosis ?diagnosis.} + OPTIONAL {?session nb:isSubjectGroup ?subject_group.} + OPTIONAL {?session nb:hasAssessment ?assessment.} { SELECT ?subject (count(distinct ?phenotypic_session) as ?num_matching_phenotypic_sessions) WHERE { @@ -47,21 +33,12 @@ WHERE { OPTIONAL { ?subject nb:hasSession ?phenotypic_session. ?phenotypic_session a nb:PhenotypicSession. - OPTIONAL { - ?phenotypic_session nb:hasAge ?age. - } - OPTIONAL { - ?phenotypic_session nb:hasSex ?sex. - } - OPTIONAL { - ?phenoypic_session nb:hasDiagnosis ?diagnosis. - } - OPTIONAL { - ?phenotypic_session nb:isSubjectGroup ?subject_group. - } - OPTIONAL { - ?phenotypic_session nb:hasAssessment ?assessment. - } + + OPTIONAL {?phenotypic_session nb:hasAge ?age.} + OPTIONAL {?phenotypic_session nb:hasSex ?sex.} + OPTIONAL {?phenotypic_session nb:hasDiagnosis ?diagnosis.} + OPTIONAL {?phenotypic_session nb:isSubjectGroup ?subject_group.} + OPTIONAL {?phenotypic_session nb:hasAssessment ?assessment.} } } GROUP BY ?subject @@ -72,7 +49,8 @@ WHERE { ?subject a nb:Subject. OPTIONAL { ?subject nb:hasSession ?imaging_session. - ?imaging_session nb:hasAcquisition/nb:hasContrastType ?image_modal. + ?imaging_session a nb:ImagingSession; + nb:hasAcquisition/nb:hasContrastType ?image_modal. } } GROUP BY ?subject