protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
              {
            if (Request["recall"] != null)
            {
              string recallNumber = (string)Request["recall"];
              List<RecallFoodAlertData> recallList = (List<RecallFoodAlertData>)Session["recallList"];
              selectedRecall = recallList.Where(t => t.RecallNumber == recallNumber).FirstOrDefault();
              if (selectedRecall != null)
              {
            switch (selectedRecall.Classification.ToUpper())
            {
              case "CLASS I":
                riskLevel = "High";
                riskText = "Dangerous or defective products that predictably could cause serious health problems or death. Examples include: food found to contain botulinum toxin, food with undeclared allergens, a label mix-up on a lifesaving drug, or a defective artificial heart valve.";
                imgRisk.Src = "img/risk-high.png";
                break;
              case "CLASS II":
                riskLevel = "Medium";
                riskText = "Products that might cause a temporary health problem, or pose only a slight threat of a serious nature. Example: a drug that is under-strength but that is not used to treat life-threatening situations.";
                imgRisk.Src = "img/risk-med.png";
                break;
              case "CLASS III":
                riskLevel = "Low";
                riskText = "Products that are unlikely to cause any adverse health reaction, but that violate FDA labeling or manufacturing laws. Examples include: a minor container defect and lack of English labeling in a retail food.";
                imgRisk.Src = "img/risk-low.png";
                break;
              default:
                riskLevel = "Unknown";
                riskText = "";
                break;
            }

              }
            }
            else
            {
              Response.Redirect("Home.aspx");
            }
              }
        }
Exemple #2
0
        public List<RecallFoodAlertData> callAPI(string searchText, string state)
        {
            // string returnJson = "";
              List<RecallFoodAlertData> recallList = new List<RecallFoodAlertData>();
              if (searchText.Length > 0 || state.Length > 0)
              {
            string openFdaApiKey = "?api_key=ovNVdm7TO3IlzJr8ABOS6Zpdad70SNsBV3NW757e";

            // Assemble the search parameter
            string openFdaSearch = "&search=";
            string openFdaSearchParms = "";
            if (searchText.Trim().Length > 0)
            {
              openFdaSearchParms += string.Format("product_description:{0}+recalling_firm:{0}", searchText.Replace("'", ""));
            }
            if (state.Trim().Length > 0 && !state.Trim().ToUpper().Equals("USA"))
            {
              if (openFdaSearchParms.Length > 0)
              {
            openFdaSearchParms += "+AND+";
              }
              openFdaSearchParms += string.Format("state:{0}", state.Trim().ToUpper());
            }
            if (openFdaSearchParms.Length > 0)
            {
              openFdaSearchParms += "+AND+";
            }
            openFdaSearchParms += "product_type:Food";
            openFdaSearch += openFdaSearchParms;

            // Limit the results for the purposes of this prototype
            string openFdaLimit = "&limit=100";

            var fdaUrl = this.OpenFdaSite + openFdaApiKey + openFdaLimit + openFdaSearch;

            WebRequest wrGetUrl;
            wrGetUrl = WebRequest.Create(fdaUrl);

            Stream objStream = null;

            try
            {
              objStream = wrGetUrl.GetResponse().GetResponseStream();
            }
            catch (Exception ex)
            {
              log.Info(ex.Message);
            }
            if (objStream != null)
            {
              StreamReader objReader = new StreamReader(objStream);

              string sLine = "";
              int i = 0;

              System.Text.StringBuilder result = new System.Text.StringBuilder();
              while (sLine != null)
              {
            i++;
            sLine = objReader.ReadLine();
            if (sLine != null)
            {
              result.Append(sLine);
            }
              }

              // Parse the JSON result
              if (result.Length > 0)
              {
            JsonTextReader jtr = new JsonTextReader(new StringReader(result.ToString()));
            // var js = new JsonSerializer();
            JObject x = JObject.Parse(result.ToString());
            // JToken rslt = x["results"];
            IList<JToken> results = x["results"].Children().ToList();
            foreach (JToken t in results)
            {
              RecallFoodAlertData rfad = new RecallFoodAlertData();
              rfad.RecallNumber = "";
              rfad.RecallReason = "";
              rfad.Status = "";
              rfad.DistPattern = "";
              rfad.ProductQuantity = "";
              rfad.InitiationDate = new DateTime(1, 1, 1, 0, 0, 0);
              rfad.State = "";
              rfad.EventId = "";
              rfad.ProductType = "";
              rfad.ProductDescription = "";
              rfad.Country = "";
              rfad.City = "";
              rfad.FirmName = "";
              rfad.ReportDate = new DateTime(1, 1, 1, 0, 0, 0);
              rfad.VoluntaryMandated = "";
              rfad.Classification = "";
              rfad.CodeInfo = "";

              if (t["recall_number"] != null)
              {
                rfad.RecallNumber = t["recall_number"].ToString();
              }
              if (t["reason_for_recall"] != null)
              {
                rfad.RecallReason = t["reason_for_recall"].ToString();
              }
              if (t["status"] != null)
              {
                rfad.Status = t["status"].ToString();
              }
              if (t["distribution_pattern"] != null)
              {
                rfad.DistPattern = t["distribution_pattern"].ToString();
              }
              if (t["product_quantity"] != null)
              {
                rfad.ProductQuantity = t["product_quantity"].ToString();
              }
              if (t["recall_initiation_date"] != null)
              {
                rfad.InitiationDate = convertApiDate(t["recall_initiation_date"].ToString());
              }
              if (t["state"] != null)
              {
                rfad.State = t["state"].ToString();
              }
              if (t["event_id"] != null)
              {
                rfad.EventId = t["event_id"].ToString();
              }
              if (t["product_type"] != null)
              {
                rfad.ProductType = t["product_type"].ToString();
              }
              if (t["product_description"] != null)
              {
                rfad.ProductDescription = t["product_description"].ToString();
              }
              if (t["country"] != null)
              {
                rfad.Country = t["country"].ToString();
              }
              if (t["city"] != null)
              {
                rfad.City = t["city"].ToString();
              }
              if (t["recalling_firm"] != null)
              {
                rfad.FirmName = t["recalling_firm"].ToString();
              }
              if (t["report_date"] != null)
              {
                rfad.ReportDate = convertApiDate(t["report_date"].ToString());
              }
              if (t["voluntary_mandated"] != null)
              {
                rfad.VoluntaryMandated = t["voluntary_mandated"].ToString();
              }
              if (t["classification"] != null)
              {
                rfad.Classification = t["classification"].ToString();
              }
              if (t["code_info"] != null)
              {
                rfad.CodeInfo = t["code_info"].ToString();
              }

              recallList.Add(rfad);
            }

              }
            }
              }
              return recallList;
        }