/
structuredReportToText.ts
108 lines (100 loc) · 2.6 KB
/
structuredReportToText.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {
TextStream,
InterfaceTypes,
runPipeline
} from 'itk-wasm'
import StructuredReportToTextOptions from './StructuredReportToTextOptions.js'
import StructuredReportToTextResult from './StructuredReportToTextResult.js'
/**
* Read a DICOM structured report file and generate a plain text representation
*
* @param {Uint8Array} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToTextResult>} - result object
*/
async function structuredReportToText(
webWorker: null | Worker,
dicomFile: Uint8Array,
options: StructuredReportToTextOptions = {})
: Promise<StructuredReportToTextResult> {
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 = 'structured-report-to-text'
const {
webWorker: usedWebWorker,
returnValue,
stderr,
outputs
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs)
if (returnValue !== 0) {
throw new Error(stderr)
}
const result = {
webWorker: usedWebWorker as Worker,
outputText: (outputs[0].data as TextStream).data,
}
return result
}
export default structuredReportToText