1
Vote

Data type DTM missing

description

Hi,
in the HAPI project I can see the DTM type starting from the version 2.4 but I cannot find it in the nHapi project.

The DTM (date and time) data type replaces TS. The TS data type consisted of 2 components. The second component of TS had the aim of conveying the precision of the date and time value contained in the first component.

The definition of DTM is equal to that of TS - without the second component. The DTM data type allows for a 4-digit year and optional 2-digit and further additional 2-digit day; further optional hours and minutes (n.b., not hours alone); further optional (fractional) seconds, with or without time zone.

Here is my implementation of the type ( I did it for the version 2.3.1):
using System;
using NHapi.Base.Model;
using NHapi.Base.Log;
using NHapi.Base;
using NHapi.Base.Model.Primitive;

namespace NHapi.Model.V231.Datatype
{

    ///<summary>
    /// <p>The HL7 TS (time stamp) data type.  Consists of the following components: </p><ol>
    /// <li>time of an event (TSComponentOne)</li>
    /// <li>degree of precision (ST)</li>
    /// </ol>
    ///</summary>
    [Serializable]
    public class DTM : AbstractType, IComposite
    {
        private IType[] data;

        ///<summary>
        /// Creates a TS.
        /// <param name="message">The Message to which this Type belongs</param>
        ///</summary>
        public DTM(IMessage message) : this(message, null) { }

        ///<summary>
        /// Creates a TS.
        /// <param name="message">The Message to which this Type belongs</param>
        /// <param name="description">The description of this type</param>
        ///</summary>
        public DTM(IMessage message, string description)
            : base(message, description)
        {
            data = new IType[2];
            data[0] = new TSComponentOne(message, "Time of an event");
        }

        ///<summary>
        /// Returns an array containing the data elements.
        ///</summary>
        public IType[] Components
        {
            get
            {
                return this.data;
            }
        }

        ///<summary>
        /// Returns an individual data component.
        /// @throws DataTypeException if the given element number is out of range.
        ///<param name="index">The index item to get (zero based)</param>
        ///<returns>The data component (as a type) at the requested number (ordinal)</returns>
        ///</summary>
        public IType this[int index]
        {

            get
            {
                try
                {
                    return this.data[index];
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    throw new DataTypeException("Element " + index + " doesn't exist in 1 element DTM composite");
                }
            }
        }
        ///<summary>
        /// Returns time of an event (component #0).  This is a convenience method that saves you from 
        /// casting and handling an exception.
        ///</summary>
        public TSComponentOne TimeOfAnEvent
        {
            get
            {
                TSComponentOne ret = null;
                try
                {
                    ret = (TSComponentOne)this[0];
                }
                catch (DataTypeException e)
                {
                    HapiLogFactory.GetHapiLog(this.GetType()).Error("Unexpected problem accessing known data type component - this is a bug.", e);
                    throw new System.Exception("An unexpected error ocurred", e);
                }
                return ret;
            }

        }
    }
}

comments