-
Notifications
You must be signed in to change notification settings - Fork 631
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
JsonDicomConverter allows serializing DS/IS dicom item with invalid values #1354
JsonDicomConverter allows serializing DS/IS dicom item with invalid values #1354
Conversation
Codecov Report
@@ Coverage Diff @@
## development #1354 +/- ##
===============================================
- Coverage 79.49% 79.46% -0.04%
===============================================
Files 276 276
Lines 24409 24427 +18
===============================================
+ Hits 19405 19411 +6
- Misses 5004 5016 +12
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me!
WriteJsonElement<string>(writer, (DicomElement)item, (w, v) => writer.WriteStringValue(v)); | ||
break; | ||
// Always serialize DS, IS as string for best compatibility while autoValidate is False. | ||
WriteJsonElement<string>(writer, (DicomElement)item, (w, v) => writer.WriteStringValue(v)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this line to the IS
and DS
cases below instead of doing it upfront? Perhaps we simply use WriteJsonElement<string>
for IS
, but update WriteJsonDecimalString
to accept the autoValidate
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe have method WriteJsonIntegerString
to handle IS individually?
@@ -11,10 +11,11 @@ public static class DicomJson | |||
/// </summary> | |||
/// <param name="writeTagsAsKeywords">Whether to write the json keys as DICOM keywords instead of tags. This makes the json non-compliant to DICOM JSON.</param> | |||
/// <param name="formatIndented">Gets or sets a value that defines whether JSON should use pretty printing. By default, JSON is serialized without any extra white space.</param> | |||
public static string ConvertDicomToJson(DicomDataset dataset, bool writeTagsAsKeywords = false, bool formatIndented = false) | |||
/// <param name="autoValidate">Whether the content of DicomItems shall be validated when serializing or deserializing. </param> | |||
public static string ConvertDicomToJson(DicomDataset dataset, bool writeTagsAsKeywords = false, bool formatIndented = false, bool autoValidate = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this auto-validation work with DicomValidation.PerformValidation
? This is isolated to simply DicomDataset
or should that also define this behavior too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the structure is a bit confusing, guess there is some historical reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 steps to turn validation off. By default fo-dicom should do validation. but you can turn the validation off explicitly for some DicomDatasets (that was requested by some users). And then the worst thing is, to turn validation off globally (was also requested). This property to turn validation off globally is marked obsolete, so that you at least get some warning that you should not do that :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i am pretty fine, if the global PerformValidation is not implemented here. Lets wait, until it is requested, fine?
@pengchen0692 Thanks for the nice PR. We stumbled upon the same issue and I was just about to fix it myself until I found this PR. Once you set your So say we have the following valid dataset:
then setting
and setting
So my proposed solution would be to first try and parse the values as numbers, if that fails and |
I see, that there is a difference. Throuh both are valid, according to standard: https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.3.html Do you think, storing the value as number has some advantages for some reason than storing as string? The option autovalidate actually just forwards the string content (because IS is a string-type in DICOM), instead of parsing it as integer. |
Hi @gofal! I like your idea of making the parameter more explicit. Come to think of it, an Meanwhile I've had an internal discussion with @amoerie and would propose the following:
The possible values for
Then the next question is: what should we do with an invalid number in case I'd like to hear your feedback on this @gofal. What would be a sensible default? FYI, we also considered to look at the |
Yeah, a nice addition to this story could have been to default to AsNumber for validated DICOM datasets and AsString for unvalidated DICOM datasets, but AFAIK there is no public property that indicates whether a DICOM dataset is already validated. I also found it confusing that "autoValidate" suddenly also applies to serialisation. My assumption was that this parameter only applied to deserialisation. Therefore, I think a new parameter of type NumberSerializationMode with default value NumberSerializationMode.AsString makes the most sense. |
@pvrobays I also like this idea of having a serialization parameter. I'd be fine with both, if AsString or AsNumber would be the default. The AsNumber would be backwardscompatible (and maybe prevent some unittests to get red suddenly) and should normally not be any problem. The AsString would be the savest choice. So the PreferablyAsNumber would be the best out of the two worlds! |
The DicomDataset.AutoValidate property is something that I had to add due to the preasure of the community. I strongly think that a library has the responsibility to only create valid data. Therefore the validation was introduced. If the user wants to overrule this for some reason, then he takes responsibility and has to set the autovalidation property of a dataset to "false" before adding messy data to the dataset. |
Ok, then I guess it's time to create a new issue and a new PR with that changes? |
Thanks for the background information @gofal. I'll open an issue and PR one of the following days. So to conclude:
|
Fixes #1355 .
Checklist
Changes proposed in this pull request:
autoValidate
is false, write DS or IS value asstring
instead of number