Skip to content

Commit

Permalink
feat(dsr2html): generate TS wrapper (bindgen) for structured-report-t…
Browse files Browse the repository at this point in the history
…o-html

Generate typescript wrapper and add test cases for
structured-report-to-html operation.
  • Loading branch information
jadh4v committed Sep 26, 2022
1 parent 1be234a commit f1fc133
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 5 deletions.
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ build-wasi
src/io/internal/ImageIOIndex.ts
src/io/internal/MeshIOIndex.ts

dist
dist/*
!dist/dicom

dist/dicom/*
!dist/dicom/cypress
!dist/dicom/dist
!dist/dicom/src
!dist/dicom/test

dist/dicom/dist/*
!dist/dicom/dist/demo

dist/dicom/dist/demo/*
!dist/dicom/dist/demo/app.js

node_modules
.DS_Store
yarn.lock
Expand Down
7 changes: 7 additions & 0 deletions dist/dicom/src/StructuredReportToHtmlNodeResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface StructuredReportToHtmlNodeResult {
/** Output text file */
outputText: string

}

export default StructuredReportToHtmlNodeResult
125 changes: 125 additions & 0 deletions dist/dicom/src/StructuredReportToHtmlOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
interface StructuredReportToHtmlOptions {
/** read file format only */
readFileOnly?: boolean

/** read data set without file meta information */
readDataset?: boolean

/** use TS recognition (default) */
readXferAuto?: boolean

/** ignore TS specified in the file meta header */
readXferDetect?: boolean

/** read with explicit VR little endian TS */
readXferLittle?: boolean

/** read with explicit VR big endian TS */
readXferBig?: boolean

/** read with implicit VR little endian TS */
readXferImplicit?: boolean

/** show currently processed content item */
processingDetails?: boolean

/** accept unknown/missing relationship type */
unknownRelationship?: boolean

/** accept invalid content item value
(e.g. violation of VR or VM definition) */
invalidItemValue?: boolean

/** ignore relationship content constraints */
ignoreConstraints?: boolean

/** do not abort on content item errors, just warn
(e.g. missing value type specific attributes) */
ignoreItemErrors?: boolean

/** skip invalid content items (incl. sub-tree) */
skipInvalidItems?: boolean

/** disable check for VR-conformant string values */
disableVrChecker?: boolean

/** require declaration of ext. charset (default) */
charsetRequire?: boolean

/** [c]harset: string, assume charset c if no extended charset declared */
charsetAssume?: string

/** check all data elements with string values
(default: only PN, LO, LT, SH, ST, UC and UT) */
charsetCheckAll?: boolean

/** convert all element values that are affected
by Specific Character Set (0008,0005) to UTF-8 */
convertToUtf8?: boolean

/** use only HTML version 3.2 compatible features */
html32?: boolean

/** allow all HTML version 4.01 features (default) */
html40?: boolean

/** comply with XHTML version 1.1 specification */
xhtml11?: boolean

/** add reference to SGML document type definition */
addDocumentType?: boolean

/** URL: string. Add reference to specified CSS to document */
cssReference?: string

/** [f]ilename: string. Embed content of specified CSS into document */
cssFile?: string

/** expand short content items inline (default) */
expandInline?: boolean

/** never expand content items inline */
neverExpandInline?: boolean

/** always expand content items inline */
alwaysExpandInline?: boolean

/** render full data of content items */
renderFullData?: boolean

/** render section titles inline, not separately */
sectionTitleInline?: boolean

/** use document type as document title (default) */
documentTypeTitle?: boolean

/** use patient information as document title */
patientInfoTitle?: boolean

/** do not render general document information */
noDocumentHeader?: boolean

/** render codes in continuous text blocks */
renderInlineCodes?: boolean

/** render code of concept names */
conceptNameCodes?: boolean

/** render code of numeric measurement units */
numericUnitCodes?: boolean

/** use code value as measurement unit (default) */
codeValueUnit?: boolean

/** use code meaning as measurement unit */
codeMeaningUnit?: boolean

/** render all codes (implies +Ci, +Cn and +Cu) */
renderAllCodes?: boolean

/** render code details as a tooltip (implies +Cc) */
codeDetailsTooltip?: boolean

}

export default StructuredReportToHtmlOptions
10 changes: 10 additions & 0 deletions dist/dicom/src/StructuredReportToHtmlResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface StructuredReportToHtmlResult {
/** WebWorker used for computation */
webWorker: Worker | null

/** Output text file */
outputText: string

}

