function get_lims_sampletestresults_with_references_testparameters_lims_testparameters
Queries a Neo4j graph database to retrieve LIMS_Testparameters nodes that are connected to a specific LIMS_SampleTestResults node through a REFERENCES_TESTPARAMETERS relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1321 - 1328
simple
Purpose
This function is designed to traverse a Laboratory Information Management System (LIMS) graph database to find test parameters associated with a specific sample test result. It's useful for retrieving configuration or metadata about tests that were performed on a sample, enabling analysis of test specifications, parameters, and settings used during sample testing.
Source Code
def get_lims_sampletestresults_with_references_testparameters_lims_testparameters(source_id, limit=100):
"""Get LIMS_Testparameters nodes connected to a LIMS_SampleTestResults via REFERENCES_TESTPARAMETERS"""
query = """
MATCH (source:LIMS_SampleTestResults {id: $source_id})-[r:REFERENCES_TESTPARAMETERS]->(target:LIMS_Testparameters)
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 node in the Neo4j database.
limit: Maximum number of LIMS_Testparameters nodes to return. Defaults to 100. This parameter controls query performance and prevents returning excessively large result sets. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of LIMS_Testparameters nodes that match the query criteria. The exact return type depends on the implementation of run_query, but it likely returns Neo4j query results containing node properties and data for each matching LIMS_Testparameters node. If no matches are found, it returns an empty result set.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is established
# Example run_query implementation:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
def run_query(query, params):
with driver.session() as session:
result = session.run(query, params)
return [record['target'] for record in result]
# Use the function to get test parameters for a specific sample test result
sample_test_id = 'STR_12345'
test_parameters = get_lims_sampletestresults_with_references_testparameters_lims_testparameters(sample_test_id, limit=50)
# Process the results
for param in test_parameters:
print(f"Test Parameter: {param}")
# Get all test parameters (up to 100) for another sample
all_params = get_lims_sampletestresults_with_references_testparameters_lims_testparameters('STR_67890')
Best Practices
- Ensure the source_id exists in the database before calling this function to avoid empty results
- Adjust the limit parameter based on expected result size to optimize query performance
- Handle the case where no test parameters are found (empty result set)
- Consider implementing error handling for database connection issues
- The run_query function should properly manage Neo4j sessions and transactions
- Close the Neo4j driver connection when the application terminates
- Validate that source_id is properly sanitized if it comes from user input (though parameterized queries provide protection against injection)
- Consider adding pagination if working with large datasets instead of just using a limit
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_testparameters_with_references_parameters_lims_parameters 93.2% similar
-
function get_lims_testparameters_with_references_tests_lims_tests 92.0% similar
-
function get_lims_sampletestresults_with_references_samples_lims_samples 89.6% similar
-
function get_lims_sampletestresultdetails_with_references_samples_lims_samples 88.7% similar
-
function get_lims_parameters_with_references_parameters_lims_parameters 85.6% similar