Esempio n. 1
0
 /// <summary>
 /// Returns true if the client registry is available. This
 /// is done by sending an unsupported message to the CR,
 /// if the CR responds with anything then it is up, otherwise
 /// it is unavailable
 /// </summary>
 public bool IsCrAvailable(WcfClientConnector connector)
 {
     try
     {
         return(SendReceive(connector, new MCCI_IN000002UV01(
                                Guid.NewGuid(),
                                DateTime.Now,
                                MCCI_IN000002UV01.GetInteractionId(),
                                ProcessingID.Debugging,
                                "T",
                                new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Receiver(),
                                new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Sender()
                                )) != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Handles PRPA_IN201301UV02 ITI-44
        /// </summary>
        private IGraphable HandlePatientRegistryRecordAdded(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_IN201301UV02;

            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_IN201301UV02.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
            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
                UvComponentUtil cu = new UvComponentUtil()
                {
                    Context = this.Context
                };
                var 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.Register(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 for audit
                audit = dataUtil.CreateAuditData("ITI-44",
                                                 result.VersionId.UpdateMode == UpdateModeType.Update ? ActionType.Update : ActionType.Create,
                                                 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
                audit = 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)
                {
                    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);
        }
        /// <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_IN000002UV01 response = new MCCI_IN000002UV01(
                new II(configService.OidRegistrar.GetOid("CR_MSGID").Oid, Guid.NewGuid().ToString()),
                DateTime.Now,
                null,
                HL7StandardVersionCode.Version3_Prerelease1,
                MCCI_IN000002UV01.GetInteractionId(),
                new SET <II>(MCCI_IN000002UV01.GetProfileId()),
                ProcessingID.Production,
                "T",
                null,
                null,
                null,
                MessageUtil.CreateSenderUv(e.ReceiveEndpoint, configService),
                null,
                new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Acknowledgement(
                    AcknowledgementType.AcceptAcknowledgementCommitReject,
                    new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.TargetMessage(
                        (receivedMessage.Structure as IIdentifiable).Id
                        )
                    )
                );

            // Add a detail
            if (solicitation.InteractionId != null && solicitation.InteractionId.Extension != receivedMessage.Structure.GetType().Name)
            {
                response.Acknowledgement[0].AcknowledgementDetail.Add(
                    new AcknowledgementDetail(
                        AcknowledgementDetailType.Error,
                        new CE <String>(Util.ToWireFormat(MARC.Everest.RMIM.CA.R020402.Vocabulary.AcknowledgementDetailCode.ValueDoesNotMatchFixedValue), "2.16.840.1.113883.5.1100"),
                        String.Format("Interaction ID '{0}' not supported for message type '{1}'", solicitation.InteractionId.Extension, receivedMessage.Structure.GetType().Name),
                        null));
            }
            else
            {
                response.Acknowledgement[0].AcknowledgementDetail.Add(
                    new AcknowledgementDetail(
                        AcknowledgementDetailType.Error,
                        new CE <String>(Util.ToWireFormat(MARC.Everest.RMIM.CA.R020402.Vocabulary.AcknowledgementDetailCode.UnsupportedInteraction), "2.16.840.1.113883.5.1100"),
                        "Cannot process this interaction",
                        null)
                    );
            }

            // Validation detils
            response.Acknowledgement[0].AcknowledgementDetail.AddRange(MessageUtil.CreateAckDetailsUv(receivedMessage.Details));

            // Populate the receiver
            Sender originalSolicitor = solicitation.GetType().GetProperty("Sender").GetValue(solicitation, null) as Sender;
            var    receiver          = MessageUtil.CreateReceiver(originalSolicitor);

            response.Receiver.Add(receiver);

            return(response);
        }