Skip to content

Commit

Permalink
Fixes JSON converter problem with decimal conversion on different cul…
Browse files Browse the repository at this point in the history
…ture settings (german) Issue81 (DICOMcloud#82)

Fixes JSON converter problem with decimal conversion on different culture settings (german) Issue81. Thanks @nutzlastfan
  • Loading branch information
Zaid-Safadi committed Feb 7, 2020
1 parent 231a9b1 commit bf2afd5
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions DICOMcloud/DICOMcloud/JsonDicomConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -221,17 +221,18 @@ DicomVR dicomVr
{
string stringValue = GetTrimmedString ( element.Get<string> ( index ) ) ;


if ( _numberBasedVrs.Contains ( element.ValueRepresentation.Code ) )
{
//parse with the greatest type that can handle
//need to do that to remove the ' ' around the string
if ( _decimalBasedVrs.Contains ( element.ValueRepresentation.Code ) )
{
writer.WriteValue ( double.Parse (stringValue, System.Globalization.NumberStyles.Any) );
writer.WriteValue ( double.Parse (stringValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture) );
}
else
{
writer.WriteValue ( long.Parse (stringValue, System.Globalization.NumberStyles.Number) );
writer.WriteValue ( long.Parse (stringValue, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture) );
}
}
else
Expand Down Expand Up @@ -449,6 +450,8 @@ int level
{
//if VR was the first property we already read the right thing above,
//otherwise we'll got it from the dictionary. Could it be defined after the value?


switch ( vr.Code )
{
case DicomVRCode.SQ:
Expand All @@ -463,6 +466,12 @@ int level
}
break;

case DicomVRCode.DS:
{
ReadVr_DS(reader, tag, dataset);
}
break;

default:
{
List<string> values = new List<string> ( );
Expand All @@ -472,7 +481,7 @@ int level
{
while ( reader.Read ( ) && reader.TokenType != JsonToken.EndArray )
{
values.Add ( System.Convert.ToString ( reader.Value ) );
values.Add ( System.Convert.ToString ( reader.Value ));
}

break;
Expand All @@ -483,13 +492,32 @@ int level
TransferSyntaxUID = values.FirstOrDefault ( ) ;
}

dataset.AddOrUpdate<string> ( vr, tag, values.ToArray ( ) );
dataset.AddOrUpdate<string> ( vr, tag, System.Text.Encoding.Default ,values.ToArray ( ) );
}
break ;
}

}


protected virtual void ReadVr_DS(JsonTextReader reader, DicomTag tag, DicomDataset dataset)
{

List<string> values = new List<string>();

while (reader.Read() && reader.TokenType == JsonToken.StartArray)
{
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
{
values.Add(System.Convert.ToString(reader.Value, System.Globalization.CultureInfo.InvariantCulture));
}

break;
}

dataset.AddOrUpdate<string>(DicomVR.DS, tag, values.ToArray());
}

protected virtual void ReadVr_PN ( JsonTextReader reader, DicomTag tag, DicomDataset dataset )
{
List<string> pnNames = new List<string> ( );
Expand Down

0 comments on commit bf2afd5

Please sign in to comment.