Skip to content

DICOM Text SR Writer Updates#578

Open
bluna301 wants to merge 3 commits intoProject-MONAI:mainfrom
bluna301:bl/dicom_text_sr_writer_op_updates
Open

DICOM Text SR Writer Updates#578
bluna301 wants to merge 3 commits intoProject-MONAI:mainfrom
bluna301:bl/dicom_text_sr_writer_op_updates

Conversation

@bluna301
Copy link
Copy Markdown
Contributor

@bluna301 bluna301 commented Feb 12, 2026

When preparing MAP pipelines for clinical integration, the DICOM SRs produced by the default DICOMTextSRWriterOperator were validated using libraries such as dciodvfy and dicom-validator. The following validation logs are produced:

Warning - Bad FileMetaInformationVersion Attribute - wrong VR, length or not 0x00,0x01

BasicTextSR

Error - Missing attribute Type 2 Required Element=<ReferencedPerformedProcedureStepSequence> Module=<SRDocumentSeries>
Error - Missing attribute Type 1 Required Element=<CompletionFlag> Module=<SRDocumentGeneral>
Error - Missing attribute Type 2 Required Element=<PerformedProcedureCodeSequence> Module=<SRDocumentGeneral>
Warning - Attribute is not present in standard DICOM IOD - (0x0008,0x002a) DT Acquisition DateTime
Warning - Attribute is not present in standard DICOM IOD - (0x0018,0x0015) CS Body Part Examined
Warning - Attribute is not present in standard DICOM IOD - (0x0018,0x1002) UI Device UID
Warning - Attribute is not present in standard DICOM IOD - (0x0040,0x1001) SH Requested Procedure ID
Warning - Dicom dataset contains attributes not present in standard DICOM IOD - this is a Standard Extended SOP Class

The non-standard attributes that throw warnings are defined in write_common_modules within dicom_utils.py; these are recognized in the source code as extensions of the DICOM IOD. This PR resolves the remaining warnings and errors.


The FileMetaInformation tags on the DICOM SR are written as follows (MicroDICOM viewer):

image

This is manually set in write_common_modules:

# File meta info data set
file_meta = Dataset()
file_meta.FileMetaInformationGroupLength = 198
file_meta.FileMetaInformationVersion = bytes("01", "utf-8")  # '\x00\x01'

However, this seems to encode the character 0 and 1 to their UTF-8 byte values of 0x30 and 0x31, respectively, which results in a value of b"\x30\x31" --> 30\31. This was updated to write the literal bytes 00 01 i.e. b"\x00\x01"; FileMetaInformationGroupLength setting was also removed, as this will be handled automatically during DICOM writing.


CompletionFlag indicates the degree of completeness of the DICOM SR. Considering the DICOM SR is complete in the context of the AI model (i.e. it is a finalized AI output from the model), this tag value was set to COMPLETE.

ReferencedPerformedProcedureStepSequence uniquely identifies the Performed Procedure Step SOP Instance for which the series is created. However, we are not tracking the Modality Performed Procedure Step (MPPS) via MAPs/MONAI Deploy; while this tag is Type 3 (Optional) for most modalities, it is not copied by write_common_modules. As such, this tag value was written as an empty Sequence.

PerformedProcedureCodeSequence conveys the codes of the performed procedures pertaining to this SOP Instance. However, we are not tracking the Modality Performed Procedure Step (MPPS) via MAPs/MONAI Deploy and this tag is not present for most imaging modalities. As such, this tag value was written as an empty Sequence.


Miscellaneous Updates:

  • seg_purpose_of_reference_code.CodeMeaning = '"Processing Algorithm' typo corrected
  • setuptools<81.0.0 pin; pkg_resources is deprecated above this version
  • Formatting in test files

Summary by CodeRabbit

  • Bug Fixes

    • Corrected metadata string formatting in DICOM segmentation output for proper data integrity
    • Added required metadata fields to DICOM structured report documents to improve compliance with medical imaging standards
  • Chores

    • Updated dependency version constraints for improved environment compatibility
    • Reformatted test files for consistency

@bluna301 bluna301 marked this pull request as draft February 12, 2026 22:02
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 12, 2026

Warning

Rate limit exceeded

@bluna301 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 32 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dfce3df0-b6d2-43bd-9bae-2af871ee0eba

📥 Commits

Reviewing files that changed from the base of the PR and between a3a64b2 and 07b50eb.

📒 Files selected for processing (1)
  • requirements-min.txt

Walkthrough

