Exemplo n.º 1
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(SendC32Request request)
        {
            SendC32Response response = CreateTypedResponse();

            Staff staff = Session.QueryOver <Staff> ().Where(s => s.Key == request.StaffKey).SingleOrDefault();

            string fromAddress     = staff.DirectAddressCredential.DirectAddress.Address;
            var    fromDisplayName = staff.StaffProfile.StaffName.Complete;

            long patientKey = request.PatientKey;

            // Build Normative C32 Document
            string c32 = _builder.BuildC32Xml(patientKey, false);

            // Build Html Document representing the C32
            string c32Html = CreateHtmlC32(c32);

            string body = request.Body;

            string toAddress = request.ToDirectEmail;

            var mailMessageBuilder = new MailMessageBuilder();

            mailMessageBuilder
            .Compose(fromAddress, fromDisplayName, toAddress, string.Empty, request.Subject, body)
            .WithAttachment(c32, string.Format("{0}{1}", DateTime.Now.Ticks, ".xml"))
            .WithAttachment(c32Html, "Preview.html");

            _mailMessageSender.Send(mailMessageBuilder.MailMessage);

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Posts the C32 to pop health poster.
        /// </summary>
        /// <param name="patientKey">The patient key.</param>
        /// <returns>A <see cref="System.String"/></returns>
        public string PostC32ToPopHealthPoster(long patientKey)
        {
            var c32Xml = _c32Builder.BuildC32Xml(patientKey, true);

            ServicePointManager.ServerCertificateValidationCallback = CertificateCallback;

            var webRequest = WebRequest.Create(_requestUriString);

            webRequest.Credentials = new NetworkCredential("pophealth", "pophealth");
            webRequest.Method      = "POST";
            webRequest.ContentType = "application/xml";

            var byteArray = Encoding.ASCII.GetBytes(c32Xml);

            var postStream = webRequest.GetRequestStream();

            postStream.Write(byteArray, 0, byteArray.Length);
            postStream.Close();

            var popHealthResponse = ( HttpWebResponse )webRequest.GetResponse();

            var receiveStream = popHealthResponse.GetResponseStream();

            var encode = Encoding.GetEncoding("utf-8");

            var streamReader  = new StreamReader(receiveStream, encode);
            var read          = new char[256];
            var count         = streamReader.Read(read, 0, 256);
            var stringBuilder = new StringBuilder();

            while (count > 0)
            {
                stringBuilder.Append(new string ( read, 0, count ));
                count = streamReader.Read(read, 0, 256);
            }

            streamReader.Close();
            receiveStream.Close();
            popHealthResponse.Close();

            ServicePointManager.ServerCertificateValidationCallback = null;

            return(stringBuilder.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the C32.
        /// </summary>
        /// <param name="patientKey">The patient key.</param>
        /// <returns>
        /// A C32 string.
        /// </returns>
        public string GetC32(long patientKey)
        {
            var c32Xml = _c32Builder.BuildC32Xml(patientKey, false);

            return(c32Xml);
        }