🔍 Code Extractor

function create_lims_sampletypes

Maturity: 44

Creates a new LIMS_SampleTypes 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:
361 - 370
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_SampleTypes node 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 useful for Laboratory Information Management Systems (LIMS) that need to store and manage sample type information in a graph database structure.

Source Code

def create_lims_sampletypes(properties):
    """Create a new LIMS_SampleTypes node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_SampleTypes)
    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_SampleTypes node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, lists, etc.). Example: {'name': 'Blood Sample', 'code': 'BLD001', 'active': True}

Return Value

Returns the first element from the query result (the created LIMS_SampleTypes 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 dictionary-like object containing the node's properties and metadata from Neo4j.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured

# Define properties for the new sample type
sample_properties = {
    'name': 'Blood Sample',
    'code': 'BLD001',
    'description': 'Whole blood sample for testing',
    'active': True,
    'created_date': '2024-01-15'
}

# Create the LIMS_SampleTypes node
result = create_lims_sampletypes(sample_properties)

if result:
    print(f"Successfully created sample type: {result}")
else:
    print("Failed to create sample type")

Best Practices

  • Validate the properties dictionary before passing it to ensure all required fields are present and properly formatted
  • Handle potential exceptions from the run_query function to manage database connection errors gracefully
  • Ensure property keys in the dictionary match the expected schema for LIMS_SampleTypes nodes
  • Consider adding input sanitization to prevent Cypher injection attacks if properties come from user input
  • Check if a node with similar properties already exists to avoid duplicates before creating a new one
  • Use transactions appropriately in the run_query function to ensure data consistency
  • Consider adding unique constraints on certain properties (like 'code') at the database level to maintain data integrity

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_sampletypeproperties 90.9% similar

    Creates a new LIMS_SampleTypeProperties node in a Neo4j graph database with the provided properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_sampletypetests 90.7% 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_samples 87.9% 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_sampletestresults 83.1% similar

    Creates a new LIMS_SampleTestResults 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_references_sampletypes_relationship_v1 81.4% similar

    Creates a REFERENCES_SAMPLETYPES relationship in a Neo4j graph database between a LIMS_Samples node and a LIMS_SampleTypes node, with optional properties on the relationship.

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