Exemplo n.º 1
0
        /// <summary>
        /// Patient registry get identifiers query
        /// </summary>
        /// <param name="e"></param>
        /// <param name="receivedMessage"></param>
        /// <returns></returns>
        private IGraphable PatientRegistryGetIdentifiers(UnsolicitedDataEventArgs e, IReceiveResult receivedMessage)
        {
            // Setup the lists of details and issues
            List <IResultDetail> dtls = new List <IResultDetail>(receivedMessage.Details);

            // System configuration service
            ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService;

            // Localization service
            ILocalizationService locale = Context.GetService(typeof(ILocalizationService)) as ILocalizationService;

            // Data Service
            IClientRegistryDataService dataSvc = Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService;

            // Do basic check and add common validation errors
            MessageUtil.ValidateTransportWrapperUv(receivedMessage.Structure as IInteraction, configService, dtls);

            // Check the request is valid
            var request = receivedMessage.Structure as PRPA_IN201309UV02;

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

            // Determine if the received message was interpreted properly
            bool isValid = MessageUtil.IsValid(receivedMessage);

            // set the URI
            if (request.controlActProcess != null)
            {
                request.controlActProcess.Code = request.controlActProcess.Code ?? Util.Convert <CD <String> >(PRPA_IN201302UV02.GetTriggerEvent());
            }
            if (request.Receiver.Count > 0)
            {
                request.Receiver[0].Telecom = request.Receiver[0].Telecom ?? e.ReceiveEndpoint.ToString();
            }


            // Construct the acknowledgment
            var response = new PRPA_IN201310UV02(
                new II(configService.OidRegistrar.GetOid("CR_MSGID").Oid, Guid.NewGuid().ToString()),
                DateTime.Now,
                PRPA_IN201310UV02.GetInteractionId(),
                request.ProcessingCode,
                request.ProcessingModeCode,
                AcknowledgementCondition.Never,
                MessageUtil.CreateReceiver(request.Sender),
                MessageUtil.CreateSenderUv(e.ReceiveEndpoint, configService),
                null
                );


            // Create the support classes
            AuditData audit = null;

            IheAuditUtil dataUtil = new IheAuditUtil()
            {
                Context = this.Context
            };

            // Try to execute the record
            try
            {
                // Determine if the message is valid
                if (!isValid)
                {
                    throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure);
                }

                // Construct the canonical data structure
                GetIdentifiersQueryResponseFactory fact = new GetIdentifiersQueryResponseFactory()
                {
                    Context = this.Context
                };
                RegistryQueryRequest filter = fact.CreateFilterData(request, dtls);

                if (filter.QueryRequest == null)
                {
                    throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure);
                }

                // Query
                var results = dataSvc.Query(filter);
                dtls.AddRange(results.Details);

                // Prepare for audit
                audit = dataUtil.CreateAuditData("ITI-45",
                                                 ActionType.Execute,
                                                 dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success,
                                                 e,
                                                 receivedMessage,
                                                 results,
                                                 filter.QueryRequest.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant
                                                 );


                response = fact.Create(request, results, dtls) as PRPA_IN201310UV02;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                // Prepare for audit
                audit = dataUtil.CreateAuditData("ITI-45", ActionType.Execute, OutcomeIndicator.EpicFail, e, receivedMessage,
                                                 new List <VersionedDomainIdentifier>(),
                                                 null
                                                 );

                dtls.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex));
                response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement(
                                                 AcknowledgementType.AcceptAcknowledgementCommitError,
                                                 new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id)
                                                 ));
            }
            finally
            {
                IAuditorService auditService = Context.GetService(typeof(IAuditorService)) as IAuditorService;
                if (auditService != null)
                {
                    auditService.SendAudit(audit);
                }
            }

            // Common response parameters
            response.ProfileId     = new SET <II>(MCCI_IN000002UV01.GetProfileId());
            response.VersionCode   = HL7StandardVersionCode.Version3_Prerelease1;
            response.AcceptAckCode = AcknowledgementCondition.Never;
            response.Acknowledgement[0].AcknowledgementDetail.AddRange(MessageUtil.CreateAckDetailsUv(dtls.ToArray()));
            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle duplicates resolved message
        /// </summary>
        private IGraphable HandlePatientRegistryDuplicatesResolved(MARC.Everest.Connectors.UnsolicitedDataEventArgs e, MARC.Everest.Connectors.IReceiveResult receivedMessage)
        {
            // Setup the lists of details and issues
            List <IResultDetail> dtls = new List <IResultDetail>(receivedMessage.Details);

            // System configuration service
            ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService;

            // Localization service
            ILocalizationService locale = Context.GetService(typeof(ILocalizationService)) as ILocalizationService;

            // Data Service
            IClientRegistryDataService dataSvc = Context.GetService(typeof(IClientRegistryDataService)) as IClientRegistryDataService;

            // Do basic check and add common validation errors
            MessageUtil.ValidateTransportWrapperUv(receivedMessage.Structure as IInteraction, configService, dtls);

            // Check the request is valid
            var request = receivedMessage.Structure as PRPA_IN201304UV02;

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

            // Determine if the received message was interpreted properly
            bool isValid = MessageUtil.IsValid(receivedMessage);

            // set the URI
            if (request.controlActProcess != null)
            {
                request.controlActProcess.Code = request.controlActProcess.Code ?? Util.Convert <CD <String> >(PRPA_IN201302UV02.GetTriggerEvent());
            }
            if (request.Receiver.Count > 0)
            {
                request.Receiver[0].Telecom = request.Receiver[0].Telecom ?? e.ReceiveEndpoint.ToString();
            }

            // Construct the acknowledgment
            var response = new MCCI_IN000002UV01(
                new II(configService.OidRegistrar.GetOid("CR_MSGID").Oid, Guid.NewGuid().ToString()),
                DateTime.Now,
                MCCI_IN000002UV01.GetInteractionId(),
                request.ProcessingCode,
                request.ProcessingModeCode,
                MessageUtil.CreateReceiver(request.Sender),
                MessageUtil.CreateSenderUv(e.ReceiveEndpoint, configService)
                );


            // Create the support classes
            List <AuditData> audits = new List <AuditData>();

            IheAuditUtil dataUtil = new IheAuditUtil()
            {
                Context = this.Context
            };

            // Try to execute the record
            try
            {
                // Determine if the message is valid
                if (!isValid)
                {
                    throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure);
                }

                // Construct the canonical data structure
                UvComponentUtil cu = new UvComponentUtil()
                {
                    Context = this.Context
                };
                RegistrationEvent data = cu.CreateComponents(request.controlActProcess, dtls);

                // Componentization fail?
                if (data == null || !dataUtil.ValidateIdentifiers(data, dtls))
                {
                    throw new MessageValidationException(locale.GetString("MSGE00A"), receivedMessage.Structure);
                }

                // Store
                var result = dataSvc.Merge(data, request.ProcessingCode != ProcessingID.Production ? DataPersistenceMode.Debugging : DataPersistenceMode.Production);

                if (result == null || result.VersionId == null)
                {
                    throw new Exception(locale.GetString("DTPE001"));
                }

                dtls.AddRange(result.Details);

                // prepare the delete audit
                var person = data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf) as Person;
                var replc  = person.FindAllComponents(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.ReplacementOf);

                foreach (PersonRegistrationRef rplc in replc)
                {
                    audits.Add(dataUtil.CreateAuditData("ITI-44",
                                                        ActionType.Delete,
                                                        dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success,
                                                        e,
                                                        receivedMessage,
                                                        new List <VersionedDomainIdentifier>()
                    {
                        new VersionedDomainIdentifier()
                        {
                            Domain     = rplc.AlternateIdentifiers[0].Domain,
                            Identifier = rplc.AlternateIdentifiers[0].Identifier
                        }
                    },
                                                        data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant));
                }


                // Prepare for audit
                audits.Add(dataUtil.CreateAuditData("ITI-44",
                                                    ActionType.Update,
                                                    dtls.Exists(r => r.Type == ResultDetailType.Error) ? OutcomeIndicator.MinorFail : OutcomeIndicator.Success,
                                                    e,
                                                    receivedMessage,
                                                    new List <VersionedDomainIdentifier>()
                {
                    result.VersionId
                },
                                                    data.FindComponent(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.AuthorOf) as HealthcareParticipant
                                                    ));

                // Add ack
                response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Acknowledgement(
                                                 AcknowledgementType.AcceptAcknowledgementCommitAccept,
                                                 new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id)
                                                 ));
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                // Prepare for audit
                audits.Add(dataUtil.CreateAuditData("ITI-44", ActionType.Create, OutcomeIndicator.EpicFail, e, receivedMessage,
                                                    new List <VersionedDomainIdentifier>(),
                                                    null
                                                    ));

                dtls.Add(new ResultDetail(ResultDetailType.Error, ex.Message, ex));
                response.Acknowledgement.Add(new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Acknowledgement(
                                                 AcknowledgementType.AcceptAcknowledgementCommitError,
                                                 new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id)
                                                 ));
            }
            finally
            {
                IAuditorService auditService = Context.GetService(typeof(IAuditorService)) as IAuditorService;
                if (auditService != null)
                {
                    foreach (var aud in audits)
                    {
                        auditService.SendAudit(aud);
                    }
                }
            }

            // Common response parameters
            response.ProfileId     = new SET <II>(MCCI_IN000002UV01.GetProfileId());
            response.VersionCode   = HL7StandardVersionCode.Version3_Prerelease1;
            response.AcceptAckCode = AcknowledgementCondition.Never;
            response.Acknowledgement[0].AcknowledgementDetail.AddRange(MessageUtil.CreateAckDetailsUv(dtls.ToArray()));
            return(response);
        }
