예제 #1
0
        /// <summary>
        /// This method takes in integer values for the hour and minute and performs validations,
        /// it then sets the value field formatted as an HL7 time value
        /// with hour and minute precision (HHMM).
        /// </summary>
        public virtual void SetHourMinutePrecision(int hr, int min)
        {
            try
            {
                HourPrecision = hr;

                // validate input minute value
                if ((min < 0) || (min > 59))
                {
                    var msg = "The minute value of the TM datatype must be >=0 and <=59";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                Minute      = min;
                Second      = 0;
                FractSecond = 0;
                GMTOffset   = 0;

                // Here the offset is not defined, we should omit showing it in the
                // return value from the getValue() method
                omitOffsetFg = 'y';
                valueRenamed = valueRenamed + DataTypeUtil.PreAppendZeroes(min, 2);
            }
            catch (DataTypeException e)
            {
                // TODO: this will remove the stack trace - is that correct?
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException(e.Message);
            }
        }
예제 #2
0
파일: CommonDT.cs 프로젝트: noorsyyad/nHapi
        /// <summary> This method takes in integer values for the year and month and day
        /// and performs validations, it then sets the value in the object
        /// formatted as an HL7 date value with year and month and day precision (YYYYMMDD).
        /// </summary>
        public virtual void SetYearMonthDayPrecision(int yr, int mnth, int dy)
        {
            try
            {
                // ensure that the year field is four digits long
                if (Convert.ToString(yr).Length != 4)
                {
                    var msg = "The input year value must be four digits long";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                var cal = new GregorianCalendar();

                // validate the input month/day combination
                new DateTime(yr, mnth, dy, cal);
                Year         = yr;
                Month        = mnth;
                Day          = dy;
                valueRenamed = Convert.ToString(yr) + DataTypeUtil.PreAppendZeroes(mnth, 2) + DataTypeUtil.PreAppendZeroes(dy, 2);
            }
            catch (DataTypeException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception occurred", e);
            }
        }
예제 #3
0
        /// <summary>
        /// This method takes in integer values for the hour, minute, seconds, and fractional seconds
        /// (going to the ten thousandths precision).
        /// The method performs validations and then sets the value field formatted as an
        /// HL7 time value with a precision that starts from the hour and goes down to the ten thousandths
        /// of a second (HHMMSS.SSSS).
        /// Note: all of the precisions from tenths down to ten thousandths of a
        /// second are optional. If the precision goes below ten thousandths of a second then the second
        /// value will be rounded to the nearest ten thousandths of a second.
        /// </summary>
        public virtual void SetHourMinSecondPrecision(int hr, int min, float sec)
        {
            try
            {
                SetHourMinutePrecision(hr, min);

                // multiply the seconds input value by 10000 and round the result
                // then divide the number by ten thousand and store it back.
                // This will round the fractional seconds to the nearest ten thousandths
                var secMultRound = (int)Math.Round((double)(10000F * sec));
                sec = secMultRound / 10000F;

                // Now store the second and fractional component
                Second = (int)Math.Floor(sec);

                // validate input seconds value
                if ((Second < 0) || (Second >= 60))
                {
                    var msg = "The (rounded) second value of the TM datatype must be >=0 and <60";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                var fractionOfSecInt = (int)(secMultRound - (Second * 10000));
                FractSecond = fractionOfSecInt / 10000F;
                var fractString = string.Empty;

                // Now convert the fractionOfSec field to a string without the leading zero
                if (FractSecond != 0.0F)
                {
                    fractString = FractSecond.ToString().Substring(1);
                }

                // Now update the value field
                GMTOffset = 0;

                // Here the offset is not defined, we should omit showing it in the
                // return value from the getValue() method
                omitOffsetFg = 'y';
                valueRenamed = valueRenamed + DataTypeUtil.PreAppendZeroes(Second, 2) + fractString;
            }
            catch (DataTypeException e)
            {
                // TODO: this will remove the stack trace - is that correct?
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception occurred", e);
            }
        }