Class: Candid::PreEncounter::PatientMerges::V1::Client
- Inherits:
-
Object
- Object
- Candid::PreEncounter::PatientMerges::V1::Client
- Defined in:
- lib/candid/pre_encounter/patient_merges/v_1/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Candid::PreEncounter::PatientMerges::V1::Types::PatientMerge
Creates a new patient merge record.
-
#deactivate(request_options: {}, **params) ⇒ untyped
Deactivates a patient merge record.
-
#get_all_by_mrn(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::PatientMerges::V1::Types::PatientMerge]
Gets all patient merge records that have the given mrn.
-
#get_status(request_options: {}, **params) ⇒ Candid::PreEncounter::PatientMerges::V1::Types::PatientMergeStatus
Gets the merge status for a patient by patient ID or mrn.
- #initialize(client:, base_url: nil, environment: nil) ⇒ void constructor
-
#scan(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::PatientMerges::V1::Types::PatientMerge]
Scans up to 1000 patient merge updates.
Constructor Details
#initialize(client:, base_url: nil, environment: nil) ⇒ void
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.
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: [: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: ) 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.
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: [:base_url] || @base_url || @environment&.dig(:pre_encounter), method: "DELETE", path: "/patient-merge/v1/#{params[:id]}/#{params[:version]}", 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.
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: [:base_url] || @base_url || @environment&.dig(:pre_encounter), method: "GET", path: "/patient-merge/v1/all/#{params[:mrn]}", 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.
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: [:base_url] || @base_url || @environment&.dig(:pre_encounter), method: "GET", path: "/patient-merge/v1/status/#{params[:mrn_or_id]}", 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:
- Make your initial request with a
sincetimestamp (e.g.,since=2020-01-01T13:00:00.000Z) - The API returns 100 by default and up to 1000 patient merge records, sorted by
updated_atascending - Find the
updated_atvalue from the last record in the response - Use that
updated_atvalue as thesinceparameter in your next request - Repeat steps 2-4 to ingest updates until you receive an empty list
Important Notes:
- The
sinceparameter 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, andupdating_userfields for tracking changes - Timestamps have millisecond resolution for precise ordering
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: [:base_url] || @base_url || @environment&.dig(:pre_encounter), method: "GET", path: "/patient-merge/v1/updates/scan", query: query_params, 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 |