Skip to content

Conversation

fderuiter
Copy link
Owner

@fderuiter fderuiter commented Aug 23, 2025

No description provided.

fderuiter and others added 10 commits August 19, 2025 16:15
…chema. modified readme for postman collection.
feat: Update documentation and add new quick start test script
This commit addresses several items of technical debt in the repository:

-   Updated the Python version support to 3.11-3.12, dropping support for 3.10.
-   Updated all dependencies to their latest versions.
-   Fixed a pytest collection issue by configuring test paths.
-   Resolved several deprecation warnings in the test suite.
-   Corrected the mypy configuration to exclude the scripts directory.
-   Renamed a misplaced test script to avoid confusion.
Refactor: Address technical debt
This commit introduces a new CLI command for testing purposes to import a data dictionary.

The new command `imednet testing data-dictionary load` allows a user to load a data dictionary from either a single zip file or from four individual CSV files:
- BUSINESS_LOGIC.csv
- CHOICES.csv
- FORMS.csv
- QUESTIONS.csv

This functionality is useful for setting up a testing environment with a specific data dictionary.

The implementation includes:
- A new `testing` command group in the CLI.
- The `data-dictionary load` command with options for zip file or individual CSV files.
- Unit tests for the new CLI command.
This commit significantly enhances the testing utilities by introducing a business logic engine to the record generation process.

The `RecordGenerator` is now capable of parsing and applying business rules defined in the `BUSINESS_LOGIC.csv` file of a data dictionary. This allows for the generation of more realistic and internally consistent test data.

Key features of this commit:
- A new `LogicParser` class that parses the business logic XML into structured objects.
- A new `LogicEngine` class that evaluates the parsed rules against the record data.
- Integration of the parser and engine into the `RecordGenerator`. The generator now applies "disable and clear" and "hide and clear" actions based on the business logic.
- A more robust data generation process that handles a wider range of variable types.
- Comprehensive unit tests for the new parser and engine, and updated tests for the record generator and CLI.

This provides a solid foundation for handling more complex business logic in the future.
Extrapolates on the existing business logic engine by implementing new conditions and actions found in the `BUSINESS_LOGIC.csv` file.

New features include:
- Parsing for new condition tags: `<gt>`, `<lt>`, `<blank>`.
- Evaluation logic in the `LogicEngine` for `GreaterThan`, `LessThan`, and `IsBlank` conditions, with support for numeric and date-based comparisons.
- An `execute` method in the `LogicEngine` to apply actions to data.
- Execution logic for `DisableAndClearField` and `HideAndClearField` actions.
- Comprehensive unit tests for all new functionality in both the parser and the engine.
feat(testing): Add data dictionary importer command
feat(testing): Enhance Logic Engine with new conditions and actions
@fderuiter fderuiter changed the title Develop Dev -> Main v0.3.0 Aug 23, 2025
google-labs-jules bot and others added 19 commits August 23, 2025 01:44
This commit introduces a new workflow for providing clinical guidance based on FDA recommendations.

The `ClinicalGuidanceWorkflow` includes methods to:
- Retrieve standard user roles and responsibilities.
- Get requirements for delegation of authority.
- Get recommendations for electronic source data.
- Identify users who may need to be on a Delegation of Authority log, using fuzzy matching to compare roles.
- Annotate users with information about their roles based on standard guidance, also using fuzzy matching.

This workflow helps to operationalize FDA guidance within the iMednet SDK.
Ran the full linting and static analysis suite and fixed the
issues reported by `ruff` and `mypy`.

- Fixed several "line too long" errors in `imednet/workflows/clinical_guidance.py`.
- Added asserts to `imednet/testing/data_dictionary.py` to fix `mypy` errors.
- Ran `black` and `isort` to fix formatting and import order.
Fix linting and type checking errors
This commit introduces a number of refactorings to improve the overall code design and maintainability of the SDK.

