🔍 Code Extractor

function get_dbo_interventionprotocols_by_uid

Maturity: 39

Retrieves a single dbo_InterventionProtocols node from a Neo4j graph database by matching its unique identifier (UID).

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
976 - 983
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific intervention protocol node. It's designed for retrieving individual protocol records when the exact UID is known, commonly used in healthcare or clinical trial data management systems where intervention protocols need to be accessed by their unique identifiers.

Source Code

def get_dbo_interventionprotocols_by_uid(uid):
    """Get a dbo_InterventionProtocols node by its UID"""
    query = """
    MATCH (n:dbo_InterventionProtocols {UID: $uid})
    RETURN n
    """
    result = run_query(query, {"uid": uid})
    return result[0] if result else None

Parameters

Name Type Default Kind
uid - - positional_or_keyword

Parameter Details

uid: The unique identifier (UID) of the dbo_InterventionProtocols node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be an exact match as the query uses equality comparison.

Return Value

Returns the first matching dbo_InterventionProtocols node as a dictionary-like object if found, or None if no node with the specified UID exists. The returned node contains all properties stored in the Neo4j database for that intervention protocol. The function assumes run_query returns a list of results and extracts the first element.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is already defined and Neo4j is configured
# Example 1: Retrieve an intervention protocol by UID
protocol = get_dbo_interventionprotocols_by_uid('PROTO-12345')
if protocol:
    print(f"Found protocol: {protocol}")
else:
    print("Protocol not found")

# Example 2: Access specific properties from the returned node
protocol = get_dbo_interventionprotocols_by_uid('PROTO-67890')
if protocol:
    protocol_name = protocol.get('name')
    protocol_description = protocol.get('description')
    print(f"Protocol: {protocol_name} - {protocol_description}")

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate the uid parameter before passing it to prevent injection attacks or invalid queries
  • Consider adding error handling for database connection failures or query execution errors
  • The function assumes run_query returns a list; verify this behavior matches your implementation
  • Consider adding logging for debugging purposes, especially when nodes are not found
  • For production use, implement proper connection pooling and transaction management in the run_query function
  • Consider adding type hints to the function signature for better code documentation (e.g., def get_dbo_interventionprotocols_by_uid(uid: str) -> Optional[Dict])

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_interventionprotocols_by_id 90.7% similar

    Retrieves a single dbo_InterventionProtocols node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_uid 87.8% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by matching its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_id 79.7% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_interventionprotocols 79.3% similar

    Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_InterventionProtocols' with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols 78.0% similar

    Queries a Neo4j graph database to retrieve dbo_InterventionProtocols nodes that are connected to a specific dbo_InterventionProtocolFlocks node via a REFERENCES_INTERVENTIONPROTOCOLS relationship.

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