Skip to content

Commit

Permalink
feat(KOS): Key object selection (KOS) structured report (SR)
Browse files Browse the repository at this point in the history
Bump DCMTK to include changes for fixing dcmsr. This will
include the fix for accepting the hyperlink prefix for
key object references as an argument (std::string).

$ git shortlog 66fce68..f9da0c6
Shreeraj Jadhav (1):
      ENH: Replace HTML_HYPERLINK_PREFIX_FOR_CGI with std::string argument

Modify operation structured-report-to-html to accept the hyperlink
prefix as a string argument. This will be passed to the
DSRDocument::renderHTML() function.

Generate/update TS bindings for structured-report-to-html.
  • Loading branch information
jadh4v committed Oct 5, 2022
1 parent 4220397 commit 564255c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 27 deletions.
3 changes: 3 additions & 0 deletions dist/dicom/src/StructuredReportToHtmlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ interface StructuredReportToHtmlOptions {
by Specific Character Set (0008,0005) to UTF-8 */
convertToUtf8?: boolean

/** URL: string. Append specificed URL prefix to hyperlinks of referenced composite objects in the document. */
urlPrefix?: string

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

Expand Down
3 changes: 2 additions & 1 deletion dist/dicom/src/readDicomEncapsulatedPdf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BinaryStream,
InterfaceTypes,
PipelineInput,
runPipeline
} from 'itk-wasm'

