-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(itk-dicom): Node.js bundling and interface
- Loading branch information
Showing
12 changed files
with
444 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { nodeResolve } from '@rollup/plugin-node-resolve' | ||
import typescript from '@rollup/plugin-typescript' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import json from '@rollup/plugin-json' | ||
import { terser } from 'rollup-plugin-terser' | ||
|
||
export default { | ||
input: './src/indexNode.ts', | ||
output: [ | ||
{ | ||
file: './dist/itk-dicom.node.js', | ||
format: 'es', | ||
sourcemap: true, | ||
plugins: [terser(),], | ||
}, | ||
], | ||
plugins: [ | ||
commonjs({ | ||
transformMixedEsModules: true | ||
}), | ||
nodeResolve({ | ||
preferBuiltins: true, | ||
browser: false, | ||
}), | ||
typescript(), | ||
json(), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface StructuredReportToTextNodeResult { | ||
/** Output text file */ | ||
outputText: string | ||
|
||
} | ||
|
||
export default StructuredReportToTextNodeResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
import StructuredReportToTextNodeResult from './StructuredReportToTextNodeResult.js' | ||
export type { StructuredReportToTextNodeResult } | ||
|
||
import StructuredReportToTextOptions from './StructuredReportToTextOptions.js' | ||
export type { StructuredReportToTextOptions } | ||
|
||
import structuredReportToTextNode from './structuredReportToTextNode.js' | ||
export { structuredReportToTextNode } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { | ||
TextStream, | ||
InterfaceTypes, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import StructuredReportToTextOptions from './StructuredReportToTextOptions.js' | ||
import StructuredReportToTextNodeResult from './StructuredReportToTextNodeResult.js' | ||
|
||
|
||
import path from 'path' | ||
|
||
/** | ||
* Read a DICOM structured report file and generate a plain text representation | ||
* | ||
* @param {Uint8Array} dicomFile - Input DICOM file | ||
* | ||
* @returns {Promise<StructuredReportToTextNodeResult>} - result object | ||
*/ | ||
async function structuredReportToTextNode( dicomFile: Uint8Array, | ||
options: StructuredReportToTextOptions = {}) | ||
: Promise<StructuredReportToTextNodeResult> { | ||
|
||
const desiredOutputs = [ | ||
{ type: InterfaceTypes.TextStream }, | ||
] | ||
const inputs = [ | ||
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
args.push('file0') | ||
// Outputs | ||
args.push('0') | ||
// Options | ||
args.push('--memory-io') | ||
if (options.unknownRelationship) { | ||
args.push('--unknown-relationship') | ||
} | ||
if (options.invalidItemValue) { | ||
args.push('--invalid-item-value') | ||
} | ||
if (options.ignoreConstraints) { | ||
args.push('--ignore-constraints') | ||
} | ||
if (options.ignoreItemErrors) { | ||
args.push('--ignore-item-errors') | ||
} | ||
if (options.skipInvalidItems) { | ||
args.push('--skip-invalid-items') | ||
} | ||
if (options.noDocumentHeader) { | ||
args.push('--no-document-header') | ||
} | ||
if (options.numberNestedItems) { | ||
args.push('--number-nested-items') | ||
} | ||
if (options.shortenLongValues) { | ||
args.push('--shorten-long-values') | ||
} | ||
if (options.printInstanceUid) { | ||
args.push('--print-instance-uid') | ||
} | ||
if (options.printSopclassShort) { | ||
args.push('--print-sopclass-short') | ||
} | ||
if (options.printSopclassLong) { | ||
args.push('--print-sopclass-long') | ||
} | ||
if (options.printSopclassUid) { | ||
args.push('--print-sopclass-uid') | ||
} | ||
if (options.printAllCodes) { | ||
args.push('--print-all-codes') | ||
} | ||
if (options.printInvalidCodes) { | ||
args.push('--print-invalid-codes') | ||
} | ||
if (options.printTemplateId) { | ||
args.push('--print-template-id') | ||
} | ||
if (options.indicateEnhanced) { | ||
args.push('--indicate-enhanced') | ||
} | ||
if (options.printColor) { | ||
args.push('--print-color') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'structured-report-to-text') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
outputText: (outputs[0].data as TextStream).data, | ||
} | ||
return result | ||
} | ||
|
||
export default structuredReportToTextNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import fs from 'fs' | ||
import test from 'ava' | ||
import { structuredReportToTextNode } from '../dist/itk-dicom.node.js' | ||
|
||
test('structuredReportToText', async t => { | ||
|
||
const fileName = '88.33-comprehensive-SR.dcm' | ||
const testFilePath = `../../build-emscripten/ExternalData/test/Input/${fileName}` | ||
|
||
const dicomFileBuffer = fs.readFileSync(testFilePath) | ||
const dicomFile = new Uint8Array(dicomFileBuffer) | ||
|
||
const { outputText } = await structuredReportToTextNode(dicomFile) | ||
|
||
t.assert(outputText.includes('Comprehensive SR Document')) | ||
|
||
const { outputText: outputTextNoHeader } = await structuredReportToTextNode(dicomFile, { noDocumentHeader: true }) | ||
t.assert(!outputTextNoHeader.includes('Comprehensive SR Document')) | ||
t.assert(outputTextNoHeader.includes('Breast Imaging Report')) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.