Skip to content

DICOM Text SR Writer Updates#578

Merged
MMelQin merged 1 commit into
Project-MONAI:mainfrom
bluna301:bl/dicom_text_sr_writer_op_updates
Jun 9, 2026
Merged

DICOM Text SR Writer Updates#578
MMelQin merged 1 commit into
Project-MONAI:mainfrom
bluna301:bl/dicom_text_sr_writer_op_updates

Conversation

@bluna301

@bluna301 bluna301 commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

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 DICOM metadata string formatting in Segmentation writer
    • Fixed initialization of Structured Report verification and completion flags
    • Ensured proper initialization of DICOM metadata sequences to meet structural requirements
    • Updated DICOM file metadata encoding for improved compatibility
  • Chores

    • Updated copyright year information

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

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR corrects DICOM metadata encoding issues and enhances SR writer compliance across three operator modules. CodeMeaning strings in Contributing Equipment Sequences are fixed, SR-specific metadata fields are added, and FileMetaInformation handling is refined. Copyright years are updated. No functional control flow is altered.

Changes

DICOM Writer Operators and Utilities

Layer / File(s) Summary
DICOM Segmentation writer CodeMeaning correction
monai/deploy/operators/dicom_seg_writer_operator.py
CodeMeaning string in the Purpose of Reference Code Sequence of Contributing Equipment Sequence is corrected from a malformed format; copyright year is updated.
SR writer metadata population and completeness
monai/deploy/operators/dicom_text_sr_writer_operator.py
CompletionFlag set to COMPLETE and VerificationFlag set to UNVERIFIED; empty ReferencedPerformedProcedureStepSequence and PerformedProcedureCodeSequence are initialized to satisfy SR document structural requirements; header and comment updates applied.
File metadata information and CodeMeaning corrections
monai/deploy/operators/dicom_utils.py
FileMetaInformationGroupLength assignment is commented out; FileMetaInformationVersion changed to direct byte string b"\x00\x01"; CodeMeaning in Contributing Equipment Sequence is corrected; copyright year range is expanded.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 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 title 'DICOM Text SR Writer Updates' is vague and generic, using the term 'Updates' without specifying what improvements or changes were made. Consider using a more specific title that highlights the main fix, such as 'Fix DICOM Text SR Writer validation issues' or 'Add required SR attributes and fix File Meta Information encoding'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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

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 2 times, most recently 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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

@chezhia chezhia left a comment

Copy link
Copy Markdown
Contributor

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.

@sonarqubecloud

Copy link
Copy Markdown

@bluna301

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor
✅ 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
…m typo fix

Signed-off-by: bluna301 <luna.bryanr@gmail.com>
@MMelQin MMelQin force-pushed the bl/dicom_text_sr_writer_op_updates branch from 07b50eb to 8769f64 Compare June 9, 2026 01:12
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

@MMelQin MMelQin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rebased and tested.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
monai/deploy/operators/dicom_utils.py (1)

201-201: ⚡ Quick win

Remove the commented-out assignment.

Please delete this stale commented code line instead of keeping it inline; it leaves a lingering analyzer warning and reduces readability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@monai/deploy/operators/dicom_utils.py` at line 201, Remove the stale
commented-out assignment line "# file_meta.FileMetaInformationGroupLength = 198"
from monai/deploy/operators/dicom_utils.py to eliminate the lingering analyzer
warning and improve readability; simply delete that single commented line where
it appears near the file_meta usage in the DICOM metadata assembly code (search
for the file_meta variable or surrounding DICOM metadata setup functions to
locate it).

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@monai/deploy/operators/dicom_utils.py`:
- Line 201: Remove the stale commented-out assignment line "#
file_meta.FileMetaInformationGroupLength = 198" from
monai/deploy/operators/dicom_utils.py to eliminate the lingering analyzer
warning and improve readability; simply delete that single commented line where
it appears near the file_meta usage in the DICOM metadata assembly code (search
for the file_meta variable or surrounding DICOM metadata setup functions to
locate it).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 72f50476-29c6-4377-a1e3-2debd1515132

📥 Commits

Reviewing files that changed from the base of the PR and between a3a64b2 and 8769f64.

📒 Files selected for processing (3)
  • monai/deploy/operators/dicom_seg_writer_operator.py
  • monai/deploy/operators/dicom_text_sr_writer_operator.py
  • monai/deploy/operators/dicom_utils.py
✅ Files skipped from review due to trivial changes (1)
  • monai/deploy/operators/dicom_seg_writer_operator.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • monai/deploy/operators/dicom_text_sr_writer_operator.py

@MMelQin MMelQin merged commit ed0e50a into Project-MONAI:main Jun 9, 2026
6 checks passed
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