/// <summary> /// Handles a received message /// </summary> public MARC.Everest.Interfaces.IGraphable HandleMessageReceived(object sender, UnsolicitedDataEventArgs e, MARC.Everest.Connectors.IReceiveResult receivedMessage) { // audit the error IAuditorService auditor = Context.GetService(typeof(IAuditorService)) as IAuditorService; AuditData ad = new AuditData( DateTime.Now, ActionType.Execute, OutcomeIndicator.EpicFail, EventIdentifierType.ApplicationActivity, new CodeValue(String.Format("{0}", receivedMessage.Structure)) ); ad.Actors.AddRange(new List <AuditActorData>(10) { new AuditActorData() { NetworkAccessPointId = e.ReceiveEndpoint.ToString(), NetworkAccessPointType = NetworkAccessPointType.IPAddress, UserIsRequestor = false }, new AuditActorData() { NetworkAccessPointType = NetworkAccessPointType.MachineName, NetworkAccessPointId = Environment.MachineName, UserIsRequestor = false } } ); ad.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.Verification, ObjectId = (receivedMessage.Structure as IIdentifiable).Id.Root, Role = AuditableObjectRole.Subscriber, Type = AuditableObjectType.SystemObject }); if (auditor != null) { auditor.SendAudit(ad); } IInteraction solicitation = receivedMessage.Structure as IInteraction; // get the configuration ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // construct a generic response MCCI_IN000002CA response = new MCCI_IN000002CA( Guid.NewGuid(), DateTime.Now, new CV <ResponseMode>(ResponseMode.Immediate), MCCI_IN000002CA.GetInteractionId(), MCCI_IN000002CA.GetProfileId(), ProcessingID.Debugging, AcknowledgementCondition.Never, null, MessageUtil.CreateSender(e.ReceiveEndpoint, configService), new Acknowledgement( AcknowledgementType.ApplicationAcknowledgementReject, new TargetMessage( (receivedMessage.Structure as IIdentifiable).Id ) ) ); // Add a detail if (solicitation.InteractionId != null && solicitation.InteractionId.Extension != receivedMessage.Structure.GetType().Name) { response.Acknowledgement.AcknowledgementDetail.Add( new AcknowledgementDetail( AcknowledgementDetailType.Error, Util.ToWireFormat(MARC.Everest.RMIM.CA.R020402.Vocabulary.AcknowledgementDetailCode.ValueDoesNotMatchFixedValue), String.Format("Interaction ID '{0}' not supported for message type '{1}'", solicitation.InteractionId.Extension, receivedMessage.Structure.GetType().Name), null)); } else { response.Acknowledgement.AcknowledgementDetail.Add( new AcknowledgementDetail( AcknowledgementDetailType.Error, Util.ToWireFormat(MARC.Everest.RMIM.CA.R020402.Vocabulary.AcknowledgementDetailCode.UnsupportedInteraction), "Cannot process this interaction", null) ); } // Validation detils response.Acknowledgement.AcknowledgementDetail.AddRange(MessageUtil.CreateGenAckDetails(receivedMessage.Details)); // Populate the receiver Sender originalSolicitor = solicitation.GetType().GetProperty("Sender").GetValue(solicitation, null) as Sender; Receiver receiver = MessageUtil.CreateReceiver(originalSolicitor); response.Receiver = receiver; return(response); }
/// <summary> /// Create the interaction /// </summary> public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <MARC.Everest.Connectors.IResultDetail> details) { // GEt the config services ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; List <MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity> > retHl7v3 = new List <MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity> >(results.Results.Count()); CaDeComponentUtil dCompUtil = new CaDeComponentUtil(); dCompUtil.Context = this.Context; PRPA_IN101103CA rqst = request as PRPA_IN101103CA; // Convert results to HL7v3 foreach (RegistrationEvent res in results.Results) { var retRec = new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>( dCompUtil.CreateRegistrationEvent(res, details) ); if (retRec.RegistrationEvent == null) { retRec = new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>( new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.RegistrationEvent <MARC.Everest.RMIM.CA.R020403.PRPA_MT101104CA.IdentifiedEntity>() { NullFlavor = NullFlavor.NoInformation } ); } retHl7v3.Add(retRec); } // HACK: Sort by confidence score (if present) retHl7v3.Sort((a, b) => b.RegistrationEvent.Subject.registeredRole.SubjectOf.ObservationEvent.Value.CompareTo(a.RegistrationEvent.Subject.registeredRole.SubjectOf.ObservationEvent.Value)); // Create the response PRPA_IN101104CA response = new PRPA_IN101104CA ( Guid.NewGuid(), DateTime.Now, ResponseMode.Immediate, PRPA_IN101104CA.GetInteractionId(), PRPA_IN101104CA.GetProfileId(), ProcessingID.Production, AcknowledgementCondition.Never, MessageUtil.CreateReceiver(rqst.Sender), MessageUtil.CreateSender(rqst.Receiver.Telecom == null ? null : new Uri(rqst.Receiver.Telecom.Value), configService), new MARC.Everest.RMIM.CA.R020403.MCCI_MT002200CA.Acknowledgement( details.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError, new MARC.Everest.RMIM.CA.R020403.MCCI_MT002200CA.TargetMessage(request.Id) ) ); response.Acknowledgement.AcknowledgementDetail = MessageUtil.CreateAckDetails(details.ToArray()); response.controlActEvent = PRPA_IN101104CA.CreateControlActEvent( new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString()), PRPA_IN101104CA.GetTriggerEvent(), new MARC.Everest.RMIM.CA.R020403.QUQI_MT120008CA.QueryAck( rqst.controlActEvent.QueryByParameter.QueryId, results.TotalResults == 0 ? QueryResponse.NoDataFound : (AcknowledgementType)response.Acknowledgement.TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : QueryResponse.DataFound, results.TotalResults, results.Results.Count, results.TotalResults - results.Results.Count - results.StartRecordNumber ), rqst.controlActEvent.QueryByParameter ); response.controlActEvent.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context); if (details.Count(o => o is DetectedIssueResultDetail) > 0) { response.controlActEvent.SubjectOf.AddRange(MessageUtil.CreateDetectedIssueEventsQuery(details.OfType <DetectedIssueResultDetail>().Select(o => o.Issue).ToList())); } response.controlActEvent.Subject.AddRange(retHl7v3); return(response); }