Example #1
0
        public string PostResult(ClsPostResult result)
        {
            String error = String.Empty;

            try
            {
                repository.AddResult(result);
            }
            catch (Exception e)
            {
                error = e.Message;
                //throw new Exception("400|" + e.Message, e);
            }

            return(error);
        }
        public async Task <HttpResponseMessage> PostResult()
        {
            ClsPostResult result = new ClsPostResult();

            byte[] filebData   = null;
            string errorMsg    = String.Empty;
            var    messageList = new JObject();

            //ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
            //var appId = principal.Claims.Where(c => c.Type == "clientId").Single().Value;
            //var orgId = principal.Claims.Where(c => c.Type == "orgId").Single().Value;

            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try
            {
                result.appId    = "appId";
                result.remoteIP = Request.GetClientIpAddress();

                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                if (provider.FileData.Count == 0)
                {
                    errorMsg = "Result file is required; ";
                }
                else
                {
                    MultipartFileData file = provider.FileData[0];
                    //result.fileName = file.Headers.ContentDisposition.FileName;


                    if (provider.FormData.GetValues("filename") == null)
                    {
                        result.fileName = "Result.pdf";
                    }
                    //else
                    //{

                    //}
                    //String fileName = provider.FormData.GetValues("filename").FirstOrDefault();

                    //if (String.IsNullOrEmpty(fileName))
                    //{
                    //    result.fileName = "Result.pdf";
                    //}
                    else
                    {
                        result.fileName = provider.FormData.GetValues("filename").FirstOrDefault();
                    }
                    FileStream fbs      = new System.IO.FileStream(file.LocalFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                    int        filebLen = (int)fbs.Length;
                    filebData = new byte[filebLen];
                    fbs.Read(filebData, 0, (int)filebLen);
                    fbs.Close();
                    result.resultBinaryStream = filebData;
                }

                if (provider.FormData.GetValues("clientId") == null)
                {
                    errorMsg += "clientId is required; ";
                }
                else
                {
                    result.clientId = provider.FormData.GetValues("clientId").FirstOrDefault();
                }

                if (provider.FormData.GetValues("orderId") == null)
                {
                    errorMsg += "orderId is required; ";
                }
                else
                {
                    result.orderId = provider.FormData.GetValues("orderId").FirstOrDefault();
                }


                if (provider.FormData.GetValues("orderCode") == null)
                {
                    errorMsg += "orderCode is required; ";
                }
                else
                {
                    result.orderCode = provider.FormData.GetValues("orderCode").FirstOrDefault();
                }

                if (provider.FormData.GetValues("resultFlag") == null)
                {
                    errorMsg += "resultFlag is required; ";
                }
                else
                {
                    result.resultFlag = provider.FormData.GetValues("resultFlag").FirstOrDefault();
                }

                if (provider.FormData.GetValues("normalRange") != null)
                {
                    result.normalRange = provider.FormData.GetValues("normalRange").FirstOrDefault();
                }

                //if (provider.FormData.GetValues("resultDate") != null)
                //{
                //    result.resultDate = provider.FormData.GetValues("resultDate").FirstOrDefault();
                //}

                if (provider.FormData.GetValues("resultName") == null)
                {
                    errorMsg += "resultName is required; ";
                }
                else
                {
                    result.resultName = provider.FormData.GetValues("resultName").FirstOrDefault();
                }

                if (provider.FormData.GetValues("resultText") != null)
                {
                    result.resultText = provider.FormData.GetValues("resultText").FirstOrDefault();
                }

                if (provider.FormData.GetValues("resultType") == null)
                {
                    errorMsg += "resultType is required; ";
                }
                else
                {
                    result.resultType = provider.FormData.GetValues("resultType").FirstOrDefault();
                }

                if (provider.FormData.GetValues("resultUnits") != null)
                {
                    result.resultUnits = provider.FormData.GetValues("resultUnits").FirstOrDefault();
                }

                if (errorMsg.Equals(String.Empty))
                {
                    errorMsg = this.iICLabsService.PostResult(result);

                    if (errorMsg.Equals(String.Empty))
                    {
                        messageList["Message"] = "Result added for Order Id:" + result.orderId + " and Order code:" + result.orderCode;
                        message.Add(messageList);

                        this.response = this.Request.CreateResponse(HttpStatusCode.OK, GetResponseBody("ok", message));
                    }
                    else
                    {
                        errorsList["Error"] = errorMsg;
                        errors.Add(errorsList);
                        return(this.Request.CreateResponse(HttpStatusCode.OK, GetResponseBody("error", errors)));
                    }
                }
                else
                {
                    errorsList["Error"] = errorMsg;
                    errors.Add(errorsList);
                    return(this.Request.CreateResponse(HttpStatusCode.OK, GetResponseBody("error", errors)));
                }
            }
            catch (Exception e)
            {
                errorsList["Error"] = e.Message;
                errors.Add(errorsList);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, GetResponseBody("error", errors)));
            }


            return(response);
        }
