public List <SearchResultDrugEvent> GetDeviceEventByDescription(string keyword) { var deviceEventList = new List <AdverseDeviceEvent>(); const OpenFdaApiEndPoints endPointType = OpenFdaApiEndPoints.DeviceEvent; var dataSetSize = 0; var yearCheck = -1; //Limit first query to a 1 year window var beginDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(1)); var endDate = string.Format("{0:yyyyMMdd}", DateTime.Now.AddYears(yearCheck)); ResetSearch(); AddSearchFilter(endPointType, FdaFilterTypes.DeviceEventDescription, new List <string>(new[] { keyword }), FilterCompairType.And); AddSearchFilter(endPointType, FdaFilterTypes.Date, new List <string>(new[] { beginDate, endDate }), FilterCompairType.And); var limit = AddResultLimit(100); var apiUrl = BuildUrl(endPointType); var 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.DeviceEventDescription, new List <string>(new[] { keyword }), 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.DeviceEventDescription, new List <string>(new[] { keyword }), 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 = AdverseDeviceEvent.CnvJsonDataToList(searchResults); deviceEventList.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)); } var tmpSearchResultDeviceEvent = AdverseDeviceEvent.CnvDeviceEventsToResultDrugEvents(deviceEventList); return(tmpSearchResultDeviceEvent); }
/// <summary> /// Convert JSON Data /// </summary> /// <param name="jsondata">JSON Object</param> /// <returns>List of Adverse Device Events</returns> /// <remarks></remarks> public static List<AdverseDeviceEvent> CnvJsonDataToList(JObject jsondata) { var result = new List<AdverseDeviceEvent>(); //jsondata.dump("In") foreach (var obj in jsondata.GetValue("results")) { //obj.Dump("Obj") var tmp = new AdverseDeviceEvent(); tmp.AdverseEventFlag = Utilities.GetJTokenString(obj, "adverse_event_flag"); tmp.ProductProblemFlag = Utilities.GetJTokenString(obj, "product_problem_flag"); tmp.DateOfEvent = Utilities.GetJTokenString(obj, "date_of_event"); tmp.DateReport = Utilities.GetJTokenString(obj, "date_report"); tmp.DateReceived = Utilities.GetJTokenString(obj, "date_received"); tmp.NumberDevicesInEvent = Utilities.GetJTokenString(obj, "number_devices_in_event"); tmp.NumberPatientsInEvent = Utilities.GetJTokenString(obj, "number_patients_in_event"); //Source tmp.ReportSourceCode = Utilities.GetJTokenString(obj, "report_source_code"); tmp.HealthProfessional = Utilities.GetJTokenString(obj, "health_professional"); tmp.ReporterOccupationCode = Utilities.GetJTokenString(obj, "reporter_occupation_code"); tmp.InitialReportToFda = Utilities.GetJTokenString(obj, "initial_report_to_fda"); tmp.ReprocessedAndReusedFlag = Utilities.GetJTokenString(obj, "reprocessed_and_reused_flag"); var reportTypes = obj.Value<JArray>("type_of_report"); if (reportTypes != null) { foreach (var itm in reportTypes) { tmp.TypeOfReport.Add((itm).ToString()); } } // Not an array //var remedialAction = obj.Value<JArray>("remedial_action"); //if (remedialAction != null) //{ // foreach (var itm in remedialAction) // { // tmp.RemedialAction.Add((itm).ToString()); // } //} var sourceType = obj.Value<JArray>("source_type"); if (sourceType != null) { foreach (var itm in sourceType) { tmp.SourceType.Add((itm).ToString()); } } tmp.DateFacilityAware = Utilities.GetJTokenString(obj, "date_facility_aware"); tmp.ReportDate = Utilities.GetJTokenString(obj, "report_date"); tmp.ReportToFda = Utilities.GetJTokenString(obj, "report_to_fda"); tmp.DateReportToFda = Utilities.GetJTokenString(obj, "date_report_to_fda"); tmp.ReportToManufacturer = Utilities.GetJTokenString(obj, "report_to_manufacturer"); tmp.DateReportToManufacturer = Utilities.GetJTokenString(obj, "date_report_to_manufacturer"); tmp.EventLocation = Utilities.GetJTokenString(obj, "event_location"); tmp.DistributorName = Utilities.GetJTokenString(obj, "distributor_name"); tmp.DistributorAddress1 = Utilities.GetJTokenString(obj, "distributor_address_1"); tmp.DistributorAddress2 = Utilities.GetJTokenString(obj, "distributor_address_2"); tmp.DistributorCity = Utilities.GetJTokenString(obj, "distributor_city"); tmp.DistributorState = Utilities.GetJTokenString(obj, "distributor_state"); tmp.DistributorZipCode = Utilities.GetJTokenString(obj, "distributor_zip_code"); tmp.DistributorZipCodeExt = Utilities.GetJTokenString(obj, "distributor_zip_code_ext"); tmp.ManufacturerName = Utilities.GetJTokenString(obj, "manufacturer_name"); tmp.ManufacturerAddress1 = Utilities.GetJTokenString(obj, "manufacturer_address_1"); tmp.ManufacturerAddress2 = Utilities.GetJTokenString(obj, "manufacturer_address_2"); tmp.ManufacturerCity = Utilities.GetJTokenString(obj, "manufacturer_city"); tmp.ManufacturerState = Utilities.GetJTokenString(obj, "manufacturer_state"); tmp.ManufacturerZipCode = Utilities.GetJTokenString(obj, "manufacturer_zip_code"); tmp.ManufacturerZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_zip_code_ext"); tmp.ManufacturerCountry = Utilities.GetJTokenString(obj, "manufacturer_country"); tmp.ManufacturerPostalCode = Utilities.GetJTokenString(obj, "manufacturer_postal_code"); tmp.EventType = Utilities.GetJTokenString(obj, "event_type"); tmp.DeviceDateOfManufacture = Utilities.GetJTokenString(obj, "device_date_of_manufacture"); tmp.SingleUseFlag = Utilities.GetJTokenString(obj, "single_use_flag"); tmp.PreviousUseCode = Utilities.GetJTokenString(obj, "previous_use_code"); tmp.RemovalCorrectionNumber = Utilities.GetJTokenString(obj, "removal_correction_number"); tmp.ManufactureContactNameTitle = Utilities.GetJTokenString(obj, "manufacturer_contact_t_name"); tmp.ManufactureContactNameFirst = Utilities.GetJTokenString(obj, "manufacturer_contact_f_name"); tmp.ManufactureContactNameLast = Utilities.GetJTokenString(obj, "manufacturer_contact_l_name"); tmp.ManufactureContactStreet1 = Utilities.GetJTokenString(obj, "manufacturer_contact_street_1"); tmp.ManufactureContactStreet2 = Utilities.GetJTokenString(obj, "manufacturer_contact_street_2"); tmp.ManufactureContactCity = Utilities.GetJTokenString(obj, "manufacturer_contact_city"); tmp.ManufactureContactState = Utilities.GetJTokenString(obj, "manufacturer_contact_state"); tmp.ManufactureContactZipCode = Utilities.GetJTokenString(obj, "manufacturer_contact_zip_code"); tmp.ManufactureContactZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_contact_zip_ext"); tmp.ManufactureContactPostal = Utilities.GetJTokenString(obj, "manufacturer_contact_postal"); tmp.ManufactureContactCountry = Utilities.GetJTokenString(obj, "manufacturer_contact_country"); tmp.ManufactureContactPhoneCountry = Utilities.GetJTokenString(obj, "manufacturer_contact_pcountry"); tmp.ManufactureContactPhoneAreaCode = Utilities.GetJTokenString(obj, "manufacturer_contact_area_code"); tmp.ManufactureContactPhoneExchange = Utilities.GetJTokenString(obj, "manufacturer_contact_exchange"); tmp.ManufactureContactPhoneExtension = Utilities.GetJTokenString(obj, "manufacturer_contact_extension"); tmp.ManufactureContactPhoneCity = Utilities.GetJTokenString(obj, "manufacturer_contact_pcity"); tmp.ManufactureContactPhoneNumber = Utilities.GetJTokenString(obj, "manufacturer_contact_phone_number"); tmp.ManufactureContactLocal = Utilities.GetJTokenString(obj, "manufacturer_contact_plocal"); tmp.ManufactureName = Utilities.GetJTokenString(obj, "manufacturer_g1_name"); tmp.ManufactureStreet1 = Utilities.GetJTokenString(obj, "manufacturer_g1_street_1"); tmp.ManufactureStreet2 = Utilities.GetJTokenString(obj, "manufacturer_g1_street_2"); tmp.ManufactureCity = Utilities.GetJTokenString(obj, "manufacturer_g1_city"); tmp.ManufactureState = Utilities.GetJTokenString(obj, "manufacturer_g1_state"); tmp.ManufactureZipCode = Utilities.GetJTokenString(obj, "manufacturer_g1_zip_code"); tmp.ManufactureZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_g1_zip_ext"); tmp.ManufacturePostalCode = Utilities.GetJTokenString(obj, "manufacturer_g1_postal_code"); tmp.ManufactureCountry = Utilities.GetJTokenString(obj, "manufacturer_g1_country"); tmp.DateManufacturerReceived = Utilities.GetJTokenString(obj, "date_manufacturer_received"); tmp.EventKey = Utilities.GetJTokenString(obj, "event_key"); tmp.MdrReportKey = Utilities.GetJTokenString(obj, "mdr_report_key"); tmp.ManufacturerLinkFlag = Utilities.GetJTokenString(obj, "manufacturer_link_flag_"); tmp.Device = DeviceEventDeviceData.CnvJsonDataToList((JArray) Utilities.GetJTokenObject(obj, "device")); tmp.Patient = DeviceEventPatientData.CnvJsonDataToList((JArray) Utilities.GetJTokenObject(obj, "patient")); tmp.MdrText = DeviceEventMdrTextData.CnvJsonDataToList((JArray) Utilities.GetJTokenObject(obj, "mdr_text")); result.Add(tmp); } return result; }
/// <summary> /// Convert JSON Data /// </summary> /// <param name="jsondata">JSON Object</param> /// <returns>List of Adverse Device Events</returns> /// <remarks></remarks> public static List <AdverseDeviceEvent> CnvJsonDataToList(JObject jsondata) { var result = new List <AdverseDeviceEvent>(); //jsondata.dump("In") foreach (var obj in jsondata.GetValue("results")) { //obj.Dump("Obj") var tmp = new AdverseDeviceEvent(); tmp.AdverseEventFlag = Utilities.GetJTokenString(obj, "adverse_event_flag"); tmp.ProductProblemFlag = Utilities.GetJTokenString(obj, "product_problem_flag"); tmp.DateOfEvent = Utilities.GetJTokenString(obj, "date_of_event"); tmp.DateReport = Utilities.GetJTokenString(obj, "date_report"); tmp.DateReceived = Utilities.GetJTokenString(obj, "date_received"); tmp.NumberDevicesInEvent = Utilities.GetJTokenString(obj, "number_devices_in_event"); tmp.NumberPatientsInEvent = Utilities.GetJTokenString(obj, "number_patients_in_event"); //Source tmp.ReportSourceCode = Utilities.GetJTokenString(obj, "report_source_code"); tmp.HealthProfessional = Utilities.GetJTokenString(obj, "health_professional"); tmp.ReporterOccupationCode = Utilities.GetJTokenString(obj, "reporter_occupation_code"); tmp.InitialReportToFda = Utilities.GetJTokenString(obj, "initial_report_to_fda"); tmp.ReprocessedAndReusedFlag = Utilities.GetJTokenString(obj, "reprocessed_and_reused_flag"); var reportTypes = obj.Value <JArray>("type_of_report"); if (reportTypes != null) { foreach (var itm in reportTypes) { tmp.TypeOfReport.Add((itm).ToString()); } } // Not an array //var remedialAction = obj.Value<JArray>("remedial_action"); //if (remedialAction != null) //{ // foreach (var itm in remedialAction) // { // tmp.RemedialAction.Add((itm).ToString()); // } //} var sourceType = obj.Value <JArray>("source_type"); if (sourceType != null) { foreach (var itm in sourceType) { tmp.SourceType.Add((itm).ToString()); } } tmp.DateFacilityAware = Utilities.GetJTokenString(obj, "date_facility_aware"); tmp.ReportDate = Utilities.GetJTokenString(obj, "report_date"); tmp.ReportToFda = Utilities.GetJTokenString(obj, "report_to_fda"); tmp.DateReportToFda = Utilities.GetJTokenString(obj, "date_report_to_fda"); tmp.ReportToManufacturer = Utilities.GetJTokenString(obj, "report_to_manufacturer"); tmp.DateReportToManufacturer = Utilities.GetJTokenString(obj, "date_report_to_manufacturer"); tmp.EventLocation = Utilities.GetJTokenString(obj, "event_location"); tmp.DistributorName = Utilities.GetJTokenString(obj, "distributor_name"); tmp.DistributorAddress1 = Utilities.GetJTokenString(obj, "distributor_address_1"); tmp.DistributorAddress2 = Utilities.GetJTokenString(obj, "distributor_address_2"); tmp.DistributorCity = Utilities.GetJTokenString(obj, "distributor_city"); tmp.DistributorState = Utilities.GetJTokenString(obj, "distributor_state"); tmp.DistributorZipCode = Utilities.GetJTokenString(obj, "distributor_zip_code"); tmp.DistributorZipCodeExt = Utilities.GetJTokenString(obj, "distributor_zip_code_ext"); tmp.ManufacturerName = Utilities.GetJTokenString(obj, "manufacturer_name"); tmp.ManufacturerAddress1 = Utilities.GetJTokenString(obj, "manufacturer_address_1"); tmp.ManufacturerAddress2 = Utilities.GetJTokenString(obj, "manufacturer_address_2"); tmp.ManufacturerCity = Utilities.GetJTokenString(obj, "manufacturer_city"); tmp.ManufacturerState = Utilities.GetJTokenString(obj, "manufacturer_state"); tmp.ManufacturerZipCode = Utilities.GetJTokenString(obj, "manufacturer_zip_code"); tmp.ManufacturerZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_zip_code_ext"); tmp.ManufacturerCountry = Utilities.GetJTokenString(obj, "manufacturer_country"); tmp.ManufacturerPostalCode = Utilities.GetJTokenString(obj, "manufacturer_postal_code"); tmp.EventType = Utilities.GetJTokenString(obj, "event_type"); tmp.DeviceDateOfManufacture = Utilities.GetJTokenString(obj, "device_date_of_manufacture"); tmp.SingleUseFlag = Utilities.GetJTokenString(obj, "single_use_flag"); tmp.PreviousUseCode = Utilities.GetJTokenString(obj, "previous_use_code"); tmp.RemovalCorrectionNumber = Utilities.GetJTokenString(obj, "removal_correction_number"); tmp.ManufactureContactNameTitle = Utilities.GetJTokenString(obj, "manufacturer_contact_t_name"); tmp.ManufactureContactNameFirst = Utilities.GetJTokenString(obj, "manufacturer_contact_f_name"); tmp.ManufactureContactNameLast = Utilities.GetJTokenString(obj, "manufacturer_contact_l_name"); tmp.ManufactureContactStreet1 = Utilities.GetJTokenString(obj, "manufacturer_contact_street_1"); tmp.ManufactureContactStreet2 = Utilities.GetJTokenString(obj, "manufacturer_contact_street_2"); tmp.ManufactureContactCity = Utilities.GetJTokenString(obj, "manufacturer_contact_city"); tmp.ManufactureContactState = Utilities.GetJTokenString(obj, "manufacturer_contact_state"); tmp.ManufactureContactZipCode = Utilities.GetJTokenString(obj, "manufacturer_contact_zip_code"); tmp.ManufactureContactZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_contact_zip_ext"); tmp.ManufactureContactPostal = Utilities.GetJTokenString(obj, "manufacturer_contact_postal"); tmp.ManufactureContactCountry = Utilities.GetJTokenString(obj, "manufacturer_contact_country"); tmp.ManufactureContactPhoneCountry = Utilities.GetJTokenString(obj, "manufacturer_contact_pcountry"); tmp.ManufactureContactPhoneAreaCode = Utilities.GetJTokenString(obj, "manufacturer_contact_area_code"); tmp.ManufactureContactPhoneExchange = Utilities.GetJTokenString(obj, "manufacturer_contact_exchange"); tmp.ManufactureContactPhoneExtension = Utilities.GetJTokenString(obj, "manufacturer_contact_extension"); tmp.ManufactureContactPhoneCity = Utilities.GetJTokenString(obj, "manufacturer_contact_pcity"); tmp.ManufactureContactPhoneNumber = Utilities.GetJTokenString(obj, "manufacturer_contact_phone_number"); tmp.ManufactureContactLocal = Utilities.GetJTokenString(obj, "manufacturer_contact_plocal"); tmp.ManufactureName = Utilities.GetJTokenString(obj, "manufacturer_g1_name"); tmp.ManufactureStreet1 = Utilities.GetJTokenString(obj, "manufacturer_g1_street_1"); tmp.ManufactureStreet2 = Utilities.GetJTokenString(obj, "manufacturer_g1_street_2"); tmp.ManufactureCity = Utilities.GetJTokenString(obj, "manufacturer_g1_city"); tmp.ManufactureState = Utilities.GetJTokenString(obj, "manufacturer_g1_state"); tmp.ManufactureZipCode = Utilities.GetJTokenString(obj, "manufacturer_g1_zip_code"); tmp.ManufactureZipCodeExt = Utilities.GetJTokenString(obj, "manufacturer_g1_zip_ext"); tmp.ManufacturePostalCode = Utilities.GetJTokenString(obj, "manufacturer_g1_postal_code"); tmp.ManufactureCountry = Utilities.GetJTokenString(obj, "manufacturer_g1_country"); tmp.DateManufacturerReceived = Utilities.GetJTokenString(obj, "date_manufacturer_received"); tmp.EventKey = Utilities.GetJTokenString(obj, "event_key"); tmp.MdrReportKey = Utilities.GetJTokenString(obj, "mdr_report_key"); tmp.ManufacturerLinkFlag = Utilities.GetJTokenString(obj, "manufacturer_link_flag_"); tmp.Device = DeviceEventDeviceData.CnvJsonDataToList((JArray)Utilities.GetJTokenObject(obj, "device")); tmp.Patient = DeviceEventPatientData.CnvJsonDataToList((JArray)Utilities.GetJTokenObject(obj, "patient")); tmp.MdrText = DeviceEventMdrTextData.CnvJsonDataToList((JArray)Utilities.GetJTokenObject(obj, "mdr_text")); result.Add(tmp); } return(result); }