# frozen_string_literal: true require "yaml" module OpenFdaApi # Interact with the Drugs API Endpoint: # - Adverse Events # - Product Labeling # - NDC Directory # - Recall Enforcement Reports # - Drugs@FDA) class Drugs < Endpoint # @param search [Array] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param sort [Array] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param count [Array] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/ # @param skip [Integer] Number of results to skip # @param limit [Integer] Number of results to return # @return Response from the API parsed as JSON def adverse_events(search: [], sort: [], count: [], skip: 0, limit: 1) endpoint = "event.json" inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit) query = build_query(inputs, self.class.valid_adverse_events_fields) make_request(endpoint, query) end # @param search [Array] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param sort [Array] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param count [Array] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/ # @param skip [Integer] Number of results to skip # @param limit [Integer] Number of results to return # @return Response from the API parsed as JSON def product_labeling(search: [], sort: [], count: [], skip: 0, limit: 1) endpoint = "label.json" inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit) query = build_query(inputs, {}) # TODO: Upload valid fields make_request(endpoint, query) end # @param search [Array] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param sort [Array] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param count [Array] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/ # @param skip [Integer] Number of results to skip # @param limit [Integer] Number of results to return # @return Response from the API parsed as JSON def ndc_directory(search: [], sort: [], count: [], skip: 0, limit: 1) endpoint = "ndc.json" inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit) query = build_query(inputs, {}) # TODO: Upload valid fields make_request(endpoint, query) end # @param search [Array] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param sort [Array] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param count [Array] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/ # @param skip [Integer] Number of results to skip # @param limit [Integer] Number of results to return # @return Response from the API parsed as JSON def recall_enforcement_reports(search: [], sort: [], count: [], skip: 0, limit: 1) endpoint = "enforcement.json" inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit) query = build_query(inputs, {}) # TODO: Upload valid fields make_request(endpoint, query) end # @param search [Array] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param sort [Array] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @param count [Array] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/ # @param skip [Integer] Number of results to skip # @param limit [Integer] Number of results to return # @return Response from the API parsed as JSON def drugs_at_fda(search: [], sort: [], count: [], skip: 0, limit: 1) endpoint = "drugsfda.json" inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit) query = build_query(inputs, {}) # TODO: Upload valid fields make_request(endpoint, query) end def self.valid_adverse_events_fields @valid_adverse_events_fields ||= ::YAML.load_file("#{__dir__}/adverse_events_fields.yml") end private def endpoint_path "/drug" end end end