private IList <string> GetDateTimeValues(fo.DicomElement dateElement, fo.DicomElement timeElement)
        {
            List <string> values          = new List <string> ( );
            int           dateValuesCount = dateElement == null ? 0 : (int)dateElement.Count;
            int           timeValuesCount = timeElement == null ? 0 : (int)timeElement.Count;
            int           dateTimeIndex   = 0;

            for (; dateTimeIndex < dateValuesCount || dateTimeIndex < timeValuesCount; dateTimeIndex++)
            {
                string dateString = null;
                string timeString = null;

                if (dateTimeIndex < dateValuesCount)
                {
                    dateString = dateElement == null || dateElement.Count == 0 ? null : dateElement.Get <string>(0); //TODO: test - original code returns "" as default
                }

                if (dateTimeIndex < dateValuesCount)
                {
                    timeString = timeElement == null || timeElement.Count == 0 ? null : timeElement.Get <string>(0); //TODO: test - original code returns "" as default
                }

                values.AddRange(GetDateTimeValues(dateString, timeString));
            }

            return(values);
        }
예제 #2
0
        public override bool CanMatch(fo.DicomItem item)
        {
            //if SQ casting will fail and be null
            fo.DicomElement element = item as fo.DicomElement;


            if (element == null || element.Count == 0)
            {
                return(false);
            }

            string elementValue = element.ToString( );

            if (element.ValueRepresentation.Equals(fo.DicomVR.DA) ||
                element.ValueRepresentation.Equals(fo.DicomVR.DT) ||
                element.ValueRepresentation.Equals(fo.DicomVR.TM))
            {
                if (elementValue.Contains("-"))
                {
                    return(false);
                }
            }
            else
            {
                if (HasWildcardMatching(elementValue))
                {
                    return(false);
                }
            }

            return(base.CanMatch(element));
        }
예제 #3
0
        protected virtual void WriteVR_Default(fo.DicomDataset ds, fo.DicomElement element, XmlWriter writer)
        {
            fo.DicomVR dicomVr = element.ValueRepresentation;


            for (int index = 0; index < element.Count; index++)
            {
                writer.WriteStartElement(Constants.ATTRIBUTE_VALUE_NAME);

                WriteNumberAttrib(writer, index);

                if (dicomVr.Equals(fo.DicomVR.AT))
                {
                    var    atElement   = ds.Get <fo.DicomElement>    (element.Tag, null);
                    var    tagValue    = atElement.Get <fo.DicomTag> ( );
                    string stringValue = tagValue.ToString("J", null);

                    writer.WriteString(stringValue);
                }
                else
                {
                    writer.WriteString(GetTrimmedString(ds.Get <string> (element.Tag, index, string.Empty)));
                }

                writer.WriteEndElement( );
            }
        }
예제 #4
0
        protected virtual void WriteVR_PN(fo.DicomElement element, XmlWriter writer)
        {
            for (int index = 0; index < element.Count; index++)
            {
                writer.WriteStartElement(Constants.PN_PERSON_NAME);
                WriteNumberAttrib(writer, index);

                var pnComponents = GetTrimmedString(element.Get <string> ( )).Split('=');

                for (int compIndex = 0; (compIndex < pnComponents.Length) && (compIndex < 3); compIndex++)
                {
                    writer.WriteStartElement(Utilities.PersonNameComponents.PN_Components[compIndex]);

                    fo.DicomPersonName pn = new fo.DicomPersonName(element.Tag, pnComponents[compIndex]);

                    writer.WriteElementString(Utilities.PersonNameParts.PN_Family, pn.Last);
                    writer.WriteElementString(Utilities.PersonNameParts.PN_Given, pn.First);
                    writer.WriteElementString(Utilities.PersonNameParts.PN_Midlle, pn.Middle);
                    writer.WriteElementString(Utilities.PersonNameParts.PN_Prefix, pn.Prefix);
                    writer.WriteElementString(Utilities.PersonNameParts.PN_Suffix, pn.Suffix);

                    writer.WriteEndElement( );
                }
                writer.WriteEndElement( );
            }
        }
예제 #5
0
        public override bool CanMatch(fo.DicomItem item)
        {
            fo.DicomElement element = item as fo.DicomElement;

            if (null == element || element.Count > 0)
            {
                return(false);
            }

            return(base.CanMatch(element));
        }
