Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add untilTag option to readFile #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

swederik
Copy link
Member

@swederik swederik commented Jul 2, 2020

Test it with:

const fs = require('fs');
const dcmjs = require('./build/dcmjs.js')
const buffer = fs.readFileSync('1-001.dcm');

const { DicomMessage, DicomMetaDictionary } = dcmjs.data;
console.time('readFile');
const fullData = DicomMessage.readFile(buffer.buffer)
console.timeEnd('readFile');

console.time('readFile with untilTag');
const dicomData = DicomMessage.readFile(buffer.buffer, { 'untilTag': '7FE00010' });
console.timeEnd('readFile with untilTag');

const dataset = DicomMetaDictionary.naturalizeDataset(dicomData.dict);
dataset._meta = DicomMetaDictionary.namifyDataset(dicomData.meta);

console.log(dataset.PixelData);

@swederik swederik requested a review from pieper July 2, 2020 12:34
@swederik
Copy link
Member Author

swederik commented Jul 2, 2020

@pieper suggests switching it to allow namified version instead and I agree. I'll do that before merging

@jmhmd
Copy link
Contributor

jmhmd commented Aug 28, 2020

@swederik May be helpful also to have an stopAfterTag option as well, to include the provided tag and exclude everything after. I implemented this quickly in my own fork like this:

while (!bufferStream.end()) {
  if (breakOnNextLoop === true) {
      break;
  }
  const readInfo = DicomMessage.readTag(bufferStream, syntax);
  const cleanTagString = readInfo.tag.toCleanString();

  if (untilTag && untilTag === cleanTagString) {
      break;
  }
  if (stopAfterTag && stopAfterTag === cleanTagString) {
      breakOnNextLoop = true;
  }

  ...
}

Would submit pull request but looks like you want to allow namified version to these options. Happy to help if you like, but still getting my bearings with this library!

@jmhmd
Copy link
Contributor

jmhmd commented Sep 7, 2020

Opened PR #149 to address these issues, including namified support. Would appreciate feedback/review!

@swederik swederik mentioned this pull request Mar 2, 2021
@Ouwen
Copy link
Contributor

Ouwen commented Mar 4, 2021

@jmhmd Great PR on #149, I think the fromDirtyString function is quite convenient.

@pieper @swederik @jmhmd
Would it be okay to simplify the API to just untilTag, and ignoreTheUntilTagValue?
This will change the default behavior of untilTag to finish adding the value to the dict (so it becomes like stopTag).

ignoreTheUntilTagValue will decide whether or not to actually parse the tag value and hook into the ReadTag function where bytes are parsed.

The only major deviation will be that this will return a dict where a tag is present with null values and null value representation. I don't think this should be a big issue since the existence of the tag key is a useful flag for whether the untilTag condition was met. Additionally, the user explicitly asked to ignore values of the tag in question and can delete this strange key prior to passing it to other dcmjs functions.

@pieper
Copy link
Collaborator

pieper commented Mar 4, 2021

fromDirtyString function is quite convenient

True, but as a matter of style I'd like to encourage the use of the keywords from the data dictionary and keep the hex out of the code for readability.

Would it be okay to simplify the API to just untilTag, and ignoreTheUntilTagValue?

That make sense. There's a general guideline to use positive statements for boolean flags, so maybe better is readUntilTagValue or includeUntilTagValue.

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.

None yet

4 participants