Skip to content

Commit 4db237d

Browse files
authored
Merge pull request #983 from hubmapconsortium/Derek-Furst/bulk-ids
Derek furst/bulk ids
2 parents 1995a5c + 25cdbf7 commit 4db237d

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

entity-api-spec.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,3 +3140,46 @@ paths:
31403140
description: The given dataset is unpublished and the user does not have the authorization to view it.
31413141
'500':
31423142
description: Internal error
3143+
'/entities/batch-ids':
3144+
post:
3145+
summary: Retrieve the HuBMAP ID and UUID for each entity id provided in a list.
3146+
requestBody:
3147+
required: true
3148+
content:
3149+
application/json:
3150+
schema:
3151+
type: array
3152+
description: List of entity identifiers (HuBMAP IDs or UUIDs)
3153+
items:
3154+
type: string
3155+
responses:
3156+
'200':
3157+
description: Mapping of input entity identifiers to their resolved HuBMAP ID and UUID. If no items are found, will simply return empty.
3158+
content:
3159+
application/json:
3160+
schema:
3161+
type: object
3162+
additionalProperties:
3163+
type: object
3164+
properties:
3165+
hubmap_id:
3166+
type: string
3167+
description: Canonical HuBMAP ID for the entity
3168+
uuid:
3169+
type: string
3170+
format: uuid
3171+
description: UUID for the entity
3172+
required:
3173+
- hubmap_id
3174+
- uuid
3175+
examples:
3176+
batchidsexample:
3177+
value:
3178+
HBM123.ABCD.456:
3179+
hubmap_id: "HBM123.ABCD.456"
3180+
uuid: "a8098c1a-f86e-11da-bd1a-00112444be1e"
3181+
abcd1234-ef56-gh78-ij90-klmnop123456:
3182+
hubmap_id: "HBM987.WXYZ.321"
3183+
uuid: "abcd1234-ef56-gh78-ij90-klmnop123456"
3184+
'500':
3185+
description: Internal Error

src/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,6 +4319,33 @@ 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+
Request Body
4326+
------------
4327+
JSON array of entity identifiers (either uuids or HuBMAP IDs)
4328+
4329+
Example:
4330+
[
4331+
"HBM123.ABCD.456",
4332+
"a1234b56-c78d-90de-fg1h-23456789i01j"
4333+
]
4334+
4335+
Returns
4336+
-------
4337+
json
4338+
JSON object keyed by the entity identifier. Each value is a mapping containing the HuBMAP ID and UUID for that entity
4339+
"""
4340+
@app.route('/entities/batch-ids', methods = ['POST'])
4341+
def get_batch_ids():
4342+
validate_token_if_auth_header_exists(request)
4343+
require_json(request)
4344+
json_data_dict = request.get_json()
4345+
ids = app_neo4j_queries.get_batch_ids(neo4j_driver_instance, json_data_dict)
4346+
return jsonify(ids)
4347+
4348+
43224349
####################################################################################################
43234350
## Internal Functions
43244351
####################################################################################################

src/app_neo4j_queries.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)