function get_lims_sampletestresults_with_references_samples_lims_samples
Queries a Neo4j graph database to retrieve LIMS_Samples nodes that are connected to a specific LIMS_SampleTestResults node through a REFERENCES_SAMPLES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1289 - 1296
simple
Purpose
This function is designed to traverse a Laboratory Information Management System (LIMS) graph database to find all sample records associated with a particular test result. It's useful for tracking which samples were involved in specific test results, enabling traceability and data lineage in laboratory workflows. The function supports pagination through a limit parameter to handle large result sets efficiently.
Source Code
def get_lims_sampletestresults_with_references_samples_lims_samples(source_id, limit=100):
"""Get LIMS_Samples nodes connected to a LIMS_SampleTestResults via REFERENCES_SAMPLES"""
query = """
MATCH (source:LIMS_SampleTestResults {id: $source_id})-[r:REFERENCES_SAMPLES]->(target:LIMS_Samples)
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_SampleTestResults node from which to start the traversal. This should be a string or value that matches the 'id' property of a LIMS_SampleTestResults node in the Neo4j database.
limit: Maximum number of LIMS_Samples nodes to return. Defaults to 100. This parameter helps control query performance and memory usage when dealing with test results that reference many samples. Must be a positive integer.
Return Value
Returns the result of the Neo4j query execution via the run_query function. The exact return type depends on the run_query implementation, but typically returns a list of records containing LIMS_Samples node data (properties like id, name, and other sample attributes). If no matching samples are found, returns an empty result set. The result is limited to the number specified by the limit parameter.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j connection is configured
# Example 1: Get samples for a specific test result with default limit
test_result_id = "TEST_RESULT_12345"
samples = get_lims_sampletestresults_with_references_samples_lims_samples(test_result_id)
# Example 2: Get samples with custom limit
test_result_id = "TEST_RESULT_67890"
samples = get_lims_sampletestresults_with_references_samples_lims_samples(test_result_id, limit=50)
# Example 3: Process returned samples
for record in samples:
sample_node = record['target']
print(f"Sample ID: {sample_node['id']}")
Best Practices
- Always validate that source_id exists in the database before calling this function to avoid empty results
- Use appropriate limit values based on expected result sizes to balance performance and completeness
- Handle empty result sets gracefully in calling code as not all test results may have associated samples
- Consider implementing error handling around the run_query call to catch database connection issues
- Ensure proper indexing on the 'id' property of LIMS_SampleTestResults nodes for optimal query performance
- Be aware that this function depends on the run_query helper function which must handle Neo4j session management and error handling
- Consider adding pagination support (offset parameter) if working with very large datasets that exceed reasonable limit values
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletestresultdetails_with_references_samples_lims_samples 97.2% similar
-
function get_lims_sampletestresults_with_references_testparameters_lims_testparameters 89.6% similar
-
function get_lims_samples_with_references_requests_lims_requests 89.5% similar
-
function get_lims_samples_with_references_sampletypes_lims_sampletypes 89.4% similar
-
function get_lims_sampletypetests_with_references_tests_lims_tests 87.7% similar