Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-count queries? #6

Open
cdeterman opened this issue Feb 25, 2016 · 5 comments
Open

Non-count queries? #6

cdeterman opened this issue Feb 25, 2016 · 5 comments

Comments

@cdeterman
Copy link

I am trying to duplicate one of the non-count examples from the openfda webpage.

https://api.fda.gov/drug/event.json?search=receivedate:[20040101+TO+20081231]&limit=1

However, when I try to do this same query with the R package all I get is NULL

fda_query("/drug/event.json") %>%
  fda_search("receivedate:[20040101+TO+20081231]") %>%
  fda_exec()
NULL

Did I miss something here?

@tajubenv
Copy link

This is a little late, but hopefully this can help anyone else who runs into this. The filtering should be done using the fda_filter function. The code below recreates that query:

fda_query("/drug/event.json") %>%
  fda_filter("receivedate","[20040101+TO+20081231]")  %>%
  fda_limit(1) %>%
  fda_search() %>%
  fda_exec()

The fda_search() function is used to select which specific field you want. So if you wanted the first 5 results from the patientonsetage field, you would use the following:

fda_query("/drug/event.json") %>%
  fda_filter("receivedate","[20040101+TO+20081231]")  %>%
  fda_limit(5) %>%
  fda_search("patient.patientonsetage") %>%
  fda_exec()

@shussai2
Copy link

Hello,

Quick question, when I run the following:

https://api.fda.gov/device/event.json?search=device.device_report_product_code:CAW&limit=1

in https://open.fda.gov/apis/device/event/example-api-queries/, it gives me the correct result:
.
.
.
"results": [
{
"manufacturer_contact_zip_ext": "",
"manufacturer_g1_address_2": "",
"event_location": "",
"report_to_fda": "N",
"manufacturer_contact_t_name": "",
"manufacturer_contact_state": "OH",
"manufacturer_link_flag": "Y",
"manufacturer_g1_city": "SANFORD",
"manufacturer_contact_address_2": "",
"manufacturer_contact_address_1": "ONE INVACARE WAY",
"event_type": "Death",
"manufacturer_contact_pcity": "44032963",
"report_number": "1525712-2008-00010",
"type_of_report": [
"Initial submission"
],
.
.
.
.

However, when I formulate the query using the openfda wrapper:

device_events = fda_query("/device/event.json") %>%
  fda_filter("device.device_report_product_code", "CAW") %>%
  fda_limit(1) %>%
  fda_exec()
print(device_events)

I get the following error:

[1] "No operation defined (try fda_count or fda_search)!"
[1] "fda_query(https://api.fda.gov/device/event.json?search=device.device_report_product_code:CAW&limit=1)"
Warning: Error in as.data.frame.default: cannot coerce class ‘"fda_query"’ to a data.frame
100: stop
99: as.data.frame.default
97: transform
96: func
94: f
93: Reduce
84: do
83: hybrid_chain
82: origRenderFunc
81: output$atable
1: runApp

Can you please let me know me what I am doing wrong in terms of formulation of query.

I am trying to search for device adverse events using a product code "CAW" (which is for Oxygen Concentrater).
Also all the examples are calling drug adverse events database. Can you please add examples of device event or reports as well.

@tajubenv
Copy link

You should just need to add either fda_count or fda_search to the pipe, like so:

device_events = fda_query("/device/event.json") %>%
  fda_filter("device.device_report_product_code", "CAW") %>%
  fda_limit(1) %>%
  fda_search() %>%
  fda_exec()
print(device_events)

@shussai2
Copy link

Hello,

Thank you so much, I have the following query running:

https://api.fda.gov/device/event.json?search=device.device_report_product_code.exact:CAW+AND+date_received:[20180101+TO+20190101]

device_events = fda_query("/device/event.json") %>%
  fda_filter("device.device_report_product_code.exact", "CAW") %>%
  fda_filter("date_received","[20180101+TO+20190101]") %>%
  fda_search() %>%
  fda_exec()
print(device_events)

@shussai2
Copy link

shussai2 commented Aug 6, 2019

Hello,

I am trying to get all the records/reports reported from a period of 20180101 to 20190101 fro product code CAW (Oxygen Concentrator).

Currently I have the following query setup:

deviceReports = fda_query("/device/event.json") %>%
  fda_filter("device.device_report_product_code.exact", "CAW") %>%
  fda_filter("date_received", "[20180101+TO+20190101]") %>%
  fda_limit(100) %>%
  fda_search() %>%
  fda_exec() 
print("DEVICE REPORTS: ")
print(deviceReports)

The following is reported as fetched:

Fetching: https://api.fda.gov/device/event.json?search=device.device_report_product_code.exact:CAW+AND+date_received:[20180101+TO+20190101]&limit=100

I do see a dataframe, however, my question is how do I simply get all the reports between a time period without hardcoding the fda_limit(100).

I have tried removing fda_limit() and simply using fda_search(). But that only returns 1 record/row. Is there a way to get all the reports within a time span.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants