Example #1
0
        static void Main(string[] args)
        {
            // Create the WcfClient connector
            WcfConnectionStringBuilder builder = new WcfConnectionStringBuilder();

            builder.EndpointName = "ApplicationClient";
            WcfClientConnector client = new WcfClientConnector(builder.GenerateConnectionString()); // Endpoint name should match the ep name in app.config

            // Setup the formatter
            client.Formatter = new MARC.Everest.Formatters.XML.ITS1.Formatter();
            client.Formatter.GraphAides.Add(new DatatypeFormatter());

            // We want the service to validate our messages, not the formatter, so lets just turn off the
            // formatter validation for now
            (client.Formatter as MARC.Everest.Formatters.XML.ITS1.Formatter).ValidateConformance = false;

            // Open the connection
            client.Open();

            // Start the async send
            IAsyncResult iaSendResult = client.BeginSend(CreateInstance(), null, null);

            Console.WriteLine("Formatting and sending, please wait...");
            iaSendResult.AsyncWaitHandle.WaitOne(); // Wait until the response is received

            // Now we have to check that the message was actually sent to the remote system
            WcfSendResult sndResult = client.EndSend(iaSendResult) as WcfSendResult;

            // The result of sending the message wasn't good.
            if (sndResult.Code != ResultCode.Accepted && sndResult.Code != ResultCode.AcceptedNonConformant)
            {
                Console.WriteLine("The message wasn't sent!");
            }
            else // The connector has sent the message
            {
                // Receive the result (this involves waiting...)
                IAsyncResult iaRcvResult = client.BeginReceive(sndResult, null, null);
                Console.WriteLine("Parsing result...");
                iaRcvResult.AsyncWaitHandle.WaitOne(); // Wait for deserialization
                WcfReceiveResult rcvResult = client.EndReceive(iaRcvResult) as WcfReceiveResult;

                // Now lets print out the structure
                client.Formatter.Graph(Console.OpenStandardOutput(), rcvResult.Structure);
            }

            // Close the connection
            client.Close();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 /// <summary>
 /// Patient demographics consumer
 /// </summary>
 /// <param name="callbackDispatcher"></param>
 public PatientDemographicsConsumer(Dispatcher callbackDispatcher)
 {
     this.m_dispatcher = callbackDispatcher;
     // Create
     this.m_clientConnector           = new WcfClientConnector("endpointname=pds");
     this.m_clientConnector.Formatter = new XmlIts1Formatter()
     {
         ValidateConformance = false
     };
     this.m_clientConnector.Formatter.GraphAides.Add(new DatatypeFormatter()
     {
         ValidateConformance = false
     });
 }
        /// <summary>
        /// Send HL7v3 messages to a specified endpoint.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="endpointName">Name of the endpoint.</param>
        /// <returns><c>true</c> If the message sent successfully, <c>false</c> otherwise.</returns>
        public static bool Sendv3Messages(IGraphable message, string endpointName)
        {
            var retVal = true;

            var client = new WcfClientConnector($"endpointName={endpointName}");

            var formatter = new XmlIts1Formatter
            {
                ValidateConformance = true
            };

            client.Formatter = formatter;
            client.Formatter.GraphAides.Add(new DatatypeFormatter());

            client.Open();

            var sendResult = client.Send(message);

            traceSource.TraceEvent(TraceEventType.Verbose, 0, "Sending HL7v3 message to endpoint: " + client.ConnectionString);

            if (sendResult.Code != ResultCode.Accepted && sendResult.Code != ResultCode.AcceptedNonConformant)
            {
                traceSource.TraceEvent(TraceEventType.Error, 0, "Send result: " + Enum.GetName(typeof(ResultCode), sendResult.Code));
                retVal = false;
            }

            var receiveResult = client.Receive(sendResult);

            if (receiveResult.Code != ResultCode.Accepted && receiveResult.Code != ResultCode.AcceptedNonConformant)
            {
                traceSource.TraceEvent(TraceEventType.Error, 0, "Receive result: " + Enum.GetName(typeof(ResultCode), receiveResult.Code));
                retVal = false;
            }

            var result = receiveResult.Structure;

            if (result == null)
            {
                traceSource.TraceEvent(TraceEventType.Error, 0, "Receive result structure is null");
                retVal = false;
            }

            client.Close();

            return(retVal);
        }
Example #4
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);
     }
 }
 /// <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_IN000002CA(
                                Guid.NewGuid(),
                                DateTime.Now,
                                ResponseMode.Immediate,
                                MCCI_IN000002CA.GetInteractionId(),
                                MCCI_IN000002CA.GetProfileId(),
                                ProcessingID.Debugging,
                                AcknowledgementCondition.Always,
                                new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Receiver(),
                                new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Sender(),
                                null
                                )) != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #6
