Beispiel #1
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetSymptomsInfo/{UserId}")] HttpRequest req, string UserId,
            ILogger log)
        {
            if (req == null || String.IsNullOrEmpty(UserId))
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            try
            {
                SymptomsInfo symptomsInfo = await DbHelper.GetDataAsync <SymptomsInfo>(Constants.getSymptomsInfo, UserId).ConfigureAwait(false);

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

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(symptomsInfo), Encoding.UTF8, "application/json")
                });
            }
            catch (System.Exception ex)
            {
                log.LogInformation(ex.Message);
                throw new Exception(ex.ToString());
            }
        }
 public Task <int> SaveSymptomsLog(SymptomsInfo log)
 {
     if (log.ID != 0)
     {
         return(Database.UpdateAsync(log));
     }
     else
     {
         return(Database.InsertAsync(log));
     }
 }
        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"));
                }
                SymptomsInfo symptomsInfo = await req.Content.ReadAsAsync <SymptomsInfo>().ConfigureAwait(false);

                if (checkEmptyOrNull(symptomsInfo))
                {
                    return(new BadRequestObjectResult("Error: Incorrect payload"));
                }
                bool dataRecorded = DbHelper.PostDataAsync(symptomsInfo, Constants.postSymptomsInfo);
                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"));
            }
        }
        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));
                }
                SymptomsInfo symptomsInfo = await req.Content.ReadAsAsync <SymptomsInfo>().ConfigureAwait(false);

                if (checkEmptyOrNull(symptomsInfo))
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
                bool dataRecorded = DbHelper.PostDataAsync(symptomsInfo, Constants.postSymptomsInfo);
                if (dataRecorded)
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
            catch (HttpRequestException httpEx)
            {
                log.LogInformation(httpEx.Message);
                throw new HttpRequestException(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 void SendSummaryEmailWithQRCode(string DestEmail, string SrcEmail, string AuthorName, string RecipientName, bool isClearToWork, SymptomsInfo symptomsInfo, string imageBase64Encoding, string SendGridAPIKey, string DateOfEntry)
        {
            try
            {
                var EmailClient = new SendGridClient(SendGridAPIKey);

                var EmailMessage = new SendGridMessage();
                EmailMessage.SetFrom(new EmailAddress(SrcEmail, AuthorName));
                EmailMessage.AddTo(DestEmail);
                EmailMessage.SetSubject("Return To Work Assessment Results");
                if (isClearToWork == true)
                {
                    var MessageContent = "<p>" + RecipientName + ", thank you for taking Screening Assessment.</p> <p><b>Summary</b>:</p> <p>Result: <font style=\"color: green\">You are cleared to work today.</font></p> <p>Date of Assessment: " + DateOfEntry + " UTC </p> <p>Please use the QR Code attached to show at your facility entrance.\n\n </p>";
                    EmailMessage.AddAttachment("qrcode.png", imageBase64Encoding);
                    EmailMessage.AddContent(MimeType.Html, MessageContent);
                }
                else
                {
                    List <String> lstOfSymptoms = new List <String>();

                    bool isSymptoms = false;
                    bool isExposed  = false;

                    foreach (var property in symptomsInfo.GetType().GetProperties())
                    {
                        string        propertyType        = property.PropertyType.Name.ToString();
                        string        propertyName        = property.Name.ToString();
                        List <String> propertiesToExclude = new List <String> {
                            "IsSymptomatic", "UserIsSymptomatic", "ClearToWorkToday"
                        };
                        if (propertyType == "Boolean" && propertiesToExclude.Contains(propertyName) == false)
                        {
                            bool status = (bool)property.GetValue(symptomsInfo, null);
                            if (status == true)
                            {
                                if (propertyName == "UserIsExposed")
                                {
                                    isExposed = true;
                                }
                                else
                                {
                                    lstOfSymptoms.Add(propertyName.Replace("Symptom", ""));
                                    isSymptoms = true;
                                }
                            }
                        }
                    }
                    string symptomsStr = "";
                    if (isSymptoms == true)
                    {
                        symptomsStr = "You have the following symptoms today: ";
                        symptomsStr = symptomsStr + string.Join(", ", lstOfSymptoms);
                        symptomsStr = symptomsStr + ". ";
                    }
                    if (isExposed)
                    {
                        symptomsStr = symptomsStr + "You are currently in quarantine.";
                    }
                    var MessageContent = "<p>" + RecipientName + ", thank you for taking Screening Assessment.</p> <p><b>Summary</b>:</p> <p>Result: <font style=\"color: red\">You are NOT cleared to work today.</font></p> <p>Date of Assessment: " + DateOfEntry + " UTC </p> <p>Reaons: " + symptomsStr + "\n\n </p>";
                    EmailMessage.AddContent(MimeType.Html, MessageContent);
                }
                var EmailResponse = EmailClient.SendEmailAsync(EmailMessage);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
 private static bool checkEmptyOrNull(SymptomsInfo symptomsInfo)
 {
     return(symptomsInfo == null || String.IsNullOrEmpty(symptomsInfo.UserId) || String.IsNullOrEmpty(symptomsInfo.DateOfEntry) ||
            String.IsNullOrEmpty(symptomsInfo.UserIsExposed.ToString()) || String.IsNullOrEmpty(symptomsInfo.IsSymptomatic.ToString()) ||
            String.IsNullOrEmpty(symptomsInfo.ClearToWorkToday.ToString()));
 }
        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"));
                }
                SymptomsInfo symptomsInfo = await req.Content.ReadAsAsync <SymptomsInfo>().ConfigureAwait(false);

                if (checkEmptyOrNull(symptomsInfo))
                {
                    return(new BadRequestObjectResult("Error: Incorrect payload"));
                }

                bool dataRecorded = DbHelper.PostDataAsync(symptomsInfo, Constants.postSymptomsInfo);
                if (dataRecorded)
                {
                    string SrcEmail       = Environment.GetEnvironmentVariable("SrcEmail", EnvironmentVariableTarget.Process);
                    string AuthorName     = Environment.GetEnvironmentVariable("AuthorName", EnvironmentVariableTarget.Process);
                    string SendGridAPIKey = Environment.GetEnvironmentVariable("SendGridAPIKey", EnvironmentVariableTarget.Process);
                    if (!String.IsNullOrEmpty(SrcEmail) && !String.IsNullOrEmpty(AuthorName) && !String.IsNullOrEmpty(SendGridAPIKey))
                    {
                        UserContactInfo userContactInfo = DbHelper.GetSingleUserContactInfo(symptomsInfo.UserId.ToString());
                        string          DestEmail       = userContactInfo.EmailAddress.ToString();

                        string RecipientName       = userContactInfo.FullName.ToString();
                        bool   isClearToWork       = symptomsInfo.ClearToWorkToday;
                        string recordGUID          = "";
                        string imageBase64Encoding = "";
                        if (isClearToWork == true)
                        {
                            recordGUID          = Guid.NewGuid().ToString();
                            symptomsInfo.GUID   = recordGUID;
                            imageBase64Encoding = NotificationHelper.GenerateQRCode(recordGUID);
                        }

                        string DateOfEntry = symptomsInfo.DateOfEntry.ToString();

                        NotificationHelper.SendSummaryEmailWithQRCode(DestEmail, SrcEmail, AuthorName, RecipientName, isClearToWork, symptomsInfo, imageBase64Encoding, SendGridAPIKey, DateOfEntry);
                    }
                    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. One or more configuration parameters for SendGrid are missing."));
            }
            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"));
            }
        }
        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);
            }
        }
 public Task <int> DeleteSymptomsEval(SymptomsInfo log)
 {
     return(Database.DeleteAsync(log));
 }