export default StructuredReportToHtmlResult
10 changes: 10 additions & 0 deletions dist/dicom/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@


import StructuredReportToHtmlResult from './StructuredReportToHtmlResult.js'
export type { StructuredReportToHtmlResult }

import StructuredReportToHtmlOptions from './StructuredReportToHtmlOptions.js'
export type { StructuredReportToHtmlOptions }

import structuredReportToHtml from './structuredReportToHtml.js'
export { structuredReportToHtml }


import StructuredReportToTextResult from './StructuredReportToTextResult.js'
export type { StructuredReportToTextResult }

Expand Down
10 changes: 10 additions & 0 deletions dist/dicom/src/indexNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@


import StructuredReportToHtmlNodeResult from './StructuredReportToHtmlNodeResult.js'
export type { StructuredReportToHtmlNodeResult }

import StructuredReportToHtmlOptions from './StructuredReportToHtmlOptions.js'
export type { StructuredReportToHtmlOptions }

import structuredReportToHtmlNode from './structuredReportToHtmlNode.js'
export { structuredReportToHtmlNode }


import StructuredReportToTextNodeResult from './StructuredReportToTextNodeResult.js'
export type { StructuredReportToTextNodeResult }

Expand Down
174 changes: 174 additions & 0 deletions dist/dicom/src/structuredReportToHtml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import {
TextStream,
InterfaceTypes,
runPipeline
} from 'itk-wasm'

import StructuredReportToHtmlOptions from './StructuredReportToHtmlOptions.js'
import StructuredReportToHtmlResult from './StructuredReportToHtmlResult.js'

/**
* Render DICOM SR file and data set to HTML/XHTML
*
* @param {Uint8Array} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToHtmlResult>} - result object
*/
async function structuredReportToHtml(
webWorker: null | Worker,
dicomFile: Uint8Array,
options: StructuredReportToHtmlOptions = {})
: Promise<StructuredReportToHtmlResult> {

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.readFileOnly) {
args.push('--read-file-only')
}
if (options.readDataset) {
args.push('--read-dataset')
}
if (options.readXferAuto) {
args.push('--read-xfer-auto')
}
if (options.readXferDetect) {
args.push('--read-xfer-detect')
}
if (options.readXferLittle) {
args.push('--read-xfer-little')
}
if (options.readXferBig) {
args.push('--read-xfer-big')
}
if (options.readXferImplicit) {
args.push('--read-xfer-implicit')
}
if (options.processingDetails) {
args.push('--processing-details')
}
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.disableVrChecker) {
args.push('--disable-vr-checker')
}
if (options.charsetRequire) {
args.push('--charset-require')
}
if (options.charsetAssume) {
args.push('--charset-assume', '1')
}
if (options.charsetCheckAll) {
args.push('--charset-check-all')
}
if (options.convertToUtf8) {
args.push('--convert-to-utf8')
}
if (options.html32) {
args.push('--html-3.2')
}
if (options.html40) {
args.push('--html-4.0')
}
if (options.xhtml11) {
args.push('--xhtml-1.1')
}
if (options.addDocumentType) {
args.push('--add-document-type')
}
if (options.cssReference) {
args.push('--css-reference', '2')
}
if (options.cssFile) {
args.push('--css-file', '3')
}
if (options.expandInline) {
args.push('--expand-inline')
}
if (options.neverExpandInline) {
args.push('--never-expand-inline')
}
if (options.alwaysExpandInline) {
args.push('--always-expand-inline')
}
if (options.renderFullData) {
args.push('--render-full-data')
}
if (options.sectionTitleInline) {
args.push('--section-title-inline')
}
if (options.documentTypeTitle) {
args.push('--document-type-title')
}
if (options.patientInfoTitle) {
args.push('--patient-info-title')
}
if (options.noDocumentHeader) {
args.push('--no-document-header')
}
if (options.renderInlineCodes) {
args.push('--render-inline-codes')
}
if (options.conceptNameCodes) {
args.push('--concept-name-codes')
}
if (options.numericUnitCodes) {
args.push('--numeric-unit-codes')
}
if (options.codeValueUnit) {
args.push('--code-value-unit')
}
if (options.codeMeaningUnit) {
args.push('--code-meaning-unit')
}
if (options.renderAllCodes) {
args.push('--render-all-codes')
}
if (options.codeDetailsTooltip) {
args.push('--code-details-tooltip')
}

const pipelinePath = 'structured-report-to-html'

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 structuredReportToHtml
Loading

0 comments on commit f1fc133

Please sign in to comment.