0
        /// <summary>
        /// Initialize the client connector
        /// </summary>
        private void InitializeConnector()
        {
            // Build connection string
            WcfConnectionStringBuilder csBuilder = new WcfConnectionStringBuilder();

            csBuilder.EndpointName = "pdqSupplier";

            // Create formatter
            XmlIts1Formatter fmtr = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            fmtr.GraphAides.Add(new CanadianDatatypeFormatter()
            {
                ValidateConformance = false
            });

            // Setup and open
            this.m_clientConnector           = new WcfClientConnector(csBuilder.GenerateConnectionString());
            this.m_clientConnector.Formatter = fmtr;
            this.m_clientConnector.Open();
        }
        /// <summary>
        /// Notify
        /// </summary>
        /// <param name="workItem"></param>
        public void Notify(NotificationQueueWorkItem workItem)
        {
            ILocalizationService locale = this.Context.GetService(typeof(ILocalizationService)) as ILocalizationService;

            // Create a message utility
            MessageUtility msgUtil = new MessageUtility()
            {
                Context = this.Context
            };

            // Create the EV formatters
            XmlIts1Formatter formatter = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            formatter.GraphAides.Add(new DatatypeFormatter()
            {
                ValidateConformance = false
            });

            // Iterate through the targets attempting to notify each one
            using (WcfClientConnector wcfClient = new WcfClientConnector(Target.ConnectionString))
            {
                wcfClient.Formatter = formatter;
                wcfClient.Open();

                // Build the message
                Trace.TraceInformation("Sending notification to '{0}'...", this.Target.Name);
                IInteraction notification = msgUtil.CreateMessage(workItem.Event, workItem.Action, this.Target);

                // Send it
                var sendResult = wcfClient.Send(notification);
                if (sendResult.Code != Everest.Connectors.ResultCode.Accepted &&
                    sendResult.Code != Everest.Connectors.ResultCode.AcceptedNonConformant)
                {
                    Trace.TraceWarning(string.Format(locale.GetString("NTFW002"), this.Target.Name));
                    DumpResultDetails(sendResult.Details);
                    return;
                }

                // Receive the response
                var rcvResult = wcfClient.Receive(sendResult);
                if (rcvResult.Code != Everest.Connectors.ResultCode.Accepted &&
                    rcvResult.Code != Everest.Connectors.ResultCode.AcceptedNonConformant)
                {
                    Trace.TraceWarning(string.Format(locale.GetString("NTFW003"), this.Target.Name));
                    DumpResultDetails(rcvResult.Details);
                    return;
                }

                // Get structure
                var response = rcvResult.Structure as MCCI_IN000002UV01;
                if (response == null)
                {
                    Trace.TraceWarning(string.Format(locale.GetString("NTFW003"), this.Target.Name));
                    return;
                }

                if (response.Acknowledgement.Count == 0 ||
                    response.Acknowledgement[0].TypeCode != AcknowledgementType.AcceptAcknowledgementCommitAccept)
                {
                    Trace.TraceWarning(string.Format(locale.GetString("NTFW004"), this.Target.Name));
                    return;
                }


                // Close the connector and continue
                wcfClient.Close();
            }
        }
        /// <summary>
        /// Generate the auto complete data
        /// </summary>
        public String[] Filter(WcfClientConnector connector, string filter)
        {
            List <String> retVal = new List <String>();

            // Create the instance
            PRPA_IN101103CA instance = new PRPA_IN101103CA(
                Guid.NewGuid(),
                DateTime.Now,
                ResponseMode.Immediate,
                PRPA_IN101103CA.GetInteractionId(),
                PRPA_IN101103CA.GetProfileId(),
                ProcessingID.Debugging,
                AcknowledgementCondition.Always,
                new Receiver()
            {
                Telecom = new TEL("http://cr.marc-hi.ca:8080/cr"),
                Device  = new Device2(
                    new II("1.3.6.1.4.1.33349.3.1.1.20.4", "CR-FAKE"),
                    "MARC-HI Client Registry",
                    null
                    )
            },
                new Sender()
            {
                Telecom = new TEL()
                {
                    NullFlavor = NullFlavor.NoInformation
                },
                Device = new Device1(
                    new II("1.2.3.4.5.4", "Sample"),
                    "Everest Sample",
                    null,
                    null,
                    null,
                    "An Example"
                    )
            },
                new ControlActEvent <MARC.Everest.RMIM.CA.R020402.PRPA_MT101103CA.ParameterList>(
                    Guid.NewGuid(),
                    PRPA_IN101103CA.GetTriggerEvent(),
                    new Author(DateTime.Now),
                    new MARC.Everest.RMIM.CA.R020402.QUQI_MT120008CA.QueryByParameter <MARC.Everest.RMIM.CA.R020402.PRPA_MT101103CA.ParameterList>(
                        Guid.NewGuid(),
                        ResponseModality.RealTime,
                        10,
                        QueryRequestLimit.Record,
                        new MARC.Everest.RMIM.CA.R020402.PRPA_MT101103CA.ParameterList()
                        )
                    ));

            instance.controlActEvent.EffectiveTime = new IVL <TS>(DateTime.Now);

            // Set the author
            instance.controlActEvent.Author.SetAuthorPerson(
                SET <II> .CreateSET(new II("1.3.6.1.4.1.21367.2010.3.2.202", "0008")),
                new MARC.Everest.RMIM.CA.R020402.COCT_MT090102CA.Person(
                    new PN(EntityNameUse.License,
                           new ENXP[] {
                new ENXP("Birth", EntityNamePartType.Family),
                new ENXP("John", EntityNamePartType.Given)
            }
                           ),
                    null
                    )
                );

            // Set the filter for given then family
            foreach (var enpt in new EntityNamePartType[] { EntityNamePartType.Given, EntityNamePartType.Family })
            {
                instance.Id = Guid.NewGuid();
                instance.controlActEvent.QueryByParameter.QueryId = Guid.NewGuid();

                // Set the name
                instance.controlActEvent.QueryByParameter.parameterList.PersonName.Clear();
                instance.controlActEvent.QueryByParameter.parameterList.PersonName.Add(
                    new MARC.Everest.RMIM.CA.R020402.PRPA_MT101103CA.PersonName(
                        new PN(EntityNameUse.Legal, new ENXP[] {
                    new ENXP(filter, enpt)
                })
                        )
                    );

                // Make the query
                PRPA_IN101104CA response = this.SendReceive(connector, instance) as PRPA_IN101104CA;

                // Interpret the response code
                if (response.Acknowledgement.TypeCode != AcknowledgementType.ApplicationAcknowledgementAccept ||
                    response.controlActEvent == null)
                {
                    continue;
                }
                foreach (var subj in response.controlActEvent.Subject)
                {
                    // Ensure that the relationships exist
                    if (subj.RegistrationEvent == null ||
                        subj.RegistrationEvent.Subject == null ||
                        subj.RegistrationEvent.Subject.registeredRole == null ||
                        subj.RegistrationEvent.Subject.registeredRole.IdentifiedPerson == null ||
                        subj.RegistrationEvent.Subject.registeredRole.IdentifiedPerson.Name == null ||
                        subj.RegistrationEvent.Subject.registeredRole.IdentifiedPerson.Name.IsEmpty)
                    {
                        continue;
                    }

                    // Add the formatted name
                    var legalName = subj.RegistrationEvent.Subject.registeredRole.IdentifiedPerson.Name.Find(o => o.Use != null && o.Use.Contains(EntityNameUse.Legal));
                    if (legalName == null)
                    {
                        legalName = subj.RegistrationEvent.Subject.registeredRole.IdentifiedPerson.Name[0];
                    }
                    retVal.Add(String.Format("{0}@{1} - {2}",
                                             subj.RegistrationEvent.Subject.registeredRole.Id[0].Root,
                                             subj.RegistrationEvent.Subject.registeredRole.Id[0].Extension,
                                             legalName.ToString("{FAM}, {GIV}")));
                }
            }

            // Now return results
            return(retVal.ToArray());
        }
