🔍 Code Extractor

function get_lims_samples_with_references_houses_dbo_houses

Maturity: 40

Retrieves dbo_Houses nodes from a Neo4j graph database that are connected to a specific LIMS_Samples node via REFERENCES_HOUSES relationships.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1545 - 1552
Complexity:
simple

Purpose

This function queries a Neo4j graph database to find all house records (dbo_Houses nodes) that are referenced by a specific laboratory information management system (LIMS) sample. It's useful for tracing relationships between laboratory samples and physical house locations or properties in a connected data system, such as environmental testing, real estate analysis, or property inspection workflows.

Source Code

def get_lims_samples_with_references_houses_dbo_houses(source_id, limit=100):
    """Get dbo_Houses nodes connected to a LIMS_Samples via REFERENCES_HOUSES"""
    query = """
    MATCH (source:LIMS_Samples {id: $source_id})-[r:REFERENCES_HOUSES]->(target:dbo_Houses)
    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 of the LIMS_Samples node to query from. 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 dbo_Houses 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 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 dbo_Houses node data, where each record represents a house connected to the specified LIMS sample. Returns an empty result set if no matching relationships are found.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j connection is configured
# 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
sample_id = 'SAMPLE_12345'
houses = get_lims_samples_with_references_houses_dbo_houses(sample_id, limit=50)

# Process results
for house in houses:
    print(f"House ID: {house['id']}, Address: {house.get('address', 'N/A')}")

# Query with default limit
all_houses = get_lims_samples_with_references_houses_dbo_houses('SAMPLE_67890')

Best Practices

  • Ensure the source_id parameter matches existing LIMS_Samples node IDs in the database to avoid empty results
  • Use appropriate limit values to balance between completeness and performance; large limits may impact query performance
  • Handle cases where no relationships exist (empty result sets) in calling code
  • Ensure proper Neo4j connection management and error handling in the run_query function
  • Consider adding indexes on the 'id' property of LIMS_Samples nodes for better query performance
  • Validate that the run_query function properly closes database connections to prevent resource leaks
  • Consider implementing pagination for large result sets instead of relying solely on the limit parameter

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_references_houses_relationship 82.6% similar

    Creates a REFERENCES_HOUSES relationship in a Neo4j graph database between a LIMS_Samples node and a dbo_Houses node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresults_with_references_samples_lims_samples 80.6% similar

    Queries a Neo4j graph database to retrieve LIMS_Samples nodes that are connected to a specific LIMS_SampleTestResults node through a REFERENCES_SAMPLES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_with_references_establishment_dbo_establishment 79.2% similar

    Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific LIMS_Samples node through a REFERENCES_ESTABLISHMENT relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_with_references_requests_lims_requests 79.1% similar

    Queries a Neo4j graph database to retrieve LIMS_Requests nodes that are connected to a specific LIMS_Samples node via a REFERENCES_REQUESTS relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresultdetails_with_references_samples_lims_samples 78.8% similar

    Queries a Neo4j graph database to retrieve LIMS_Samples nodes that are connected to a specific LIMS_SampleTestResultDetails node through a REFERENCES_SAMPLES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse