{"id":19487163,"url":"https://github.com/tylerlittlefield/openfda-extract","last_synced_at":"2025-07-16T12:43:34.900Z","repository":{"id":48215870,"uuid":"293624267","full_name":"tylerlittlefield/openfda-extract","owner":"tylerlittlefield","description":"🩺 Convert openFDA device data from JSON files to tables and store in a database","archived":false,"fork":false,"pushed_at":"2021-01-14T05:17:39.000Z","size":24,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T01:32:10.349Z","etag":null,"topics":["openfda","rstats"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tylerlittlefield.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-07T20:19:01.000Z","updated_at":"2024-03-26T10:07:38.000Z","dependencies_parsed_at":"2022-09-02T18:01:50.388Z","dependency_job_id":null,"html_url":"https://github.com/tylerlittlefield/openfda-extract","commit_stats":null,"previous_names":["tylerlittlefield/openfda-extract"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerlittlefield%2Fopenfda-extract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerlittlefield%2Fopenfda-extract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerlittlefield%2Fopenfda-extract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerlittlefield%2Fopenfda-extract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tylerlittlefield","download_url":"https://codeload.github.com/tylerlittlefield/openfda-extract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250872304,"owners_count":21500797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openfda","rstats"],"created_at":"2024-11-10T20:44:20.302Z","updated_at":"2025-04-25T18:32:18.212Z","avatar_url":"https://github.com/tylerlittlefield.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\"\n)\n```\n\n# openfda-extract\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nThis repository collects [adverse events data](https://open.fda.gov/apis/device/event/download/) from openFDA. A single [script](/data-raw/loop.R) attempts to:\n\n1. Convert JSON files to tabular format using `jsonlite::fromJSON` and `tidyr::unnest`.\n2. Save the data to a database.\n\nThe data is relational as described [here](https://opendata.stackexchange.com/a/2187). Converting the data to tabular format may not be efficient and causes lots of duplication. To avoid duplication, I have tried to store nested data in different tables:\n\n1. `adverse_events`\n2. `adverse_events.mdr_text`\n3. `adverse_events.product_problems`\n4. `adverse_events.source_type`\n5. `adverse_events.device`\n6. `adverse_events.patient`\n7. `adverse_events.remedial_action`\n8. `adverse_events.type_of_report`\n\nWhere the naming convention is `mainframe.\u003clist col\u003e`.\n\n## Hardware\n\n1. I transformed the data on:\n    * 2013 15\" MacBook Pro, 8 GB Memory, 8 Core CPU.\n2. I wrote the data to:\n    * Postgres database hosted on a digital ocean droplet.\n    * 2 GB Memory, 2 vCPUs, 60 GB Disk, Ubuntu 18.04.3 (LTS) x64.\n    \nFor context, this was the result of my first run:\n\n```\n~ openFDA database refresh completed in [17.4161201466454 hours]\n```\n\n## Examples\n\nIf you have successfully ran everything, you should have 8 tables with millions of observations that you can explore.\n\n```{r}\nlibrary(dplyr, warn.conflicts = FALSE)\nlibrary(DBI)\n\n# credentials\ndw \u003c- config::get(\"datawarehouse\")\n\n# connect to db\ncon \u003c- DBI::dbConnect(\n  odbc::odbc(),\n  Driver = dw$driver,\n  Server = dw$server,\n  Database = dw$database,\n  UID = dw$uid,\n  PWD = dw$pwd,\n  Port = dw$port\n)\n\n# list all available tables\ndbListTables(con)\n\n# query the mdr text\ntbl(con, \"adverse_events.mdr_text\") %\u003e% \n  select(text) %\u003e% \n  head(1)\n\n# query the device information\ntbl(con, \"adverse_events.device\") %\u003e% \n  filter(manufacturer_d_name == \"ETHICON, INC.\") %\u003e% \n  glimpse()\n\n# disconnect\ndbDisconnect(con)\n```\n\nNote that there is an `id` column in every table, for example:\n\n* `2014q4-0002-0003-3683`\n* `\u003cyear quarter\u003e-\u003cpart n\u003e-\u003cn parts\u003e-\u003crow number\u003e`\n\nI made this column so that tables can be joined (though this ID in some other form might already exist in the data, I just haven't figured out if that is the case or not).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerlittlefield%2Fopenfda-extract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerlittlefield%2Fopenfda-extract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerlittlefield%2Fopenfda-extract/lists"}