fo-dicom icon indicating copy to clipboard operation
fo-dicom copied to clipboard

structuredReport with utf-8 enconding

Open unosbaghaie opened this issue 5 years ago • 9 comments

Hi I want to add items to structuredReport with utf-8 enconding.

var strReport = new DicomStructuredReport(file.Dataset);

            var titleContentItem = new DicomContentItem(
               new DicomCodeItem(model.Title, "companyName", "Title"),
               DicomRelationship.Contains,
               new DicomCodeItem(model.Title, "companyName", "Title"));
            strReport.Add(titleContentItem);

How can I save model.Title with utf-8 enconding?

unosbaghaie avatar Aug 25 '19 12:08 unosbaghaie

And when my text is too long I get this error value exceeds maximum length of 16 characters

unosbaghaie avatar Aug 26 '19 06:08 unosbaghaie

Agree, there is no parameter for Encoding, fo-dicom always assumes DicomEncoding.Default. Have to add an overload, that passes through some encoding

gofal avatar Aug 26 '19 12:08 gofal

The exception is fine, because DICOM defines the tag CodeValue (0008,0100) to be of Value Representation SH, which is a Shortstring with 16 characters maximum.

gofal avatar Aug 26 '19 12:08 gofal

Currently as a solution I want to save the base64 form of my text.
in which field of StructuredReport can I save more characters?

unosbaghaie avatar Aug 27 '19 07:08 unosbaghaie

Code Scheme designator (0008,0102, SH) identifies who desfined the codes, the Code Value (0008,0100, SH) then has to be a short unique code (typically not human readable), and the Code Meaning (0008,0104, LO) is then a human readable descriptive value. It is LO, that means 64 charachters. That should be enought?

Some famous example of such codes is for example this:

Coding Scheme Designator Code Value Code Meaning
SRT R-10224 medio-lateral
SRT R-10226 medio-lateral oblique
SRT R-10228 latero-medial
SRT R-10230 latero-medial oblique

you can also read here: https://dicom.innolitics.com/ciods/rt-dose/rt-series/00400260/00080104

gofal avatar Aug 27 '19 07:08 gofal

Ah, you edited the question meanwhile. I am only familiar with structured reports in terms of CAD (mammo findings). So I know about the codes and values. But I have no experience with long texts.

gofal avatar Aug 27 '19 07:08 gofal

Thanks for your answer. I think my problem is something else. look at the below image

sr

Is StructuredReport files I need a part like this. How can I generate this part in an dicom file?

update: I know I should use DicomTag.SequenceDelimitationItem, but I don't know how to use it in fa-dicom.

unosbaghaie avatar Aug 31 '19 06:08 unosbaghaie

Hi, I facet with same problem and created custom implementation of IOManager. `///

/// Implementation of for global UTF-8 encoding setting /// Methods implementations taken from ) /// public class CustomIOManager : IOManager { /// protected override Encoding BaseEncodingImpl => Encoding.UTF8;

    /// <inheritdoc />
    protected override IPath PathImpl => DesktopPath.Instance;

    /// <inheritdoc />
    protected override IFileReference CreateFileReferenceImpl(string fileName)
    {
        return new DesktopFileReference(fileName);
    }

    /// <inheritdoc />
    protected override IDirectoryReference CreateDirectoryReferenceImpl(string directoryName)
    {
        return new DesktopDirectoryReference(directoryName);
    }
}`

Also you should register this implementation IOManager.SetImplementation(new CustomIOManager()); and set tag SpecificCharacterSet _dicomFile.Dataset.AddOrUpdate(DicomTag.SpecificCharacterSet, "ISO_IR 192"); //https://dcm4chee-arc-cs.readthedocs.io/en/latest/charsets.html

FacetOfVerity avatar Sep 17 '19 13:09 FacetOfVerity

With latest version the IOManager became obsolete and the handling of Encodings has becomme better.

Now you should be able to do something like that:

// setting the encoding as SpecificCharacterSet in dataset is important, so that then applications reading this file know that they have to decode as UTF8
file.Dataset.AddOrUpdate(DicomTag.SpecificCharacterSet, DicomEncoding.GetCharset(Encoding.UTF8));

// then when adding texts to the dataset or to nested datasets, the encoding of the parent/root dataset is used. Only if there is no specific encoding, then DicomEncoding.Default is used.
var strReport = new DicomStructuredReport(file.Dataset);

        var titleContentItem = new DicomContentItem(
           new DicomCodeItem(model.Title, "companyName", "Title"),
           DicomRelationship.Contains,
           new DicomCodeItem(model.Title, "companyName", "Title"));
        strReport.Add(titleContentItem);

Please verify, that this now works as expected.

gofal avatar Mar 25 '24 07:03 gofal

Closing due to inactivity. If you still observe a problem with latest version of fo-dicom, then please reopen this issue and provide actual informations.

gofal avatar Sep 16 '24 06:09 gofal