function create_lims_importerrors
Creates a new LIMS_ImportErrors node in a Neo4j graph database with the specified properties and returns the created node.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
49 - 58
simple
Purpose
This function is designed to log import errors in a Laboratory Information Management System (LIMS) by creating error nodes in a Neo4j graph database. It dynamically constructs a Cypher query to create a node with custom properties, making it useful for tracking and auditing data import failures or validation errors in LIMS workflows.
Source Code
def create_lims_importerrors(properties):
"""Create a new LIMS_ImportErrors node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:LIMS_ImportErrors)
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_ImportErrors node. Keys should be valid Neo4j property names (strings), and values can be any Neo4j-compatible data types (strings, numbers, booleans, dates, etc.). Example: {'error_message': 'Invalid sample ID', 'timestamp': '2024-01-01T10:00:00', 'source_file': 'samples.csv'}
Return Value
Returns the first element from the query result (the created LIMS_ImportErrors node) if the query execution is successful and returns results. Returns None if the query fails or returns an empty result set. The returned node is typically a dictionary-like object containing all the properties set on the created node.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j connection is configured
# Example 1: Create an import error node with basic properties
error_properties = {
'error_message': 'Duplicate sample ID found',
'error_code': 'ERR_001',
'timestamp': '2024-01-15T14:30:00',
'source_file': 'batch_import_2024.csv',
'line_number': 42,
'severity': 'high'
}
result = create_lims_importerrors(error_properties)
if result:
print(f"Error node created successfully: {result}")
else:
print("Failed to create error node")
# Example 2: Create error node with minimal properties
minimal_error = {
'error_message': 'Connection timeout',
'timestamp': '2024-01-15T15:00:00'
}
error_node = create_lims_importerrors(minimal_error)
Best Practices
- Always validate the properties dictionary before passing it to ensure it contains valid Neo4j property types
- Include timestamp information in properties for proper error tracking and chronological ordering
- Check the return value for None to handle cases where node creation fails
- Sanitize user input in properties to prevent Cypher injection attacks
- Consider adding error handling around the function call to catch potential Neo4j connection or query execution errors
- Use consistent property naming conventions across all LIMS_ImportErrors nodes for easier querying
- Avoid passing empty dictionaries as properties parameter, as this would create a node with no properties
- Consider implementing property validation or a schema to ensure required fields are present
- Be aware that the function uses parameterized queries which helps prevent injection attacks, but property keys are directly interpolated into the query string
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_importerrors_by_id 82.7% similar
-
function get_all_lims_importerrors 81.2% similar
-
function create_lims_requests 78.3% similar
-
function get_lims_importerrors_by_uid 77.2% similar
-
function create_lims_parameters 76.2% similar