/// <summary>
        /// Creates filter data from the request
        /// </summary>
        public RegistryQueryRequest CreateFilterData(MARC.Everest.Interfaces.IInteraction request, List <MARC.Everest.Connectors.IResultDetail> dtls)
        {
            ILocalizationService locale = Context.GetService(typeof(ILocalizationService)) as ILocalizationService;

            // Componentize the message into the data model
            CaComponentUtil compUtil = new CaComponentUtil();

            compUtil.Context = this.Context;
            PRPA_IN101101CA rqst = request as PRPA_IN101101CA;

            List <DomainIdentifier> ids = new List <DomainIdentifier>();
            var queryData = compUtil.CreateQueryMatch(rqst.controlActEvent, dtls, ref ids);

            if (ids == null || queryData == null)
            {
                throw new MessageValidationException(locale.GetString("MSGE00A"), request);
            }

            var filter = MessageUtil.CreateQueryData(rqst.controlActEvent.QueryByParameter, String.Format("{1}^^^&{0}&ISO",
                                                                                                          rqst.Sender.Device.Id.Root,
                                                                                                          rqst.Sender.Device.Id.Extension)
                                                     );

            filter.OriginalMessageQueryId = String.Format("{1}^^^&{0}&ISO", request.Id.Root, request.Id.Extension);
            filter.QueryRequest           = queryData;
            filter.TargetDomain           = ids;
            filter.IsSummary = false;

            return(filter);
        }
        /// <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_MT101102CA.IdentifiedEntity> > retHl7v3 = new List <MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.IdentifiedEntity> >(results.Results.Count());
            CaDeComponentUtil dCompUtil = new CaDeComponentUtil();

            dCompUtil.Context = this.Context;

            PRPA_IN101101CA rqst = request as PRPA_IN101101CA;

            // 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_MT101102CA.IdentifiedEntity>(
                    dCompUtil.CreateRegistrationEventDetailEx(res, details)
                    );
                if (retRec.RegistrationEvent == null)
                {
                    retRec = new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.Subject2 <MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.IdentifiedEntity>(
                        new MARC.Everest.RMIM.CA.R020403.MFMI_MT700746CA.RegistrationEvent <MARC.Everest.RMIM.CA.R020403.PRPA_MT101102CA.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_IN101102CA response = new PRPA_IN101102CA
                                       (
                Guid.NewGuid(),
                DateTime.Now,
                ResponseMode.Immediate,
                PRPA_IN101102CA.GetInteractionId(),
                PRPA_IN101102CA.GetProfileId(),
                ProcessingID.Production,
                AcknowledgementCondition.Never,
                MessageUtil.CreateReceiver(rqst.Sender),
                MessageUtil.CreateSender(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_IN101102CA.CreateControlActEvent(
                new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString()),
                PRPA_IN101102CA.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.Where(o => o is DetectedIssueResultDetail).Select(o => (o as DetectedIssueResultDetail).Issue).ToList()));
            }
            response.controlActEvent.Subject.AddRange(retHl7v3);

            return(response);
        }