Example #9
0
        /// <summary>
        /// Generate the auto complete data
        /// </summary>
        public String[] Filter(WcfClientConnector connector, string filter)
        {
            List <String> retVal = new List <String>();

            // Create the instance
            PRPA_IN201305UV02 instance = new PRPA_IN201305UV02(
                Guid.NewGuid(),
                DateTime.Now,
                PRPA_IN201305UV02.GetInteractionId(),
                ProcessingID.Production,
                "T",
                AcknowledgementCondition.Always,
                new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Receiver()
            {
                Telecom = new TEL("http://cr.marc-hi.ca:8080/pdqsupplier"),
                Device  = new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Device(
                    SET <II> .CreateSET(new II("1.3.6.1.4.1.33349.3.1.1.20.4", "CR"))
                    )
            },
                new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Sender()
            {
                Telecom = new TEL()
                {
                    NullFlavor = NullFlavor.NoInformation
                },
                Device = new MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Device(
                    SET <II> .CreateSET(new II("1.2.3.4.5.4", "Sample"))
                    )
            },
                new MARC.Everest.RMIM.UV.NE2008.QUQI_MT021001UV01.ControlActProcess <MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter>("EVN")
            {
                Id   = SET <II> .CreateSET(Guid.NewGuid()),
                Code = CD <String> .Parse(PRPA_IN201305UV02.GetTriggerEvent()),
                AuthorOrPerformer = new List <MARC.Everest.RMIM.UV.NE2008.MFMI_MT700701UV01.AuthorOrPerformer>(),
                queryByParameter  = new MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter(
                    Guid.NewGuid(),
                    "new",
                    new MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.ParameterList()

                    )
                {
                    InitialQuantity = 10
                }
            }
                );

            instance.controlActProcess.EffectiveTime = new IVL <TS>(DateTime.Now);

            // Set the author
            instance.controlActProcess.AuthorOrPerformer.Add(new MARC.Everest.RMIM.UV.NE2008.MFMI_MT700701UV01.AuthorOrPerformer());
            instance.controlActProcess.AuthorOrPerformer[0].SetParticipationChoice(new MARC.Everest.RMIM.UV.NE2008.COCT_MT090300UV01.AssignedDevice(
                                                                                       SET <II> .CreateSET(new II("1.2.3.4.5.4", "Sample")),
                                                                                       "DEV"
                                                                                       )
                                                                                   );

            // Set the filter for given then family
            foreach (var enpt in new EntityNamePartType[] { EntityNamePartType.Given, EntityNamePartType.Family })
            {
                instance.Id = Guid.NewGuid();
                instance.controlActProcess.queryByParameter.QueryId = Guid.NewGuid();

                // Set the name
                instance.controlActProcess.queryByParameter.ParameterList.LivingSubjectName.Clear();
                instance.controlActProcess.queryByParameter.ParameterList.LivingSubjectName.Add(
                    new MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectName(
                        SET <EN> .CreateSET(new EN(EntityNameUse.Search, new ENXP[] {
                    new ENXP(filter, enpt)
                })),
                        "livingSubject.name"
                        )
                    );

                // Make the query
                PRPA_IN201306UV02 response = this.SendReceive(connector, instance) as PRPA_IN201306UV02;

                // Interpret the response code
                if (response.Acknowledgement[0].TypeCode != AcknowledgementType.ApplicationAcknowledgementAccept ||
                    response.controlActProcess == null)
                {
                    continue;
                }
                foreach (var subj in response.controlActProcess.Subject)
                {
                    // Ensure that the relationships exist
                    if (subj.RegistrationEvent == null ||
                        subj.RegistrationEvent.Subject1 == null ||
                        subj.RegistrationEvent.Subject1.registeredRole == null ||
                        subj.RegistrationEvent.Subject1.registeredRole.GetPatientEntityChoiceSubjectAsPRPA_MT201310UV02Person() == null ||
                        subj.RegistrationEvent.Subject1.registeredRole.GetPatientEntityChoiceSubjectAsPRPA_MT201310UV02Person().Name == null ||
                        subj.RegistrationEvent.Subject1.registeredRole.GetPatientEntityChoiceSubjectAsPRPA_MT201310UV02Person().Name.IsEmpty)
                    {
                        continue;
                    }

                    // Add the formatted name
                    var legalName = subj.RegistrationEvent.Subject1.registeredRole.GetPatientEntityChoiceSubjectAsPRPA_MT201310UV02Person().Name.Find(o => o.Use != null && o.Use.Contains(EntityNameUse.Legal));
                    if (legalName == null)
                    {
                        legalName = subj.RegistrationEvent.Subject1.registeredRole.GetPatientEntityChoiceSubjectAsPRPA_MT201310UV02Person().Name[0];
                    }
                    retVal.Add(String.Format("{0}@{1} - {2}",
                                             subj.RegistrationEvent.Subject1.registeredRole.Id[0].Root,
                                             subj.RegistrationEvent.Subject1.registeredRole.Id[0].Extension,
                                             legalName.ToString("{FAM}, {GIV}")));
                }
            }

            // Now return results
            return(retVal.ToArray());
        }