Exemplo n.º 1
0
        public int GetDrugEventsByDrugNameCount(string drugName)
        {
            //Dim tmpAdverseDrugEventtList As List(Of AdverseDrugEvent)
            var endPointType  = OpenFdaApiEndPoints.DrugEvent;
            var dataSetSize   = 0;
            var yearCheck     = -1;
            var apiUrl        = "";
            var searchResults = "";

            //Limit first query to a 1 year window
            var beginDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(1));
            var endDate   = string.Empty;

            ResetSearch();
            AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
            {
                drugName
            }), FilterCompairType.And);
            AddCountField("receivedate");

            apiUrl        = BuildUrl(endPointType);
            searchResults = Execute(apiUrl);

            if (!string.IsNullOrEmpty(searchResults))
            {
                var jo = JObject.Parse(searchResults);

                var maxEventDate = (from el in jo["results"]
                                    select Utilities.ConvertDateStringToDate(el["time"].ToString(), "yyyyMMdd")).Max();

                if (!(maxEventDate == null))
                {
                    endDate = string.Format("{0:yyyyMMdd}", maxEventDate.AddYears(yearCheck));
                }
            }

            if (string.IsNullOrEmpty(endDate))
            {
                return(0);
            }

            ResetSearch();
            AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
            {
                drugName
            }), FilterCompairType.And);
            AddSearchFilter(endPointType, FdaFilterTypes.Date, new List <string>(new[]
            {
                beginDate,
                endDate
            }), FilterCompairType.And);
            //Dim limit As String = AddResultLimit(100)

            apiUrl        = BuildUrl(endPointType);
            searchResults = Execute(apiUrl);
            dataSetSize   = GetMetaResults().
                            Total;

            do
            {
                // If there was not data in the 1 yr window the get all results.
                // Check date range window for results year 2 thur year 5.
                if (dataSetSize == 0)
                {
                    yearCheck--;
                    endDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddYears(yearCheck));

                    ResetSearch();
                    AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
                    {
                        drugName
                    }), FilterCompairType.And);
                    AddSearchFilter(endPointType, FdaFilterTypes.Date, new List <string>(new[]
                    {
                        beginDate,
                        endDate
                    }), FilterCompairType.And);

                    apiUrl = BuildUrl(endPointType);

                    searchResults = Execute(apiUrl);
                    //OpenFdaApiHits += 1

                    dataSetSize = GetMetaResults().
                                  Total;
                }
            }while (!(dataSetSize > 0 || Math.Abs(yearCheck) >= 5));

            //Search w/o Date range filter
            if (string.IsNullOrEmpty(searchResults))
            {
                ResetSearch();
                AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
                {
                    drugName
                }), FilterCompairType.And);

                apiUrl = BuildUrl(endPointType);

                searchResults = Execute(apiUrl);
            }

            if (!string.IsNullOrEmpty(searchResults))
            {
                dataSetSize = GetMetaResults().
                              Total;
            }

            return(dataSetSize);
        }
Exemplo n.º 2
0
        public List <SearchResultDrugEvent> GetDrugEventsByDrugName(string drugName)
        {
            var drugEventList            = new List <AdverseDrugEvent>();
            var tmpSearchResultDrugEvent = new List <SearchResultDrugEvent>();
            var endPointType             = OpenFdaApiEndPoints.DrugEvent;
            var dataSetSize = 0;
            var yearCheck   = -1;

            var apiUrl        = "";
            var searchResults = "";
            var limit         = "";

            //Limit first query to a 1 year window
            var beginDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(1));
            var endDate   = string.Empty;

            ResetSearch();
            AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
            {
                drugName
            }), FilterCompairType.And);
            AddCountField("receivedate");

            apiUrl        = BuildUrl(endPointType);
            searchResults = Execute(apiUrl);

            if (!string.IsNullOrEmpty(searchResults))
            {
                var jo           = JObject.Parse(searchResults);
                var maxEventDate = (from el in jo["results"]
                                    select Utilities.ConvertDateStringToDate(el["time"].ToString(), "yyyyMMdd")).Max();

                if (!(maxEventDate == null))
                {
                    endDate = string.Format("{0:yyyyMMdd}", maxEventDate.AddYears(yearCheck));
                }
            }

            if (string.IsNullOrEmpty(endDate))
            {
                return(tmpSearchResultDrugEvent);
            }

            ResetSearch();
            AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
            {
                drugName
            }), FilterCompairType.And);
            AddSearchFilter(endPointType, FdaFilterTypes.Date, new List <string>(new[]
            {
                beginDate,
                endDate
            }), FilterCompairType.And);

            limit         = AddResultLimit(100);
            apiUrl        = BuildUrl(endPointType);
            searchResults = Execute(apiUrl + limit);
            dataSetSize   = GetMetaResults().
                            Total;

            do
            {
                // If there was not data in the 1 yr window the get all results.
                // Check date range window for results year 2 thur year 5.
                if (dataSetSize == 0)
                {
                    yearCheck--;
                    endDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddYears(yearCheck));

                    ResetSearch();
                    AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
                    {
                        drugName
                    }), FilterCompairType.And);
                    AddSearchFilter(endPointType, FdaFilterTypes.Date, new List <string>(new[]
                    {
                        beginDate,
                        endDate
                    }), FilterCompairType.And);

                    apiUrl = BuildUrl(endPointType);

                    searchResults = Execute(apiUrl + limit);
                    //OpenFdaApiHits += 1

                    dataSetSize = GetMetaResults().
                                  Total;
                }
            }while (!(dataSetSize > 0 || Math.Abs(yearCheck) >= 5));

            //Search w/o Date range filter
            if (string.IsNullOrEmpty(searchResults))
            {
                ResetSearch();
                AddSearchFilter(endPointType, FdaFilterTypes.DrugEventDrugName, new List <string>(new[]
                {
                    drugName
                }), FilterCompairType.And);

                apiUrl = BuildUrl(endPointType);

                searchResults = Execute(apiUrl + limit);
                //OpenFdaApiHits += 1
                dataSetSize = GetMetaResults().
                              Total;
            }

            if (!string.IsNullOrEmpty(searchResults))
            {
                dataSetSize = GetMetaResults().
                              Total;
            }

            // LIMIT the number of page request to a MAX of 5
            var pageLimit = (int)(decimal.Ceiling((decimal)((double)dataSetSize / 100)));

            if (pageLimit > 5)
            {
                pageLimit = 5;
            }

            var skipValue = 0;

            if (dataSetSize > 0)
            {
                do
                {
                    pageLimit--;

                    if (!string.IsNullOrEmpty(searchResults))
                    {
                        var result = AdverseDrugEvent.CnvJsonDataToList(searchResults);
                        drugEventList.AddRange(result);
                    }

                    if (pageLimit > 0)
                    {
                        skipValue += 100;
                        //Dim newApiUrl As String = apiUrl.Replace("&limit=100", String.Format("&limit=100&skip={0}", skipValue))
                        limit         = string.Format("&limit=100&skip={0}", skipValue);
                        searchResults = Execute(apiUrl + limit);
                        // OpenFdaApiHits += 1
                    }
                }while (!(pageLimit == 0));
            }

            tmpSearchResultDrugEvent = SearchResultDrugEvent.ConvertJsonData(drugEventList);

            //Dim sortedResult = (From el In tmpSearchResultDrugEvent Select el Order By el.ReportDate Descending).ToList()

            return(tmpSearchResultDrugEvent);
        }