public static DateTimeIndex GetDateTimeIndex(Period value)
        {
            DateTimeIndex DateTimeIndexStart = null;
            DateTimeIndex DateTimeIndexEnd   = null;

            var             DateTimeIndex      = new DateTimeIndex();
            PartialDateTime?PartialDateTimeLow = null;

            if (value.StartElement != null)
            {
                PartialDateTimeLow = value.StartElement.ToPartialDateTime();
                DateTimeIndexStart = ParsePartialDateTime(PartialDateTimeLow);
            }

            PartialDateTime?PartialDateTimeHigh = null;

            if (value.EndElement != null)
            {
                PartialDateTimeHigh = value.EndElement.ToPartialDateTime();
                DateTimeIndexEnd    = ParsePartialDateTime(PartialDateTimeHigh);
            }

            if (DateTimeIndexStart != null)
            {
                DateTimeIndex.Low = DateTimeIndexStart.Low;
            }
            if (DateTimeIndexEnd != null)
            {
                DateTimeIndex.High = DateTimeIndexEnd.High;
            }

            return(DateTimeIndex);
        }
Exemple #2
0
        public static DateTimeIndex GetDateTimeIndex(Period value)
        {
            var             DateTimeIndex      = new DateTimeIndex();
            PartialDateTime?PartialDateTimeLow = null;

            if (value.StartElement != null)
            {
                PartialDateTimeLow = value.StartElement.ToPartialDateTime();
            }

            PartialDateTime?PartialDateTimeHigh = null;

            if (value.EndElement != null)
            {
                PartialDateTimeHigh = value.EndElement.ToPartialDateTime();
            }

            if (PartialDateTimeLow.HasValue)
            {
                DateTimeIndex.Low = PartialDateTimeLow.Value.ToUniversalTime().ToLocalTime();
            }
            if (PartialDateTimeHigh.HasValue)
            {
                DateTimeIndex.High = PartialDateTimeHigh.Value.ToUniversalTime().ToLocalTime();
            }

            return(DateTimeIndex);
        }
