🔍 Code Extractor

function get_document_type_name

Maturity: 35

Looks up and returns the full document type name corresponding to a given document type code by searching through a DOCUMENT_TYPES dictionary.

File:
/tf/active/vicechatdev/CDocs/settings_prod.py
Lines:
345 - 350
Complexity:
simple

Purpose

This function serves as a reverse lookup utility to convert document type codes into their human-readable names. It iterates through the DOCUMENT_TYPES dictionary (which maps names to codes) and returns the name when a matching code is found. If no match is found, it returns the original code as a fallback. This is useful for displaying user-friendly document type names in UI, logs, or reports when only the code is available.

Source Code

def get_document_type_name(code):
    """Get full document type name from code."""
    for name, type_code in DOCUMENT_TYPES.items():
        if type_code == code:
            return name
    return code

Parameters

Name Type Default Kind
code - - positional_or_keyword

Parameter Details

code: The document type code to look up. This should be a value that exists in the DOCUMENT_TYPES dictionary. The type is not explicitly constrained but is expected to match the type of values stored in DOCUMENT_TYPES (likely string or integer). Can be any value, and if not found, will be returned as-is.

Return Value

Returns a string representing the full document type name if a matching code is found in DOCUMENT_TYPES. If no match is found, returns the original 'code' parameter unchanged. The return type matches the type of keys in DOCUMENT_TYPES (likely string) when found, or the type of the input 'code' parameter when not found.

Usage Example

# Assuming DOCUMENT_TYPES is defined as:
# DOCUMENT_TYPES = {'Invoice': 'INV', 'Receipt': 'RCP', 'Contract': 'CTR'}

# Get document type name from code
type_name = get_document_type_name('INV')
print(type_name)  # Output: 'Invoice'

# Handle unknown code
unknown_type = get_document_type_name('XYZ')
print(unknown_type)  # Output: 'XYZ'

# Typical usage in document processing
doc_code = 'RCP'
full_name = get_document_type_name(doc_code)
print(f"Processing document type: {full_name}")  # Output: 'Processing document type: Receipt'

Best Practices

  • Ensure DOCUMENT_TYPES dictionary is properly defined and accessible in the module scope before calling this function
  • The function performs a linear search through the dictionary, so for large DOCUMENT_TYPES dictionaries, consider creating a reverse mapping dictionary for O(1) lookup performance
  • The function returns the original code if not found, which provides graceful degradation but may mask data quality issues - consider logging when codes are not found
  • Consider adding type hints to the function signature for better code documentation and IDE support
  • If DOCUMENT_TYPES is modified at runtime, this function will reflect those changes immediately due to its lookup approach

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_document_type_code 91.1% similar

    Retrieves a document type code from a dictionary lookup using the provided document type name, returning the name itself if no mapping exists.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_status_code 72.3% similar

    Retrieves a document status code from a dictionary lookup using the provided full name, returning the name itself if not found.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_type 71.9% similar

    Retrieves configuration details for a specific document type by looking it up in DOCUMENT_CONFIG or DOCUMENT_TYPES, returning a dictionary with document metadata or an empty dict if not found.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_status_name 71.9% similar

    Retrieves the full document status name corresponding to a given status code by performing a reverse lookup in the DOCUMENT_STATUSES dictionary.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_types 65.7% similar

    Retrieves document type configurations from application settings, optionally filtering by a specific type code, and returns them as a list of dictionaries with detailed metadata.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
← Back to Browse