The main changes are:
- Renamed `load_config` to `load_config_from_env` for clarity.
- Refactored `ImednetSDK` to use a `ClientFactory` for client creation.
- Moved the `Workflows` class to `imednet/workflows/__init__.py`.
- Added a `--version` option to the CLI.
- Refactored the CLI to be more testable by modifying the `with_sdk` decorator and updating the tests to mock `ImednetSDK` directly.
- Updated documentation and examples to reflect these changes.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…lysis of the repository's foundation and developer experience. The report covers the README.md, essential meta-files, and directory structure, providing recommendations for future growth. (#491)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit addresses several issues related to code quality and maintainability, identified during a deep analysis of the codebase.

    The main changes are:
    - Simplified the `ImednetSDK` initialization by moving configuration loading to a dedicated `imednet.config` module.
    - Deprecated the convenience methods in the `ImednetSDK` class in favor of a more consistent API.
    - Implemented a dynamic endpoint registry to make the SDK more extensible and easier to maintain.
    - Standardized error reporting with a dedicated error model in `imednet.models.error`.
    - Removed a broken and unused testing framework related to a "business logic engine".

    A detailed report of the analysis and the changes can be found in `REPO_HEALTH_ANALYSIS.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
The `sanitize_base_url` function was using a case-sensitive regex to remove the `/api` suffix from URLs. This meant that URLs with a capitalized `/API` suffix were not being sanitized correctly.

This commit fixes the issue by adding the `re.IGNORECASE` flag to the `re.sub` call, making the suffix removal case-insensitive.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This change adds docstrings to all public functions, methods, and classes
across the entire codebase. It also updates the README.md file to be a
more complete guide for new developers, with improved sections on features,
architecture, and usage examples.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
…495)

The `export_to_sql_by_form` function was using the global `variable_whitelist` when fetching records for each form. This was incorrect as it should only filter for variables that are part of the current form being processed.

This change corrects the logic to use the form-specific `variable_keys` list, which is already computed within the function, for the `variableNames` filter in the API call. This ensures that the record fetching is more efficient and correct.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Removes deprecated convenience methods from the `ImednetSDK` class.

These methods were marked as deprecated and their use generated warnings.
Their removal cleans up the SDK's public interface and encourages the use
of the modern, more explicit endpoint-based pattern (e.g., `sdk.studies.list()`).

The corresponding tests for these methods have also been removed.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* fix(dates): Make fractional second padding in date parsing more robust

The `parse_iso_datetime` function used `str.replace()` to pad fractional seconds to 6 digits. This is not robust, as it could replace other parts of the string if the fractional second pattern repeats.

This change replaces the unsafe `str.replace()` with a targeted replacement using string slicing based on the regex match positions. This ensures only the intended part of the string is modified.

A new test case was added to demonstrate the issue. Although the test passes with both the original and fixed code due to the leniency of `datetime.fromisoformat`, the fix improves the robustness of the parsing logic.

* fix(validators): Raise TypeError for invalid dict input

The `parse_dict_or_default` function in `imednet/utils/validators.py`
previously returned a default empty dictionary when a non-dict, non-None
value was provided. This could lead to silent data loss and hide
potential bugs.

This commit changes the behavior to raise a `TypeError` when the input is
not a dictionary or None, making the function's behavior more explicit
and preventing silent failures.

An existing test was updated to reflect this new behavior, and a new
test file was added with more specific tests for the function.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* fix(url): Handle whitespace in URL sanitization

The `sanitize_base_url` function failed to correctly sanitize URLs that
contained leading or trailing whitespace. This caused the subsequent
regex matching for the `/api` suffix to fail.

This commit replaces `url.rstrip("/")` with `url.strip(" /")` to
ensure that both whitespace and slashes are stripped from both ends
of the URL before processing.

A new test case has been added to verify the fix.

* Fix: Add missing get_job and poll_job methods to ImednetSDK

The `ImednetSDK` class was missing the `get_job` and `poll_job` methods,
which are used in the CLI, scripts, and documentation. This would cause
an `AttributeError` at runtime.

This change implements the missing methods and adds unit tests to verify
their functionality. The `get_job` method is a simple wrapper around the
`jobs.get` method, and the `poll_job` method uses the existing `JobPoller`
class to poll for job status.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
The `get_queries_by_site` workflow method did not correctly handle cases where the `additional_filter` contained a `subject_key`. Instead of intersecting the subject keys from the site with the subject keys from the filter, it would overwrite the site's subjects with the ones from the filter.

This commit fixes the bug by ensuring that the subject keys from the site and the filter are intersected. This ensures that the function returns only the queries for the subjects that belong to the specified site and also match the additional filter criteria.

A new test case has been added to verify the fix.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This refactoring introduces a new `imednet/api` submodule to better organize the project structure. All low-level API client code, including the core client, endpoints, models, and other related components, has been moved into this new submodule.

This change improves the separation of concerns, making the project easier to understand, maintain, and extend. The public API of the SDK remains unchanged.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* Refactor: Create imednet/api submodule

This refactoring introduces a new `imednet/api` submodule to better organize the project structure. All low-level API client code, including the core client, endpoints, models, and other related components, has been moved into this new submodule.

This change improves the separation of concerns, making the project easier to understand, maintain, and extend. The public API of the SDK remains unchanged.

* fix(utils): correct sanitize_base_url to handle relative URLs

The `sanitize_base_url` function was using `url.strip(" /")` which
incorrectly removed leading slashes from relative URLs, changing their
meaning. For example, `/my/api/` would become `my` instead of `/my`.

This commit changes the implementation to only strip trailing slashes
and the `/api` suffix, without affecting the beginning of the URL.
This is done by first stripping whitespace, then using a regex to
remove a trailing `/api` or `/api/`, and finally `rstrip('/')` to
remove any remaining trailing slashes.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
fderuiter and others added 5 commits September 13, 2025 13:33
* Refactor: Create imednet/api submodule

This refactoring introduces a new `imednet/api` submodule to better organize the project structure. All low-level API client code, including the core client, endpoints, models, and other related components, has been moved into this new submodule.

This change improves the separation of concerns, making the project easier to understand, maintain, and extend. The public API of the SDK remains unchanged.

* Fix: Raise ValueError for unsupported typed values in tests

The `_typed_value` function in `tests/live/conftest.py` would previously
return an empty string for variable types that were not found in the
`_TYPED_VALUES` map. This could lead to silent failures in live tests,
as an empty string might be an invalid value for a required field,
causing an API error that is hard to debug.

This change modifies `_typed_value` to raise a `ValueError` when an
unsupported variable type is provided. This ensures that tests will fail
fast with a clear error message if they try to use an unsupported type.

A new unit test has been added to `tests/unit/test_typed_values.py` to
verify this new behavior.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* Refactor: Create imednet/api submodule

This refactoring introduces a new `imednet/api` submodule to better organize the project structure. All low-level API client code, including the core client, endpoints, models, and other related components, has been moved into this new submodule.

This change improves the separation of concerns, making the project easier to understand, maintain, and extend. The public API of the SDK remains unchanged.

* Fix: Raise ValueError for invalid boolean strings

The `parse_bool` function in `imednet/utils/validators.py` would previously
return `False` for any string that it did not recognize as a representation
of a boolean value. This could mask data quality issues by silently
converting invalid strings to `False`.

This change modifies `parse_bool` to raise a `ValueError` when it
encounters a string that it cannot interpret as a boolean. This makes the
function's behavior more explicit and prevents silent failures.

In addition, the tests for the `validators` module have been consolidated
from `tests/unit/test_models_validators.py` into
`tests/unit/utils/test_validators.py` to improve the organization of the
test suite. The old test file has been deleted.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
The `parse_bool` function in `imednet/utils/validators.py` would previously
return `False` for any unhandled input types (e.g., `None`, lists, or
dicts). This could mask potential data issues by silently coercing
invalid input to a boolean.

This commit changes the behavior to raise a `TypeError` when an unhandled
type is passed to `parse_bool`. This makes the function's behavior more
explicit and consistent with its handling of unparseable strings, where
it raises a `ValueError`.

A new test case has been added to verify that a `TypeError` is raised for
unhandled types, and the existing tests have been updated to reflect this
new behavior.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
The schema validator incorrectly used an integer-only validator for the
'number' type, causing floating-point values to be rejected.

This change maps the 'number' type to the float validator, which correctly
handles both integers and floats. A new unit test is added to verify
that float values are now accepted for variables of this type.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
The `parse_bool` function did not correctly parse string representations
of floating-point numbers (e.g., "1.0", "0.0"). While it handled
floats directly, it would raise a ValueError for their string
equivalents.

This commit adds logic to attempt to parse the string as a float if it's
not one of the recognized boolean string values. This makes the
function more robust and handles a wider range of string inputs
consistently with how it handles numeric types.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@fderuiter fderuiter linked an issue Sep 13, 2025 that may be closed by this pull request
44 tasks
The `parse_bool` function did not correctly parse string representations
of floating-point numbers (e.g., "1.0", "0.0"). While it handled
floats directly, it would raise a ValueError for their string
equivalents.

This commit adds logic to attempt to parse the string as a float if it's
not one of the recognized boolean string values. This makes the
function more robust and handles a wider range of string inputs
consistently with how it handles numeric types.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
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.

Docs: consistency and completeness sweep

1 participant