Exemplo n.º 3
0
        /// <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 response message
        /// </summary>
        public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <IResultDetail> dtls)
        {
            // GEt the config services
            ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService;
            ILocalizationService        localeService = Context.GetService(typeof(ILocalizationService)) as ILocalizationService;

            var retHl7v3 = new List <MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object> >(results.Results.Count);

            UvDeComponentUtil dCompUtil = new UvDeComponentUtil();

            dCompUtil.Context = this.Context;

            PRPA_IN201309UV02 rqst = request as PRPA_IN201309UV02;

            // Convert results to HL7v3
            foreach (RegistrationEvent res in results.Results)
            {
                var retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>(
                    false,
                    dCompUtil.CreateRegistrationEventDetail(res, dtls)
                    );
                if (retRec.RegistrationEvent == null)
                {
                    retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>(
                        false,
                        new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.RegistrationEvent <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>()
                    {
                        NullFlavor = NullFlavor.NoInformation
                    }
                        );
                }
                retHl7v3.Add(retRec);
            }

            if (retHl7v3.Count > 1)
            {
                dtls.Add(new InsufficientRepetitionsResultDetail(ResultDetailType.Warning, localeService.GetString("MSGE06E"), null));
            }

            // Create the response
            PRPA_IN201310UV02 response = new PRPA_IN201310UV02
                                         (
                Guid.NewGuid(),
                DateTime.Now,
                PRPA_IN201310UV02.GetInteractionId(),
                ProcessingID.Production,
                "T",
                AcknowledgementCondition.Never,
                MessageUtil.CreateReceiver(rqst.Sender),
                MessageUtil.CreateSenderUv(new Uri(rqst.Receiver[0].Telecom.Value), configService),
                null
                                         )
            {
                Acknowledgement = new List <MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement>()
                {
                    new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement(
                        dtls.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError,
                        new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id)
                        )
                }
            };

            response.controlActProcess = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201307UV02.QueryByParameter, MARC.Everest.RMIM.UV.NE2008.PRPA_MT201304UV02.Patient, object>("EVN")
            {
                Id       = SET <II> .CreateSET(new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString())),
                Code     = new CD <string>(PRPA_IN201310UV02.GetTriggerEvent().Code, PRPA_IN201310UV02.GetTriggerEvent().CodeSystem),
                QueryAck = new MARC.Everest.RMIM.UV.NE2008.QUQI_MT120001UV01.QueryAck(
                    rqst.controlActProcess.queryByParameter.QueryId,
                    "complete",
                    (AcknowledgementType)response.Acknowledgement[0].TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : results.TotalResults == 0 ? QueryResponse.NoDataFound : QueryResponse.DataFound,
                    results.TotalResults,
                    results.Results.Count,
                    results.TotalResults - results.Results.Count - results.StartRecordNumber
                    ),
                queryByParameter = rqst.controlActProcess.queryByParameter
            };

            response.controlActProcess.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context);
            if (retHl7v3.Count > 0)
            {
                response.controlActProcess.Subject.Add(retHl7v3[0]);
            }
            return(response);
        }
        /// <summary>
        /// Create the interaction type
        /// </summary>
        public MARC.Everest.Interfaces.IInteraction Create(MARC.Everest.Interfaces.IInteraction request, RegistryQueryResult results, List <IResultDetail> dtls)
        {
            // GEt the config services
            ISystemConfigurationService configService = Context.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService;

            var retHl7v3 = new List <MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object> >();
            //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());
            UvDeComponentUtil dCompUtil = new UvDeComponentUtil();

            dCompUtil.Context = this.Context;

            PRPA_IN201305UV02 rqst = request as PRPA_IN201305UV02;

            // Convert results to HL7v3
            foreach (RegistrationEvent res in results.Results)
            {
                var retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>(
                    true,
                    dCompUtil.CreateRegistrationEvent(res, dtls)
                    );
                if (retRec.RegistrationEvent == null)
                {
                    retRec = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.Subject1 <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>(
                        false,
                        new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.RegistrationEvent <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>()
                    {
                        NullFlavor = NullFlavor.NoInformation
                    }
                        );
                }
                retHl7v3.Add(retRec);
            }

            // HACK: Sort by confidence score (if present)
            //retHl7v3.Sort((a, b) =>
            //    a != null && b != null &&
            //    a.RegistrationEvent != null && b.RegistrationEvent != null &&
            //    a.RegistrationEvent.Subject1 != null && b.RegistrationEvent.Subject1 != null &&
            //    a.RegistrationEvent.Subject1.registeredRole != null && b.RegistrationEvent.Subject1.registeredRole != null &&
            //    (a.RegistrationEvent.Subject1.registeredRole.SubjectOf1.Count > 0) && (b.RegistrationEvent.Subject1.registeredRole.SubjectOf1.Count > 0) ?
            //    (b.RegistrationEvent.Subject1.registeredRole.SubjectOf1[0].QueryMatchObservation.Value as INT).CompareTo((a.RegistrationEvent.Subject1.registeredRole.SubjectOf1[0].QueryMatchObservation.Value as INT)) : 0);

            // Create the response
            PRPA_IN201306UV02 response = new PRPA_IN201306UV02
                                         (
                Guid.NewGuid(),
                DateTime.Now,
                PRPA_IN201306UV02.GetInteractionId(),
                ProcessingID.Production,
                "T",
                AcknowledgementCondition.Never,
                MessageUtil.CreateReceiver(rqst.Sender),
                MessageUtil.CreateSenderUv(new Uri(rqst.Receiver[0].Telecom.Value), configService),
                null
                                         )
            {
                Acknowledgement = new List <MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement>()
                {
                    new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100300UV01.Acknowledgement(
                        dtls.Count(a => a.Type == ResultDetailType.Error) == 0 ? AcknowledgementType.ApplicationAcknowledgementAccept : AcknowledgementType.ApplicationAcknowledgementError,
                        new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(request.Id)
                        )
                }
            };

            response.controlActProcess = new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter, MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient, object>("EVN")
            {
                Id       = SET <II> .CreateSET(new II(configService.Custodianship.Id.Domain, Guid.NewGuid().ToString())),
                Code     = new CD <string>(PRPA_IN201306UV02.GetTriggerEvent().Code, PRPA_IN201306UV02.GetTriggerEvent().CodeSystem),
                QueryAck = new MARC.Everest.RMIM.UV.NE2008.QUQI_MT120001UV01.QueryAck(
                    rqst.controlActProcess.queryByParameter.QueryId,
                    "complete",
                    (AcknowledgementType)response.Acknowledgement[0].TypeCode == AcknowledgementType.ApplicationAcknowledgementError ? QueryResponse.ApplicationError : results.TotalResults == 0 ? QueryResponse.NoDataFound : QueryResponse.DataFound,
                    results.TotalResults,
                    results.Results.Count,
                    results.TotalResults - results.Results.Count - results.StartRecordNumber
                    ),
                queryByParameter = rqst.controlActProcess.queryByParameter
            };

            response.controlActProcess.LanguageCode = MessageUtil.GetDefaultLanguageCode(this.Context);

            if (retHl7v3.Count > 0)
            {
                response.controlActProcess.Subject.AddRange(retHl7v3);
            }
            return(response);
        }
Exemplo n.º 6
0
        /// <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);
        }