function create_lims_requests
Creates a new LIMS_Requests node in a Neo4j graph database with the specified properties and returns the created node.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
166 - 175
simple
Purpose
This function is designed to insert a new LIMS_Requests node into a Neo4j graph database. It dynamically constructs a Cypher query based on the provided properties dictionary, executes the query using a run_query helper function, and returns the newly created node. This is typically used in Laboratory Information Management System (LIMS) applications to track and manage laboratory requests.
Source Code
def create_lims_requests(properties):
"""Create a new LIMS_Requests node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:LIMS_Requests)
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 LIMS_Requests node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, etc.). Example: {'request_id': '12345', 'status': 'pending', 'created_date': '2024-01-01'}
Return Value
Returns the first element from the query result (the created LIMS_Requests node) if the query execution is successful and returns results. Returns None if the query returns no results or fails. The returned node is typically a Neo4j node object containing all the properties that were set during creation.
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 LIMS request
request_properties = {
'request_id': 'REQ-2024-001',
'sample_type': 'blood',
'status': 'pending',
'priority': 'high',
'created_date': '2024-01-15'
}
new_request = create_lims_requests(request_properties)
if new_request:
print(f'Successfully created LIMS request: {new_request}')
else:
print('Failed to create LIMS request')
Best Practices
- Ensure the properties dictionary contains valid data types supported by Neo4j before calling this function
- Validate and sanitize input properties to prevent injection attacks, even though parameterized queries are used
- Handle the None return value appropriately in calling code to detect creation failures
- Consider adding error handling and logging within or around this function for production use
- Ensure the run_query function properly manages database connections and handles exceptions
- Use unique identifiers in properties to avoid duplicate nodes if business logic requires uniqueness
- Consider adding constraints or indexes on LIMS_Requests nodes in Neo4j for better performance and data integrity
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_lims_parameters 83.4% similar
-
function create_lims_tests 82.5% similar
-
function create_lims_samples 82.0% similar
-
function create_lims_sampletestresults 79.7% similar
-
function create_lims_testparameters 79.4% similar