function get_parameter_medicationtypeproperties_by_uid
Retrieves a Parameter_MedicationTypeProperties node from a Neo4j graph database using its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
547 - 554
simple
Purpose
This function queries a Neo4j database to fetch a specific Parameter_MedicationTypeProperties node by matching its UID property. It's designed for retrieving medication type parameter configurations or properties stored in a graph database structure. The function returns the first matching node or None if no match is found.
Source Code
def get_parameter_medicationtypeproperties_by_uid(uid):
"""Get a Parameter_MedicationTypeProperties node by its UID"""
query = """
MATCH (n:Parameter_MedicationTypeProperties {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 Parameter_MedicationTypeProperties node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be a valid, existing UID for a Parameter_MedicationTypeProperties node.
Return Value
Returns the first Parameter_MedicationTypeProperties node object that matches the provided UID if found, or None if no matching node exists. The returned node object contains all properties associated with that Parameter_MedicationTypeProperties node in the database. The return type is either a dictionary-like node object or None.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
from neo4j import GraphDatabase
# Assuming run_query is defined elsewhere
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['n'] for record in result]
driver.close()
# Use the function
uid_to_find = 'med-type-123'
node = get_parameter_medicationtypeproperties_by_uid(uid_to_find)
if node:
print(f'Found node: {node}')
else:
print('Node not found')
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
- Consider adding error handling for database connection failures
- The function assumes run_query returns a list; ensure this contract is maintained
- Consider adding logging for debugging purposes when nodes are not found
- Ensure proper Neo4j driver cleanup in the run_query implementation
- Consider adding type hints for better code documentation (e.g., uid: str -> Optional[Dict])
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_parameter_medicationtypes_by_uid 93.8% similar
-
function get_parameter_medicationtypeproperties_by_id 89.3% similar
-
function get_parameter_medicationtypes_by_id 83.5% similar
-
function get_parameter_medicationtypeproperties_with_references_medicationtypes_parameter_medicationtypes 81.0% similar
-
function get_all_parameter_medicationtypeproperties 79.7% similar