function get_parameter_medicationtypes_by_id
Retrieves a single Parameter_MedicationTypes node from a Neo4j graph database by its unique identifier.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
577 - 584
simple
Purpose
This function queries a Neo4j database to fetch a specific Parameter_MedicationTypes node using its ID. It's designed for retrieving medication type parameter configurations or metadata stored in a graph database. The function returns the first matching node or None if no node with the given ID exists.
Source Code
def get_parameter_medicationtypes_by_id(id):
"""Get a Parameter_MedicationTypes node by its ID"""
query = """
MATCH (n:Parameter_MedicationTypes {id: $id})
RETURN n
"""
result = run_query(query, {"id": id})
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
id |
- | - | positional_or_keyword |
Parameter Details
id: The unique identifier of the Parameter_MedicationTypes node to retrieve. Expected to be a string or integer that matches the 'id' property of nodes in the Neo4j database. This should correspond to a valid node ID in the Parameter_MedicationTypes label.
Return Value
Returns a dictionary-like object representing the Parameter_MedicationTypes node if found, containing all properties of the node. Returns None if no node with the specified ID exists. The exact structure depends on the properties stored in the Neo4j node, but typically includes the 'id' field and other medication type parameters.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is already defined and 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['n'] for record in result]
# Retrieve a medication type parameter by ID
medication_type = get_parameter_medicationtypes_by_id('med_type_001')
if medication_type:
print(f"Found medication type: {medication_type}")
# Access properties like: medication_type['name'], medication_type['category'], etc.
else:
print("Medication type not found")
Best Practices
- Ensure the run_query function is properly implemented with error handling and connection management
- Validate the ID parameter before passing it to prevent injection attacks or invalid queries
- Consider adding type hints to the function signature for better code documentation
- Handle potential None returns appropriately in calling code
- Ensure proper Neo4j driver cleanup and connection pooling in the run_query implementation
- Consider adding logging for debugging database queries
- Index the 'id' property in Neo4j for optimal query performance
- Consider adding exception handling for database connection errors
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_parameter_medicationtypes_by_uid 90.2% similar
-
function get_parameter_medicationtypeproperties_by_id 90.0% similar
-
function get_all_parameter_medicationtypes 85.7% similar
-
function get_parameter_medicationtypeproperties_with_references_medicationtypes_parameter_medicationtypes 85.1% similar
-
function get_parameter_medicationtypeproperties_by_uid 83.5% similar