Skip to content

feat: add ConfigService and GlobalsRegistrar helpers#7

Merged
kojiromike merged 1 commit intomainfrom
feat/config-service-globals-registrar
Mar 30, 2026
Merged

feat: add ConfigService and GlobalsRegistrar helpers#7
kojiromike merged 1 commit intomainfrom
feat/config-service-globals-registrar

Conversation

@kojiromike
Copy link
Copy Markdown
Contributor

@kojiromike kojiromike commented Mar 30, 2026

Summary

  • ConfigService: saveSetting() and saveEncryptedSetting() — upsert module settings to the OpenEMR globals table, with an encrypted variant using CryptoGen
  • GlobalsRegistrar + GlobalsSectionDescriptor: register a module globals section (enable/disable toggle + settings page link) via GlobalsInitializedEvent, eliminating boilerplate from every module bootstrap
  • Adds openemr/openemr as a dev dependency (package repo pattern) and symfony/event-dispatcher as a runtime dependency

Usage

// Save settings
$configService = new ConfigService();
$configService->saveSetting($key, $value);
$configService->saveEncryptedSetting($key, $secret);

// Register globals section
$registrar = new GlobalsRegistrar($globalsBag);
$registrar->register($eventDispatcher, new GlobalsSectionDescriptor(
    sectionName: 'OpenCoreEMR My Module',
    moduleDirName: 'oce-module-my-module',
    enableKey: 'oce_my_module_enabled',
    settingsDescription: 'API credentials and module options.',
));

Closes #6

Test plan

  • All 80 tests pass (7 new tests for ConfigService, GlobalsRegistrar, GlobalsSectionDescriptor)
  • PHPStan level 10 clean
  • PHPCS / Rector clean
  • Composer require-checker clean (OpenEMR symbols whitelisted)
  • Integration: migrate oce-module-sinch-conversations to use these shared classes

🤖 Generated with Claude Code

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds shared helpers for OpenCoreEMR modules to persist settings into the globals table and to register a module’s globals section (enable toggle + settings link) via the GlobalsInitializedEvent, along with unit tests and supporting test mocks.

Changes:

  • Introduces ConfigService for globals-table upserts, including an encrypted-save helper using CryptoGen::encryptStandard().
  • Introduces GlobalsRegistrar + GlobalsSectionDescriptor to reduce module bootstrap boilerplate for globals-section registration.
  • Updates dependencies and adds PHPUnit tests + OpenEMR stubs/mocks for test execution.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ConfigService.php Adds globals-table upsert helpers (plaintext + encrypted).
src/GlobalsRegistrar.php Registers globals section, enable toggle, and settings-link via event listener.
src/GlobalsSectionDescriptor.php Adds a descriptor object for globals registration parameters.
tests/Unit/ConfigServiceTest.php Verifies upsert SQL + encryption behavior via mocked QueryUtils/CryptoGen.
tests/Unit/GlobalsRegistrarTest.php Verifies globals metadata created by registration listener dispatch.
tests/Unit/GlobalsSectionDescriptorTest.php Verifies descriptor property accessibility.
tests/Mocks/MockQueryUtils.php Mocks OpenEMR QueryUtils for query capture/exception simulation.
tests/Mocks/MockCryptoGen.php Mocks OpenEMR CryptoGen encryption for deterministic tests.
tests/Mocks/openemr_functions.php Stubs OpenEMR global functions used by generated HTML.
tests/bootstrap.php Loads mocks for tests.
composer.json Adds symfony/event-dispatcher runtime dep and openemr/openemr dev dep + repositories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ConfigService.php
Comment thread tests/Mocks/openemr_functions.php Outdated
Comment thread src/GlobalsRegistrar.php Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/bootstrap.php Outdated
Comment thread tests/Unit/GlobalsRegistrarTest.php
Comment thread src/ConfigService.php
@kojiromike kojiromike force-pushed the feat/config-service-globals-registrar branch from 4fec463 to 2fe2edd Compare March 30, 2026 23:31
@kojiromike kojiromike requested a review from Copilot March 30, 2026 23:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ConfigService.php
Comment thread tests/Unit/GlobalsRegistrarTest.php
@kojiromike kojiromike force-pushed the feat/config-service-globals-registrar branch from 2fe2edd to 5253940 Compare March 30, 2026 23:40
@kojiromike kojiromike requested a review from Copilot March 30, 2026 23:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Extract two patterns duplicated across every OCE module into this
shared library:

- ConfigService: upsert settings to the globals table via
  saveSetting() and saveEncryptedSetting() (CryptoGen). Uses
  portable ON DUPLICATE KEY UPDATE with bound parameters for
  MariaDB/MySQL compatibility.

- GlobalsRegistrar + GlobalsSectionDescriptor: register a module's
  globals section (enable/disable toggle + settings page link) via
  GlobalsInitializedEvent, replacing identical boilerplate in every
  module bootstrap.

Also adds openemr/openemr as a dev dependency (package repo pattern)
and symfony/event-dispatcher as a runtime dependency.

Closes #6

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kojiromike kojiromike force-pushed the feat/config-service-globals-registrar branch from 5253940 to cecd310 Compare March 30, 2026 23:48
@kojiromike kojiromike merged commit f0a94cb into main Mar 30, 2026
12 checks passed
@kojiromike kojiromike deleted the feat/config-service-globals-registrar branch March 30, 2026 23:54
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.

feat: add ConfigService and globals registration helpers

2 participants