Exemple #3
0
        //Check all DateTime values in the list and find the earliest value.
        private DateTime ResolveTargetEventDateTime(Timing Timing, bool TargetLowest, int searchParameterId)
        {
            DateTime TargetEventDateTime;

            if (TargetLowest)
            {
                TargetEventDateTime = DateTime.MaxValue.ToUniversalTime();
            }
            else
            {
                TargetEventDateTime = DateTime.MinValue.ToUniversalTime();
            }

            foreach (var EventDateTime in Timing.EventElement)
            {
                if (!string.IsNullOrWhiteSpace(EventDateTime.Value))
                {
                    if (FhirDateTime.IsValidValue(EventDateTime.Value))
                    {
                        PartialDateTime?PartialDateTimeType = EventDateTime.ToPartialDateTime();
                        if (PartialDateTimeType.HasValue)
                        {
                            IndexDateTime?DateTimeIndexOffSetValue = ParsePartialDateTime(PartialDateTimeType.Value, searchParameterId);
                            if (DateTimeIndexOffSetValue is object)
                            {
                                if (TargetLowest)
                                {
                                    if (DateTimeIndexOffSetValue.Low.HasValue)
                                    {
                                        if (TargetEventDateTime > DateTimeIndexOffSetValue.Low.Value)
                                        {
                                            TargetEventDateTime = DateTimeIndexOffSetValue.Low.Value;
                                        }
                                    }
                                }
                                else
                                {
                                    if (DateTimeIndexOffSetValue.High.HasValue)
                                    {
                                        if (TargetEventDateTime < DateTimeIndexOffSetValue.High.Value)
                                        {
                                            TargetEventDateTime = DateTimeIndexOffSetValue.High.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(TargetEventDateTime);
        }
Exemple #4
0
        public IndexDateTime?GetDateTimeIndex(Instant value, int searchParameterId)
        {
            PartialDateTime?PartialDateTimeType = value.ToPartialDateTime();

            if (PartialDateTimeType.HasValue)
            {
                return(ParsePartialDateTime(PartialDateTimeType.Value, searchParameterId));
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        private static DateTimeIndex ParsePartialDateTimeOLD(PartialDateTime?PartialDateTimeType)
        {
            //2012-12-01T12:00:00+01:00
            //DateTimeOffset Low = PartialDateTimeType.Value.ToUniversalTime().ToLocalTime();
            //Get the localTime offset (+8:00 is Perth Australia, will always be relevent to the server location, Sydney +10:00 for PyroHealth.net)
            // var LocalTimeOffSet = DateTimeOffset.Now.Offset;
            //Convert to DateTimeOffset, which is done by caling ToUniversalTime(), yet this converts to UniversalTime
            // So we then set the timezone to the local timezone, which converts the time value to plus that timezone
            // So then subtract that timezone hours from the final result
            //Now we have the original timezone and correct time.
            //DateTimeOffset Low = PartialDateTimeType.Value.ToUniversalTime().ToOffset(LocalTimeOffSet).Subtract(LocalTimeOffSet);

            DateTimeOffset?Low = FhirDateTimeSupport.ConvertToDateTimeOffSetLow(PartialDateTimeType.Value.ToString());

            DateTimeOffset High = DateTimeOffset.MaxValue;

            if (Low.HasValue)
            {
                int DateCharCount = PartialDateTimeType.Value.ToString().Count();
                if (DateCharCount == 4)
                {
                    High = Low.Value.AddYears(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 7)
                {
                    High = Low.Value.AddMonths(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 10)
                {
                    High = Low.Value.AddDays(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 25)
                {
                    High = Low.Value.AddSeconds(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 27 || DateCharCount == 28 || DateCharCount == 29)
                {
                    High = Low.Value.AddMilliseconds(1);
                }
                else if (DateCharCount > 29)
                {
                    High = Low.Value.AddTicks(1);
                }
                return(new DateTimeIndex(Low.Value, High));
            }
            return(null);
        }
        private static DateTimeIndex ParsePartialDateTime(PartialDateTime?PartialDateTimeType)
        {
            FhirDateTimeSupport FhirDateTimeSupport = new FhirDateTimeSupport(PartialDateTimeType.Value.ToString());

            if (FhirDateTimeSupport.IsValid)
            {
                DateTimeOffset?Low  = FhirDateTimeSupport.Value;
                DateTimeOffset High = DateTimeOffset.MaxValue;

                switch (FhirDateTimeSupport.Precision)
                {
                case FhirDateTimeSupport.DateTimePrecision.Year:
                    High = Low.Value.AddYears(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Month:
                    High = Low.Value.AddMonths(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Day:
                    High = Low.Value.AddDays(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.HourMin:
                    High = Low.Value.AddSeconds(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Sec:
                    High = Low.Value.AddMilliseconds(999);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.MilliSec:
                    High = Low.Value.AddMilliseconds(1).AddTicks(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Tick:
                    High = Low.Value.AddTicks(1);
                    break;

                default:
                    break;
                }
                return(new DateTimeIndex(Low.Value, High));
            }
            return(null);
        }
        //Check all DateTime values in the list and find the earliest value.
        private static DateTimeOffset ResolveTargetEventDateTime(Timing Timing, bool TargetLowest)
        {
            DateTimeOffset TargetEventDateTime;

            if (TargetLowest)
            {
                TargetEventDateTime = DateTimeOffset.MaxValue.ToUniversalTime();
            }
            else
            {
                TargetEventDateTime = DateTimeOffset.MinValue.ToUniversalTime();
            }

            foreach (var EventDateTime in Timing.EventElement)
            {
                if (!string.IsNullOrWhiteSpace(EventDateTime.Value))
                {
                    if (FhirDateTime.IsValidValue(EventDateTime.Value))
                    {
                        PartialDateTime?PartialDateTimeType = EventDateTime.ToPartialDateTime();
                        if (PartialDateTimeType.HasValue)
                        {
                            DateTimeIndex DateTimeIndexOffSetValue = ParsePartialDateTime(PartialDateTimeType.Value);

                            DateTimeOffset DateTimeOffSetValue = PartialDateTimeType.Value.ToUniversalTime().ToLocalTime();
                            if (TargetLowest)
                            {
                                if (TargetEventDateTime > DateTimeIndexOffSetValue.Low.Value)
                                {
                                    TargetEventDateTime = DateTimeIndexOffSetValue.Low.Value;
                                }
                            }
                            else
                            {
                                if (TargetEventDateTime < DateTimeIndexOffSetValue.High.Value)
                                {
                                    TargetEventDateTime = DateTimeIndexOffSetValue.High.Value;
                                }
                            }
                        }
                    }
                }
            }
            return(TargetEventDateTime);
        }
Exemple #8
0
        public IndexDateTime?GetDateTimeIndex(Period value, int searchParameterId)
        {
            IndexDateTime?DateTimeIndexStart = null;
            IndexDateTime?DateTimeIndexEnd   = null;

            PartialDateTime?PartialDateTimeLow = null;

            if (value.StartElement != null)
            {
                PartialDateTimeLow = value.StartElement.ToPartialDateTime();
                if (PartialDateTimeLow.HasValue)
                {
                    DateTimeIndexStart = ParsePartialDateTime(PartialDateTimeLow.Value, searchParameterId);
                }
            }

            PartialDateTime?PartialDateTimeHigh = null;

            if (value.EndElement != null)
            {
                PartialDateTimeHigh = value.EndElement.ToPartialDateTime();
                if (PartialDateTimeHigh.HasValue)
                {
                    DateTimeIndexEnd = ParsePartialDateTime(PartialDateTimeHigh.Value, searchParameterId);
                }
            }

            var DateTimeIndex = new IndexDateTime(searchParameterId);

            if (DateTimeIndexStart is object)
            {
                DateTimeIndex.Low = DateTimeIndexStart.Low;
            }
            if (DateTimeIndexEnd is object)
            {
                DateTimeIndex.High = DateTimeIndexEnd.High;
            }


            return(DateTimeIndex);
        }
        public static DateTimeIndex GetDateTimeIndex(Instant value)
        {
            PartialDateTime?PartialDateTimeType = value.ToPartialDateTime();

            return(ParsePartialDateTime(PartialDateTimeType));
        }