in python/website/research_pacs/website/permission.py [0:0]
def get_jsonpath_query(self, query):
"""
The solution makes JSONPath queries to the PostgreSQL database to find DICOM instances that
match specific criteria. This function translate the "human-readable" query like `Modality
StrEquals CT` into a JSONPath, and apply eventual profile-specific JSONPath queries that
restrict access to a subset of DICOM instances (attribute `DICOMQueryFilter`).
Args:
query (str): Input query
"""
jsonpath_query = rpacs_dicom_json.translate_query_to_jsonpath(query)
matching_profiles = self._get_matching_profiles()
raise_error_if_no_permission(matching_profiles)
# Return `jsonpath_query` if at least one matching profile allows access to all DICOM
# instances without restriction (`DICOMQueryFilter` is not specified or empty for this
# profile)
for profile_name in matching_profiles:
profile = self._permissions['Profiles'][profile_name]
if not 'DICOMQueryFilter' in profile or profile['DICOMQueryFilter'] == '':
return jsonpath_query
# The current user can access a given DICOM instance if any of the matching profiles allows
# access (JSONPath queries connected by an OR operand)
jsonpath_profiles = [self._permissions['Profiles'][profile_name]['JSONPathQuery'] for profile_name in matching_profiles]
jsonpath_filter = '(' + ')||('.join(jsonpath_profiles) + ')'
# If `query` is empty, return only the "filtering" JSONPath query issued from the matching
# profiles. Otherwise, the resulting JSONPath query is an AND expression between the user
# query `jsonpath_query` and the filter query `jsonpath_filter`
if query == '':
return jsonpath_filter
else:
return f"(({jsonpath_query})&&{jsonpath_filter})"