Class: Candid::EncounterAttachments::V1::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/candid/encounter_attachments/v_1/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, base_url: nil, environment: nil) ⇒ void

Parameters:



12
13
14
15
16
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 12

def initialize(client:, base_url: nil, environment: nil)
  @client = client
  @base_url = base_url
  @environment = environment
end

Instance Method Details

#create(request_options: {}, **params) ⇒ String

Uploads a file to the encounter. The file will be stored in the encounter’s attachments. Deprecated: Use create-v2 instead.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:

  • (String)


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
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 61

def create(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  body.add_part(params[:attachment_file].to_form_data_part(name: "attachment_file")) if params[:attachment_file]
  if params[:attachment_type]
    body.add(
      name: "attachment_type",
      value: params[:attachment_type]
    )
  end

  request = Candid::Internal::Multipart::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "PUT",
    path: "/api/encounter-attachments/v1/#{params[:encounter_id]}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Candid::EncounterAttachments::V1::Types::AttachmentId.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_with_charge_capture_external_id(request_options: {}, **params) ⇒ String

Uploads a file using an external identifier. For Charge Capture, the file will be associated with the Encounter at Encounter creation time.

Note: Attachments created via this endpoint are not searchable via the get endpoint until they are associated with an encounter.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:

  • (String)


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 161

def create_with_charge_capture_external_id(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  if params[:charge_capture_external_id]
    body.add(
      name: "charge_capture_external_id",
      value: params[:charge_capture_external_id]
    )
  end
  body.add_part(params[:attachment_file].to_form_data_part(name: "attachment_file")) if params[:attachment_file]
  if params[:attachment_type]
    body.add(
      name: "attachment_type",
      value: params[:attachment_type]
    )
  end
  if params[:description]
    body.add(
      name: "description",
      value: params[:description]
    )
  end

  request = Candid::Internal::Multipart::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "POST",
    path: "/api/encounter-attachments/v1/create-from-charge-capture-external-id",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Candid::EncounterAttachments::V1::Types::AttachmentId.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_with_description(request_options: {}, **params) ⇒ String

Uploads a file to the encounter. The file will be stored in the encounter’s attachments.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:

  • (String)


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 107

def create_with_description(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  body.add_part(params[:attachment_file].to_form_data_part(name: "attachment_file")) if params[:attachment_file]
  if params[:attachment_type]
    body.add(
      name: "attachment_type",
      value: params[:attachment_type]
    )
  end
  if params[:description]
    body.add(
      name: "description",
      value: params[:description]
    )
  end

  request = Candid::Internal::Multipart::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "PUT",
    path: "/api/encounter-attachments/v1/#{params[:encounter_id]}/v2",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Candid::EncounterAttachments::V1::Types::AttachmentId.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete(request_options: {}, **params) ⇒ untyped

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:

  • (untyped)

Raises:

  • (error_class)


285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 285

def delete(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  request_data = Candid::EncounterAttachments::V1::Types::DeleteAttachmentRequest.new(params).to_h
  non_body_param_names = ["encounter_id"]
  body = request_data.except(*non_body_param_names)

  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "DELETE",
    path: "/api/encounter-attachments/v1/#{params[:encounter_id]}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Candid::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#delete_by_charge_capture_external_id(request_options: {}, **params) ⇒ untyped

Deletes an attachment associated with the given charge capture external ID.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :charge_capture_external_id (String)

Returns:

  • (untyped)

Raises:

  • (error_class)


250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 250

def delete_by_charge_capture_external_id(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  request_data = Candid::EncounterAttachments::V1::Types::DeleteExternalAttachmentRequest.new(params).to_h
  non_body_param_names = ["charge_capture_external_id"]
  body = request_data.except(*non_body_param_names)

  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "DELETE",
    path: "/api/encounter-attachments/v1/by-charge-capture-external-id/#{params[:charge_capture_external_id]}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Candid::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#get(request_options: {}, **params) ⇒ Array[Candid::EncounterAttachments::V1::Types::EncounterAttachment]

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:

Raises:

  • (error_class)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 28

def get(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "GET",
    path: "/api/encounter-attachments/v1/#{params[:encounter_id]}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Candid::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#get_by_charge_capture_external_id(request_options: {}, **params) ⇒ Array[Candid::EncounterAttachments::V1::Types::ChargeCaptureAttachment]

Returns all attachments associated with the given charge capture external ID.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :charge_capture_external_id (String)

Returns:

Raises:

  • (error_class)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/candid/encounter_attachments/v_1/client.rb', line 218

def get_by_charge_capture_external_id(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "GET",
    path: "/api/encounter-attachments/v1/by-charge-capture-external-id/#{params[:charge_capture_external_id]}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Candid::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Candid::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end