Skip to content

feat(fhir): scaffold @dcmjs-org/fhir and port the Patient mappers (finding 19) - #574

Merged
awatson1978 merged 3 commits into
release/1.0-beta-fhirfrom
fhir-pr1-patient
Oct 2, 2026
Merged

awatson1978 merged 3 commits into
release/1.0-beta-fhirfrom
fhir-pr1-patient

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This starts the @dcmjs-org/fhir package: the scaffold plus the Patient direction of the DICOM ↔ FHIR mapping, with review finding 19 fixed inside the port. The package comes from the v2 branch's packages/fhir/, which is fully self-contained — six source files, zero imports from the rest of the tree — so the port is mechanical: the scope renames to @dcmjs-org/fhir, the package-local .babelrc is dropped (the root babel.config.js covers workspace packages now), and the sources are prettier-normalized to this repo's config. This first slice carries helpers.js (the shared value mappers: PN parsing, UID urns, DA/TM ↔ ISO dates, the administrative-gender tables), patient.js (naturalized dataset → FHIR Patient) and patientToDataset.js (the inverse: Patient → the four patient-module attributes, deterministic overwrite by design). The ImagingStudy and DocumentReference mappers follow in the next two slices, and the event-stream integration (fromFhir and the facade methods) is deferred until the pdfs/video/media waves land, because it depends on both.

Everything here except the fix is a verbatim port: the three source files and the 13-test patientToDataset suite come over unchanged apart from formatting and the test imports, which now point at the concrete modules because the package index (with the toFhir surface it exports) arrives in slice two. The hand-written portion is the scaffold package.json, the finding fix, and its regression tests.

The finding, with its regression written against the ported-but-unfixed code and observed failing before the fix:

  • Finding 19 (MED). humanNameToPersonName read only family, given, prefix and suffix, never HumanName.text, and returned null when all four were absent. Since patientToDataset deterministically overwrites the whole patient module, a text-only name — common in real FHIR feeds — erased the existing PatientName outright: {name: [{text: "Jane Doe"}]} came back as PatientName: "". The fix falls back to text as a single-component PN when no structured part exists. I considered splitting a "Family, Given" shape out of the text and decided against fabricating structure the resource never asserted — the text goes in whole. If reviewers prefer the split, it is a small follow-up.

The mapping in its current shape:

import { patientFromDataset } from "./packages/fhir/src/patient.js";
import { patientToDataset } from "./packages/fhir/src/patientToDataset.js";

const resource = patientFromDataset({
    PatientName: [{ Alphabetic: "FOX^JANE" }],
    PatientID: "22446688",
    PatientBirthDate: "19800415",
    PatientSex: "F"
});
// → { resourceType: "Patient", identifier: [MR 22446688],
//     name: [{ family: "FOX", given: ["JANE"], text: "FOX JANE" }],
//     birthDate: "1980-04-15", gender: "female", extension: [birthsex, sex] }

patientToDataset(resource);
// → { PatientName: "FOX^JANE", PatientID: "22446688",
//     PatientBirthDate: "19800415", PatientSex: "F" }

26 tests in the new suite — the 13 ported ones (the JANE FOX identity, name-use preference, the exhaustive genderToSex table, round trips with the sink direction) plus the finding-19 regressions. 870 passing overall on this branch, and pnpm run build is green.

🤖 Generated with Claude Code

awatson1978 and others added 3 commits October 2, 2026 12:30
…elopment

helpers.js, patient.js and patientToDataset.js come over verbatim from
the v2 packages/fhir sources (prettier-normalized to this repo's config).
The test imports are rewired to the concrete modules because the package
index lands in a later slice.

Co-Authored-By: Claude Fable 5 <[email protected]>
…exist

A text-only HumanName used to map to null, and patientToDataset's
deterministic overwrite then erased the patient's name entirely (review
finding 19 on PR #512). When family/given/prefix/suffix are all absent,
the free-text form now survives as a single-component PN.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 19ca7e9 into release/1.0-beta-fhir Oct 2, 2026
10 checks passed
@awatson1978
awatson1978 deleted the fhir-pr1-patient branch October 2, 2026 18:12
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.

1 participant