function create_lims_sampletypeproperties
Creates a new LIMS_SampleTypeProperties node in a Neo4j graph database with the provided properties and returns the created node.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
283 - 292
moderate
Purpose
This function is designed to insert a new node of type LIMS_SampleTypeProperties into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the properties dictionary provided, sets all properties on the new node, and returns the created node. This is useful for Laboratory Information Management Systems (LIMS) that need to store sample type property configurations in a graph database structure.
Source Code
def create_lims_sampletypeproperties(properties):
"""Create a new LIMS_SampleTypeProperties node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:LIMS_SampleTypeProperties)
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_SampleTypeProperties node. Keys should be valid Neo4j property names (strings), and values can be any Neo4j-compatible data types (strings, numbers, booleans, lists, etc.). The dictionary should not be empty as it defines the characteristics of the sample type.
Return Value
Returns the created LIMS_SampleTypeProperties node object (typically a dictionary-like structure containing the node's properties and metadata) if the creation was successful. Returns None if the query execution fails or returns no results. The returned node will contain all properties that were set during creation.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
# Example run_query implementation:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
def run_query(query, parameters=None):
with driver.session() as session:
result = session.run(query, parameters or {})
return [record['n'] for record in result]
# Create sample type properties
properties = {
'sample_type': 'Blood',
'storage_temp': -80,
'max_storage_days': 365,
'requires_consent': True,
'allowed_tests': ['CBC', 'Chemistry', 'Serology']
}
node = create_lims_sampletypeproperties(properties)
if node:
print(f'Created node with properties: {node}')
else:
print('Failed to create node')
Best Practices
- Ensure the properties dictionary is validated before passing to this function to prevent injection attacks or invalid data
- The run_query function must be properly implemented with error handling and connection management
- Consider adding input validation to check if properties dictionary is not empty
- Use parameterized queries (as this function does) to prevent Cypher injection attacks
- Implement proper transaction handling in the run_query function for data consistency
- Consider adding unique constraints or indexes on LIMS_SampleTypeProperties nodes to prevent duplicates
- Handle potential Neo4j connection errors and database unavailability scenarios
- Consider adding logging for debugging and audit trail purposes
- Ensure proper cleanup of Neo4j driver connections to prevent resource leaks
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_lims_sampletypes 90.9% similar
-
function create_lims_sampletypetests 86.6% similar
-
function create_lims_samples 86.5% similar
-
function get_lims_sampletypeproperties_by_id 82.6% similar
-
function create_lims_sampletestresults 82.4% similar