/// <summary>
        ///     Gets a detailed list of issues. Issues are enforcements (Recalls) of food, drug and device (identified by
        ///     classification) and events of drug and devices
        /// </summary>
        /// <param name="keyWord"></param>
        /// <param name="state"></param>
        /// <returns>FDA Result object</returns>
        /// <remarks></remarks>
        public FdaResult GetFdaResult(string keyWord, string state)
        {
            var dataYearsBack = 1;

            var searchResultLocal = new FdaResult()
            {
                Keyword = keyWord,
                Results = new List <SearchResultItemBase>()
            };

            var mapList   = new Dictionary <string, SearchResultMapData>();
            var graphData = new ReportData();

            var tmp = GetRecallInfo(keyWord, state);

            var dateInit = DateTime.Now.AddYears(-dataYearsBack);

            // Initialize graph data
            for (var i = 1; i <= 12 * dataYearsBack; i++)
            {
                dateInit = dateInit.AddMonths(1);

                graphData.Labels.Add(dateInit.ToString("MMM-yyyy"));
                graphData.Data1.Add(0);
                graphData.Data2.Add(0);
                graphData.Data3.Add(0);
                graphData.DataE.Add(0);
            }

            // Reconstruct recall data as searchresultitem object
            foreach (var itm in tmp) // should be in order by newest date
            {
                var newItemDate   = DateTime.ParseExact(itm.Recall_Initiation_Date, "yyyyMMdd", CultureInfo.InvariantCulture);
                var tmpReportDate = DateTime.ParseExact(itm.Report_Date, "yyyyMMdd", CultureInfo.InvariantCulture);

                var tmpSearchResultItem = new SearchResultItem()
                {
                    City                = itm.City,
                    DateStarted         = newItemDate.ToString("ddMMMyyyy"),
                    Content             = string.Format("{0} {1}", itm.Reason_For_Recall, itm.Code_info),
                    DistributionPattern = itm.Distribution_Pattern,
                    ProductDescription  = itm.Product_Description,
                    State               = itm.State,
                    Status              = itm.Status,
                    Country             = itm.Country,
                    RecallNumber        = itm.Recall_Number,
                    ProductQuantity     = itm.Product_Quantity,
                    EventId             = itm.Event_Id,
                    RecallingFirm       = itm.Recalling_Firm,
                    ReportDate          = tmpReportDate.ToString("ddMMMyyyy"),
                    CodeInfo            = itm.Code_info,
                    Classification      = itm.Classification,
                    Voluntary           = itm.Voluntary_Mandated
                };

                searchResultLocal.Results.Add(tmpSearchResultItem);
            }

            // Lets Get the Events And Mix them In.
            var drugee = new OpenFda();

            //Get Drug Events
            var drugs = drugee.GetDrugEventsByDrugName(keyWord);

            searchResultLocal.Results.AddRange(drugs);

            //Get Device Events
            drugs = drugee.GetDeviceEventByDescription(keyWord);
            searchResultLocal.Results.AddRange(drugs);

            //'Sort for most recient at the top of the list

            // searchResultLocal.Results cannot be sorted because
            searchResultLocal.Results = ((from el in searchResultLocal.Results
                                          select el).OrderByDescending(el => el.SortDate)).ToList();

            // Now that the data is combined and sorted, Process data for maps and graphs
            foreach (var itm in searchResultLocal.Results)
            {
                var classification = string.Empty;
                var reportDate     = string.Empty;

                // Map Processing first
                switch (itm.GetType().
                        ToString())
                {
                case "ShopAware.Core.DataObjects.SearchResultItem":
                    ProcessResultRecordForRecall((SearchResultItem)itm, mapList);
                    classification = ((SearchResultItemBase)itm).Classification;
                    reportDate     = ((SearchResultItemBase)itm).ReportDate;
                    break;

                case "ShopAware.Core.DataObjects.SearchResultDrugEvent":
                    ProcessResultRecordForDrugEvent((SearchResultDrugEvent)itm, mapList);
                    classification = ((SearchResultItemBase)itm).Classification;
                    reportDate     = ((SearchResultItemBase)itm).ReportDate;
                    break;
                }

                // Now process graph data
                var tmpReportDate = DateTime.ParseExact(reportDate, "ddMMMyyyy", CultureInfo.InvariantCulture);
                var dateForReport = tmpReportDate.ToString("MMM-yyyy");
                var found         = false;

                switch (classification)
                {
                case "Class I":

                    for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                    {
                        if (graphData.Labels[i] == dateForReport)
                        {
                            found = true;
                            graphData.Data1[i] += 1;

                            break;
                        }
                    }

                    if (!found)
                    {
                        graphData.Labels.Insert(0, dateForReport);
                        graphData.Data1.Insert(0, 1);
                        graphData.Data2.Insert(0, 0);
                        graphData.Data3.Insert(0, 0);
                        graphData.DataE.Insert(0, 0);
                    }
                    break;

                case "Class II":

                    for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                    {
                        if (graphData.Labels[i] == dateForReport)
                        {
                            found = true;
                            graphData.Data2[i] += 1;
                        }
                    }

                    if (!found)
                    {
                        graphData.Labels.Insert(0, dateForReport);
                        graphData.Data1.Insert(0, 0);
                        graphData.Data2.Insert(0, 1);
                        graphData.Data3.Insert(0, 0);
                        graphData.DataE.Insert(0, 0);
                    }
                    break;

                case "Class III":

                    for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                    {
                        if (graphData.Labels[i] == dateForReport)
                        {
                            found = true;
                            graphData.Data3[i] += 1;
                        }
                    }

                    if (!found)
                    {
                        graphData.Labels.Insert(0, dateForReport);
                        graphData.Data1.Insert(0, 0);
                        graphData.Data2.Insert(0, 0);
                        graphData.Data3.Insert(0, 1);
                        graphData.DataE.Insert(0, 0);
                    }
                    break;

                case "Device Event":
                case "Drug Event":
                case "Event":

                    for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                    {
                        if (graphData.Labels[i] == dateForReport)
                        {
                            found = true;
                            graphData.DataE[i] += 1;
                        }
                    }

                    if (!found)
                    {
                        graphData.Labels.Insert(0, dateForReport);
                        graphData.Data1.Insert(0, 0);
                        graphData.Data2.Insert(0, 0);
                        graphData.Data3.Insert(0, 0);
                        graphData.DataE.Insert(0, 1);
                    }
                    break;
                }
            }

            searchResultLocal.MapObjects   = ConvertDictionaryMapObjectsToSearchResult(mapList);
            searchResultLocal.GraphObjects = graphData;

            return(searchResultLocal);
        }
        /// <summary>
        ///     Gets a detailed list of issues. Issues are enforcements (Recalls) of food, drug and device (identified by
        ///     classification) and events of drug and devices
        /// </summary>
        /// <param name="keyWord"></param>
        /// <param name="state"></param>
        /// <returns>FDA Result object</returns>
        /// <remarks></remarks>
        public FdaResult GetFdaResult(string keyWord, string state)
        {
            var dataYearsBack = 1;

            var searchResultLocal = new FdaResult()
                                    {
                                        Keyword = keyWord,
                                        Results = new List<SearchResultItemBase>()
                                    };

            var mapList = new Dictionary<string, SearchResultMapData>();
            var graphData = new ReportData();

            var tmp = GetRecallInfo(keyWord, state);

            var dateInit = DateTime.Now.AddYears(-dataYearsBack);

            // Initialize graph data
            for (var i = 1; i <= 12*dataYearsBack; i++)
            {
                dateInit = dateInit.AddMonths(1);

                graphData.Labels.Add(dateInit.ToString("MMM-yyyy"));
                graphData.Data1.Add(0);
                graphData.Data2.Add(0);
                graphData.Data3.Add(0);
                graphData.DataE.Add(0);
            }

            // Reconstruct recall data as searchresultitem object
            foreach (var itm in tmp) // should be in order by newest date
            {
                var newItemDate = DateTime.ParseExact(itm.Recall_Initiation_Date, "yyyyMMdd", CultureInfo.InvariantCulture);
                var tmpReportDate = DateTime.ParseExact(itm.Report_Date, "yyyyMMdd", CultureInfo.InvariantCulture);

                var tmpSearchResultItem = new SearchResultItem()
                                          {
                                              City = itm.City,
                                              DateStarted = newItemDate.ToString("ddMMMyyyy"),
                                              Content = string.Format("{0} {1}", itm.Reason_For_Recall, itm.Code_info),
                                              DistributionPattern = itm.Distribution_Pattern,
                                              ProductDescription = itm.Product_Description,
                                              State = itm.State,
                                              Status = itm.Status,
                                              Country = itm.Country,
                                              RecallNumber = itm.Recall_Number,
                                              ProductQuantity = itm.Product_Quantity,
                                              EventId = itm.Event_Id,
                                              RecallingFirm = itm.Recalling_Firm,
                                              ReportDate = tmpReportDate.ToString("ddMMMyyyy"),
                                              CodeInfo = itm.Code_info,
                                              Classification = itm.Classification,
                                              Voluntary = itm.Voluntary_Mandated
                                          };

                searchResultLocal.Results.Add(tmpSearchResultItem);
            }

            // Lets Get the Events And Mix them In.
            var drugee = new OpenFda();

            //Get Drug Events
            var drugs = drugee.GetDrugEventsByDrugName(keyWord);
            searchResultLocal.Results.AddRange(drugs);

            //Get Device Events
            drugs = drugee.GetDeviceEventByDescription(keyWord);
            searchResultLocal.Results.AddRange(drugs);

            //'Sort for most recient at the top of the list

            // searchResultLocal.Results cannot be sorted because
            searchResultLocal.Results = ((from el in searchResultLocal.Results
                                          select el).OrderByDescending(el => el.SortDate)).ToList();

            // Now that the data is combined and sorted, Process data for maps and graphs
            foreach (var itm in searchResultLocal.Results)
            {
                var classification = string.Empty;
                var reportDate = string.Empty;

                // Map Processing first
                switch (itm.GetType().
                            ToString())
                {
                    case "ShopAware.Core.DataObjects.SearchResultItem":
                        ProcessResultRecordForRecall((SearchResultItem) itm, mapList);
                        classification = ((SearchResultItemBase) itm).Classification;
                        reportDate = ((SearchResultItemBase) itm).ReportDate;
                        break;

                    case "ShopAware.Core.DataObjects.SearchResultDrugEvent":
                        ProcessResultRecordForDrugEvent((SearchResultDrugEvent) itm, mapList);
                        classification = ((SearchResultItemBase) itm).Classification;
                        reportDate = ((SearchResultItemBase) itm).ReportDate;
                        break;
                }

                // Now process graph data
                var tmpReportDate = DateTime.ParseExact(reportDate, "ddMMMyyyy", CultureInfo.InvariantCulture);
                var dateForReport = tmpReportDate.ToString("MMM-yyyy");
                var found = false;

                switch (classification)
                {
                    case "Class I":

                        for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                        {
                            if (graphData.Labels[i] == dateForReport)
                            {
                                found = true;
                                graphData.Data1[i] += 1;

                                break;
                            }
                        }

                        if (!found)
                        {
                            graphData.Labels.Insert(0, dateForReport);
                            graphData.Data1.Insert(0, 1);
                            graphData.Data2.Insert(0, 0);
                            graphData.Data3.Insert(0, 0);
                            graphData.DataE.Insert(0, 0);
                        }
                        break;

                    case "Class II":

                        for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                        {
                            if (graphData.Labels[i] == dateForReport)
                            {
                                found = true;
                                graphData.Data2[i] += 1;
                            }
                        }

                        if (!found)
                        {
                            graphData.Labels.Insert(0, dateForReport);
                            graphData.Data1.Insert(0, 0);
                            graphData.Data2.Insert(0, 1);
                            graphData.Data3.Insert(0, 0);
                            graphData.DataE.Insert(0, 0);
                        }
                        break;

                    case "Class III":

                        for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                        {
                            if (graphData.Labels[i] == dateForReport)
                            {
                                found = true;
                                graphData.Data3[i] += 1;
                            }
                        }

                        if (!found)
                        {
                            graphData.Labels.Insert(0, dateForReport);
                            graphData.Data1.Insert(0, 0);
                            graphData.Data2.Insert(0, 0);
                            graphData.Data3.Insert(0, 1);
                            graphData.DataE.Insert(0, 0);
                        }
                        break;

                    case "Device Event":
                    case "Drug Event":
                    case "Event":

                        for (var i = 0; i <= graphData.Labels.Count - 1; i++)
                        {
                            if (graphData.Labels[i] == dateForReport)
                            {
                                found = true;
                                graphData.DataE[i] += 1;
                            }
                        }

                        if (!found)
                        {
                            graphData.Labels.Insert(0, dateForReport);
                            graphData.Data1.Insert(0, 0);
                            graphData.Data2.Insert(0, 0);
                            graphData.Data3.Insert(0, 0);
                            graphData.DataE.Insert(0, 1);
                        }
                        break;
                }
            }

            searchResultLocal.MapObjects = ConvertDictionaryMapObjectsToSearchResult(mapList);
            searchResultLocal.GraphObjects = graphData;

            return searchResultLocal;
        }