Expand All @@ -23,7 +24,7 @@ async function readDicomEncapsulatedPdf(
const desiredOutputs = [
{ type: InterfaceTypes.BinaryStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

Expand Down
3 changes: 2 additions & 1 deletion dist/dicom/src/readDicomEncapsulatedPdfNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BinaryStream,
InterfaceTypes,
PipelineInput,
runPipelineNode
} from 'itk-wasm'

Expand All @@ -24,7 +25,7 @@ async function readDicomEncapsulatedPdfNode( dicomFile: Uint8Array,
const desiredOutputs = [
{ type: InterfaceTypes.BinaryStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

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

Expand All @@ -23,7 +24,7 @@ async function structuredReportToHtml(
const desiredOutputs = [
{ type: InterfaceTypes.TextStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

Expand Down Expand Up @@ -80,14 +81,17 @@ async function structuredReportToHtml(
args.push('--charset-require')
}
if (options.charsetAssume) {
args.push('--charset-assume', '1')
args.push('--charset-assume', options.charsetAssume.toString())
}
if (options.charsetCheckAll) {
args.push('--charset-check-all')
}
if (options.convertToUtf8) {
args.push('--convert-to-utf8')
}
if (options.urlPrefix) {
args.push('--url-prefix', options.urlPrefix.toString())
}
if (options.html32) {
args.push('--html-3.2')
}
Expand All @@ -101,10 +105,14 @@ async function structuredReportToHtml(
args.push('--add-document-type')
}
if (options.cssReference) {
args.push('--css-reference', '2')
const inputCountString = inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextStream, data: { data: options.cssReference } })
args.push('--css-reference', inputCountString)
}
if (options.cssFile) {
args.push('--css-file', '3')
const inputFile = 'file' + inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextFile, data: { data: options.cssFile, path: inputFile } })
args.push('--css-file', inputFile)
}
if (options.expandInline) {
args.push('--expand-inline')
Expand Down
16 changes: 12 additions & 4 deletions dist/dicom/src/structuredReportToHtmlNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TextStream,
InterfaceTypes,
PipelineInput,
runPipelineNode
} from 'itk-wasm'

Expand All @@ -24,7 +25,7 @@ async function structuredReportToHtmlNode( dicomFile: Uint8Array,
const desiredOutputs = [
{ type: InterfaceTypes.TextStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

Expand Down Expand Up @@ -81,14 +82,17 @@ async function structuredReportToHtmlNode( dicomFile: Uint8Array,
args.push('--charset-require')
}
if (options.charsetAssume) {
args.push('--charset-assume', '1')
args.push('--charset-assume', options.charsetAssume.toString())
}
if (options.charsetCheckAll) {
args.push('--charset-check-all')
}
if (options.convertToUtf8) {
args.push('--convert-to-utf8')
}
if (options.urlPrefix) {
args.push('--url-prefix', options.urlPrefix.toString())
}
if (options.html32) {
args.push('--html-3.2')
}
Expand All @@ -102,10 +106,14 @@ async function structuredReportToHtmlNode( dicomFile: Uint8Array,
args.push('--add-document-type')
}
if (options.cssReference) {
args.push('--css-reference', '2')
const inputCountString = inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextStream, data: { data: options.cssReference } })
args.push('--css-reference', inputCountString)
}
if (options.cssFile) {
args.push('--css-file', '3')
const inputFile = 'file' + inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextFile, data: { data: options.cssFile, path: inputFile } })
args.push('--css-file', inputFile)
}
if (options.expandInline) {
args.push('--expand-inline')
Expand Down
3 changes: 2 additions & 1 deletion dist/dicom/src/structuredReportToText.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TextStream,
InterfaceTypes,
PipelineInput,
runPipeline
} from 'itk-wasm'

Expand All @@ -23,7 +24,7 @@ async function structuredReportToText(
const desiredOutputs = [
{ type: InterfaceTypes.TextStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

Expand Down
3 changes: 2 additions & 1 deletion dist/dicom/src/structuredReportToTextNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TextStream,
InterfaceTypes,
PipelineInput,
runPipelineNode
} from 'itk-wasm'

Expand All @@ -24,7 +25,7 @@ async function structuredReportToTextNode( dicomFile: Uint8Array,
const desiredOutputs = [
{ type: InterfaceTypes.TextStream },
]
const inputs = [
const inputs: [ PipelineInput ] = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
]

Expand Down
2 changes: 1 addition & 1 deletion src/docker/itk-wasm-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN git clone https://github.com/KitwareMedical/ITK.git && \
RUN sed -i -e '/^set(DCMTK_GIT_REPOSITORY/c\set(DCMTK_GIT_REPOSITORY "https://github.com/InsightSoftwareConsortium/DCMTK.git")' \
/ITK/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake

RUN sed -i -e '/^set(DCMTK_GIT_TAG/c\set(DCMTK_GIT_TAG "66fce6822afb16bcfd926ac8a5f4ed8d7cd10981")' \
RUN sed -i -e '/^set(DCMTK_GIT_TAG/c\set(DCMTK_GIT_TAG "f9da0c6a79bac564cd5c102bb470c4524279d351")' \
/ITK/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake

ARG CMAKE_BUILD_TYPE=Release
Expand Down
50 changes: 36 additions & 14 deletions src/io/internal/pipelines/dicom/structured-report-to-html.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*
*/
#include "itkPipeline.h"
#include "itkInputTextStream.h"
#include "itkOutputTextStream.h"

#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
Expand Down Expand Up @@ -79,7 +80,8 @@ static OFCondition renderFile(STD_NAMESPACE ostream &out,
const size_t readFlags,
const size_t renderFlags,
const OFBool checkAllStrings,
const OFBool convertToUTF8)
const OFBool convertToUTF8,
const std::string& urlPrefixForReferencedObjects)
{
OFCondition result = EC_Normal;

Expand Down Expand Up @@ -169,8 +171,20 @@ static OFCondition renderFile(STD_NAMESPACE ostream &out,
}
}
if (result.good())
result = dsrdoc->renderHTML(out, renderFlags, cssName);
} else {
{
if (urlPrefixForReferencedObjects.empty())
{
// this allows to set the default argument value: HTML_HYPERLINK_PREFIX_FOR_CGI
result = dsrdoc->renderHTML(out, renderFlags, cssName);
}
else
{
result = dsrdoc->renderHTML(out, renderFlags, cssName, urlPrefixForReferencedObjects);
}
}
}
else
{
OFLOG_FATAL(dsr2htmlLogger, OFFIS_CONSOLE_APPLICATION << ": error (" << result.text()
<< ") parsing file: " << ifname);
}
Expand Down Expand Up @@ -251,6 +265,9 @@ int main(int argc, char * argv[])
pipeline.add_flag("--convert-to-utf8", convertToUTF8, "convert all element values that are affected\nby Specific Character Set (0008,0005) to UTF-8");
#endif
// Group("output options:")
std::string urlPrefixValue;
pipeline.add_option("--url-prefix", urlPrefixValue, "URL: string. Append specificed URL prefix to hyperlinks of referenced composite objects in the document.");

// SubGroup("HTML/XHTML compatibility:")
bool html32{false}, html40{false}, xhtml11{false}, addDocumentType{false};
auto html32CliOption = pipeline.add_flag("--html-3.2", html32, "use only HTML version 3.2 compatible features");
Expand All @@ -259,12 +276,12 @@ int main(int argc, char * argv[])
pipeline.add_flag("--add-document-type", addDocumentType, "add reference to SGML document type definition");

// SubGroup("cascading style sheet (CSS), not with HTML 3.2:")
std::string cssReferenceValue;
auto cssReferenceValueCliOption = pipeline.add_option("--css-reference", cssReferenceValue, "URL: string. Add reference to specified CSS to document")->type_name("INPUT_TEXT_STREAM");
cssReferenceValueCliOption->excludes(html32CliOption);
std::string cssFileValue;
auto cssFileValueCliOption = pipeline.add_option("--css-file", cssFileValue, "[f]ilename: string. Embed content of specified CSS into document")->type_name("INPUT_TEXT_STREAM");
cssFileValueCliOption->excludes(html32CliOption);
itk::wasm::InputTextStream cssReference;
auto cssReferenceCliOption = pipeline.add_option("--css-reference", cssReference, "URL: string. Add reference to specified CSS to document")->type_name("INPUT_TEXT_STREAM");
cssReferenceCliOption->excludes(html32CliOption);
std::string cssFile;
auto cssFileCliOption = pipeline.add_option("--css-file", cssFile, "[f]ilename: string. Embed content of specified CSS into document")->check(CLI::ExistingFile)->type_name("INPUT_TEXT_FILE");
cssFileCliOption->excludes(html32CliOption);

// SubGroup("general rendering:");
bool expandInline{false};
Expand Down Expand Up @@ -311,6 +328,11 @@ int main(int argc, char * argv[])
E_TransferSyntax opt_ixfer = EXS_Unknown;
OFBool opt_checkAllStrings = OFFalse;
OFBool opt_convertToUTF8 = OFFalse;

std::string cssReferenceContent;
if(cssReference.GetPointer() != nullptr) {
cssReferenceContent = std::string{ std::istreambuf_iterator<char>(cssReference.Get()), std::istreambuf_iterator<char>() };
}

/* input options */
if(readFileOnly) {
Expand Down Expand Up @@ -403,21 +425,21 @@ int main(int argc, char * argv[])
}

/* cascading style sheet */
if (!cssReferenceValue.empty())
if (!cssReferenceContent.empty())
{
if((opt_renderFlags & DSRTypes::HF_HTML32Compatibility) > 0) {
std::cerr << "--css-reference and --html-3.2 are conflicting options." << std::endl;
}
opt_renderFlags &= ~DSRTypes::HF_copyStyleSheetContent;
opt_cssName = cssReferenceValue.c_str();
opt_cssName = cssReferenceContent.c_str();
}
if (!cssFileValue.empty())
if (!cssFile.empty())
{
if ((opt_renderFlags & DSRTypes::HF_HTML32Compatibility) > 0) {
std::cerr << "--css-file and --html-3.2 are conflicting options." << std::endl;
}
opt_renderFlags |= DSRTypes::HF_copyStyleSheetContent;
opt_cssName = cssFileValue.c_str();
opt_cssName = cssFile.c_str();
}

/* general rendering */
Expand Down Expand Up @@ -518,7 +540,7 @@ int main(int argc, char * argv[])
const char *ifname = dicomFileName.c_str();

if (renderFile(outputText.Get(), ifname, opt_cssName, opt_defaultCharset, opt_readMode, opt_ixfer, opt_readFlags,
opt_renderFlags, opt_checkAllStrings, opt_convertToUTF8).bad())
opt_renderFlags, opt_checkAllStrings, opt_convertToUTF8, urlPrefixValue).bad())
{
result = 3;
}
Expand Down

0 comments on commit 564255c

Please sign in to comment.