/// <summary> /// Notifies a remote system. /// </summary> /// <param name="workItem">The work item of the notification.</param> public void Notify <T>(NotificationQueueWorkItem <T> workItem) where T : IdentifiedData { IMessage notificationMessage = null; var patient = workItem.Event as Patient; MSH msh = null; PID pid = null; EVN evn = null; PV1 pv1 = null; switch (workItem.ActionType) { case ActionType.Create: case ActionType.DuplicatesResolved: case ActionType.Update: { tracer.TraceEvent(TraceEventType.Information, 0, "Received update notification"); ADT_A05 message = new ADT_A05(); msh = message.MSH; msh.MessageType.TriggerEvent.Value = "A31"; pid = message.PID; evn = message.EVN; evn.EventTypeCode.Value = "A31"; pv1 = message.PV1; notificationMessage = message; break; } default: throw new ArgumentOutOfRangeException($"Invalid notification type {workItem.ActionType}"); } NotifierBase.UpdateMSH(msh, patient, this.TargetConfiguration); evn.RecordedDateTime.TimeOfAnEvent.Value = (TS)patient.CreationTime.DateTime; NotifierBase.UpdatePID(patient, pid, this.TargetConfiguration); pv1.PatientClass.Value = "N"; var queueItem = new MessageQueueWorkItem(notificationMessage, this.TargetConfiguration); if (!queueItem.TrySend()) { tracer.TraceEvent(TraceEventType.Warning, 0, "Unable to send message to remote endpoint: {0}", this.TargetConfiguration.ConnectionString); Hl7MessageQueue.Current.Enqueue(queueItem); } }
/// <summary> /// Notifies a remote system. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="workItem">The work item of the notification.</param> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public void Notify <T>(NotificationQueueWorkItem <T> workItem) where T : IdentifiedData { IMessage notificationMessage; var patient = workItem.Event as Patient; MSH msh; PID pid; EVN evn; PV1 pv1; MRG mrg = null; switch (workItem.ActionType) { case ActionType.Create: { tracer.TraceEvent(TraceEventType.Information, 0, "Received create notification"); var message = new ADT_A01(); msh = message.MSH; msh.MessageType.MessageType.Value = "ADT"; msh.MessageType.MessageStructure.Value = "ADT_A01"; msh.MessageType.TriggerEvent.Value = "A01"; pid = message.PID; evn = message.EVN; evn.EventTypeCode.Value = "A01"; pv1 = message.PV1; notificationMessage = message; break; } case ActionType.DuplicatesResolved: { tracer.TraceEvent(TraceEventType.Information, 0, "Received duplicates resolved notification"); var message = new ADT_A39(); msh = message.MSH; msh.MessageType.MessageType.Value = "ADT"; msh.MessageType.MessageStructure.Value = "ADT_A40"; msh.MessageType.TriggerEvent.Value = "A40"; pid = message.GetPATIENT(0).PID; evn = message.EVN; evn.EventTypeCode.Value = "A40"; pv1 = message.GetPATIENT(0).PV1; mrg = message.GetPATIENT(0).MRG; notificationMessage = message; break; } case ActionType.Update: { tracer.TraceEvent(TraceEventType.Information, 0, "Received update notification"); var message = new ADT_A01(); msh = message.MSH; msh.MessageType.MessageType.Value = "ADT"; msh.MessageType.MessageStructure.Value = "ADT_A08"; msh.MessageType.TriggerEvent.Value = "A08"; pid = message.PID; evn = message.EVN; evn.EventTypeCode.Value = "A08"; pv1 = message.PV1; notificationMessage = message; break; } default: throw new ArgumentOutOfRangeException($"Invalid notification type {workItem.ActionType}"); } NotifierBase.UpdateMSH(msh, patient, this.TargetConfiguration); evn.RecordedDateTime.TimeOfAnEvent.Value = (TS)patient.CreationTime.DateTime; NotifierBase.UpdatePID(patient, pid, this.TargetConfiguration); pv1.PatientClass.Value = "I"; // TODO: populate the merge information if (mrg != null) { } var queueItem = new MessageQueueWorkItem(notificationMessage, this.TargetConfiguration); if (!queueItem.TrySend()) { tracer.TraceEvent(TraceEventType.Warning, 0, "Unable to send message to remote endpoint: {0}", this.TargetConfiguration.ConnectionString); Hl7MessageQueue.Current.Enqueue(queueItem); } }
/// <summary> /// Notify /// </summary> /// <param name="workItem"></param> public void Notify(NotificationQueueWorkItem workItem) { ILocalizationService locale = this.Context.GetService(typeof(ILocalizationService)) as ILocalizationService; // Create a message utility MessageUtility msgUtil = new MessageUtility() { Context = this.Context }; // Create the EV formatters XmlIts1Formatter formatter = new XmlIts1Formatter() { ValidateConformance = false }; formatter.GraphAides.Add(new DatatypeFormatter() { ValidateConformance = false }); // Iterate through the targets attempting to notify each one using (WcfClientConnector wcfClient = new WcfClientConnector(Target.ConnectionString)) { wcfClient.Formatter = formatter; wcfClient.Open(); // Build the message Trace.TraceInformation("Sending notification to '{0}'...", this.Target.Name); IInteraction notification = msgUtil.CreateMessage(workItem.Event, workItem.Action, this.Target); // Send it var sendResult = wcfClient.Send(notification); if (sendResult.Code != Everest.Connectors.ResultCode.Accepted && sendResult.Code != Everest.Connectors.ResultCode.AcceptedNonConformant) { Trace.TraceWarning(string.Format(locale.GetString("NTFW002"), this.Target.Name)); DumpResultDetails(sendResult.Details); return; } // Receive the response var rcvResult = wcfClient.Receive(sendResult); if (rcvResult.Code != Everest.Connectors.ResultCode.Accepted && rcvResult.Code != Everest.Connectors.ResultCode.AcceptedNonConformant) { Trace.TraceWarning(string.Format(locale.GetString("NTFW003"), this.Target.Name)); DumpResultDetails(rcvResult.Details); return; } // Get structure var response = rcvResult.Structure as MCCI_IN000002UV01; if (response == null) { Trace.TraceWarning(string.Format(locale.GetString("NTFW003"), this.Target.Name)); return; } if (response.Acknowledgement.Count == 0 || response.Acknowledgement[0].TypeCode != AcknowledgementType.AcceptAcknowledgementCommitAccept) { Trace.TraceWarning(string.Format(locale.GetString("NTFW004"), this.Target.Name)); return; } // Close the connector and continue wcfClient.Close(); } }