Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
416 stars 81 forks source link

Add ISO IR 13 and ISO IR 87 to SpecificCharacterSet #444

Open 9enki opened 10 months ago

9enki commented 10 months ago

issue #443

9enki commented 10 months ago

@Enet4 Hi, thanks for creating issue #443

For Japanese, Chinese or Korean, the Specific Character Set (0008,0005) may have multiple values. https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_H.3.html https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_H.3.2.html

In that case, the Patient Name value needs to be decoded in the Specific Character Set for each = separated part. In the current code, it seems that even if there are multiple values in the Specification Character Set, they are decoded by the first element in that set, is my understanding correct?

If so, I would like to fix it in this PR or another PR, could you please advise where I should consider fixing it? I am tracing the code back from the following function https://github.com/ikneg/dicom-rs/blob/7538e4f16d73e8bf0a36b472e0812f2541879be9/object/src/lib.rs#L189

I guessed that the place where the values are read from the binary data is the following place, so I tried to output the values to the log here with info! https://github.com/ikneg/dicom-rs/blob/7538e4f16d73e8bf0a36b472e0812f2541879be9/object/src/mem.rs#L1514

2023-11-27T02:26:26.629565Z  INFO dicom_object::mem: next tokne: Ok(PrimitiveValue(Strs(["填塹^些灼=\u{1b}$BCf;3\u{1b}(J^\u{1b}$B9'<#\u{1b}(J "])))

But here it is already of type Strs, so it seems that I need to understand more of the preceding code, but it is stuck here.

9enki commented 10 months ago
>>> specification_character_set = ["shift_jis", "iso2022_jp"]
>>> "ヤマダ^タロウ".encode(specification_character_set[0]) + "=".encode("utf-8") + "山田^太郎".encode(specification_character_set[1])
b'\xd4\xcf\xc0\xde^\xc0\xdb\xb3=\x1b$B;3ED\x1b(B^\x1b$BB@O:\x1b(B'

As a sample, when written in python, the Patinant Name value seems to be generated like this, so I want to be able to decode the value generated like this as ヤマダ^タロウ=山田^太郎.

Enet4 commented 10 months ago

Thank you for working on this @ikneg! Could you please add a few sample texts as unit tests? There should be some for other text encodings at the end of the module, so you would just need to follow the pattern there with new data.

9enki commented 10 months ago

@Enet4 Thank you for your reply. I have added a test.

9enki commented 10 months ago

@Enet4 Hi, thanks for creating issue #443

For Japanese, Chinese or Korean, the Specific Character Set (0008,0005) may have multiple values. https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_H.3.html https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_H.3.2.html

In that case, the Patient Name value needs to be decoded in the Specific Character Set for each = separated part. In the current code, it seems that even if there are multiple values in the Specification Character Set, they are decoded by the first element in that set, is my understanding correct?

If so, I would like to fix it in this PR or another PR, could you please advise where I should consider fixing it? I am tracing the code back from the following function https://github.com/ikneg/dicom-rs/blob/7538e4f16d73e8bf0a36b472e0812f2541879be9/object/src/lib.rs#L189

I guessed that the place where the values are read from the binary data is the following place, so I tried to output the values to the log here with info! https://github.com/ikneg/dicom-rs/blob/7538e4f16d73e8bf0a36b472e0812f2541879be9/object/src/mem.rs#L1514

2023-11-27T02:26:26.629565Z  INFO dicom_object::mem: next tokne: Ok(PrimitiveValue(Strs(["填塹^些灼=\u{1b}$BCf;3\u{1b}(J^\u{1b}$B9'<#\u{1b}(J "])))

But here it is already of type Strs, so it seems that I need to understand more of the preceding code, but it is stuck here.

Since this specification is complicated, I would like to remove it from the scope of this PR and create another PR to discuss it.