public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
            ILogger log)
        {
            try
            {
                if (req == null)
                {
                    return(new BadRequestObjectResult("Error: Request object missing"));
                }

                LabTestInfo labTestInfo = await req.Content.ReadAsAsync <LabTestInfo>().ConfigureAwait(false);

                if (labTestInfo == null || String.IsNullOrEmpty(labTestInfo.UserId) || String.IsNullOrEmpty(labTestInfo.DateOfEntry))
                {
                    return(new BadRequestObjectResult("Error: Incorrect payload"));
                }

                bool dataRecorded = DbHelper.PostDataAsync(labTestInfo, Constants.postLabTestInfo);

                if (dataRecorded)
                {
                    return(new OkObjectResult("Status: OK"));
                }
                else
                {
                    return(new BadRequestObjectResult("Error: Writing to database did not complete"));
                }
            }
            catch (HttpRequestException httpEx)
            {
                log.LogInformation(httpEx.Message);
                return(new BadRequestObjectResult("Error: Incorrect Request"));
            }
            catch (ArgumentNullException argNullEx)
            {
                log.LogInformation(argNullEx.Message);
                return(new BadRequestObjectResult("Error: Writing to database did not complete"));
            }
            catch (Newtonsoft.Json.JsonSerializationException serializeEx)
            {
                log.LogInformation(serializeEx.Message);
                return(new BadRequestObjectResult("Error: Incorrect payload"));
            }
            catch (SqlException sqlEx)
            {
                log.LogInformation(sqlEx.Message);
                return(new BadRequestObjectResult("Error: Writing to database did not complete"));
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.Message);
                return(new BadRequestObjectResult("Error: Something went wrong, could not save your details"));
            }
        }
