Skip to content

feat(codemods): runnable codemods for the upgrade to dcmjs 1.0; fix(core): a single PN value is array-like - #646

Merged
wayfarer3130 merged 5 commits into
1.0-betafrom
docs/1.0-beta-codemods
Nov 24, 2026
Merged

wayfarer3130 merged 5 commits into
1.0-betafrom
docs/1.0-beta-codemods

Conversation

@wayfarer3130

@wayfarer3130 wayfarer3130 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds runnable codemods for the upgrade from dcmjs 0.x to 1.0, in packages/codemods/. The codemods use the format of the Codemod registry, with the same layout as the Cornerstone3D codemods (packages/codemods/registry/cornerstone3d/6). The PR also fixes the shape of a single PN value.

npx codemod @dcmjs-org/dcmjs-1 --dry-run

Each package is self-contained. It has a codemod.yaml, a workflow.yaml, an ast-grep transform in scripts/, fixture tests in tests/<language>/<case>/, and a README. The README gives what the codemod changes, what it reports, and what it cannot find.

Package What it does
@dcmjs-org/dcmjs-1 Runs the two packages below, in order.
@dcmjs-org/dcmjs-1-package-name Changes package.json and the module name dcmjs to @dcmjs-org/dcmjs. Reports a 0.x subpath and a jest configuration.
@dcmjs-org/dcmjs-1-naturalized-values Rewrites an array method on a single-item sequence (Array.from), a string compare or string method on a single PN value (String()), and removes addTagAccessors. Reports a list-VM keyword that the code uses as a scalar, the private-data round trip, _vrMap iteration, hex-key patterns, and nameMap writes.
@dcmjs-org/dcmjs-1-event-stream Optional. Replaces readFile + naturalizeDataset and new DicomDict + write with the event stream, only in an async function or at the top level of an ES module, so that no caller changes. Reports the other sites, with the reason.

The codemods write no comment into the code. A site that needs a person goes into the metric dcmjs-1-manual or dcmjs-1-review, with the rule, the file and the line.

This PR removes the markdown descriptions docs/codemods/*.md of the first version of this PR. Their content moved into the package READMEs. docs/MIGRATION.md links to packages/codemods.

Fix: a single PN value is array-like

In 0.x, ds.PatientName[0].Alphabetic worked. In the 1.0 beta, ds.PatientName[0] was undefined. This PR applies the rule of a single-item sequence (NAT-U-SQ-1) to a single PN value:

  • toPersonNameValue in packages/core/src/utilities/personNameValue.js calls the existing addAccessors on a single component object.
  • ds.PatientName[0] === ds.PatientName, ds.PatientName.length is 1, and for...of gives the name once.
  • Array.isArray(ds.PatientName) is false. Object.keys, JSON.stringify, String() and denaturalize do not change.

NAT-U-VAL-5 in docs/specs/naturalized-dataset.md and change 5 in docs/MIGRATION.md record the rule.

Test

  • pnpm run validate in packages/codemods runs codemod workflow validate on the 4 packages, and then 13 fixture tests (JavaScript, TypeScript and package.json). Each fixture with a report has a metrics.json.
  • I ran the three child workflows from the checkout on a sample project with npx codemod workflow run. The result was correct, and the report named the expected site.
  • A new test in test/core/naturalizeDataset.test.js checks the PN shape for naturalizeDataset, NaturalizedListener and an assigned string. The full jest suite passes: 1246 tests pass, and 12 tests are skipped.

Open items

  • The CI does not run the codemod fixtures yet. The fixtures need npx codemod, which the CI must download.
  • A maintainer must publish the four packages to the Codemod registry (npx codemod publish), the child packages before @dcmjs-org/dcmjs-1. Until then, the npx codemod @dcmjs-org/dcmjs-1 command does not work. npx codemod workflow run -w <package directory> works from a checkout.

🤖 Generated with Claude Code

wayfarer3130 and others added 3 commits November 24, 2026 10:30
… 1.0

Phase 1: change the package name to @dcmjs/dcmjs (CM-1), and adapt the
code to the naturalized values of 1.0 (CM-2). Phase 2: read Part 10
directly to a naturalized dataset (CM-3), and write a naturalized
dataset directly to Part 10 (CM-4), with the event stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A single PN value is the component object, and now also has a hidden [0]
(the object), a length of 1 and an iterator (NAT-U-VAL-5, NAT-U-SQ-1).
So the 0.x form ds.PatientName[0].Alphabetic keeps working, and
ds.PatientName[0] === ds.PatientName.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130 wayfarer3130 changed the title docs(migration): codemod descriptions for the upgrade from dcmjs 0.x to 1.0 docs(migration): codemods for the upgrade to dcmjs 1.0; fix(core): a single PN value is array-like Nov 24, 2026
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 24, 2026 15:48
Replace the codemod descriptions in docs/codemods with packages of the
Codemod registry, in the layout of the Cornerstone3D codemods. Each
package has a codemod.yaml, a workflow.yaml, an ast-grep transform, the
fixture tests and a README:

- @dcmjs-org/dcmjs-1: runs the two packages below.
- @dcmjs-org/dcmjs-1-package-name: package.json and the module name.
- @dcmjs-org/dcmjs-1-naturalized-values: the naturalized values of 1.0.
- @dcmjs-org/dcmjs-1-event-stream: optional, the read and the write with
  the event stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130 wayfarer3130 changed the title docs(migration): codemods for the upgrade to dcmjs 1.0; fix(core): a single PN value is array-like feat(codemods): runnable codemods for the upgrade to dcmjs 1.0; fix(core): a single PN value is array-like Nov 24, 2026
@wayfarer3130
wayfarer3130 requested a review from sedghi November 24, 2026 16:19
@wayfarer3130

Copy link
Copy Markdown
Contributor Author

@sedghi - could you re-review with your requested change already applied?

@sedghi sedghi 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.

Please test it on an dcmjs 0.x repo i approved if it works

@wayfarer3130
wayfarer3130 merged commit be31856 into 1.0-beta Nov 24, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants