Class: Candid::PreEncounter::PatientMerges::V1::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/candid/pre_encounter/patient_merges/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/patient_merges/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::PatientMerges::V1::Types::PatientMerge

Creates a new patient merge record.

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/patient_merges/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: "/patient-merge/v1",
    body: Candid::PreEncounter::PatientMerges::V1::Types::MutablePatientMerge.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::PatientMerges::V1::Types::PatientMerge.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

Deactivates a patient merge record. Path must contain next version.

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)


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/candid/pre_encounter/patient_merges/v_1/client.rb', line 133

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: "/patient-merge/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_all_by_mrn(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::PatientMerges::V1::Types::PatientMerge]

Gets all patient merge records that have the given mrn.

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

  • :mrn (String)

Returns:

Raises:

  • (error_class)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/candid/pre_encounter/patient_merges/v_1/client.rb', line 100

def get_all_by_mrn(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: "/patient-merge/v1/all/#{params[:mrn]}",
    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_status(request_options: {}, **params) ⇒ Candid::PreEncounter::PatientMerges::V1::Types::PatientMergeStatus

Gets the merge status for a patient by patient ID or mrn. If the provided value is a valid UUID, it will be treated as a patient ID. Otherwise, it will be treated as an MRN.

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

  • :mrn_or_id (String)

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/candid/pre_encounter/patient_merges/v_1/client.rb', line 66

def get_status(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: "/patient-merge/v1/status/#{params[:mrn_or_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::PatientMerges::V1::Types::PatientMergeStatus.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::PatientMerges::V1::Types::PatientMerge]

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

Polling Pattern: To continuously poll for updates without gaps:

  1. Make your initial request with a since timestamp (e.g., since=2020-01-01T13:00:00.000Z)
  2. The API returns 100 by default and up to 1000 patient merge records, sorted by updated_at ascending
  3. Find the updated_at value from the last record in the response
  4. Use that updated_at value as the since parameter in your next request
  5. Repeat steps 2-4 to ingest updates until you receive an empty list

Important Notes:

  • The since parameter is inclusive, so you may receive the last record from the previous batch again (you can deduplicate by ID and version)
  • All patient merge records include updated_at, id, version, deactivated, and updating_user fields for tracking changes
  • Timestamps have millisecond resolution for precise ordering

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)
  • :max_results (Integer, nil)

Returns:

Raises:

  • (error_class)


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/candid/pre_encounter/patient_merges/v_1/client.rb', line 182

def scan(request_options: {}, **params)
  params = Candid::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[since max_results]
  query_params = {}
  query_params["since"] = params[:since] if params.key?(:since)
  query_params["maxResults"] = params[:max_results] if params.key?(:max_results)
  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: "/patient-merge/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