예제 #6
0
        protected virtual void WriteVR_PN(fo.DicomElement element, JsonWriter writer)
        {
            writer.WritePropertyName(JsonConstants.ValueField);
            writer.WriteStartArray(                          );

            for (int index = 0; index < element.Count; index++)
            {
                writer.WriteStartObject( );

                var pnComponents = GetTrimmedString(element.Get <string> ( )).Split('=');

                for (int compIndex = 0; (compIndex < pnComponents.Length) && (compIndex < 3); compIndex++)
                {
                    writer.WritePropertyName(Utilities.PersonNameComponents.PN_Components[compIndex]);
                    writer.WriteValue(GetTrimmedString(pnComponents[compIndex]));
                    writer.WriteEndObject(                                                         );
                }
            }

            writer.WriteEndArray( );
        }
        protected virtual IList <string> GetValues(IDicomDataParameter condition)
        {
            if (condition is RangeMatching)
            {
                RangeMatching rangeCondition = (RangeMatching)condition;
                fo.DicomItem  dateElement    = rangeCondition.DateElement;
                fo.DicomItem  timeElement    = rangeCondition.TimeElement;


                return(GetDateTimeValues((fo.DicomElement)dateElement, (fo.DicomElement)timeElement));
            }
            else if (condition.VR.Equals(fo.DicomVR.DA) || condition.VR.Equals(fo.DicomVR.DT))
            {
                fo.DicomElement dateElement = null;
                fo.DicomElement timeElement = null;

                foreach (var element in condition.Elements)
                {
                    if (element.ValueRepresentation.Equals(fo.DicomVR.DA))
                    {
                        dateElement = (fo.DicomElement)element;
                        continue;
                    }

                    if (element.ValueRepresentation.Equals(fo.DicomVR.TM))
                    {
                        timeElement = (fo.DicomElement)element;
                    }
                }

                return(GetDateTimeValues(dateElement, timeElement));
            }
            else
            {
                return(condition.GetValues( ));
            }
        }
예제 #8
0
        protected virtual void WriteVR_Default
        (
            fo.DicomDataset ds,
            fo.DicomElement element,
            JsonWriter writer,
            fo.DicomVR dicomVr
        )
        {
            writer.WritePropertyName(JsonConstants.ValueField);
            writer.WriteStartArray( );

            for (int index = 0; index < element.Count; index++)
            {
                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));
                    }
                    else
                    {
                        writer.WriteValue(long.Parse(stringValue, System.Globalization.NumberStyles.Number));
                    }
                }
                else
                {
                    writer.WriteValue(stringValue);
                }
            }

            writer.WriteEndArray( );
        }
예제 #9
0
        public T Get <T>(DicomTag tag, int n, T defaultValue)
        {
            DicomItem item = null;

            if (!_items.TryGetValue(tag, out item))
            {
                return(defaultValue);
            }

            if (typeof(T) == typeof(DicomItem))
            {
                return((T)(object)item);
            }

            if (typeof(T).IsSubclassOf(typeof(DicomItem)))
            {
                return((T)(object)item);
            }

            if (typeof(T) == typeof(DicomVR))
            {
                return((T)(object)item.ValueRepresentation);
            }

            if (item.GetType().IsSubclassOf(typeof(DicomElement)))
            {
                DicomElement element = (DicomElement)item;

                if (typeof(IByteBuffer).IsAssignableFrom(typeof(T)))
                {
                    return((T)(object)element.Buffer);
                }

                if (typeof(T) == typeof(byte[]))
                {
                    return((T)(object)element.Buffer.Data);
                }

                if (n >= element.Count || element.Count == 0)
                {
                    return(defaultValue);
                }

                return((T)(object)element.Get <T>(n));
            }

            if (item.GetType() == typeof(DicomSequence))
            {
                if (typeof(T) == typeof(DicomCodeItem))
                {
                    return((T)(object)new DicomCodeItem((DicomSequence)item));
                }

                if (typeof(T) == typeof(DicomMeasuredValue))
                {
                    return((T)(object)new DicomMeasuredValue((DicomSequence)item));
                }

                if (typeof(T) == typeof(DicomReferencedSOP))
                {
                    return((T)(object)new DicomReferencedSOP((DicomSequence)item));
                }
            }

            throw new DicomDataException(
                      "Unable to get a value type of {0} from DICOM item of type {1}",
                      typeof(T),
                      item.GetType());
        }
예제 #10
0
 public Task <bool> OnElementAsync(DicomElement element)
 {
     return(Task.FromResult(this.OnElement(element)));
 }