PantelisGeorgiadis / dcmjs-dimse

DICOM DIMSE implementation for Node.js using the dcmjs library
MIT License
63 stars 12 forks source link

When using C-FIND, how to set the character encoding? #60

Open suoc opened 3 weeks ago

suoc commented 3 weeks ago

When using C-FIND , how to set the character encoding? Garbled characters may appear when using Chinese or other language characters. The character encoding set by the peer SCU is GB18030.For example, when the patient's name is '测试', garbled characters will appear when returned to the SCU end.

PantelisGeorgiadis commented 2 weeks ago

Hello @suoc, Thank you for your question! Setting the character encoding is easy... all you have to do is to set the response's SpecificCharacterSet tag to the character set value you need, like the following:

const pendingResponse = CFindResponse.fromRequest(request);
pendingResponse.setDataset(new Dataset({ SpecificCharacterSet: 'GB18030', PatientID: '12345', PatientName: 'JOHN^DOE' }));
pendingResponse.setStatus(Status.Success);

The hard part would be to provide the right bytes for the "encodable" VRs (SH, LO, ST, PN, LT, UC or UT) of the specified character encoding. Unfortunately, dcmjs doesn't provide such functionality, as far as I know and, therefore, you need to use an external library (e.g. iconv, TextEncoder, etc.) and figure a way to inject the character bytes in the tag values.

PantelisGeorgiadis commented 1 week ago

Hello @suoc, Did you manage to properly encode your datasets so you can return strings represented in specific character sets?

suoc commented 1 week ago

OK, I'll try it. I haven't looked at this question recently. I'll give you feedback when I get the result.

suoc commented 6 days ago

After testing, the character encoding can only be set to SpecificCharacterSet: 'ISO_IR 192', which requires the same support from the device. By viewing the source code and test cases of dcmjs, it can be seen that dcmjs does not perform character encoding according to the configuration of SpecificCharacterSet.

PantelisGeorgiadis commented 5 days ago

Right, dcmjs does not perform character encoding according to the configuration of SpecificCharacterSet. That's why I mentioned that "you need to use an external library (e.g. iconv, TextEncoder, etc.) and figure a way to inject the character bytes in the tag values". I would be very interested to see if this is feasible!