Example #1
0
        /// <summary>
        /// Returns the DBMS specific datatype for storing a dicom tag of the supplied <paramref name="keyword"/> (must be a dicom tag name).
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="tt"></param>
        /// <returns></returns>
        public static string GetDataTypeForTag(string keyword, ITypeTranslater tt)
        {
            var tag = DicomDictionary.Default.FirstOrDefault(t => t.Keyword == keyword);

            if (tag == null)
            {
                throw new NotSupportedException("Keyword '" + keyword + "' is not a valid Dicom Tag.");
            }

            var type = DicomTypeTranslater.GetNaturalTypeForVr(tag.ValueRepresentations, tag.ValueMultiplicity);

            return(tt.GetSQLDBTypeForCSharpType(type));
        }
        public void ExampleUsage_Types()
        {
            var tag = DicomDictionary.Default["PatientAddress"];

            DatabaseTypeRequest type = DicomTypeTranslater.GetNaturalTypeForVr(tag.DictionaryEntry.ValueRepresentations, tag.DictionaryEntry.ValueMultiplicity);

            Assert.AreEqual(typeof(string), type.CSharpType);
            Assert.AreEqual(64, type.MaxWidthForStrings);

            TypeTranslater tt = new MicrosoftSQLTypeTranslater();

            Assert.AreEqual("varchar(64)", tt.GetSQLDBTypeForCSharpType(type));

            tt = new OracleTypeTranslater();
            Assert.AreEqual("varchar2(64)", tt.GetSQLDBTypeForCSharpType(type));
        }
Example #3
0
        protected override void UpdateTag(DicomTag dicomTag, DicomDataset dataset, string cellValue)
        {
            var cSharpType = DicomTypeTranslater.GetNaturalTypeForVr(dicomTag.DictionaryEntry.ValueRepresentations,
                                                                     dicomTag.DictionaryEntry.ValueMultiplicity)?.CSharpType;

            object writeValue = cellValue;

            //if it's a supported type e.g. DateTime parse it
            if (cSharpType != null && _factory.IsSupported(cSharpType))
            {
                if (_factory.Dictionary[cSharpType].IsAcceptableAsType(cellValue, Ignore.Me))
                {
                    writeValue = _factory.Dictionary[cSharpType].Parse(cellValue);
                }
            }

            dataset.Remove(dicomTag);
            DicomTypeTranslaterWriter.SetDicomTag(dataset, dicomTag, writeValue);
        }
Example #4
0
        private bool IsValidLength(IDataLoadEventListener listener, DicomTag tag, string value)
        {
            lock (_oDictLock)
            {
                if (!_maxTagLengths.ContainsKey(tag))
                {
                    DatabaseTypeRequest type = DicomTypeTranslater.GetNaturalTypeForVr(
                        tag.DictionaryEntry.ValueRepresentations, tag.DictionaryEntry.ValueMultiplicity);
                    _maxTagLengths.Add(tag, type.MaxWidthForStrings ?? -1);
                }

                //we don't think it's a string or the string is a fine length
                if (_maxTagLengths[tag] <= 0 || value.Length <= _maxTagLengths[tag])
                {
                    return(true);
                }

                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning,
                                                            "Found value '" + value + "' that was too long for it's VR (" + tag + ").  Max length was " +
                                                            _maxTagLengths[tag] + " supplied value was length " + value.Length));
            }

            return(false);
        }