/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Handle a PIX query. /// </summary> /// <param name="request">The request.</param> /// <param name="eventArgs">The <see cref="Hl7MessageReceivedEventArgs" /> instance containing the event data.</param> /// <returns>Returns the message result from the query.</returns> /// <exception cref="System.InvalidOperationException"></exception> internal IMessage HandlePixQuery(QBP_Q21 request, Hl7MessageReceivedEventArgs eventArgs) { var patientRepositoryService = ApplicationContext.Current.GetService <IPatientRepositoryService>(); var details = new List <IResultDetail>(); MessageUtil.Validate(request, details); IMessage response = null; // Control if (request == null) { return(null); } try { // Create Query Data var query = MessageUtil.CreateIDQuery(request.QPD); if (query == null) { throw new InvalidOperationException(ApplicationContext.Current.GetLocaleString("MSGE00A")); } var count = int.Parse(request?.RCP?.QuantityLimitedRequest?.Quantity?.Value ?? "0"); var offset = 0; var totalCount = 0; var result = patientRepositoryService.Find(query, offset, count, out totalCount); // Now process the result response = MessageUtil.CreateRSPK23(result, details); try { (response as RSP_K23).QPD.MessageQueryName.Identifier.Value = request.QPD.MessageQueryName.Identifier.Value; Terser reqTerser = new Terser(request), rspTerser = new Terser(response); rspTerser.Set("/QPD-1", reqTerser.Get("/QPD-1")); rspTerser.Set("/QPD-2", reqTerser.Get("/QPD-2")); rspTerser.Set("/QPD-3-1", reqTerser.Get("/QPD-3-1")); rspTerser.Set("/QPD-3-4-1", reqTerser.Get("/QPD-3-4-1")); rspTerser.Set("/QPD-3-4-2", reqTerser.Get("/QPD-3-4-2")); rspTerser.Set("/QPD-3-4-3", reqTerser.Get("/QPD-3-4-3")); rspTerser.Set("/QPD-4-1", reqTerser.Get("/QPD-4-1")); rspTerser.Set("/QPD-4-4-1", reqTerser.Get("/QPD-4-4-1")); rspTerser.Set("/QPD-4-4-2", reqTerser.Get("/QPD-4-4-2")); rspTerser.Set("/QPD-4-4-3", reqTerser.Get("/QPD-4-4-3")); } catch (Exception e) { this.traceSource.TraceEvent(TraceEventType.Error, 0, e.ToString()); } MessageUtil.UpdateMSH(new Terser(response), request); } catch (Exception e) { this.traceSource.TraceEvent(TraceEventType.Error, 0, e.ToString()); response = MessageUtil.CreateNack(request, details, typeof(RSP_K23)); var errTerser = new Terser(response); // HACK: Fix the generic ACK with a real ACK for this message errTerser.Set("/MSH-9-2", "K23"); errTerser.Set("/MSH-9-3", "RSP_K23"); errTerser.Set("/QAK-2", "AE"); errTerser.Set("/MSA-1", "AE"); errTerser.Set("/QAK-1", request.QPD.QueryTag.Value); } return(response); }