Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions entity-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3140,3 +3140,46 @@ paths:
description: The given dataset is unpublished and the user does not have the authorization to view it.
'500':
description: Internal error
'/entities/batch-ids':
post:
summary: Retrieve the HuBMAP ID and UUID for each entity id provided in a list.
requestBody:
required: true
content:
application/json:
schema:
type: array
description: List of entity identifiers (HuBMAP IDs or UUIDs)
items:
type: string
responses:
'200':
description: Mapping of input entity identifiers to their resolved HuBMAP ID and UUID. If no items are found, will simply return empty.
content:
application/json:
schema:
type: object
additionalProperties:
type: object
properties:
hubmap_id:
type: string
description: Canonical HuBMAP ID for the entity
uuid:
type: string
format: uuid
description: UUID for the entity
required:
- hubmap_id
- uuid
examples:
batchidsexample:
value:
HBM123.ABCD.456:
hubmap_id: "HBM123.ABCD.456"
uuid: "a8098c1a-f86e-11da-bd1a-00112444be1e"
abcd1234-ef56-gh78-ij90-klmnop123456:
hubmap_id: "HBM987.WXYZ.321"
uuid: "abcd1234-ef56-gh78-ij90-klmnop123456"
'500':
description: Internal Error
27 changes: 27 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4319,6 +4319,33 @@ def entity_bulk_update():
return jsonify(list(uuids)), 202


"""
Retrieve ids (uuid, hubmap_id) for a given id

Request Body
------------
JSON array of entity identifiers (either uuids or HuBMAP IDs)

Example:
[
"HBM123.ABCD.456",
"a1234b56-c78d-90de-fg1h-23456789i01j"
]

Returns
-------
json
JSON object keyed by the entity identifier. Each value is a mapping containing the HuBMAP ID and UUID for that entity
"""
@app.route('/entities/batch-ids', methods = ['POST'])
def get_batch_ids():
validate_token_if_auth_header_exists(request)
require_json(request)
json_data_dict = request.get_json()
ids = app_neo4j_queries.get_batch_ids(neo4j_driver_instance, json_data_dict)
return jsonify(ids)


####################################################################################################
## Internal Functions
####################################################################################################
Expand Down
33 changes: 33 additions & 0 deletions src/app_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,3 +1181,36 @@ def get_entities_by_uuid(neo4j_driver,
return None

return records

"""
Get the uuid and hubmap_id for each entity in a list of ids.

Parameters
----------
neo4j_driver : neo4j.Driver object
The neo4j database connection pool
id_list : list
The list of ids

Returns
-------
Dictionary containing the uuid and hubmap_id of each entity in the list, keyed by that entities original id given
"""
def get_batch_ids(neo4j_driver, id_list):
query = """
MATCH (e)
WHERE e.uuid IN $id_list OR e.hubmap_id IN $id_list
WITH e, [id IN $id_list WHERE id = e.uuid OR id = e.hubmap_id][0] AS original_id
RETURN original_id, e.uuid AS uuid, e.hubmap_id AS hubmap_id
"""

result_map = {}

with neo4j_driver.session() as session:
result = session.run(query, id_list=id_list)
for record in result:
result_map[record['original_id']] = {
"uuid": record['uuid'],
"hubmap_id": record['hubmap_id']
}
return result_map