Skip to content

Commit

Permalink
feat: Allow backslashes in UIDs in order to support DICOM Q&R (#277)
Browse files Browse the repository at this point in the history
Treat backslashes in UID fields as a delimiter so multiple UIDs can be specified. When using DICOM Q&R it is possible to query a list of UIDs by using a backslash as a delimiter: https://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.2.2.2.2.html
  • Loading branch information
richard-viney committed Jun 22, 2022
1 parent 3d311f1 commit 6d2d5c6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/adapters/src/ValueRepresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,26 @@ class UniqueIdentifier extends StringRepresentation {
}

readBytes(stream, length) {
return this.readNullPaddedString(stream, length).replace(
/[^0-9.]/g,
""
);
const result = this.readNullPaddedString(stream, length);

const BACKSLASH = String.fromCharCode(0x5c);
const uidRegExp = /[^0-9.]/g;

// Treat backslashes as a delimiter for multiple UIDs, in which case an
// array of UIDs is returned. This is used by DICOM Q&R to support
// querying and matching multiple items on a UID field in a single
// query. For more details see:
//
// https://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.2.2.2.2.html
// https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.4.html

if (result.indexOf(BACKSLASH) === -1) {
return result.replace(uidRegExp, "");
} else {
return result
.split(BACKSLASH)
.map(uid => uid.replace(uidRegExp, ""));
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/adapters/test/data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import os from "os";
import path from "path";
import unzipper from "unzipper";
import followRedirects from "follow-redirects";
import { promisify } from "util";

const { https } = followRedirects;

Expand Down Expand Up @@ -595,3 +596,17 @@ it("test_custom_dictionary", () => {
//check that all other fields were preserved, 15 original + 1 for _vr and +1 for "TrialName"
expect(Object.keys(dataset).length).toEqual(17);
});

it("Reads DICOM with multiplicity", async () => {
const url =
"https://github.com/dcmjs-org/data/releases/download/multiplicity/multiplicity.dcm";
const dcmPath = path.join(os.tmpdir(), "multiplicity.dcm");

await downloadToFile(url, dcmPath);

const file = await promisify(fs.readFile)(dcmPath);
const dicomDict = DicomMessage.readFile(file.buffer);

expect(dicomDict.dict["00101020"].Value).toEqual([1, 2]);
expect(dicomDict.dict["0018100B"].Value).toEqual(["1.2", "3.4"]);
});

0 comments on commit 6d2d5c6

Please sign in to comment.