File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -4319,6 +4319,28 @@ def entity_bulk_update():
43194319 return jsonify (list (uuids )), 202
43204320
43214321
4322+ """
4323+ Retrieve ids (uuid, hubmap_id) for a given id
4324+
4325+ Parameters
4326+ ----------
4327+ id : str
4328+ The HuBMAP ID (e.g. HBM123.ABCD.456) or UUID of target entity (Dataset/Sample)
4329+
4330+ Returns
4331+ -------
4332+ json array
4333+ Each item in the array is a json object containing the uuid and hubmap_id for the given entity.
4334+ """
4335+ @app .route ('/entities/batch-ids' , methods = ['POST' ])
4336+ def get_batch_ids ():
4337+ validate_token_if_auth_header_exists (request )
4338+ require_json (request )
4339+ json_data_dict = request .get_json ()
4340+ ids = app_neo4j_queries .get_batch_ids (neo4j_driver_instance , json_data_dict )
4341+ return jsonify (ids )
4342+
4343+
43224344####################################################################################################
43234345## Internal Functions
43244346####################################################################################################
Original file line number Diff line number Diff line change @@ -1181,3 +1181,36 @@ def get_entities_by_uuid(neo4j_driver,
11811181 return None
11821182
11831183 return records
1184+
1185+ """
1186+ Get the uuid and hubmap_id for each entity in a list of ids.
1187+
1188+ Parameters
1189+ ----------
1190+ neo4j_driver : neo4j.Driver object
1191+ The neo4j database connection pool
1192+ id_list : list
1193+ The list of ids
1194+
1195+ Returns
1196+ -------
1197+ Dictionary containing the uuid and hubmap_id of each entity in the list, keyed by that entities original id given
1198+ """
1199+ def get_batch_ids (neo4j_driver , id_list ):
1200+ query = """
1201+ MATCH (e)
1202+ WHERE e.uuid IN $id_list OR e.hubmap_id IN $id_list
1203+ WITH e, [id IN $id_list WHERE id = e.uuid OR id = e.hubmap_id][0] AS original_id
1204+ RETURN original_id, e.uuid AS uuid, e.hubmap_id AS hubmap_id
1205+ """
1206+
1207+ result_map = {}
1208+
1209+ with neo4j_driver .session () as session :
1210+ result = session .run (query , id_list = id_list )
1211+ for record in result :
1212+ result_map [record ['original_id' ]] = {
1213+ "uuid" : record ['uuid' ],
1214+ "hubmap_id" : record ['hubmap_id' ]
1215+ }
1216+ return result_map
You can’t perform that action at this time.
0 commit comments