Ejemplo n.º 1
0
        public static object GetElementValue(this DicomDataSet ds, long tag, bool list)
        {
            DicomVRType vr = DicomVRType.UN;

            if (Tags.ContainsKey(tag))
            {
                vr = Tags[tag].VR;
            }
            else
            {
                DicomTag dt = DicomTagTable.Instance.Find(tag);

                if (dt != null)
                {
                    vr = dt.VR;
                    Tags.Add(tag, dt);
                }
            }

            switch (vr)
            {
            case DicomVRType.AE:
            case DicomVRType.CS:
            case DicomVRType.LO:
            case DicomVRType.LT:
            case DicomVRType.SH:
            case DicomVRType.ST:
            case DicomVRType.UI:
            case DicomVRType.UT:
            case DicomVRType.PN:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <string> >(tag, null));
                }
                return(ds.GetValue <string>(tag, string.Empty));

            case DicomVRType.FL:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <float> >(tag, null));
                }
                return(ds.GetValue <float?>(tag, null));

            case DicomVRType.OW:
            case DicomVRType.SS:
            case DicomVRType.US:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <short> >(tag, null));
                }
                return(ds.GetValue <short?>(tag, null));

            case DicomVRType.DS:
            case DicomVRType.FD:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <double> >(tag, null));
                }
                return(ds.GetValue <double?>(tag, null));

            case DicomVRType.AT:
            case DicomVRType.IS:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <int> >(tag, null));
                }
                return(ds.GetValue <int?>(tag, null));

            case DicomVRType.SL:
            case DicomVRType.UL:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <long> >(tag, null));
                }
                return(ds.GetValue <long?>(tag, null));

            case DicomVRType.DA:
                if (list && ds.GetCount(tag) > 0)
                {
                    return(ds.GetValue <List <DateTime> >(tag, null));
                }
                return(ds.GetValue <DateTime?>(tag, null));
            }

            return(null);
        }