Class: FHIR::ResourceAddress
- Inherits:
-
Object
- Object
- FHIR::ResourceAddress
- Defined in:
- lib/fhir_client/resource_address.rb
Constant Summary collapse
- DEFAULTS =
{ id: nil, resource: nil, format: 'application/fhir+xml' }.freeze
- DEFAULT_CHARSET =
'UTF-8'.freeze
Class Method Summary collapse
- .append_forward_slash_to_path(path) ⇒ Object
-
.pull_out_id(resource_type, url) ⇒ Object
Get the resource ID out of the URL (e.g. Bundle.entry.response.location).
Instance Method Summary collapse
- #fhir_headers(options, use_format_param = false) ⇒ Object
- #resource_url(options, use_format_param = false) ⇒ Object
Class Method Details
.append_forward_slash_to_path(path) ⇒ Object
134 135 136 137 |
# File 'lib/fhir_client/resource_address.rb', line 134 def self.append_forward_slash_to_path(path) path += '/' unless path.last == '/' path end |
.pull_out_id(resource_type, url) ⇒ Object
Get the resource ID out of the URL (e.g. Bundle.entry.response.location)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fhir_client/resource_address.rb', line 117 def self.pull_out_id(resource_type, url) id = nil if !resource_type.nil? && !url.nil? token = "#{resource_type}/" if url.index(token) start = url.index(token) + token.length t = url[start..-1] stop = (t.index('/') || 0) - 1 stop = -1 if stop.nil? id = t[0..stop] else id = nil end end id end |
Instance Method Details
#fhir_headers(options, use_format_param = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fhir_client/resource_address.rb', line 11 def fhir_headers(, use_format_param = false) = DEFAULTS.merge() format = [:format] || FHIR::Formats::ResourceFormat::RESOURCE_XML fhir_headers = { 'User-Agent' => 'Ruby FHIR Client', 'Content-Type' => format + ';charset=' + DEFAULT_CHARSET, 'Accept-Charset' => DEFAULT_CHARSET } # remove the content-type header if the format is 'xml' or 'json' because # even those are valid _format parameter options, they are not valid MimeTypes. fhir_headers.delete('Content-Type') if %w(xml json).include?(format.downcase) if [:category] # options[:category] should be an Array of FHIR::Tag objects = { 'Category' => [:category].collect(&:to_header).join(',') } fhir_headers.merge!() .delete(:category) end if use_format_param fhir_headers.delete('Accept') .delete('Accept') .delete(:accept) else fhir_headers['Accept'] = format end fhir_headers.merge!() unless .empty? fhir_headers[:operation] = [:operation][:name] if [:operation] && [:operation][:name] fhir_headers.delete('id') fhir_headers.delete('resource') fhir_headers end |
#resource_url(options, use_format_param = false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fhir_client/resource_address.rb', line 48 def resource_url(, use_format_param = false) = DEFAULTS.merge() params = {} url = '' # handle requests for resources by class or string; useful for testing nonexistent resource types url += "/#{[:resource].try(:name).try(:demodulize) || [:resource].split('::').last}" if [:resource] url += "/#{[:id]}" if [:id] url += '/$validate' if [:validate] url += '/$match' if [:match] if [:operation] opr = [:operation] p = opr[:parameters] p = p.each { |k, v| p[k] = v[:value] } if p params.merge!(p) if p && opr[:method] == 'GET' if opr[:name] == :fetch_patient_record url += '/$everything' elsif opr[:name] == :value_set_expansion url += '/$expand' elsif opr && opr[:name] == :value_set_based_validation url += '/$validate-code' elsif opr && opr[:name] == :code_system_lookup url += '/$lookup' elsif opr && opr[:name] == :concept_map_translate url += '/$translate' elsif opr && opr[:name] == :closure_table_maintenance url += '/$closure' end end if [:history] history = [:history] url += '/_history' url += "/#{history[:id]}" if history.key?(:id) params[:_count] = history[:count] if history[:count] params[:_since] = history[:since].iso8601 if history[:since] end if [:search] = [:search] url += '/_search' if [:flag] url += "/#{[:compartment]}" if [:compartment] if [:parameters] [:parameters].each do |key, value| params[key.to_sym] = value end end end # options[:params] is simply appended at the end of a url and is used by testscripts url += [:params] if [:params] params[:_summary] = [:summary] if [:summary] if use_format_param && [:format] params[:_format] = [:format] end uri = Addressable::URI.parse(url) # params passed in options takes precidence over params calculated in this method # for use by testscript primarily uri.query_values = params unless [:params] && [:params].include?('?') uri.normalize.to_str end |