The PR includes minor bug fixes to DICOM metadata handling, particularly correcting malformed string values and adding SR-specific metadata requirements. Dependencies are constrained, test fixtures are reformatted, and copyright years are updated. No public API signatures are altered.

Changes

Cohort / File(s) Summary
DICOM Operators & Utilities
monai/deploy/operators/dicom_seg_writer_operator.py, monai/deploy/operators/dicom_text_sr_writer_operator.py, monai/deploy/operators/dicom_utils.py
Corrections to CodeMeaning string quotation in DICOM segmentation writer, addition of SR-specific metadata (CompletionFlag, VerificationsFlag, empty sequences), FileMetaInformationVersion byte literal update, and copyright year increments. No control flow changes.
Dependency Constraints
requirements-min.txt
Added upper bound constraint to setuptools version (<81.0.0) with deprecation comment for pkg_resources.
Test Fixtures & Formatting
tests/fixtures/runner_fixtures.py, tools/pipeline-generator/tests/test_cli.py
Reformatted multiline JSON and YAML string literals by consolidating closing markers; no semantic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A hop through the code, a quote here, a byte there,
Metadata mended with utmost care,
SR sequences nestled, dependencies tight,
Tests format anew—everything just right! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'DICOM Text SR Writer Updates' is vague and generic, referring broadly to updates without specifying the actual nature or scope of changes. Consider a more specific title that highlights the key fix, such as 'Fix DICOM Text SR Writer validation issues' or 'Add required DICOM SR elements and fix metadata encoding'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 28 minutes and 32 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@bluna301 bluna301 force-pushed the bl/dicom_text_sr_writer_op_updates branch from fc5c009 to 51063df Compare February 17, 2026 16:29
Signed-off-by: bluna301 <luna.bryanr@gmail.com>
…m typo fix

Signed-off-by: bluna301 <luna.bryanr@gmail.com>
@bluna301 bluna301 force-pushed the bl/dicom_text_sr_writer_op_updates branch from 51063df to a3a64b2 Compare February 17, 2026 17:11
@sonarqubecloud
Copy link
Copy Markdown

@bluna301 bluna301 changed the title [WIP] DICOM Text SR Writer Updates DICOM Text SR Writer Updates Feb 17, 2026
@bluna301 bluna301 marked this pull request as ready for review February 17, 2026 17:20
@bluna301 bluna301 self-assigned this Feb 17, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
requirements-min.txt (1)

3-3: Consider tracking pkg_resources migration to importlib as separate technical debt work.

The codebase uses pkg_resources.working_set in monai/deploy/utils/importutil.py (4 functions: is_dist_editable(), dist_module_path(), is_module_installed(), dist_requires()). While the setuptools <81.0.0 pin correctly addresses the immediate deprecation issue, migrating to importlib.metadata would eliminate this version constraint and is a worthwhile long-term improvement. However, this refactoring is best tracked as separate work since it requires code changes beyond the scope of the requirements file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@requirements-min.txt` at line 3, Create a technical-debt task to migrate uses
of pkg_resources to importlib.metadata for the functions is_dist_editable(),
dist_module_path(), is_module_installed(), and dist_requires() in
monai/deploy/utils/importutil.py; the task should list the exact functions to
change, describe replacing pkg_resources.working_set calls with
importlib.metadata (or importlib_metadata for older Python), include tests to
preserve current behavior (editable/install detection and requirement parsing),
and note that once migration is complete the setuptools>=59.5.0,<81.0.0 pin in
requirements-min.txt can be revisited or removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@requirements-min.txt`:
- Line 3: Create a technical-debt task to migrate uses of pkg_resources to
importlib.metadata for the functions is_dist_editable(), dist_module_path(),
is_module_installed(), and dist_requires() in monai/deploy/utils/importutil.py;
the task should list the exact functions to change, describe replacing
pkg_resources.working_set calls with importlib.metadata (or importlib_metadata
for older Python), include tests to preserve current behavior (editable/install
detection and requirement parsing), and note that once migration is complete the
setuptools>=59.5.0,<81.0.0 pin in requirements-min.txt can be revisited or
removed.

Comment thread requirements-min.txt Outdated
Copy link
Copy Markdown
Contributor

@chezhia chezhia left a comment

Choose a reason for hiding this comment

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

All minor changes, if we are enabling enhanced SR support in this PR, please make a not in the relevant docs too, so people are aware we support it.

Signed-off-by: bluna301 <luna.bryanr@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@bluna301
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bluna301 bluna301 requested a review from MMelQin April 30, 2026 18:37
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.

3 participants