public static List <SearchResultDrugEvent> CnvDeviceEventsToResultDrugEvents(List <AdverseDeviceEvent> tmpAdverseDeviceEventList)
            {
                var result = new List <SearchResultDrugEvent>();

                foreach (var itm in tmpAdverseDeviceEventList)
                {
                    var obj = new SearchResultDrugEvent();

                    obj.Classification = "Device Event";
                    obj.IsEvent        = false;
                    obj.IsDeviceEvent  = true;

                    if (itm.EventType.ToString().
                        Length > 1)
                    {
                        obj.Seriousness.Add(itm.EventType);
                    }

                    obj.DateStarted = Utilities.ConvertDateStringToDate(itm.DateOfEvent, "yyyyMMdd").
                                      ToString("ddMMMyyyy");
                    obj.ReportDate = Utilities.ConvertDateStringToDate(itm.DateReceived, "yyyyMMdd").
                                     ToString("ddMMMyyyy");
                    // DateTime.TryParse(itm.DateOfEvent, .DateStarted)
                    //DateTime.TryParse(itm.DateReceived, .ReceiptDate)

                    var objDetail = new SearchResultDrugEventItem();

                    foreach (var deviceItem in itm.Device)
                    {
                        if (!string.IsNullOrEmpty(deviceItem.BrandName))
                        {
                            objDetail.BrandName.Add(deviceItem.BrandName.ToTitleCase());
                        }

                        if (!string.IsNullOrEmpty(deviceItem.GenericName))
                        {
                            objDetail.GenericName.Add(deviceItem.GenericName.ToTitleCase());
                        }

                        foreach (var mdrItem in itm.MdrText)
                        {
                            obj.Description.Add(mdrItem.Text.ToTitleCase());
                        }
                    }

                    obj.DrugItem.Add(objDetail);

                    result.Add(obj);
                }

                return(result);
            }
        private void ProcessResultRecordForDrugEvent(SearchResultDrugEvent data, Dictionary <string, SearchResultMapData> list)
        {
            const string check  = "nationwide"; // add state field data.
            var          states = Enum.GetNames(typeof(States)).
                                  ToList();
            var nationwide = false;

            if (check.ToLower().
                Contains("nationwide"))
            {
                nationwide = true;
            }

            foreach (var state in states)
            {
                var stateEnum   = Enum.Parse(typeof(States), state);
                var stateName   = Utilities.GetEnumDescription(stateEnum);
                var stateCoords = Utilities.GetEnumCoordinates(stateEnum);

                if (check.Contains(state) || check.ToUpper().
                    Contains(stateName.ToUpper()) || nationwide)
                {
                    SearchResultMapData listCheck = null;

                    if (list.ContainsKey(state))
                    {
                        listCheck = list[state];
                    }
                    else
                    {
                        listCheck = new SearchResultMapData
                        {
                            State     = state,
                            Latitude  = stateCoords.Latitude.ToString(),
                            Longitude = stateCoords.Longitude.ToString()
                        };
                        list.Add(state, listCheck);
                    }

                    var tooltip = string.Concat(data.Rank);

                    listCheck.IconSet = listCheck.IconSet | IconSet.Event;

                    if (!listCheck.Tooltip.Contains(tooltip))
                    {
                        if (listCheck.Tooltip.Length > 0)
                        {
                            listCheck.Tooltip += ", ";
                        }

                        listCheck.Tooltip += tooltip;
                    }

                    // Get the Rank
                    var rank = 9;
                    switch (data.Rank.ToLower())
                    {
                    case "classi":
                        rank = 1;
                        break;

                    case "classii":
                        rank = 2;
                        break;

                    case "classiii":
                        rank = 3;
                        break;

                    case "events":
                        rank = 4;
                        break;

                    case "device event":
                        rank = 5;
                        break;

                    default:
                        rank = 5;
                        break;
                    }

                    if (listCheck.Rank > rank)
                    {
                        listCheck.Rank = rank;
                    }

                    list[state] = listCheck;

                    list[state] = listCheck;
                }
            }
        }
        private void ProcessResultRecordForDrugEvent(SearchResultDrugEvent data, Dictionary<string, SearchResultMapData> list)
        {
            const string check = "nationwide"; // add state field data.
            var states = Enum.GetNames(typeof (States)).
                              ToList();
            var nationwide = false;

            if (check.ToLower().
                      Contains("nationwide"))
            {
                nationwide = true;
            }

            foreach (var state in states)
            {
                var stateEnum = Enum.Parse(typeof (States), state);
                var stateName = Utilities.GetEnumDescription(stateEnum);
                var stateCoords = Utilities.GetEnumCoordinates(stateEnum);

                if (check.Contains(state) || check.ToUpper().
                                                   Contains(stateName.ToUpper()) || nationwide)
                {
                    SearchResultMapData listCheck = null;

                    if (list.ContainsKey(state))
                    {
                        listCheck = list[state];
                    }
                    else
                    {
                        listCheck = new SearchResultMapData
                                    {
                                        State = state,
                                        Latitude = stateCoords.Latitude.ToString(),
                                        Longitude = stateCoords.Longitude.ToString()
                                    };
                        list.Add(state, listCheck);
                    }

                    var tooltip = string.Concat(data.Rank);

                    listCheck.IconSet = listCheck.IconSet | IconSet.Event;

                    if (!listCheck.Tooltip.Contains(tooltip))
                    {
                        if (listCheck.Tooltip.Length > 0)
                        {
                            listCheck.Tooltip += ", ";
                        }

                        listCheck.Tooltip += tooltip;
                    }

                    // Get the Rank
                    var rank = 9;
                    switch (data.Rank.ToLower())
                    {
                        case "classi":
                            rank = 1;
                            break;
                        case "classii":
                            rank = 2;
                            break;
                        case "classiii":
                            rank = 3;
                            break;
                        case "events":
                            rank = 4;
                            break;
                        case "device event":
                            rank = 5;
                            break;
                        default:
                            rank = 5;
                            break;
                    }

                    if (listCheck.Rank > rank)
                    {
                        listCheck.Rank = rank;
                    }

                    list[state] = listCheck;

                    list[state] = listCheck;
                }
            }
        }
            public static List<SearchResultDrugEvent> CnvDeviceEventsToResultDrugEvents(List<AdverseDeviceEvent> tmpAdverseDeviceEventList)
            {
                var result = new List<SearchResultDrugEvent>();

                foreach (var itm in tmpAdverseDeviceEventList)
                {
                    var obj = new SearchResultDrugEvent();

                    obj.Classification = "Device Event";
                    obj.IsEvent = false;
                    obj.IsDeviceEvent = true;

                    if (itm.EventType.ToString().
                            Length > 1)
                    {
                        obj.Seriousness.Add(itm.EventType);
                    }

                    obj.DateStarted = Utilities.ConvertDateStringToDate(itm.DateOfEvent, "yyyyMMdd").
                                                ToString("ddMMMyyyy");
                    obj.ReportDate = Utilities.ConvertDateStringToDate(itm.DateReceived, "yyyyMMdd").
                                               ToString("ddMMMyyyy");
                    // DateTime.TryParse(itm.DateOfEvent, .DateStarted)
                    //DateTime.TryParse(itm.DateReceived, .ReceiptDate)

                    var objDetail = new SearchResultDrugEventItem();

                    foreach (var deviceItem in itm.Device)
                    {
                        if (!string.IsNullOrEmpty(deviceItem.BrandName))
                        {
                            objDetail.BrandName.Add(deviceItem.BrandName.ToTitleCase());
                        }

                        if (!string.IsNullOrEmpty(deviceItem.GenericName))
                        {
                            objDetail.GenericName.Add(deviceItem.GenericName.ToTitleCase());
                        }

                        foreach (var mdrItem in itm.MdrText)
                        {
                            obj.Description.Add(mdrItem.Text.ToTitleCase());
                        }
                    }

                    obj.DrugItem.Add(objDetail);

                    result.Add(obj);
                }

                return result;
            }
