Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DICOM JSON Format #128

Closed
vsaase opened this issue May 13, 2021 · 4 comments · Fixed by #373
Closed

DICOM JSON Format #128

vsaase opened this issue May 13, 2021 · 4 comments · Fixed by #373

Comments

@vsaase
Copy link
Contributor

vsaase commented May 13, 2021

Hi,
many thanks for your work!

Do you maybe have a working prototype for converting from DICOM binary format to JSON and back? Or any ideas on how to achieve this elegantly? Would be useful form DICOMWeb interaction.

I was just experimenting a bit with Serde:

use serde::Deserialize;
use serde_json::Value;
use enum_as_inner::EnumAsInner;

#[derive(Debug, Deserialize, EnumAsInner)]
#[serde(untagged)]
pub enum DICOMJsonTagValue {
    Str(String),
    Int(i32),
    DICOMJson(DICOMJson),
    Value(Value),
}

#[derive(Debug, Deserialize)]
pub struct DICOMJsonTag {
    pub vr: String,
    pub Value: Vec<DICOMJsonTagValue>,
}

pub type DICOMJson = Vec<HashMap<String, DICOMJsonTag>>;

Then this is the user facing version:

let parsed: DICOMJson = serde_json::from_str(jsonstring)?;
let study_instance_uid = parsed[0]["0020000D"].Value[0].as_str().unwrap();

I believe Serde has much more flexibility for a better API than that. Just wanted to ask your opinion before diving in deeper..

Victor

@Enet4
Copy link
Owner

Enet4 commented May 13, 2021

Thank you for reaching out, @vsaase. It is true that this project is currently not covering conversions to/from JSON, but it makes sense to have that eventually, potentially as one more crate in the DICOM-rs umbrella. It only does not exist yet because the closest topics in the roadmap have been to incorporate more functionalities specific to DICOM representations and protocols, but a DICOM Web initiative should be bound to happen eventually.

With that said, I believe that the shortest path towards converting a JSON value into an in-memory DICOM object would be to convert each element into an InMemElement through a bit of matching and conversion to primitive values (a bit of a manual procedure I fear). With a sequence of these made, they can be trivially collected into an InMemoryDicomObject, via the associated function from_element_source_with_dict. Hopefully this may at least help you have an idea on how to achieve this. I'm afraid that I do not have an implementation handy.

Please feel free to ask follow-up questions on this. And if there is interest from you to contribute to the project with a DICOM JSON proof of concept, I would also be more than grateful.

@charbeljc
Copy link
Contributor

Thank you for reaching out, @vsaase. It is true that this project is currently not covering conversions to/from JSON, but it makes sense to have that eventually, potentially as one more crate in the DICOM-rs umbrella. It only does not exist yet because the closest topics in the roadmap have been to incorporate more functionalities specific to DICOM representations and protocols, but a DICOM Web initiative should be bound to happen eventually.

With that said, I believe that the shortest path towards converting a JSON value into an in-memory DICOM object would be to convert each element into an InMemElement through a bit of matching and conversion to primitive values (a bit of a manual procedure I fear). With a sequence of these made, they can be trivially collected into an InMemoryDicomObject, via the associated function from_element_source_with_dict. Hopefully this may at least help you have an idea on how to achieve this. I'm afraid that I do not have an implementation handy.

Well, actually, I have something coming like this... I will try to submit another PR soon. Regards

Please feel free to ask follow-up questions on this. And if there is interest from you to contribute to the project with a DICOM JSON proof of concept, I would also be more than grateful.

@charbeljc
Copy link
Contributor

@Enet4 @vsaase please have a look on the last commit of #174

@vsaase
Copy link
Contributor Author

vsaase commented Sep 9, 2021

Great! I will have a look later. I have been working on dicomweb in my spare time in the last few days

@Enet4 Enet4 mentioned this issue Jul 7, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants