Skip to content

Commit ad428e6

Browse files
authored
Merge pull request #256 from hubmapconsortium/test-release
v2.0.20 release
2 parents 84116df + 919ac2d commit ad428e6

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.19
1+
2.0.20

src/app.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,59 @@ def get_revisions_list(id):
21462146

21472147
return jsonify(results)
21482148

2149+
"""
2150+
Get all organs associated with a given dataset
2151+
2152+
The gateway treats this endpoint as public accessible
2153+
2154+
Parameters
2155+
----------
2156+
id : str
2157+
The HuBMAP ID (e.g. HBM123.ABCD.456) or UUID of given entity
2158+
2159+
Returns
2160+
-------
2161+
json
2162+
a list of all the organs associated with the target dataset
2163+
"""
2164+
@app.route('/datasets/<id>/organs', methods=['GET'])
2165+
def get_associated_organs_from_dataset(id):
2166+
# Token is not required, but if an invalid token provided,
2167+
# we need to tell the client with a 401 error
2168+
validate_token_if_auth_header_exists(request)
2169+
2170+
# Use the internal token to query the target entity
2171+
# since public entities don't require user token
2172+
token = get_internal_token()
2173+
2174+
# Query target entity against uuid-api and neo4j and return as a dict if exists
2175+
entity_dict = query_target_entity(id, token)
2176+
normalized_entity_type = entity_dict['entity_type']
2177+
2178+
# Only for Dataset
2179+
if normalized_entity_type != 'Dataset':
2180+
bad_request_error("The entity of given id is not a Dataset")
2181+
2182+
# published/public datasets don't require token
2183+
if entity_dict['status'].lower() != DATASET_STATUS_PUBLISHED:
2184+
# Token is required and the user must belong to HuBMAP-READ group
2185+
token = get_user_token(request, non_public_access_required=True)
2186+
2187+
# By now, either the entity is public accessible or
2188+
# the user token has the correct access level
2189+
associated_organs = app_neo4j_queries.get_associated_organs_from_dataset(neo4j_driver_instance, entity_dict['uuid'])
2190+
2191+
# If there are zero items in the list associated organs, then there are no associated
2192+
# Organs and a 404 will be returned.
2193+
if len(associated_organs) < 1:
2194+
not_found_error("the dataset does not have any associated organs")
2195+
2196+
complete_entities_list = schema_manager.get_complete_entities_list(token, associated_organs)
2197+
2198+
# Final result after normalization
2199+
final_result = schema_manager.normalize_entities_list_for_response(complete_entities_list)
2200+
2201+
return jsonify(final_result)
21492202

21502203
####################################################################################################
21512204
## Internal Functions

src/app_neo4j_queries.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,32 @@ def get_dataset_revision_number(neo4j_driver, uuid):
891891
return revision_number
892892

893893

894+
"""
895+
Retrieve the list of uuids for organs associated with a given dataset
896+
897+
Parameters
898+
----------
899+
neo4j_driver : neo4j.Driver object
900+
The neo4j database connection pool
901+
uuid : str
902+
The uuid of the target entity: Dataset
903+
"""
904+
def get_associated_organs_from_dataset(neo4j_driver, dataset_uuid):
905+
results = []
906+
query = (f"MATCH (ds:Dataset)<-[*]-(organ:Sample {{specimen_type:'organ'}}) "
907+
f"WHERE ds.uuid='{dataset_uuid}'"
908+
f"RETURN apoc.coll.toSet(COLLECT(organ)) AS {record_field_name}")
909+
logger.debug("======get_associated_organs_from_dataset() query======")
910+
logger.debug(query)
911+
912+
with neo4j_driver.session() as session:
913+
record = session.read_transaction(_execute_readonly_tx, query)
914+
915+
if record and record[record_field_name]:
916+
results = _nodes_to_dicts(record[record_field_name])
917+
918+
return results
919+
894920
####################################################################################################
895921
## Internal Functions
896922
####################################################################################################

0 commit comments

Comments
 (0)