function get_lims_sampletypetests_with_references_sampletypes_lims_sampletypes
Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes that are connected to a specific LIMS_SampleTypeTests node through a REFERENCES_SAMPLETYPES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1353 - 1360
simple
Purpose
This function is designed to traverse a Laboratory Information Management System (LIMS) graph database to find sample types associated with a particular sample type test. It's useful for understanding which sample types are valid or applicable for a given test configuration, enabling validation of test-sample compatibility and exploration of LIMS data relationships.
Source Code
def get_lims_sampletypetests_with_references_sampletypes_lims_sampletypes(source_id, limit=100):
"""Get LIMS_SampleTypes nodes connected to a LIMS_SampleTypeTests via REFERENCES_SAMPLETYPES"""
query = """
MATCH (source:LIMS_SampleTypeTests {id: $source_id})-[r:REFERENCES_SAMPLETYPES]->(target:LIMS_SampleTypes)
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 value that matches the 'id' property of a node in the Neo4j database.
limit: Maximum number of LIMS_SampleTypes nodes to return. Defaults to 100. This parameter prevents excessive data retrieval and controls query performance. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of Neo4j records representing LIMS_SampleTypes nodes. Each record contains the 'target' node with all its properties. The exact return type depends on the run_query implementation, but it's likely a list of dictionaries or Neo4j Record objects. Returns an empty collection if no matching relationships are found or if the source_id doesn't exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j is configured
from neo4j import GraphDatabase
# Define or import run_query function
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 sample types for a specific test
test_id = 'TEST_001'
sample_types = get_lims_sampletypetests_with_references_sampletypes_lims_sampletypes(test_id, limit=50)
# Process results
for sample_type in sample_types:
print(f"Sample Type ID: {sample_type['id']}, Name: {sample_type.get('name', 'N/A')}")
Best Practices
- Ensure the run_query function properly handles database connections and closes them after use to prevent connection leaks
- Validate that source_id exists before calling this function to avoid unnecessary database queries
- Consider adjusting the limit parameter based on expected data volume and performance requirements
- Handle cases where the function returns empty results (no matching relationships found)
- Implement proper error handling around this function to catch Neo4j connection errors or query failures
- Use parameterized queries (as done here) to prevent Cypher injection attacks
- Consider adding pagination if working with large datasets instead of relying solely on the limit parameter
- Ensure proper indexing on the 'id' property of LIMS_SampleTypeTests nodes for optimal query performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletypetests_with_references_tests_lims_tests 95.4% similar
-
function get_lims_samples_with_references_sampletypes_lims_sampletypes 94.4% similar
-
function get_lims_sampletypetests_by_id 87.8% similar
-
function get_lims_sampletestresults_with_references_samples_lims_samples 86.7% similar
-
function get_all_lims_sampletypetests 86.3% similar