Example #1
0
        private DicomDataset ReadJsonDataset(ref Utf8JsonReader reader)
        {
            var dataset = _autoValidate
                ? new DicomDataset()
                : new DicomDataset().NotValidated();

            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException($"Expected the start of an object but found '{reader.TokenType}'.");
            }
            reader.Read();

            while (reader.TokenType != JsonTokenType.EndObject)
            {
                reader.Assume(JsonTokenType.PropertyName);
                var      tagstr = reader.GetString();
                DicomTag tag    = ParseTag(tagstr);
                reader.Read(); // move to value
                var item = ReadJsonDicomItem(tag, ref reader);
                dataset.Add(item);
            }

            foreach (var item in dataset)
            {
                if (item.Tag.IsPrivate && ((item.Tag.Element & 0xff00) != 0))
                {
                    var privateCreatorTag = new DicomTag(item.Tag.Group, (ushort)(item.Tag.Element >> 8));

                    if (dataset.Contains(privateCreatorTag))
                    {
                        item.Tag.PrivateCreator = new DicomPrivateCreator(dataset.GetSingleValue <string>(privateCreatorTag));
                    }
                }
            }

            return(dataset);
        }