Example #3
0
        static void Main(string[] args)
        {
            Repository rep = new Repository();

            //ICLabs.ModelV1.Repository repV1 = new ICLabs.ModelV1.Repository();
            ClsPostResult result = new ClsPostResult();

            FileStream fbs      = new System.IO.FileStream("test.pdf", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            int        filebLen = (int)fbs.Length;

            byte[] filebData = new byte[filebLen];
            fbs.Read(filebData, 0, (int)filebLen);
            fbs.Close();

            result.orderId            = "XYZ000002";
            result.orderCode          = "LP";
            result.clientId           = "Test";
            result.resultBinaryStream = filebData;
            result.resultType         = "F";
            result.resultName         = "result name";
            rep.AddResult(result);

            //result.
            //rep.AddOrganization();


            //ClsGetApplication app = new ClsGetApplication();
            //app.appId = "ZOHO";
            //app.clientSecret = "z4DNiu1ILV0VJ9fccvzv+E5jJlkoSER9LcCw6H38mpA=";

            //rep.AddApplication();
            //var ob=rep.GetApplication(app);


            //var ob = rep.GetOrder();

            //ClsOrder order = new ClsOrder();
            //order.appId = "ZOHO";
            //order.clientId = "001";
            //order.orderId = "ABC0007";
            //order.clientName = "Test Client";
            //order.collectionDate = DateTime.Now.Date.ToString("yyyyMMdd");
            //order.collectionTime = DateTime.Now.ToLocalTime().ToString("hhmm");
            //order.firstName = "patient first name";
            //order.lastName = "patient last name";
            //order.orders = "BloodTest";
            //order.priority = "ASAP";
            //order.sex = "M";
            //order.dOB = "20140101";
            //string state = rep.AddOrder(order);


            //var l = rep.GetTestList();



            //ClsGetResultFile rf = new ClsGetResultFile();
            //rf.orderId = "test5";
            //rf.test = "test5";
            //rep.GetResultFile(rf);


            //string connStr = ConfigurationManager.ConnectionStrings["CacheDB"].ConnectionString;
            //CacheConnection cnCache = new CacheConnection(connStr);
            //cnCache.Open();

            ////DataTable dt = new DataTable();
            ////ClsResult os = null;
            //try
            //{
            //    using (CacheCommand Cmd = new CacheCommand("select ResultBinaryStream from  Results.Results where orderId='test4' and OrderCode = 'test4'", cnCache))
            //    {
            //        //Cmd.Parameters.Add("@orderId", GetResult.orderId);
            //       // /Cmd.Parameters.Add("@orderCode", GetResult.test);
            //        CacheDataReader reader = Cmd.ExecuteReader();

            //        while (reader.Read())
            //        {
            //            var file = reader[0];
            //        }
            //    }

            //}
            //catch (Exception e)
            //{
            //}
            //finally
            //{
            //    cnCache.Close();
            //}
            ////return os;

            //rep.AddResult();
        }