Configuration Management - lundeen-bryan/EZLogger_SLN GitHub Wiki

Configuration Management

This page explains how EZLogger manages configuration files, loads document properties into views, and dynamically populates controls like ComboBoxes from JSON files.


Managing Configuration Files with ConfigHelper

The ConfigHelper module handles the creation, reading, and updating of configuration files used by EZLogger.

Key Responsibilities

  • Ensures the existence of the local configuration file (local_user_config.json).
  • Prompts the user to select a global configuration file (global_config.json) if necessary.
  • Provides helper functions to retrieve paths and structured data for use throughout the app.

Important Paths

Setting Location Purpose
Local Config %USERPROFILE%\.ezlogger\local_user_config.json Stores user-specific settings and the path to global config
Global Config (User-selected) Stores shared lists like opinions, report types, and alerts

Core Functions

Function Purpose
GetLocalConfigPath() Ensures and retrieves the local config file path.
EnsureLocalUserConfigFileExists() Creates the .ezlogger folder and config if missing.
PromptForGlobalConfigFile() Prompts user to select global_config.json.
UpdateLocalConfigWithGlobalPath(globalConfigPath) Saves the selected global config path.
GetGlobalConfigPath() Retrieves the stored global config path.
GetOpinionList() Loads listbox options for opinions from global config.
GetReportTypeList() Loads listbox options for report types from global config.

Example Local Config

{
  "status": "created",
  "created_at": "2025-04-17T21:01:00",
  "sp_filepath": {
    "global_config_file": "C:\\Users\\lunde\\Documents\\EZLogger\\global_config.json"
  }
}

Loading Word Document Properties into Forms

EZLogger uses a consistent pattern for pulling Word CustomDocumentProperties into form controls.

General Workflow

flowchart TD
    A[User Clicks Button] --> B[Form Calls ViewHandler]
    B --> C[Handler uses DocumentPropertyHelper]
    C --> D[Reads property from active Word document]
    D --> E[Assigns property value to form control]
Loading

Example Mapping Pattern

Create a dictionary of document property keys and form actions:

Dim fieldMap As New Dictionary(Of String, Action(Of String)) From {
    {"Patient Number", Sub(val) view.TxtPatientId.Text = val},
    {"Patient Name", Sub(val) view.LblPatientName.Content = val},
    {"Program", Sub(val) view.LblProgram.Content = val}
}

Load properties dynamically:

For Each pair In fieldMap
    Dim value = DocumentPropertyHelper.GetPropertyValue(pair.Key)
    If Not String.IsNullOrWhiteSpace(value) Then
        pair.Value.Invoke(value)
    End If
Next

This method avoids hardcoding property assignments and allows scalable mapping.


Populating ComboBoxes from JSON

Dropdown lists in EZLogger (e.g., opinions, report types) are populated dynamically from the global_config.json.

Example JSON Structure

{
  "listbox": {
    "opinions": ["Competent", "Not Yet Competent", "Malingering"],
    "report_type": ["PPR", "1370(b)(1)"]
  }
}

Loading Values into ComboBoxes

For opinions:

Imports EZLogger.Helpers

Public Class OpinionView
    Private Sub OpinionView_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        OpinionCbo.ItemsSource = ConfigHelper.GetOpinionList()
    End Sub
End Class

For report types:

ReportTypeCbo.ItemsSource = ConfigHelper.GetReportTypeList()

Troubleshooting Common Issues

  • Ensure correct file paths in local_user_config.json.
  • Confirm control names match (OpinionCbo, ReportTypeCbo).
  • Remove any hardcoded <ComboBoxItem> entries from XAML when binding dynamically.

Best Practices

  • Always validate JSON paths before using them.
  • Handle missing or malformed JSON gracefully using Try/Catch.
  • Keep mappings clean by using dictionaries rather than hardcoded assignments.
  • Keep local user settings separate from shared organizational settings.
  • Use centralized Helpers (ConfigHelper, DocumentPropertyHelper) to avoid duplicate code.

Related Pages


Last Updated: April 28, 2025

⚠️ **GitHub.com Fallback** ⚠️