function create_lims_sampletestresultdetails
Creates a new LIMS_SampleTestResultDetails node in a Neo4j graph database with the specified properties and returns the created node.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
205 - 214
simple
Purpose
This function is designed to insert a new node of type LIMS_SampleTestResultDetails 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 newly created node. This is typically used in Laboratory Information Management Systems (LIMS) to store detailed test result information for samples.
Source Code
def create_lims_sampletestresultdetails(properties):
"""Create a new LIMS_SampleTestResultDetails node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:LIMS_SampleTestResultDetails)
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 LIMS_SampleTestResultDetails node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, etc.). Example: {'test_id': '12345', 'result_value': 98.5, 'unit': 'mg/L', 'timestamp': '2024-01-15T10:30:00'}
Return Value
Returns the created LIMS_SampleTestResultDetails node object (typically a dictionary or Neo4j Record object) if the creation was successful, or None if the query returned no results or failed. The returned node contains 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 sample test result details node
properties = {
'sample_id': 'SAMPLE-001',
'test_name': 'pH Test',
'result_value': 7.2,
'unit': 'pH',
'test_date': '2024-01-15',
'technician': 'John Doe',
'status': 'completed'
}
node = create_lims_sampletestresultdetails(properties)
if node:
print(f'Created node: {node}')
else:
print('Failed to create node')
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 to detect creation failures
- Consider adding error handling around the function call to catch database connection issues
- Ensure the run_query function implements proper connection management and error handling
- Use transactions when creating multiple related nodes to maintain data consistency
- Consider adding constraints or indexes on frequently queried properties in the Neo4j database
- Validate that required properties for LIMS_SampleTestResultDetails are present before creation
- Be aware that property names with special characters may need escaping in Cypher queries
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_lims_sampletestresults 90.7% similar
-
function create_lims_samples 82.1% similar
-
function get_lims_sampletestresultdetails_by_id 82.1% similar
-
function create_lims_sampletypetests 80.8% similar
-
function create_lims_tests 80.0% similar