Skip to content

Refactor DICOM anonymizer to use Microsoft.Extensions.Configuration with strongly typed models#257

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-256
Draft

Refactor DICOM anonymizer to use Microsoft.Extensions.Configuration with strongly typed models#257
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-256

Conversation

Copy link
Copy Markdown

Copilot AI commented Aug 15, 2025

This PR refactors the DICOM anonymizer to use the standard Microsoft.Extensions.Configuration framework with strongly typed models, eliminating the AnonymizerConfigurationManager and replacing dynamic JObject deserialization with compile-time type safety.

Key Changes

  • Removed AnonymizerConfigurationManager
  • Moved configuration loading logic directly into AnonymizerEngine constructors
  • Engine now reads configuration files locally using Microsoft.Extensions.Configuration
  • Replaced dynamic JObject deserialization with strongly typed models (AnonymizerRuleModel, PerturbSettings, DateShiftSettings, etc.)
  • Enhanced configuration loading with multiple source support
  • Renamed ConvertFromIConfiguration to ToAnonymizerConfiguration for better clarity

Benefits

  • Type Safety: Compile-time validation and IntelliSense support
  • Standards Compliance: Uses .NET's standard configuration system
  • Maintainability: Eliminates reflection overhead and dynamic object access
  • Backward Compatibility: Existing configuration files work unchanged

Validation

Manual testing confirms the anonymizer successfully processes DICOM files with the new configuration system while maintaining all existing functionality.

Fixes #256.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jovinson-ms <88204686+jovinson-ms@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to standard configuration Refactor to standard Microsoft.Extensions.Configuration Aug 15, 2025
Copilot AI requested a review from jovinson-ms August 15, 2025 21:48
@jovinson-ms
Copy link
Copy Markdown
Collaborator

@copilot please restrict the changes to the DICOM project only. Please refactor the Anonymizer engine to read the configuration file locally using Microsoft.Extensions.Configuration, get rid of AnonymizerConfigurationManager, and update the files under /Rules to deserialize using models instead of using dynamic deserialization.

…strongly typed models

Co-authored-by: jovinson-ms <88204686+jovinson-ms@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Aug 15, 2025

@copilot please restrict the changes to the DICOM project only. Please refactor the Anonymizer engine to read the configuration file locally using Microsoft.Extensions.Configuration, get rid of Anonym...

I've completed the refactoring as requested. The changes are now restricted to the DICOM project only and implement all the requested improvements:

Restricted to DICOM project only - Reverted all FHIR changes from previous commits
Refactored Anonymizer engine - Uses Microsoft.Extensions.Configuration directly for local configuration file reading
Removed AnonymizerConfigurationManager - Completely eliminated and moved functionality into AnonymizerEngine
Updated Rules with strongly typed models - Replaced JObject deserialization with strongly typed models (AnonymizerRuleModel, PerturbSettings, DateShiftSettings, etc.)

The refactoring maintains full backward compatibility - existing configuration files work unchanged and the anonymizer successfully processes sample DICOM files. The solution now uses .NET's standard configuration system with compile-time type safety.

Commit: 4176041

Copilot AI changed the title Refactor to standard Microsoft.Extensions.Configuration Refactor DICOM anonymizer to use Microsoft.Extensions.Configuration with strongly typed models Aug 15, 2025
_logger.LogDebug("Successfully initialized anonymizer engine.");
}

private static AnonymizerConfiguration ConvertFromIConfiguration(IConfiguration configuration)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot function name ConvertFromIConfiguration is a bit vague. maybe "ToAnonymizerConfiguration"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the method to ToAnonymizerConfiguration for better clarity. Commit: f441d91

…ter clarity

Co-authored-by: chrisribe <1999791+chrisribe@users.noreply.github.com>
Copilot AI requested a review from chrisribe August 29, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor to standard configuration

3 participants