Skip to content

Commit

Permalink
fix(vr): Convert empty DecimalString and NumberString to null instead…
Browse files Browse the repository at this point in the history
… of to zero (#278)

This is needed when doing C-FIND with dcmjs-dimse, where "" needs to mean 'match everything', and not be converted to zero.
  • Loading branch information
richard-viney committed Jun 17, 2022
1 parent a17f2d7 commit 43cd8ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions packages/adapters/src/ValueRepresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,19 @@ class DecimalString extends StringRepresentation {
if (ds.indexOf(BACKSLASH) !== -1) {
// handle decimal string with multiplicity
const dsArray = ds.split(BACKSLASH);
ds = dsArray.map(ds => Number(ds));
ds = dsArray.map(ds => (ds === "" ? null : Number(ds)));
} else {
ds = [Number(ds)];
ds = [ds === "" ? null : Number(ds)];
}

return ds;
}

formatValue(value) {
if (value === null) {
return "";
}

const str = String(value);
if (str.length > this.maxLength) {
return value.toExponential();
Expand Down Expand Up @@ -640,16 +644,22 @@ class IntegerString extends StringRepresentation {
if (is.indexOf(BACKSLASH) !== -1) {
// handle integer string with multiplicity
const integerStringArray = is.split(BACKSLASH);
is = integerStringArray.map(is => Number(is));
is = integerStringArray.map(is => (is === "" ? null : Number(is)));
} else {
is = [Number(is)];
is = [is === "" ? null : Number(is)];
}

return is;
}

formatValue(value) {
return value === null ? "" : String(value);
}

writeBytes(stream, value, writeOptions) {
const val = Array.isArray(value) ? value.map(String) : [value];
const val = Array.isArray(value)
? value.map(is => this.formatValue(is))
: [this.formatValue(value)];
return super.writeBytes(stream, val, writeOptions);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/test/data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ it("test_null_number_vrs", () => {
dicomData.dict
);

expect(dataset.ImageAndFluoroscopyAreaDoseProduct).toEqual(0);
expect(dataset.InstanceNumber).toEqual(0);
expect(dataset.ImageAndFluoroscopyAreaDoseProduct).toEqual(null);
expect(dataset.InstanceNumber).toEqual(null);
});

it("test_exponential_notation", () => {
Expand Down

0 comments on commit 43cd8ea

Please sign in to comment.