Skip to content

Commit 53b7b11

Browse files
Merge pull request #27 from hebron-george/transparency_api_endpoints
2 parents 869cf6f + 407db83 commit 53b7b11

9 files changed

Lines changed: 138 additions & 4 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
open_fda_api (0.1.0)
4+
open_fda_api (0.2.0)
55
faraday (~> 2.0)
66

77
GEM

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,40 @@ client.other.substance_data_reports(args)
6464

6565
# Tobacco API
6666
client.tobacco.problem_reports(args)
67+
68+
# Transparency API
69+
client.transparency.complete_response_letters(args)
70+
```
71+
72+
### Transparency — Complete Response Letters
73+
74+
Complete Response Letters (CRLs) are issued by the FDA when a New Drug Application (NDA)
75+
or Biologics License Application (BLA) cannot be approved in its current form.
76+
77+
```ruby
78+
client = OpenFdaApi::Client.new
79+
80+
# Fetch the most recent CRL
81+
client.transparency.complete_response_letters(limit: 1)
82+
83+
# Search by company name
84+
client.transparency.complete_response_letters(
85+
search: [{ "company_name" => "Pfizer" }],
86+
limit: 10
87+
)
88+
89+
# Search by approver center and sort by letter date descending
90+
client.transparency.complete_response_letters(
91+
search: [{ "approver_center" => "Center for Drug Evaluation and Research" }],
92+
sort: [{ "letter_date" => "desc" }],
93+
limit: 5
94+
)
95+
96+
# Search for CRLs from a specific company OR a specific approver
97+
client.transparency.complete_response_letters(
98+
search: [{ "company_name" => "Novartis" }, { "approver_name" => "John Doe" }],
99+
limit: 10
100+
)
67101
```
68102

69103
### Querying
@@ -116,12 +150,12 @@ To release a new version, update the version number in `version.rb`, and then ru
116150
## Contributing
117151

118152
Bug reports and pull requests are welcome on GitHub at https://github.com/hebron-george/open_fda_api .
119-
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/open_fda_api/blob/master/CODE_OF_CONDUCT.md).
153+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hebron-george/open_fda_api/blob/main/CODE_OF_CONDUCT.md).
120154

121155
## License
122156

123157
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
124158

125159
## Code of Conduct
126160

127-
Everyone interacting in the OpenFdaApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/open_fda_api/blob/master/CODE_OF_CONDUCT.md).
161+
Everyone interacting in the OpenFdaApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hebron-george/open_fda_api/blob/main/CODE_OF_CONDUCT.md).

lib/open_fda_api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Error < StandardError; end
1414
autoload :Food, "open_fda_api/food"
1515
autoload :Other, "open_fda_api/other"
1616
autoload :Tobacco, "open_fda_api/tobacco"
17+
autoload :Transparency, "open_fda_api/transparency"
1718
autoload :QueryInputs, "open_fda_api/query_inputs"
1819
autoload :QueryBuilder, "open_fda_api/query_builder"
1920
end

lib/open_fda_api/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def other
3939
OpenFdaApi::Other.new(self)
4040
end
4141

42+
def transparency
43+
OpenFdaApi::Transparency.new(self)
44+
end
45+
4246
def connection
4347
@connection ||= Faraday.new(BASE_URL) do |conn|
4448
conn.request :json

lib/open_fda_api/transparency.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module OpenFdaApi
4+
# Interact with the Transparency API Endpoint:
5+
# - Complete Response Letters
6+
class Transparency < Endpoint
7+
# Complete Response Letters (CRL) are issued when the FDA determines it will not approve
8+
# a New Drug Application (NDA) or Biologics License Application (BLA) in its current form.
9+
#
10+
# @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/transparency/completeresponseletters/searchable-fields/
11+
# @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/transparency/completeresponseletters/searchable-fields/
12+
# @param count [Array<Hash>] Count fields defined in https://open.fda.gov/apis/transparency/completeresponseletters/searchable-fields/
13+
# @param skip [Integer] Number of results to skip
14+
# @param limit [Integer] Number of results to return
15+
# @return Response from the API parsed as JSON
16+
def complete_response_letters(search: [], sort: [], count: [], skip: 0, limit: 1)
17+
endpoint = "crl.json"
18+
inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
19+
query = build_query(inputs)
20+
make_request(endpoint, query)
21+
end
22+
23+
private
24+
25+
def endpoint_path
26+
"/transparency"
27+
end
28+
end
29+
end

lib/open_fda_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module OpenFdaApi
4-
VERSION = "0.1.0"
4+
VERSION = "0.2.0"
55
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"meta": {
3+
"disclaimer": "Do not rely on openFDA to make decisions regarding medical care. While we make every effort to ensure that data is accurate, you should assume all results are unvalidated. We may limit or otherwise restrict your access to the API in line with our Terms of Service.",
4+
"terms": "https://open.fda.gov/terms/",
5+
"license": "https://open.fda.gov/license/",
6+
"last_updated": "2024-01-01",
7+
"results": {
8+
"skip": 0,
9+
"limit": 1,
10+
"total": 100
11+
}
12+
},
13+
"results": [
14+
{
15+
"file_name": "example_crl.pdf",
16+
"application_number": "NDA012345",
17+
"letter_type": "COMPLETE RESPONSE",
18+
"letter_date": "2023-06-15",
19+
"company_name": "Example Pharmaceuticals Inc.",
20+
"company_rep": "Jane Smith",
21+
"company_address": "123 Pharma Way, New York, NY 10001",
22+
"approver_name": "John Doe",
23+
"approver_title": "Acting Deputy Director",
24+
"approver_center": "Center for Drug Evaluation and Research",
25+
"text": "We have completed our review of this application and have determined that we cannot approve this application in its present form."
26+
}
27+
]
28+
}

spec/open_fda_api/client_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
context "#other" do
2727
it { expect(instance.other).to be_a(OpenFdaApi::Other) }
2828
end
29+
30+
context "#transparency" do
31+
it { expect(instance.transparency).to be_a(OpenFdaApi::Transparency) }
32+
end
2933
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe OpenFdaApi::Transparency do
4+
let(:instance) { client.transparency }
5+
let(:client) { OpenFdaApi::Client.new(adapter: :test, stubs: stub) }
6+
7+
context "#complete_response_letters API call" do
8+
let(:stub) do
9+
Faraday::Adapter::Test::Stubs.new do |stub|
10+
stub.get("https://api.fda.gov/transparency/crl.json") do |_env|
11+
[200, { "Content-Type" => "application/json" },
12+
File.read("spec/fixtures/transparency/crl.json")]
13+
end
14+
end
15+
end
16+
subject(:complete_response_letters_call) { instance.complete_response_letters }
17+
18+
it "returns a response with meta and results" do
19+
expect(complete_response_letters_call).to include("meta", "results")
20+
end
21+
22+
it "returns complete response letter records" do
23+
result = complete_response_letters_call["results"].first
24+
expect(result).to include(
25+
"application_number",
26+
"letter_type",
27+
"letter_date",
28+
"company_name",
29+
"approver_name",
30+
"approver_center"
31+
)
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)