function create_dbo_interventionprotocols
Creates a new node of type dbo_InterventionProtocols in a Neo4j graph database with the specified properties.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
985 - 994
simple
Purpose
This function is designed to insert a new intervention protocol record into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query using a run_query helper function, and returns the created node. This is useful for storing medical or research intervention protocol data in a graph database structure.
Source Code
def create_dbo_interventionprotocols(properties):
"""Create a new dbo_InterventionProtocols node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:dbo_InterventionProtocols)
SET {props_list}
RETURN n
"""
result = run_query(query, properties)
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
properties |
- | - | positional_or_keyword |
Parameter Details
properties: A dictionary containing key-value pairs representing the properties to be set on the new dbo_InterventionProtocols node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, lists, etc.). Example: {'name': 'Protocol A', 'version': '1.0', 'approved': True}
Return Value
Returns the created Neo4j node object (first element from the query result) if the creation was successful, or None if the query returned no results or failed. The returned node object typically contains all properties set during creation along with Neo4j metadata like node ID and labels.
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()
# Create a new intervention protocol node
protocol_properties = {
'protocol_id': 'PROTO-001',
'name': 'Clinical Trial Protocol',
'version': '2.1',
'status': 'active',
'created_date': '2024-01-15'
}
node = create_dbo_interventionprotocols(protocol_properties)
if node:
print(f'Successfully created node: {node}')
else:
print('Failed to create node')
Best Practices
- Ensure the properties dictionary does not contain None values or invalid data types that Neo4j cannot handle
- Validate property keys to avoid Cypher injection vulnerabilities, especially if properties come from user input
- The run_query function should handle database connection errors and transaction management properly
- Consider adding error handling around the function call to catch potential database connection or query execution failures
- Use parameterized queries (as this function does with ${prop}) to prevent injection attacks
- Ensure unique constraints or indexes are defined on the database if protocol_id or similar fields should be unique
- Consider wrapping this function in a try-except block when calling it to handle potential Neo4j driver exceptions
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_dbo_interventionprotocolflocks 82.6% similar
-
function get_dbo_interventionprotocols_by_id 78.2% similar
-
function create_references_interventionprotocols_relationship 76.9% similar
-
function get_all_dbo_interventionprotocols 75.1% similar
-
function get_dbo_interventionprotocols_by_uid 72.4% similar