Пример #2
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
            ILogger log)
        {
            try
            {
                if (req == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }

                LabTestInfo labTestInfo = await req.Content.ReadAsAsync <LabTestInfo>().ConfigureAwait(false);

                if (labTestInfo == null || String.IsNullOrEmpty(labTestInfo.UserId) || String.IsNullOrEmpty(labTestInfo.DateOfEntry))
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }

                bool dataRecorded = DbHelper.PostDataAsync(labTestInfo, Constants.postLabTestInfo);

                if (dataRecorded)
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
            catch (HttpRequestException httpEx)
            {
                log.LogInformation(httpEx.Message);
                throw new Exception(httpEx.ToString());
            }
            catch (ArgumentNullException argNullEx)
            {
                log.LogInformation(argNullEx.Message);
                throw new ArgumentNullException(argNullEx.ToString());
            }
            catch (Newtonsoft.Json.JsonSerializationException serializeEx)
            {
                log.LogInformation(serializeEx.Message);
                throw new Newtonsoft.Json.JsonSerializationException(serializeEx.ToString());
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.Message);
                throw new Exception(ex.ToString());
            }
        }
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetLabTestInfo/{UserId}")] HttpRequest req, string UserId,
            ILogger log)
        {
            if (req == null || String.IsNullOrEmpty(UserId))
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            try
            {
                LabTestInfo labTestInfo = await DbHelper.GetDataAsync <LabTestInfo>(Constants.getLabTestInfo, UserId).ConfigureAwait(false);

                if (labTestInfo == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));
                }

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(labTestInfo), Encoding.UTF8, "application/json")
                });
            }
            catch (ArgumentNullException argNullEx)
            {
                log.LogInformation(argNullEx.Message);
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            catch (Newtonsoft.Json.JsonSerializationException serializeEx)
            {
                log.LogInformation(serializeEx.Message);
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            catch (SqlException sqlEx)
            {
                log.LogInformation(sqlEx.Message);
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.Message);
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }
Пример #4
0
        /// <summary>
        /// Adds the lab test.
        /// </summary>
        /// <param name="labTestInfo">The lab test info.</param>
        /// <returns>A LabTest.</returns>
        public virtual LabTest AddLabTest(LabTestInfo labTestInfo)
        {
            var labTest = new LabTest { LabSpecimen = this };
            labTest.ReviseLabTestInfo ( labTestInfo );
            _labTests.Add(labTest);

            NotifyItemAdded(() => LabTests, labTest);
            return labTest;
        }
Пример #5
0
        public static async Task <T> GetDataAsync <T>(string ops, string paramString)
        {
            try
            {
                string errorMsg;
                string sqlConnectionString = Environment.GetEnvironmentVariable("SqlConnectionString", EnvironmentVariableTarget.Process);
                if (!String.IsNullOrEmpty(sqlConnectionString))
                {
                    switch (ops)
                    {
                    case Constants.getUserInfo:
                        UserInfo userInfo = new UserInfo();
                        using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                        {
                            connection.Open();
                            using (SqlCommand cmd = new SqlCommand("GetUserInfo", connection))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = paramString;
                                cmd.Prepare();
                                using (SqlDataReader reader = cmd.ExecuteReader())
                                {
                                    if (reader != null)
                                    {
                                        while (reader.Read())
                                        {
                                            userInfo.UserId       = reader["UserId"].ToString();
                                            userInfo.FullName     = reader["FullName"].ToString();
                                            userInfo.YearOfBirth  = (int)reader["YearOfBirth"];
                                            userInfo.EmailAddress = reader["EmailAddress"].ToString();
                                        }
                                    }
                                    return((T)Convert.ChangeType(userInfo, typeof(T)));
                                }
                            }
                        }

                    case Constants.getLabTestInfo:
                        LabTestInfo labTestInfo = new LabTestInfo();
                        using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                        {
                            connection.Open();
                            using (SqlCommand cmd = new SqlCommand("GetLabTestInfo", connection))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = paramString;
                                cmd.Prepare();
                                using (SqlDataReader reader = cmd.ExecuteReader())
                                {
                                    if (reader != null)
                                    {
                                        while (reader.Read())
                                        {
                                            labTestInfo.UserId      = reader["UserId"].ToString();
                                            labTestInfo.DateOfEntry = reader["DateOfEntry"].ToString();
                                            labTestInfo.TestType    = reader["TestType"].ToString();
                                            labTestInfo.TestDate    = reader["TestDate"].ToString();
                                            labTestInfo.TestResult  = reader["TestResult"].ToString();
                                        }
                                    }
                                    return((T)Convert.ChangeType(labTestInfo, typeof(T)));
                                }
                            }
                        }

                    case Constants.getRequestStatus:
                        RequestStatus requestStatus = new RequestStatus();
                        using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                        {
                            connection.Open();
                            using (SqlCommand cmd = new SqlCommand("GetRequestStatus", connection))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = paramString;
                                cmd.Prepare();
                                using (SqlDataReader reader = cmd.ExecuteReader())
                                {
                                    if (reader != null)
                                    {
                                        while (reader.Read())
                                        {
                                            requestStatus.UserId              = reader["UserId"].ToString();
                                            requestStatus.DateOfEntry         = reader["DateOfEntry"].ToString();
                                            requestStatus.ReturnRequestStatus = reader["ReturnRequestStatus"].ToString();
                                        }
                                    }
                                    return((T)Convert.ChangeType(requestStatus, typeof(T)));
                                }
                            }
                        }

                    case Constants.getSymptomsInfo:
                        SymptomsInfo symptomsInfo = new SymptomsInfo();
                        using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                        {
                            connection.Open();
                            using (SqlCommand cmd = new SqlCommand("GetSymptomsInfo", connection))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = paramString;
                                cmd.Prepare();
                                using (SqlDataReader reader = cmd.ExecuteReader())
                                {
                                    if (reader != null)
                                    {
                                        while (reader.Read())
                                        {
                                            symptomsInfo.UserId                   = reader["UserId"].ToString();
                                            symptomsInfo.DateOfEntry              = reader["DateOfEntry"].ToString();
                                            symptomsInfo.UserIsExposed            = DBNull.Value.Equals(reader["UserIsExposed"]) ? false : (bool)reader["UserIsExposed"];
                                            symptomsInfo.ExposureDate             = reader["ExposureDate"].ToString();
                                            symptomsInfo.QuarantineStartDate      = reader["QuarantineStartDate"].ToString();
                                            symptomsInfo.QuarantineEndDate        = reader["QuarantineEndDate"].ToString();
                                            symptomsInfo.IsSymptomatic            = DBNull.Value.Equals(reader["IsSymptomatic"]) ? false : (bool)reader["IsSymptomatic"];
                                            symptomsInfo.SymptomFever             = DBNull.Value.Equals(reader["SymptomFever"]) ? false : (bool)reader["SymptomFever"];
                                            symptomsInfo.SymptomCough             = DBNull.Value.Equals(reader["SymptomCough"]) ? false : (bool)reader["SymptomCough"];
                                            symptomsInfo.SymptomShortnessOfBreath = DBNull.Value.Equals(reader["SymptomShortnessOfBreath"]) ? false : (bool)reader["SymptomShortnessOfBreath"];
                                            symptomsInfo.SymptomChills            = DBNull.Value.Equals(reader["SymptomChills"]) ? false : (bool)reader["SymptomChills"];
                                            symptomsInfo.SymptomMusclePain        = DBNull.Value.Equals(reader["SymptomMusclePain"]) ? false : (bool)reader["SymptomMusclePain"];
                                            symptomsInfo.SymptomSoreThroat        = DBNull.Value.Equals(reader["SymptomSoreThroat"]) ? false : (bool)reader["SymptomSoreThroat"];
                                            symptomsInfo.SymptomLossOfSmellTaste  = DBNull.Value.Equals(reader["SymptomLossOfSmellTaste"]) ? false : (bool)reader["SymptomLossOfSmellTaste"];
                                            symptomsInfo.SymptomVomiting          = DBNull.Value.Equals(reader["SymptomVomiting"]) ? false : (bool)reader["SymptomVomiting"];
                                            symptomsInfo.SymptomDiarrhea          = DBNull.Value.Equals(reader["SymptomDiarrhea"]) ? false : (bool)reader["SymptomDiarrhea"];
                                            symptomsInfo.Temperature              = DBNull.Value.Equals(reader["Temperature"]) ? 0 : (decimal)reader["Temperature"];
                                            symptomsInfo.UserIsSymptomatic        = DBNull.Value.Equals(reader["UserIsSymptomatic"]) ? false : (bool)reader["UserIsSymptomatic"];
                                            symptomsInfo.ClearToWorkToday         = DBNull.Value.Equals(reader["ClearToWorkToday"]) ? false : (bool)reader["ClearToWorkToday"];
                                            symptomsInfo.GUID = reader["GUID"].ToString();
                                        }
                                    }
                                    return((T)Convert.ChangeType(symptomsInfo, typeof(T)));
                                }
                            }
                        }

                    default:
                        errorMsg = "Error in getting data from database";
                        throw new ArgumentNullException(errorMsg);
                    }
                }
                errorMsg = "Error: SQL Connection Parameters not found in Configuration";
                throw new ArgumentNullException(errorMsg);
            }
            catch (SqlException sqlEx)
            {
                throw new Exception(sqlEx.Message);
            }
            catch (ArgumentNullException argNullEx)
            {
                throw new ArgumentNullException(argNullEx.Message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #6
0
        /// <summary>
        /// Revises the lab test info.
        /// </summary>
        /// <param name="labTestInfo">The lab test info.</param>
        public virtual void ReviseLabTestInfo(LabTestInfo labTestInfo)
        {
            Check.IsNotNull ( labTestInfo, () => LabTestInfo );

            LabTestInfo = labTestInfo;
        }