Class: Util::VSAC::VSACAPI
- Inherits:
-
Object
- Object
- Util::VSAC::VSACAPI
- Defined in:
- lib/util/vsac_api.rb
Constant Summary collapse
- DEFAULT_PROGRAM =
The default program to use for get_program_details and get_program_release_names calls. This can be overriden by providing a :program in the config or by the single optional parameter for those methods.
"CMS eCQM and Hybrid Measure"
- TICKET_SERVICE_PARAM =
This is the value of the service parameter passed when getting a ticket. This never changes.
"http://umlsks.nlm.nih.gov"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Requester UMLS API KEY.
Instance Method Summary collapse
-
#get_latest_profile_for_program(program = nil) ⇒ Object
Gets the latest profile for a program.
-
#get_multiple_valuesets(needed_value_sets) ⇒ Object
Get multiple valuesets (executed in parallel).
-
#get_profile_names ⇒ Object
Gets the list of profiles.
-
#get_program_details(program = nil) ⇒ Object
Gets the details for a program.
-
#get_program_names ⇒ Object
Gets the list of programs.
-
#get_program_release_names(program = nil) ⇒ Object
Gets the releases for a program.
-
#get_valueset(oid, options = {}) ⇒ Object
Gets a valueset.
-
#initialize(options) ⇒ VSACAPI
constructor
Creates a new VSACAPI.
-
#validate_api_key_vsac ⇒ Object
Attempt to retrieve the ONC Admin Sex VS to verify VSAC connectivity with the supplied UMLS API Key.
Constructor Details
#initialize(options) ⇒ VSACAPI
Creates a new VSACAPI. If credentials were provided they are checked now. If no credentials are provided then the API can still be used for utility methods.
Options for the API are passed in as a hash.
-
config -
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/util/vsac_api.rb', line 79 def initialize() # check that :config exists and has needed fields raise VSACArgumentError.new("Required param :config is missing or empty.") if [:config].nil? @config = [:config].symbolize_keys unless check_config @config raise VSACArgumentError.new("Required param :config is missing required URLs.") end @api_key = [:api_key] validate_api_key_vsac unless [:api_key].nil? end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Requester UMLS API KEY
71 72 73 |
# File 'lib/util/vsac_api.rb', line 71 def api_key @api_key end |
Instance Method Details
#get_latest_profile_for_program(program = nil) ⇒ Object
Gets the latest profile for a program. This is a separate call from the program details call. It returns JSON with only the name of the latest profile and the timestamp of the request. ex:
{
"name": "eCQM Update 2018-05-04",
"requestTime": "2018-05-21 03:39:04 PM"
}
Optional parameter program is the program to request from the API. If it is not provided it will look for a :program in the config passed in during construction. If there is no :program in the config it will use the DEFAULT_PROGRAM constant for the program.
Returns the name of the latest profile for the given program.
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/util/vsac_api.rb', line 151 def get_latest_profile_for_program(program = nil) # if no program was provided use the one in the config or default in constant program = @config.fetch(:program, DEFAULT_PROGRAM) if program.nil? # parse json response and return it parsed_response = http_get_json("#{@config[:utility_url]}/program/#{ERB::Util.url_encode(program)}/latest%20profile") # As of 5/17/18 VSAC does not return 404 when an invalid profile is provided. It just doesnt fill the name # attribute in the 200 response. We need to check this. raise VSACProgramNotFoundError.new(program) if parsed_response['name'].nil? return parsed_response['name'] end |
#get_multiple_valuesets(needed_value_sets) ⇒ Object
Get multiple valuesets (executed in parallel). Requires credentials.
Parameter needed_value_sets is an array of hashes, each hash should have at least: hash = _, value_set: {oid: _ }
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/util/vsac_api.rb', line 191 def get_multiple_valuesets(needed_value_sets) raise VSACNoCredentialsError.new unless @api_key vs_responses = get_multiple_valueset_raw_responses(needed_value_sets) vs_datas = [needed_value_sets,vs_responses].transpose.map do |needed_vs,vs_response| expected_oid = needed_vs[:value_set][:oid] process_and_validate_vsac_response(vs_response, expected_oid) end return vs_datas end |
#get_profile_names ⇒ Object
Gets the list of profiles. This may be used without credentials.
Returns a list of profile names. These are kept in the order that VSAC provides them in.
103 104 105 106 107 108 109 110 |
# File 'lib/util/vsac_api.rb', line 103 def get_profile_names profiles_response = http_get("#{@config[:utility_url]}/profiles") # parse xml response and get text content of each profile element doc = Nokogiri::XML(profiles_response) profile_list = doc.at_xpath("/ProfileList") return profile_list.xpath("//profile").map(&:text) end |
#get_program_details(program = nil) ⇒ Object
Gets the details for a program. This may be used without credentials.
Optional parameter program is the program to request from the API. If it is not provided it will look for a :program in the config passed in during construction. If there is no :program in the config it will use the DEFAULT_PROGRAM constant for the program.
Returns the JSON parsed response for program details.
130 131 132 133 134 135 136 |
# File 'lib/util/vsac_api.rb', line 130 def get_program_details(program = nil) # if no program was provided use the one in the config or default in constant program = @config.fetch(:program, DEFAULT_PROGRAM) if program.nil? return http_get_json("#{@config[:utility_url]}/program/#{ERB::Util.url_encode(program)}") rescue VSACNotFoundError raise VSACProgramNotFoundError.new(program) end |
#get_program_names ⇒ Object
Gets the list of programs. This may be used without credentials.
Returns a list of program names. These are kept in the order that VSAC provides them in.
116 117 118 119 120 |
# File 'lib/util/vsac_api.rb', line 116 def get_program_names programs_response = http_get_json("#{@config[:utility_url]}/programs") programs_info = programs_response['Program'] return programs_info.map { |program| program['name'] } end |
#get_program_release_names(program = nil) ⇒ Object
Gets the releases for a program. This may be used without credentials.
Optional parameter program is the program to request from the API. If it is not provided it will look for a :program in the config passed in during construction. If there is no :program in the config it will use the DEFAULT_PROGRAM constant for the program.
Returns a list of release names in a program. These are kept in the order that VSAC provides them in.
172 173 174 175 |
# File 'lib/util/vsac_api.rb', line 172 def get_program_release_names(program = nil) program_details = get_program_details(program) return program_details['release'].map { |release| release['name'] } end |
#get_valueset(oid, options = {}) ⇒ Object
Gets a valueset. This requires credentials.
180 181 182 183 |
# File 'lib/util/vsac_api.rb', line 180 def get_valueset(oid, = {}) needed_vs = {value_set: {oid: oid}, vs_vsac_options: } return get_multiple_valuesets([needed_vs])[0] end |
#validate_api_key_vsac ⇒ Object
Attempt to retrieve the ONC Admin Sex VS to verify VSAC connectivity with the supplied UMLS API Key.
93 94 95 96 97 |
# File 'lib/util/vsac_api.rb', line 93 def validate_api_key_vsac response = get_multiple_valueset_raw_responses([{value_set: {oid: "2.16.840.1.113762.1.4.1"}, vs_vsac_options: {}}])[0] raise VSACInvalidCredentialsError.new if !response.body || response.response_code == 401 validate_http_status(response.response_code) end |