function get_lims_sampletypetests_with_references_tests_lims_tests
Queries a Neo4j graph database to retrieve LIMS_Tests nodes that are connected to a specific LIMS_SampleTypeTests node through a REFERENCES_TESTS relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1385 - 1392
simple
Purpose
This function is designed to traverse a Laboratory Information Management System (LIMS) graph database to find test definitions (LIMS_Tests) that are referenced by a specific sample type test configuration (LIMS_SampleTypeTests). It's useful for understanding which tests are associated with particular sample types in a laboratory workflow, enabling test configuration management and sample processing workflows.
Source Code
def get_lims_sampletypetests_with_references_tests_lims_tests(source_id, limit=100):
"""Get LIMS_Tests nodes connected to a LIMS_SampleTypeTests via REFERENCES_TESTS"""
query = """
MATCH (source:LIMS_SampleTypeTests {id: $source_id})-[r:REFERENCES_TESTS]->(target:LIMS_Tests)
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_SampleTypeTests node from which to start the traversal. This should be a string or integer value that matches an existing node's id in the database.
limit: Maximum number of LIMS_Tests 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 of Neo4j Record objects representing the target LIMS_Tests nodes. Each record contains the properties of a LIMS_Tests node that has a REFERENCES_TESTS relationship from the specified LIMS_SampleTypeTests node. The exact return type depends on the implementation of run_query, but it's likely a list of dictionaries or Neo4j Record objects containing node properties.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
from neo4j import GraphDatabase
# Assuming run_query is defined elsewhere in your codebase
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]
driver.close()
# Get tests referenced by a specific sample type test
sample_type_test_id = 'STT-12345'
tests = get_lims_sampletypetests_with_references_tests_lims_tests(sample_type_test_id, limit=50)
# Process the results
for test in tests:
print(f"Test ID: {test['id']}, Name: {test.get('name', 'N/A')}")
Best Practices
- Always validate that source_id exists in the database before calling this function to avoid empty results
- Consider adjusting the limit parameter based on expected result set size to optimize performance
- Ensure proper error handling around the run_query function call to catch database connection issues
- Close Neo4j driver connections properly after use to prevent resource leaks
- Consider adding pagination if dealing with large result sets instead of just using a limit
- Validate that the run_query function is properly implemented with connection pooling for production use
- Consider adding indexes on the id property of LIMS_SampleTypeTests nodes for better query performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletypetests_with_references_sampletypes_lims_sampletypes 95.4% similar
-
function get_lims_testparameters_with_references_tests_lims_tests 89.1% similar
-
function get_lims_samples_with_references_sampletypes_lims_sampletypes 88.1% similar
-
function get_lims_sampletestresults_with_references_samples_lims_samples 87.7% similar
-
function get_lims_sampletypetests_by_id 87.3% similar