Example #5
0
            public static List <SearchResultDrugEvent> ConvertJsonData(List <AdverseDrugEvent> drugEvent)
            {
                var data = new List <SearchResultDrugEvent>();

                foreach (var itm in drugEvent)
                {
                    var obj = new SearchResultDrugEvent();

                    if (!(itm.Patient.PatientDeathDate == null))
                    {
                        obj.IsPatientDeath = true;
                    }

                    obj.PatientSex = Enum.GetName(typeof(PatientSex), itm.Patient.PatientSex);

                    if (!string.IsNullOrEmpty(itm.ReceiveDate))
                    {
                        //.DateStarted = ConvertDateStringToDate(itm.ReceiveDate, "yyyyMMdd")
                        obj.DateStarted = DateTime.ParseExact(itm.ReceiveDate, "yyyyMMdd", CultureInfo.InvariantCulture).
                                          ToString("ddMMMyyyy");
                    }

                    if (!string.IsNullOrEmpty(itm.ReceiptDate))
                    {
                        //.ReceiptDate = ConvertDateStringToDate(itm.ReceiptDate, "yyyyMMdd")
                        obj.ReportDate = DateTime.ParseExact(itm.ReceiptDate, "yyyyMMdd", CultureInfo.InvariantCulture).
                                         ToString("ddMMMyyyy");
                    }

                    //Seriousneess
                    if (!string.IsNullOrEmpty(itm.Serious))
                    {
                        switch (itm.Serious)
                        {
                        case "1":
                            obj.Seriousness.Add(
                                "The adverse event resulted in death, a life threatening condition, hospitalization, disability, congenital anomali, or other serious condition.");
                            break;

                        case "2":
                            obj.Seriousness.Add(
                                "The adverse event did not result in (death, a life threatening condition, hospitalization, disability, congenital anomali, or other serious condition.)");
                            break;
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessCongenitalAnomali))
                    {
                        if (itm.SeriousnessCongenitalAnomali == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in a congenital anomali");
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessDeath))
                    {
                        if (itm.SeriousnessDeath == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in death");
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessDisabling))
                    {
                        if (itm.SeriousnessDisabling == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in disability");
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessHospitalization))
                    {
                        if (itm.SeriousnessHospitalization == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in a hospitalization");
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessLifeThreatening))
                    {
                        if (itm.SeriousnessLifeThreatening == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in a life threatening condition");
                        }
                    }

                    if (!string.IsNullOrEmpty(itm.SeriousnessOther))
                    {
                        if (itm.SeriousnessOther == "1")
                        {
                            obj.Seriousness.Add("The adverse event resulted in some other serious condition");
                        }
                    }

                    //.Sender
                    //.Receiver
                    // .Reactions
                    foreach (var react in itm.Patient.Reaction)
                    {
                        obj.Reactions.Add(react.ReactionMedDrapt);
                    }

                    foreach (var drug in itm.Patient.Drug)
                    {
                        var drugItem = new SearchResultDrugEventItem();

                        foreach (var ofda in drug.OpenFDA.Brand_Name)
                        {
                            drugItem.BrandName.Add(ofda.ToTitleCase());
                        }

                        foreach (var ofda in drug.OpenFDA.Generic_Name)
                        {
                            drugItem.GenericName.Add(ofda.ToTitleCase());
                        }

                        foreach (var ofda in drug.OpenFDA.Manufacturer_Name)
                        {
                            drugItem.ManufacturerName.Add(ofda.ToTitleCase());
                        }

                        foreach (var ofda in drug.OpenFDA.Route)
                        {
                            drugItem.Route.Add(ofda.ToTitleCase());
                        }

                        obj.DrugItem.Add(drugItem);
                    }

                    data.Add(obj);
                }

                return(data);
            }
Example #6
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);
        }