function get_lims_samples_with_references_requests_lims_requests
Queries a Neo4j graph database to retrieve LIMS_Requests nodes that are connected to a specific LIMS_Samples node via a REFERENCES_REQUESTS relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1417 - 1424
simple
Purpose
This function is designed to traverse a graph database relationship between laboratory information management system (LIMS) samples and their associated requests. It retrieves request records that are referenced by a given sample, which is useful for tracking sample provenance, understanding request-sample relationships, and navigating LIMS data structures stored in Neo4j.
Source Code
def get_lims_samples_with_references_requests_lims_requests(source_id, limit=100):
"""Get LIMS_Requests nodes connected to a LIMS_Samples via REFERENCES_REQUESTS"""
query = """
MATCH (source:LIMS_Samples {id: $source_id})-[r:REFERENCES_REQUESTS]->(target:LIMS_Requests)
RETURN target
LIMIT $limit
"""
return run_query(query, {"source_id": source_id, "limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
source_id |
- | - | positional_or_keyword |
limit |
- | 100 | positional_or_keyword |
Parameter Details
source_id: The unique identifier (id property) of the LIMS_Samples node from which to start the traversal. This should be a string or value that matches the 'id' property of a LIMS_Samples node in the Neo4j database.
limit: Maximum number of LIMS_Requests nodes to return. Defaults to 100. This parameter controls query performance and result set size. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of LIMS_Requests nodes (as Neo4j records/dictionaries) that are connected to the specified LIMS_Samples node via the REFERENCES_REQUESTS relationship. The exact return type depends on the implementation of run_query, but it likely returns a list of dictionaries containing the properties of each target LIMS_Requests node, or an empty collection if no matching relationships exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
# def run_query(query, params):
# driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
# with driver.session() as session:
# result = session.run(query, params)
# return [record["target"] for record in result]
# Get requests associated with a specific sample
sample_id = "SAMPLE_12345"
requests = get_lims_samples_with_references_requests_lims_requests(sample_id)
# Get only the first 10 requests
requests_limited = get_lims_samples_with_references_requests_lims_requests(sample_id, limit=10)
# Process the results
for request in requests:
print(f"Request ID: {request['id']}")
Best Practices
- Ensure the run_query function is properly defined with appropriate error handling and connection management
- Consider adding input validation for source_id to prevent injection attacks or invalid queries
- The limit parameter should be adjusted based on expected data volume and performance requirements
- Always close Neo4j driver connections properly in the run_query implementation
- Consider adding error handling for cases where the source_id doesn't exist in the database
- For production use, implement connection pooling and proper transaction management
- Consider adding pagination support for large result sets instead of relying solely on the limit parameter
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletestresults_with_references_samples_lims_samples 89.5% similar
-
function get_lims_sampletestresultdetails_with_references_samples_lims_samples 87.3% similar
-
function get_lims_samples_with_references_sampletypes_lims_sampletypes 85.5% similar
-
function create_references_requests_relationship 84.0% similar
-
function get_lims_sampletypetests_with_references_tests_lims_tests 81.6% similar