コード例 #1
0
ファイル: AdtMessageHandler.cs プロジェクト: vindamle/openiz
        /// <summary>
        /// Handles an update.
        /// </summary>
        /// <param name="message">The request.</param>
        /// <param name="evt">The <see cref="Hl7MessageReceivedEventArgs" /> instance containing the event data.</param>
        /// <returns>Returns the response message from the merge event.</returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        internal IMessage HandlePixUpdate(NHapi.Model.V231.Message.ADT_A01 message, Hl7MessageReceivedEventArgs evt)
        {
            var dataService = ApplicationContext.Current.GetService <IPatientRepositoryService>();

            // Create a details array
            var details = new List <IResultDetail>();

            // Validate the inbound message
            MessageUtil.Validate(message, details);

            IMessage response = null;

            // Control
            if (message == null)
            {
                return(null);
            }

            try
            {
                // Create Query Data
                var data = MessageUtil.CreatePatient(message.MSH, message.EVN, message.PID, message.PD1, details);
                if (data == null)
                {
                    throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("MSGE00A"));
                }

                var result = dataService.Save(data);

                if (result == null || result.VersionKey == null)
                {
                    throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("DTPE001"));
                }

                //audit = auditUtil.CreateAuditData("ITI-8", result.VersionId.UpdateMode == UpdateModeType.Update ? ActionType.Update : ActionType.Create, OutcomeIndicator.Success, evt, new List<VersionedDomainIdentifier>() { result.VersionId });
                // Now process the result
                response = MessageUtil.CreateNack(message, details, typeof(NHapi.Model.V25.Message.ACK));
                MessageUtil.UpdateMSH(new NHapi.Base.Util.Terser(response), message);
                (response as NHapi.Model.V25.Message.ACK).MSH.MessageType.TriggerEvent.Value     = message.MSH.MessageType.TriggerEvent.Value;
                (response as NHapi.Model.V25.Message.ACK).MSH.MessageType.MessageStructure.Value = "ACK";
            }
            catch (Exception e)
            {
                this.traceSource.TraceEvent(TraceEventType.Error, 0, e.ToString());

                if (!details.Exists(o => o.Message == e.Message || o.Exception == e))
                {
                    details.Add(new ResultDetail(ResultDetailType.Error, e.Message, e));
                }

                response = MessageUtil.CreateNack(message, details, typeof(NHapi.Model.V25.Message.ACK));
            }

            return(response);
        }
コード例 #2
0
ファイル: AdtMessageHandler.cs プロジェクト: vindamle/openiz
        /// <summary>
        /// Handles the admit.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="eventArgs">The <see cref="Hl7MessageReceivedEventArgs"/> instance containing the event data.</param>
        /// <returns>IMessage.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// </exception>
        internal IMessage HandleAdmit(NHapi.Model.V231.Message.ADT_A01 message, Hl7MessageReceivedEventArgs eventArgs)
        {
            var patientRepositoryService = ApplicationContext.Current.GetService <IPatientRepositoryService>();

            var details = new List <IResultDetail>();

            MessageUtil.Validate(message, details);

            IMessage response;

            if (message == null)
            {
                return(null);
            }

            try
            {
                var patient = MessageUtil.CreatePatient(message.MSH, message.EVN, message.PID, message.PD1, details);

                if (details.Count(d => d.Type == ResultDetailType.Error) > 0)
                {
                    throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("MSGE00A"));
                }

                var result = patientRepositoryService.Insert(patient);

                if (result?.VersionKey == null)
                {
                    throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("DTPE001"));
                }

                response = MessageUtil.CreateNack(message, details, typeof(ACK));

                MessageUtil.UpdateMSH(new Terser(response), message);

                (response as ACK).MSH.MessageType.TriggerEvent.Value     = message.MSH.MessageType.TriggerEvent.Value;
                (response as ACK).MSH.MessageType.MessageStructure.Value = "ACK";
            }
            catch (Exception e)
            {
#if DEBUG
                this.traceSource.TraceEvent(TraceEventType.Error, 0, e.StackTrace);
#endif
                this.traceSource.TraceEvent(TraceEventType.Error, 0, e.Message);

                if (!details.Exists(o => o.Message == e.Message || o.Exception == e))
                {
                    details.Add(new ResultDetail(ResultDetailType.Error, e.Message, e));
                }

                response = MessageUtil.CreateNack(message, details, typeof(ACK));
            }

            return(response);
        }
コード例 #3
0
ファイル: AdtMessageHandler.cs プロジェクト: vindamle/openiz
        /// <summary>
        /// Handles a PIX merge request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="evt">The <see cref="Hl7MessageReceivedEventArgs" /> instance containing the event data.</param>
        /// <returns>IMessage.</returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException"></exception>
        internal IMessage HandleMerge(NHapi.Model.V231.Message.ADT_A39 request, Hl7MessageReceivedEventArgs evt)
        {
            // Get config
            var dataService = ApplicationContext.Current.GetService <IPatientRepositoryService>();

            // Create a details array
            List <IResultDetail> details = new List <IResultDetail>();

            // Validate the inbound message
            MessageUtil.Validate((IMessage)request, details);

            IMessage response = null;

            // Control
            if (request == null)
            {
                return(null);
            }

            try
            {
                // Create Data
                for (var i = 0; i < request.PATIENTRepetitionsUsed; i++)
                {
                    var patientGroup = request.GetPATIENT(i);

                    var survivor = MessageUtil.CreatePatient(request.MSH, request.EVN, patientGroup.PID, patientGroup.PD1, details);

                    if (survivor == null)
                    {
                        throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("MSGE00A"));
                    }

                    var victim = dataService.Find(o => o.Identifiers.Any(id => id.Authority.DomainName == patientGroup.MRG.GetPriorAlternatePatientID(0).AssigningAuthority.NamespaceID.Value&& id.Value == patientGroup.MRG.GetPriorAlternatePatientID(0).ID.Value)).FirstOrDefault();

                    if (victim == null)
                    {
                        throw new KeyNotFoundException();
                    }

                    var result = dataService.Merge(survivor, victim);
                }

                response = MessageUtil.CreateNack(request, details, typeof(ACK));
                MessageUtil.UpdateMSH(new NHapi.Base.Util.Terser(response), request);
                (response as NHapi.Model.V25.Message.ACK).MSH.MessageType.TriggerEvent.Value     = request.MSH.MessageType.TriggerEvent.Value;
                (response as NHapi.Model.V25.Message.ACK).MSH.MessageType.MessageStructure.Value = "ACK";
            }
            catch (Exception e)
            {
                this.traceSource.TraceEvent(TraceEventType.Error, 0, e.ToString());

                if (!details.Exists(o => o.Message == e.Message || o.Exception == e))
                {
                    details.Add(new ResultDetail(ResultDetailType.Error, e.Message, e));
                }

                response = MessageUtil.CreateNack(request, details, typeof(NHapi.Model.V25.Message.ACK));
            }

            return(response);
        }