Class: Candid::PreEncounter::Patients::V1::Client
- Inherits:
-
Object
- Object
- Candid::PreEncounter::Patients::V1::Client
- Defined in:
- lib/candid/pre_encounter/patients/v_1/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Adds a patient.
-
#create_with_mrn(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Adds a patient and hydrates their MRN with a pre-existing MRN.
-
#deactivate(request_options: {}, **params) ⇒ untyped
Sets a patient as deactivated.
-
#get(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Gets a patient.
-
#get_by_mrn(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Gets a patient by mrn.
-
#get_history(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Patients::V1::Types::Patient]
Gets a patient along with it’s full history.
-
#get_multi(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::PatientPage
Searches for patients that match the query parameters.
- #initialize(client:) ⇒ Candid::PreEncounter::Patients::V1::Client constructor
-
#reactivate(request_options: {}, **params) ⇒ untyped
Removes the deactivated flag for a patient.
-
#scan(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Patients::V1::Types::Patient]
Scans up to 1000 patient updates.
-
#search(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Patients::V1::Types::Patient]
Returns a list of Patients based on the search criteria.
-
#search_providers(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Common::Types::ExternalProvider]
Searches for referring providers that match the query parameters.
-
#update(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Updates a patient.
Constructor Details
#initialize(client:) ⇒ Candid::PreEncounter::Patients::V1::Client
9 10 11 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Adds a patient. VersionConflictError is returned when the patient’s external ID is already in use.
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 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 16 def create(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[skip_duplicate_check] _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "POST", path: "/patients/v1", query: _query, body: params ) 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::Patients::V1::Types::Patient.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_mrn(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Adds a patient and hydrates their MRN with a pre-existing MRN. Once this patient is created their MRN will not be editable. BadRequestError is returned when the MRN is greater than 20 characters. VersionConflictError is returned when the patient’s external ID is already in use.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 46 def create_with_mrn(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[skip_duplicate_check] _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "POST", path: "/patients/v1/with_mrn", query: _query, body: params ) 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::Patients::V1::Types::Patient.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 a patient as deactivated. The path must contain the most recent version plus 1 to prevent race conditions. Deactivating historic versions is not supported.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 223 def deactivate(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "DELETE", path: "/patients/v1/#{params[:id]}/#{params[:version]}" ) 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::Patients::V1::Types::Patient
Gets a patient.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 132 def get(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/#{params[:id]}" ) 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::Patients::V1::Types::Patient.load(_response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_by_mrn(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::Patient
Gets a patient by mrn.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 155 def get_by_mrn(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/mrn/#{params[:mrn]}" ) 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::Patients::V1::Types::Patient.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::Patients::V1::Types::Patient]
Gets a patient along with it’s full history. The return list is ordered by version ascending.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 178 def get_history(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/#{params[:id]}/history" ) 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_multi(request_options: {}, **params) ⇒ Candid::PreEncounter::Patients::V1::Types::PatientPage
Searches for patients that match the query parameters.
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 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 76 def get_multi(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[limit mrn page_token sort_field sort_direction] _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/get_multi", query: _query ) 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::Patients::V1::Types::PatientPage.load(_response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#reactivate(request_options: {}, **params) ⇒ untyped
Removes the deactivated flag for a patient. The path must contain the most recent version plus 1 to prevent race conditions. Reactivating historic versions is not supported.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 244 def reactivate(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "PATCH", path: "/patients/v1/#{params[:id]}/#{params[:version]}" ) 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 |
#scan(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Patients::V1::Types::Patient]
Scans up to 1000 patient 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 ‘since` timestamp (e.g., `since=2020-01-01T13:00:00.000Z`)
-
The API returns 100 by default and up to 1000 patient records, sorted by ‘updated_at` ascending
-
Find the ‘updated_at` value from the last record in the response
-
Use that ‘updated_at` value as the `since` parameter in your next request
-
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 records include ‘updated_at`, `id`, `version`, `deactivated`, and `updating_user` fields for tracking changes
-
Timestamps have millisecond resolution for precise ordering
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 305 def scan(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[since maxResults] _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/updates/scan", query: _query ) 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 |
#search(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Patients::V1::Types::Patient]
Returns a list of Patients based on the search criteria.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 265 def search(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[mrn similar_name_ordering] _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1", query: _query ) 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 |
#search_providers(request_options: {}, **params) ⇒ Array[Candid::PreEncounter::Common::Types::ExternalProvider]
Searches for referring providers that match the query parameters. The search is case-insensitive, supports fuzzy matching, and matches against provider name and NPI. The search criteria must be an alphanumeric string, and the search is limited to the first 20 results.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 105 def search_providers(request_options: {}, **params) params = Candid::Internal::Types::Utils.symbolize_keys(params) _query_param_names = %i[search_criteria] _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "GET", path: "/patients/v1/search_providers", query: _query ) 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::Patients::V1::Types::Patient
Updates a patient. The path must contain the next version number to prevent race conditions. For example, if the current version of the patient is n, you will need to send a request to this endpoint with ‘/id/n+1` to update the patient. Updating historic versions is not supported.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/candid/pre_encounter/patients/v_1/client.rb', line 199 def update(request_options: {}, **params) _request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || Candid::Environment::PRODUCTION, method: "PUT", path: "/patients/v1/#{params[:id]}/#{params[:version]}", body: Candid::PreEncounter::Patients::V1::Types::MutablePatient.new(params).to_h ) 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::Patients::V1::Types::Patient.load(_response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |