🔍 Code Extractor

function create_lims_sampletestresults

Maturity: 48

Creates a new LIMS_SampleTestResults node in a Neo4j graph database with the specified properties and returns the created node.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
244 - 253
Complexity:
simple

Purpose

This function is designed to insert Laboratory Information Management System (LIMS) sample test results data into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query, and returns the newly created node. This is useful for storing and managing laboratory test results in a graph database structure where relationships between samples, tests, and results can be easily queried and analyzed.

Source Code

def create_lims_sampletestresults(properties):
    """Create a new LIMS_SampleTestResults node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_SampleTestResults)
    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_SampleTestResults node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, lists, etc.). Example: {'sample_id': '12345', 'test_name': 'pH Test', 'result': 7.2, 'date': '2024-01-15'}. The dictionary should not be empty as it would create a node with no properties.

Return Value

Returns the first element from the query result (the created LIMS_SampleTestResults 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 that were set on the 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 a sample test result node
properties = {
    'sample_id': 'SAMPLE-001',
    'test_name': 'Blood Glucose Test',
    'result_value': 95.5,
    'unit': 'mg/dL',
    'test_date': '2024-01-15',
    'status': 'completed',
    'technician': 'John Doe'
}

node = create_lims_sampletestresults(properties)

if node:
    print(f"Created node with sample_id: {node['sample_id']}")
else:
    print("Failed to create node")

# Example 2: Create with minimal properties
minimal_props = {
    'sample_id': 'SAMPLE-002',
    'test_name': 'pH Test'
}

node2 = create_lims_sampletestresults(minimal_props)

Best Practices

  • Validate the properties dictionary before passing it to the function to ensure it contains required fields
  • Handle the None return value appropriately in calling code to detect creation failures
  • Use consistent property naming conventions across all LIMS_SampleTestResults nodes
  • Consider implementing input sanitization to prevent Cypher injection attacks if properties come from user input
  • Ensure the run_query function implements proper error handling and connection management
  • Consider adding unique constraints or indexes on key properties like sample_id in the Neo4j database
  • Use transactions appropriately if this function is part of a larger batch operation
  • Consider implementing validation to ensure properties dictionary is not empty before creating the node
  • Document the expected schema/properties for LIMS_SampleTestResults nodes for consistency

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_sampletestresultdetails 90.7% similar

    Creates a new LIMS_SampleTestResultDetails node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_samples 89.0% similar

    Creates a new LIMS_Samples node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_tests 87.5% similar

    Creates a new LIMS_Tests node in a Neo4j graph database with specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_sampletypetests 87.2% similar

    Creates a new LIMS_SampleTypeTests node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_sampletypes 83.1% similar

    Creates a new LIMS_SampleTypes node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse