🔍 Code Extractor

function get_document_type_v1

Maturity: 50

Retrieves configuration details for a specific document type by looking it up in DOCUMENT_CONFIG or DOCUMENT_TYPES dictionaries.

File:
/tf/active/vicechatdev/CDocs single class/config/settings.py
Lines:
448 - 473
Complexity:
simple

Purpose

This function serves as a lookup utility to fetch document type metadata including prefix, name, numbering format, template, and approval levels. It first checks a comprehensive DOCUMENT_CONFIG dictionary, then falls back to a simpler DOCUMENT_TYPES dictionary with default values, and returns an empty dictionary if the document type is not found in either source.

Source Code

def get_document_type(doc_type: str) -> Dict[str, Any]:
    """
    Get details for a specific document type.
    
    Args:
        doc_type: Document type code (e.g., 'SOP')
        
    Returns:
        Dictionary with document type details or empty dict if not found
    """
    # Check if the doc_type exists in the extended dictionary
    if (doc_type in DOCUMENT_CONFIG):
        return DOCUMENT_CONFIG[doc_type]
        
    # If just using the simple list, return a basic dictionary
    if doc_type in DOCUMENT_TYPES.values():
        return {
            'prefix': doc_type[:3].upper(),
            'name': doc_type,
            'numbering_format': '{prefix}-{dept}-{number:03d}',
            'template': None,
            'approval_levels': 1
        }
        
    # Not found in either place
    return {}

Parameters

Name Type Default Kind
doc_type str - positional_or_keyword

Parameter Details

doc_type: A string representing the document type code (e.g., 'SOP', 'WI', 'FORM'). This code is used to look up the document configuration in predefined dictionaries. The function is case-sensitive and expects the exact code as stored in DOCUMENT_CONFIG or DOCUMENT_TYPES.

Return Value

Type: Dict[str, Any]

Returns a Dictionary[str, Any] containing document type details. If found in DOCUMENT_CONFIG, returns the complete configuration dictionary. If found only in DOCUMENT_TYPES, returns a basic dictionary with keys: 'prefix' (3-character uppercase string), 'name' (document type name), 'numbering_format' (string template), 'template' (None), and 'approval_levels' (integer 1). Returns an empty dictionary {} if the document type is not found in either source.

Required Imports

from typing import Dict, Any

Usage Example

# Assuming DOCUMENT_CONFIG and DOCUMENT_TYPES are defined
DOCUMENT_CONFIG = {
    'SOP': {
        'prefix': 'SOP',
        'name': 'Standard Operating Procedure',
        'numbering_format': '{prefix}-{dept}-{number:03d}',
        'template': 'sop_template.docx',
        'approval_levels': 2
    }
}

DOCUMENT_TYPES = {
    'work_instruction': 'Work Instruction'
}

# Get details for a document type in DOCUMENT_CONFIG
sop_details = get_document_type('SOP')
print(sop_details['name'])  # Output: 'Standard Operating Procedure'

# Get details for a document type in DOCUMENT_TYPES
wi_details = get_document_type('Work Instruction')
print(wi_details['prefix'])  # Output: 'WOR'

# Try to get a non-existent document type
unknown = get_document_type('UNKNOWN')
print(unknown)  # Output: {}

Best Practices

  • Ensure DOCUMENT_CONFIG and DOCUMENT_TYPES dictionaries are properly initialized before calling this function
  • Handle the empty dictionary return value to avoid KeyError when accessing expected keys
  • Consider using .get() method on the returned dictionary for safer key access
  • The function performs case-sensitive lookups, so ensure doc_type parameter matches the exact case used in the configuration dictionaries
  • The fallback logic creates a prefix by taking the first 3 characters and uppercasing them, which may not be suitable for all document type names

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_document_type 97.3% 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_types 74.6% 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
  • function get_document_type_name 70.6% similar

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

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_type_code 70.0% 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_v1 57.1% similar

    Retrieves comprehensive details of a controlled document by its UID, including optional version history, review cycles, and approval workflows.

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