Class: Candid::PreEncounter::Appointments::V1::Client

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

Instance Method Summary collapse

Constructor Details

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

Parameters:



13
14
15
16
17
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 13

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

Instance Method Details

#create(request_options: {}, **params) ⇒ Candid::PreEncounter::Appointments::V1::Types::Appointment

Adds an appointment. VersionConflictError is returned when the placer_appointment_id is already in use.

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)

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 30

def create(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(:pre_encounter),
    method: "POST",
    path: "/appointments/v1",
    body: Candid::PreEncounter::Appointments::V1::Types::MutableAppointment.new(params).to_h,
    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::PreEncounter::Appointments::V1::Types::Appointment.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

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

Sets an appointment as deactivated. The path must contain the most recent version to prevent race conditions. Deactivating historic versions is not supported. Subsequent updates via PUT to the appointment will “reactivate” the appointment and set the deactivated flag to false.

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:

  • (untyped)

Raises:

  • (error_class)


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 272

def deactivate(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(:pre_encounter),
    method: "DELETE",
    path: "/appointments/v1/#{params[:id]}/#{params[:version]}",
    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) ⇒ Candid::PreEncounter::Appointments::V1::Types::Appointment

Gets an appointment.

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:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 126

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(:pre_encounter),
    method: "GET",
    path: "/appointments/v1/#{params[:id]}",
    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::PreEncounter::Appointments::V1::Types::Appointment.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_history(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Appointments::V1::Types::Appointment]

Gets an appointment along with it’s full history. The return list is ordered by version ascending.

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)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 160

def get_history(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(:pre_encounter),
    method: "GET",
    path: "/appointments/v1/#{params[:id]}/history",
    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_visits(request_options: {}, **params) ⇒ Candid::PreEncounter::Appointments::V1::Types::VisitsPage

Gets all Visits within a given time range. The return list is ordered by start_time ascending.

IMPORTANT: This endpoint requires a date filter on ‘appointment.startTimestamp` to ensure acceptable query performance. Without date filtering, the query can take 50+ seconds on large datasets due to grouping and aggregation operations.

Example filters:

  • ‘appointment.startTimestamp|gt|2024-01-01` - appointments after January 1, 2024

  • ‘appointment.startTimestamp|eq|2024-12-08` - appointments on December 8, 2024

  • ‘appointment.startTimestamp|lt|2024-12-31` - appointments before December 31, 2024

You can combine the date filter with other filters using commas:

  • ‘appointment.startTimestamp|gt|2024-01-01,appointment.status|eq|PENDING`

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:



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

def get_visits(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[page_token limit sort_field sort_direction filters]
  query_params = {}
  query_params["page_token"] = params[:page_token] if params.key?(:page_token)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["sort_field"] = params[:sort_field] if params.key?(:sort_field)
  query_params["sort_direction"] = params[:sort_direction] if params.key?(:sort_direction)
  query_params["filters"] = params[:filters] if params.key?(:filters)
  params.except(*query_param_names)

  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:pre_encounter),
    method: "GET",
    path: "/appointments/v1/visits",
    query: query_params,
    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::PreEncounter::Appointments::V1::Types::VisitsPage.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#scan(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Appointments::V1::Types::Appointment]

Scans up to 100 appointment updates. The since query parameter is inclusive, and the result list is ordered by updatedAt ascending.

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):

  • :since (String)

Returns:

Raises:

  • (error_class)


231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 231

def scan(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[since]
  query_params = {}
  query_params["since"] = params[:since] if params.key?(:since)
  params.except(*query_param_names)

  request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || @base_url || @environment&.dig(:pre_encounter),
    method: "GET",
    path: "/appointments/v1/updates/scan",
    query: query_params,
    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

#update(request_options: {}, **params) ⇒ Candid::PreEncounter::Appointments::V1::Types::Appointment

Updates an appointment. The path must contain the next version number to prevent race conditions. For example, if the current version of the appointment is n, you will need to send a request to this endpoint with ‘/id/n+1` to update the appointment. Updating historic versions is not supported.

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:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/candid/pre_encounter/appointments/v_1/client.rb', line 195

def update(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(:pre_encounter),
    method: "PUT",
    path: "/appointments/v1/#{params[:id]}/#{params[:version]}",
    body: Candid::PreEncounter::Appointments::V1::Types::MutableAppointment.new(params).to_h,
    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::PreEncounter::Appointments::V1::Types::Appointment.load(response.body)
  else
    error_class = Candid::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end