/// <summary>
        /// Gets the HL7 message.
        /// </summary>
        /// <param name="keyValues">The key values.</param>
        /// <returns>A <see cref="System.String"/></returns>
        public string GetHl7Message(Dictionary <string, long> keyValues)
        {
            var problemKey = keyValues[HttpHandlerQueryStrings.ProblemKey];
            var session    = _sessionProvider.GetSession();

            _messageLocalDateTime = DateTime.Now;
            _problem = session.Get <Problem> (keyValues[HttpHandlerQueryStrings.ProblemKey]);
            Check.IsNotNull(_problem, string.Format("Problem not found for key {0}.", problemKey));

            // Derive a visit appointment date for a problem associated with multiple visits.
            // Return the first minimum Appointment.ScheduledStartDateTime and Visit.Key where the Problem.Key is found.
            var queryResult = session.CreateQuery(
                @"select min(v.AppointmentDateTimeRange.StartDateTime) as AppointmentStartDateTime, vp.Visit.Key as VisitKey
                from VisitProblem as vp
                join vp.Visit as v
                where vp.Problem.Key = :problemKey
                group by vp.Visit.Key")
                              .SetParameter("problemKey", problemKey)
                              .List();

            _minimumVisitScheduledStartDateTime = ( DateTime )(( object[] )queryResult[0])[0];
            _minimumVisitKey = ( long )(( object[] )queryResult[0])[1];
            VerifyDerivedVisit();
            _clinicalCase = _problem.ClinicalCase;
            _patient      = _problem.ClinicalCase.Patient;

            var dto = new SyndromicSurveillanceDto
            {
                MshDto            = GetMshDto(),
                PidDto            = GetPidDto(),
                EVNDto            = GetEvnDto(),
                PV1Dto            = GetPv1Dto(),
                Observations      = GetObservations(),
                PresentedProblems = GetPresentedProblems()
            };

            var helper  = IoC.CurrentContainer.Resolve <IMessageHelper <ADT_A01, SyndromicSurveillanceDto> > ();
            var factory = IoC.CurrentContainer.Resolve <MessageFactoryBase <ADT_A01, SyndromicSurveillanceDto> >();

            AbstractMessage message;

            if (helper != null && factory != null)
            {
                message = factory.CreateMessage(dto);
            }
            else
            {
                throw new ArgumentException("HL7 message helper or factory instances were not created.");
            }
            return((new PipeParser()).Encode(message));
        }
        /// <summary>
        /// Gets the HL7 message.
        /// </summary>
        /// <param name="keyValues">The key values.</param>
        /// <returns>A <see cref="System.String"/></returns>
        public string GetHl7Message( Dictionary<string, long> keyValues )
        {
            var problemKey = keyValues[HttpHandlerQueryStrings.ProblemKey];
            var session = _sessionProvider.GetSession ();

            _messageLocalDateTime = DateTime.Now;
            _problem = session.Get<Problem> ( keyValues[HttpHandlerQueryStrings.ProblemKey] );
            Check.IsNotNull ( _problem, string.Format ( "Problem not found for key {0}.", problemKey ) );

            // Derive a visit appointment date for a problem associated with multiple visits.
            // Return the first minimum Appointment.ScheduledStartDateTime and Visit.Key where the Problem.Key is found.
            var queryResult = session.CreateQuery (
                @"select min(v.AppointmentDateTimeRange.StartDateTime) as AppointmentStartDateTime, vp.Visit.Key as VisitKey
                from VisitProblem as vp
                join vp.Visit as v
                where vp.Problem.Key = :problemKey
                group by vp.Visit.Key" )
                .SetParameter ( "problemKey", problemKey )
                .List ();

            _minimumVisitScheduledStartDateTime = ( DateTime )( ( object[] )queryResult[0] )[0];
            _minimumVisitKey = ( long )( ( object[] )queryResult[0] )[1];
            VerifyDerivedVisit ();
            _clinicalCase = _problem.ClinicalCase;
            _patient = _problem.ClinicalCase.Patient;

            var dto = new SyndromicSurveillanceDto
                {
                    MshDto = GetMshDto (),
                    PidDto = GetPidDto (),
                    EVNDto = GetEvnDto (),
                    PV1Dto = GetPv1Dto (),
                    Observations = GetObservations (),
                    PresentedProblems = GetPresentedProblems ()
                };

            var helper = IoC.CurrentContainer.Resolve<IMessageHelper<ADT_A01, SyndromicSurveillanceDto>> ();
            var factory = IoC.CurrentContainer.Resolve<MessageFactoryBase<ADT_A01, SyndromicSurveillanceDto>>();

            AbstractMessage message;
            if ( helper != null && factory != null )
            {
                message = factory.CreateMessage ( dto );
            }
            else
            {
                throw new ArgumentException ( "HL7 message helper or factory instances were not created." );
            }
            return ( new PipeParser () ).Encode ( message );
        }