Configuration Management - lundeen-bryan/EZLogger_SLN GitHub Wiki
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
- Loading Word Document Properties into Forms
- Populating ComboBoxes from JSON
- Best Practices
The ConfigHelper module handles the creation, reading, and updating of configuration files used by EZLogger.
- 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.
| 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 |
| 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. |
{
"status": "created",
"created_at": "2025-04-17T21:01:00",
"sp_filepath": {
"global_config_file": "C:\\Users\\lunde\\Documents\\EZLogger\\global_config.json"
}
}EZLogger uses a consistent pattern for pulling Word CustomDocumentProperties into form controls.
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]
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
NextThis method avoids hardcoding property assignments and allows scalable mapping.
Dropdown lists in EZLogger (e.g., opinions, report types) are populated dynamically from the global_config.json.
{
"listbox": {
"opinions": ["Competent", "Not Yet Competent", "Malingering"],
"report_type": ["PPR", "1370(b)(1)"]
}
}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 ClassFor report types:
ReportTypeCbo.ItemsSource = ConfigHelper.GetReportTypeList()- 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.
- 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.
Last Updated: April 28, 2025