open_fda_api 0.0.3 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +26 -1
- data/Gemfile.lock +36 -1
- data/README.md +48 -21
- data/bin/console +3 -0
- data/lib/open_fda_api/client.rb +20 -4
- data/lib/open_fda_api/drugs.rb +82 -18
- data/lib/open_fda_api/query_builder.rb +68 -19
- data/lib/open_fda_api/query_inputs.rb +16 -0
- data/lib/open_fda_api/version.rb +1 -1
- data/lib/open_fda_api.rb +4 -4
- data/open_fda_api.gemspec +4 -1
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc99f4c0266329d56ee1cbc6592789908b09a98580136813e3d8033e33c2328
|
4
|
+
data.tar.gz: 6fc8dc376b266e216e5f263248cbae5342c655a50ba3aa1c9d37245a6b521bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95da4769cc677e55b92f682bc4b7f05d98543cfcfa05f2d4786c8254e52a6399235e3850a11c7d70ba63dd61ea28e42fda25fc336e8ac1fb3710e9e9a4dc29ca
|
7
|
+
data.tar.gz: f93d3fa2ffc26fad6f9460333326d32f97f51f99dcd567b85ddd62b5ed4e5f868d4aff4bcc8183b37214927e7a03ff4e64fee534c8a98a1c2f5ffc3fe7ee619c
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,31 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.0.
|
3
|
+
## [0.0.9] - 2022-01-24
|
4
|
+
- Filled out the following Drug endpoints:
|
5
|
+
- product_labeling
|
6
|
+
- ndc_directory
|
7
|
+
- recall_enforcement_reports
|
8
|
+
- drugs_at_fda
|
9
|
+
|
10
|
+
## [0.0.8] - 2022-01-24
|
11
|
+
- Delete the `OpenFdaApi.client` method since its only function was to forward messages
|
12
|
+
|
13
|
+
## [0.0.7] - 2022-01-23
|
14
|
+
- Use Faraday instead of using Net::HTTP directly
|
15
|
+
- Introduce `QueryInputs` to group query params passed in together
|
16
|
+
|
17
|
+
## [0.0.6] - 2022-01-21
|
18
|
+
- Support for more query fields
|
19
|
+
|
20
|
+
## [0.0.5] - 2022-01-20
|
21
|
+
- Validate, against search fields given to us from openFDA API, when building queries.
|
22
|
+
|
23
|
+
## [0.0.4] - 2022-01-19
|
24
|
+
- Fix version string in changelog.
|
25
|
+
- Update Query Builder to group search arguments properly.
|
26
|
+
- Update Query Builder to replace spaces with pluses in search values as openFDA API documentation requires.
|
27
|
+
|
28
|
+
## [0.0.3] - 2022-01-19
|
4
29
|
- Update version again because CHANGELOG wasn't updated along with the 0.0.2 release.
|
5
30
|
|
6
31
|
## [0.0.2] - 2022-01-19
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,49 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
open_fda_api (0.0.
|
4
|
+
open_fda_api (0.0.9)
|
5
|
+
faraday (~> 1.9)
|
6
|
+
faraday_middleware (~> 1.2)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
8
10
|
specs:
|
9
11
|
ast (2.4.2)
|
12
|
+
coderay (1.1.3)
|
10
13
|
diff-lcs (1.5.0)
|
14
|
+
faraday (1.9.3)
|
15
|
+
faraday-em_http (~> 1.0)
|
16
|
+
faraday-em_synchrony (~> 1.0)
|
17
|
+
faraday-excon (~> 1.1)
|
18
|
+
faraday-httpclient (~> 1.0)
|
19
|
+
faraday-multipart (~> 1.0)
|
20
|
+
faraday-net_http (~> 1.0)
|
21
|
+
faraday-net_http_persistent (~> 1.0)
|
22
|
+
faraday-patron (~> 1.0)
|
23
|
+
faraday-rack (~> 1.0)
|
24
|
+
faraday-retry (~> 1.0)
|
25
|
+
ruby2_keywords (>= 0.0.4)
|
26
|
+
faraday-em_http (1.0.0)
|
27
|
+
faraday-em_synchrony (1.0.0)
|
28
|
+
faraday-excon (1.1.0)
|
29
|
+
faraday-httpclient (1.0.1)
|
30
|
+
faraday-multipart (1.0.3)
|
31
|
+
multipart-post (>= 1.2, < 3)
|
32
|
+
faraday-net_http (1.0.1)
|
33
|
+
faraday-net_http_persistent (1.2.0)
|
34
|
+
faraday-patron (1.0.0)
|
35
|
+
faraday-rack (1.0.0)
|
36
|
+
faraday-retry (1.0.3)
|
37
|
+
faraday_middleware (1.2.0)
|
38
|
+
faraday (~> 1.0)
|
39
|
+
method_source (1.0.0)
|
40
|
+
multipart-post (2.1.1)
|
11
41
|
parallel (1.21.0)
|
12
42
|
parser (3.1.0.0)
|
13
43
|
ast (~> 2.4.1)
|
44
|
+
pry (0.14.1)
|
45
|
+
coderay (~> 1.1)
|
46
|
+
method_source (~> 1.0)
|
14
47
|
rainbow (3.1.1)
|
15
48
|
rake (13.0.6)
|
16
49
|
regexp_parser (2.2.0)
|
@@ -40,6 +73,7 @@ GEM
|
|
40
73
|
rubocop-ast (1.15.1)
|
41
74
|
parser (>= 3.0.1.1)
|
42
75
|
ruby-progressbar (1.11.0)
|
76
|
+
ruby2_keywords (0.0.5)
|
43
77
|
unicode-display_width (2.1.0)
|
44
78
|
|
45
79
|
PLATFORMS
|
@@ -47,6 +81,7 @@ PLATFORMS
|
|
47
81
|
|
48
82
|
DEPENDENCIES
|
49
83
|
open_fda_api!
|
84
|
+
pry
|
50
85
|
rake (~> 13.0)
|
51
86
|
rspec (~> 3.0)
|
52
87
|
rubocop (~> 1.7)
|
data/README.md
CHANGED
@@ -16,37 +16,64 @@ And then execute:
|
|
16
16
|
bundle install
|
17
17
|
```
|
18
18
|
|
19
|
-
##
|
19
|
+
## Usage
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
Each category has further subcategories. Everything is accessible from the `OpenFdaApi.client`.
|
21
|
+
```ruby
|
22
|
+
client = OpenFdaApi.client
|
24
23
|
|
24
|
+
# First 20 results where (fieldA=foo AND fieldB=bar) OR (fieldC=baz AND fieldA exists)
|
25
|
+
# Sorted by (fieldD) in descending order
|
26
|
+
# Skip the first 8 results
|
27
|
+
args = {
|
28
|
+
search: [{"fieldA" => "foo", "fieldB" => "bar"}, {"fieldC" => "baz", "_exists_" => "fieldA"}],
|
29
|
+
sort: [{"fieldD" => "desc"}],
|
30
|
+
skip: 8,
|
31
|
+
limit: 20
|
32
|
+
}
|
33
|
+
|
34
|
+
# Drug API
|
35
|
+
client.drugs.adverse_events(args)
|
36
|
+
client.drugs.product_labeling(args)
|
37
|
+
client.drugs.ndc_directory(args)
|
38
|
+
client.drugs.recall_enforcement_reports(args)
|
39
|
+
client.drugs.drugs_at_fda(args)
|
40
|
+
|
41
|
+
# Device API
|
42
|
+
client.device.premarket_501ks(args)
|
43
|
+
client.device.classification(args)
|
44
|
+
client.device.recall_enforcement_reports(args)
|
45
|
+
client.device.adverse_events(args)
|
46
|
+
client.device.premarket_approval(args)
|
47
|
+
client.device.recalls(args)
|
48
|
+
client.device.registrations_and_listings(args)
|
49
|
+
client.device.covid19_serological_tests(args)
|
50
|
+
client.device.unique_device_identifier(args)
|
51
|
+
|
52
|
+
# Food API
|
53
|
+
client.food.recall_enforcement_reports(args)
|
54
|
+
client.food.adverse_events(args)
|
55
|
+
|
56
|
+
# Other API
|
57
|
+
client.other.nsde(args)
|
58
|
+
client.other.substance_data_reports(args)
|
59
|
+
|
60
|
+
# Tobacco API
|
61
|
+
client.tobacco.problem_reports(args)
|
62
|
+
```
|
25
63
|
|
26
|
-
###
|
64
|
+
### Querying
|
27
65
|
|
28
|
-
The
|
66
|
+
The openFDA API can be queried with these arguments: `search`, `sort`, `count`, `skip`, and `limit`.
|
29
67
|
|
30
|
-
|
68
|
+
`search`, `sort`, and `count` have the same format. They are arrays of hashes. Each hash has a set of fields and values
|
69
|
+
that are ANDed together and all the elements in the array are ORed together. Here are some examples to illustrate:
|
31
70
|
|
32
|
-
#### Adverse Events
|
33
71
|
```ruby
|
34
|
-
|
72
|
+
search = [{"patient.drug.openfda.pharm_class_epc" => "nonsteroidal+anti-inflammatory+drug" }]
|
35
73
|
|
36
|
-
|
37
|
-
drugs_api = client.drugs
|
38
|
-
|
39
|
-
arguments = [{"patient.reaction.reactionmeddrapt"=>"fatigue"}, {"occurcountry"=>"ca"}]
|
40
|
-
drugs_api.adverse_events(search_arguments: arguments) # => {"meta" => {...}, "results" => [...]}
|
74
|
+
# patient.drug.openfda.pharm_class_epc:"nonsteroidal+anti-inflammatory+drug"&count=patient.reaction.reactionmeddrapt.exact
|
41
75
|
```
|
42
76
|
|
43
|
-
### Device (Not Implemented Yet)
|
44
|
-
### Food (Not Implemented Yet)
|
45
|
-
### Other (Not Implemented Yet)
|
46
|
-
### Tobacco (Not Implemented Yet)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
77
|
## Development
|
51
78
|
|
52
79
|
After checking out the repo, run `bin/setup` to install dependencies.
|
data/bin/console
CHANGED
data/lib/open_fda_api/client.rb
CHANGED
@@ -1,18 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "faraday"
|
4
|
+
require "faraday_middleware"
|
4
5
|
|
5
6
|
module OpenFdaApi
|
6
7
|
# Gives you access to the main nouns in the openFDA API
|
7
8
|
class Client
|
8
|
-
attr_reader :api_key
|
9
|
+
attr_reader :api_key, :adapter
|
9
10
|
|
10
|
-
|
11
|
+
BASE_URL = "https://api.fda.gov"
|
12
|
+
|
13
|
+
def initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil)
|
11
14
|
@api_key = api_key
|
15
|
+
@adapter = adapter
|
16
|
+
@stubs = stubs
|
12
17
|
end
|
13
18
|
|
14
19
|
def drugs
|
15
|
-
OpenFdaApi::Drugs.new
|
20
|
+
OpenFdaApi::Drugs.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def connection
|
24
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
25
|
+
conn.request :json
|
26
|
+
|
27
|
+
conn.response :dates
|
28
|
+
conn.response :json, content_type: "application/json"
|
29
|
+
|
30
|
+
conn.adapter adapter, @stubs
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
18
34
|
end
|
data/lib/open_fda_api/drugs.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "net/http"
|
4
4
|
require "json"
|
5
|
-
require "
|
5
|
+
require "yaml"
|
6
6
|
|
7
7
|
module OpenFdaApi
|
8
8
|
# Interact with the Drugs API Endpoint:
|
@@ -12,36 +12,100 @@ module OpenFdaApi
|
|
12
12
|
# - Recall Enforcement Reports
|
13
13
|
# - Drugs@FDA)
|
14
14
|
class Drugs
|
15
|
-
|
15
|
+
attr_reader :client, :path_base
|
16
|
+
|
17
|
+
def initialize(client)
|
18
|
+
@client = client
|
16
19
|
@host = "api.fda.gov"
|
17
20
|
@path_base = "/drug"
|
18
21
|
end
|
19
22
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# @param
|
23
|
+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
24
|
+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
25
|
+
# @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
|
26
|
+
# @param skip [Integer] Number of results to skip
|
27
|
+
# @param limit [Integer] Number of results to return
|
28
|
+
# @return Response from the API parsed as JSON
|
29
|
+
def adverse_events(search: [], sort: [], count: [], skip: 0, limit: 1)
|
30
|
+
endpoint = "event.json"
|
31
|
+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
32
|
+
query = build_query(inputs, self.class.valid_adverse_events_fields)
|
33
|
+
make_request(endpoint, query)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
37
|
+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
38
|
+
# @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
|
39
|
+
# @param skip [Integer] Number of results to skip
|
40
|
+
# @param limit [Integer] Number of results to return
|
25
41
|
# @return Response from the API parsed as JSON
|
26
|
-
def
|
27
|
-
endpoint = "
|
28
|
-
|
29
|
-
|
30
|
-
make_request(
|
42
|
+
def product_labeling(search: [], sort: [], count: [], skip: 0, limit: 1)
|
43
|
+
endpoint = "label.json"
|
44
|
+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
45
|
+
query = build_query(inputs, {}) # TODO: Upload valid fields
|
46
|
+
make_request(endpoint, query)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
50
|
+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
51
|
+
# @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
|
52
|
+
# @param skip [Integer] Number of results to skip
|
53
|
+
# @param limit [Integer] Number of results to return
|
54
|
+
# @return Response from the API parsed as JSON
|
55
|
+
def ndc_directory(search: [], sort: [], count: [], skip: 0, limit: 1)
|
56
|
+
endpoint = "ndc.json"
|
57
|
+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
58
|
+
query = build_query(inputs, {}) # TODO: Upload valid fields
|
59
|
+
make_request(endpoint, query)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
63
|
+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
64
|
+
# @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
|
65
|
+
# @param skip [Integer] Number of results to skip
|
66
|
+
# @param limit [Integer] Number of results to return
|
67
|
+
# @return Response from the API parsed as JSON
|
68
|
+
def recall_enforcement_reports(search: [], sort: [], count: [], skip: 0, limit: 1)
|
69
|
+
endpoint = "enforcement.json"
|
70
|
+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
71
|
+
query = build_query(inputs, {}) # TODO: Upload valid fields
|
72
|
+
make_request(endpoint, query)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
76
|
+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
|
77
|
+
# @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
|
78
|
+
# @param skip [Integer] Number of results to skip
|
79
|
+
# @param limit [Integer] Number of results to return
|
80
|
+
# @return Response from the API parsed as JSON
|
81
|
+
def drugs_at_fda(search: [], sort: [], count: [], skip: 0, limit: 1)
|
82
|
+
endpoint = "drugsfda.json"
|
83
|
+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
84
|
+
query = build_query(inputs, {}) # TODO: Upload valid fields
|
85
|
+
make_request(endpoint, query)
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.valid_adverse_events_fields
|
89
|
+
@valid_adverse_events_fields ||= ::YAML.load_file("#{__dir__}/adverse_events_fields.yml")
|
31
90
|
end
|
32
91
|
|
33
92
|
private
|
34
93
|
|
35
|
-
def
|
36
|
-
|
94
|
+
def build_query(query_input, valid_search_fields)
|
95
|
+
QueryBuilder.new(query_input: query_input, valid_search_fields: valid_search_fields).build_query
|
37
96
|
end
|
38
97
|
|
39
|
-
def
|
40
|
-
|
98
|
+
def build_inputs(search:, sort:, count:, skip:, limit:)
|
99
|
+
QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
41
100
|
end
|
42
101
|
|
43
|
-
def make_request(
|
44
|
-
|
102
|
+
def make_request(endpoint, query)
|
103
|
+
url = "#{path_base}/#{endpoint}"
|
104
|
+
if query.empty?
|
105
|
+
client.connection.get(url)
|
106
|
+
else
|
107
|
+
client.connection.get(url, query)
|
108
|
+
end.body
|
45
109
|
end
|
46
110
|
end
|
47
111
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OpenFdaApi
|
4
|
+
class InvalidQueryArgument < ArgumentError; end
|
5
|
+
|
4
6
|
# A helper to build queries against the openFDA API
|
5
7
|
#
|
6
8
|
# The API supports five query parameters. The basic building block of queries is the search parameter.
|
@@ -23,34 +25,81 @@ module OpenFdaApi
|
|
23
25
|
# Use in combination with limit to paginate results. Currently, the largest allowed value for the skip parameter
|
24
26
|
# is 25000. See Paging if you require paging through larger result sets.
|
25
27
|
class QueryBuilder
|
26
|
-
# @param [
|
27
|
-
|
28
|
-
|
28
|
+
# @param [Hash] valid_search_fields
|
29
|
+
# @param [QueryInput] query_input
|
30
|
+
def initialize(query_input:, valid_search_fields:)
|
31
|
+
# TODO: Turn validations back on once we get basic functionality working; need to flex on different field types
|
32
|
+
# validate_arguments!(valid_search_fields, query_input: query_input)
|
33
|
+
warn "You've passed in a valid_search_fields arg but it isn't being used right now..." if valid_search_fields
|
34
|
+
@search = build_query_string(query_fields: query_input.search)
|
35
|
+
@sort = build_query_string(query_fields: query_input.sort)
|
36
|
+
@count = build_query_string(query_fields: query_input.count)
|
37
|
+
@skip = build_skip_string(query_input.skip)
|
38
|
+
@limit = query_input.limit
|
29
39
|
end
|
30
40
|
|
31
|
-
# @return [
|
41
|
+
# @return [Hash] the query string portion of a request
|
32
42
|
def build_query
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
{
|
44
|
+
search: @search,
|
45
|
+
sort: @sort,
|
46
|
+
count: @count,
|
47
|
+
skip: @skip,
|
48
|
+
limit: @limit
|
49
|
+
}.compact.reject { |_k, v| v.to_s.empty? }
|
38
50
|
end
|
39
51
|
|
40
52
|
private
|
41
53
|
|
42
|
-
def
|
43
|
-
|
54
|
+
def validate_arguments!(valid_search_fields, query_input:)
|
55
|
+
# `search` keys must exist in adverse_events_fields.yml
|
56
|
+
invalid_fields = get_invalid_fields(valid_search_fields: valid_search_fields, fields: query_input.search)
|
57
|
+
raise InvalidQueryArgument, "'search' has invalid fields: #{invalid_fields}" if invalid_fields.any?
|
58
|
+
|
59
|
+
# `sort` keys must exist in adverse_events_fields.yml
|
60
|
+
invalid_fields = get_invalid_fields(valid_search_fields: valid_search_fields, fields: query_input.sort)
|
61
|
+
raise InvalidQueryArgument, "'sort' has invalid fields: #{invalid_fields}" if invalid_fields.any?
|
62
|
+
|
63
|
+
# `count` keys must exist in adverse_events_fields.yml
|
64
|
+
invalid_fields = get_invalid_fields(valid_search_fields: valid_search_fields, fields: query_input.count)
|
65
|
+
raise InvalidQueryArgument, "'count' has invalid fields: #{invalid_fields}" if invalid_fields.any?
|
66
|
+
|
67
|
+
# `count` and `skip` cannot be set at the same time
|
68
|
+
return unless count_and_skip_set?(query_input.count, query_input.skip)
|
69
|
+
|
70
|
+
raise InvalidQueryArgument, "'count' and 'skip' cannot both be set at the same time!"
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_query_string(query_fields:)
|
74
|
+
return "" if query_fields.empty?
|
44
75
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
76
|
+
build_groupings(query_fields).to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_skip_string(skip)
|
80
|
+
skip.positive? ? skip.to_s : ""
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_groupings(fields)
|
84
|
+
fields.map do |and_args|
|
85
|
+
"(#{and_args.map { |k, v| "#{k}:#{v.gsub(" ", "+")}" }.join("+AND+")})"
|
86
|
+
end.join("+")
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_invalid_fields(valid_search_fields:, fields:)
|
90
|
+
# TODO: valid_search_fields define types and we need to check against those
|
91
|
+
fields.map(&:keys).flatten.select do |field|
|
92
|
+
if field.include?(".") # nested field (e.g. patient.patientagegroup)
|
93
|
+
dig_values = field.split(".").join(",properties,").split(",")
|
94
|
+
valid_search_fields["properties"].dig(*dig_values).nil?
|
95
|
+
else
|
96
|
+
!valid_search_fields["properties"].keys.include?(field.to_s)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
52
100
|
|
53
|
-
|
101
|
+
def count_and_skip_set?(count, skip)
|
102
|
+
skip.positive? && !count.empty?
|
54
103
|
end
|
55
104
|
end
|
56
105
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenFdaApi
|
4
|
+
# Group of inputs to build the query against the API with
|
5
|
+
class QueryInputs
|
6
|
+
attr_reader :search, :sort, :count, :skip, :limit
|
7
|
+
|
8
|
+
def initialize(**params)
|
9
|
+
@search = params[:search] || []
|
10
|
+
@sort = params[:sort] || []
|
11
|
+
@count = params[:count] || []
|
12
|
+
@skip = params[:skip] || 0
|
13
|
+
@limit = params[:limit] || nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/open_fda_api/version.rb
CHANGED
data/lib/open_fda_api.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "open_fda_api/version"
|
4
|
-
require_relative "open_fda_api/client"
|
5
4
|
|
6
5
|
# A Ruby wrapper for the openFDA API: https://open.fda.gov/apis/
|
7
6
|
module OpenFdaApi
|
8
7
|
class Error < StandardError; end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
autoload :Client, "open_fda_api/client"
|
10
|
+
autoload :Drugs, "open_fda_api/drugs"
|
11
|
+
autoload :QueryInputs, "open_fda_api/query_inputs"
|
12
|
+
autoload :QueryBuilder, "open_fda_api/query_builder"
|
13
13
|
end
|
data/open_fda_api.gemspec
CHANGED
@@ -27,7 +27,10 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
# Uncomment to register a new dependency of your gem
|
30
|
-
|
30
|
+
spec.add_dependency "faraday", "~> 1.9"
|
31
|
+
spec.add_dependency "faraday_middleware", "~> 1.2"
|
32
|
+
|
33
|
+
spec.add_development_dependency "pry"
|
31
34
|
|
32
35
|
# For more information and examples about making a new gem, checkout our
|
33
36
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_fda_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hebron George
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
description:
|
14
56
|
email:
|
15
57
|
- hebrontgeorge@gmail.com
|
@@ -35,6 +77,7 @@ files:
|
|
35
77
|
- lib/open_fda_api/client.rb
|
36
78
|
- lib/open_fda_api/drugs.rb
|
37
79
|
- lib/open_fda_api/query_builder.rb
|
80
|
+
- lib/open_fda_api/query_inputs.rb
|
38
81
|
- lib/open_fda_api/version.rb
|
39
82
|
- open_fda_api.gemspec
|
40
83
|
homepage: https://github.com/hebron-george/open_fda_api
|