From d9756ed5900e840f94e8f4980102347732b6182e Mon Sep 17 00:00:00 2001 From: Ryan Meyer Date: Thu, 14 Mar 2019 08:45:54 -0400 Subject: [PATCH] CDRIS-4230-display-ingestion-error-payload --- Gemfile.lock | 4 ++-- lib/cdris/gateway/patient_document.rb | 16 +++++++++++++++- lib/cdris/gateway/version.rb | 2 +- spec/cdris/gateway/patient_document_spec.rb | 19 ++++++++++++++++++- spec/fixtures/sample_ingestion_error.json | 8 ++++++++ spec/spec_helper.rb | 5 +++++ 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/sample_ingestion_error.json diff --git a/Gemfile.lock b/Gemfile.lock index 511fbec..f66a9e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - cdris_api_client (4.5.0dev0.00) + cdris_api_client (4.5.0dev0.01) activesupport (~> 3.0) api-auth (= 1.4.1) mime-types (< 2.99) @@ -111,4 +111,4 @@ DEPENDENCIES yard (= 0.8.7) BUNDLED WITH - 1.14.6 + 1.16.1 diff --git a/lib/cdris/gateway/patient_document.rb b/lib/cdris/gateway/patient_document.rb index 5a8b3be..42f6e09 100644 --- a/lib/cdris/gateway/patient_document.rb +++ b/lib/cdris/gateway/patient_document.rb @@ -182,7 +182,6 @@ def delete(patient_document_id, options = {}) end - # Gets a list of ingestion errors # # @param [Hash] params specify which root to get `:root` (optional) @@ -198,6 +197,21 @@ def ingestion_errors(params, options = {}) .to_hash end + # Gets an ingestion error by id + # + # @param [Hash] params specify which id to get `:id` + # @param [Hash] options specify query values + # @return payload of an ingestion error + # @raise [Exceptions::BadRequestError] when CDRIS returns a 4xx status + def ingestion_error_by_id(params, options = {}) + path = "#{api(options)}/patient_document/ingestion_error" + path << "/#{params[:id]}" if params[:id] + request(path, options) + .if_400_raise(Cdris::Gateway::Exceptions::BadRequestError) + .if_403_raise(Cdris::Gateway::Exceptions::InvalidTenantOperation) + .to_hash + end + # Gets a list of a hl7 document ids # # @param [Hash] params specify which documents to get, must specify `:root` diff --git a/lib/cdris/gateway/version.rb b/lib/cdris/gateway/version.rb index 9c840e1..1e74313 100644 --- a/lib/cdris/gateway/version.rb +++ b/lib/cdris/gateway/version.rb @@ -1,5 +1,5 @@ module Cdris module Gateway - VERSION = '4.5.0dev0.00'.freeze + VERSION = '4.5.0dev0.01'.freeze end end diff --git a/spec/cdris/gateway/patient_document_spec.rb b/spec/cdris/gateway/patient_document_spec.rb index fc94a57..8db9472 100644 --- a/spec/cdris/gateway/patient_document_spec.rb +++ b/spec/cdris/gateway/patient_document_spec.rb @@ -487,7 +487,7 @@ 'http://testhost:4242/api/v1/patient_document/ingestion_errors?user%5Bextension%5D=spameggs&user%5Broot%5D=foobar', body: DataSamples.ingestion_errors.to_s) - it 'requests and returns the expected patient cluster' do + it 'requests and returns the list of ingestion errors' do expect(described_class.ingestion_errors( {}, { user: { root: 'foobar', extension: 'spameggs' } @@ -496,6 +496,23 @@ end + describe 'self.ingestion_error_by_id' do + + FakeWeb.register_uri( + :get, + 'http://testhost:4242/api/v1/patient_document/ingestion_error?user%5Bextension%5D=spameggs&user%5Broot%5D=foobar', + body: DataSamples.ingestion_error.to_s) + + it 'requests and returns the ingestion error by id' do + expect(described_class.ingestion_error_by_id( + {}, { + user: { root: 'foobar', extension: 'spameggs' } + })).to eq(DataSamples.ingestion_error.to_hash) + end + + end + + describe 'self.base_uri' do context 'when id, root and extension are not given' do diff --git a/spec/fixtures/sample_ingestion_error.json b/spec/fixtures/sample_ingestion_error.json new file mode 100644 index 0000000..9bb960b --- /dev/null +++ b/spec/fixtures/sample_ingestion_error.json @@ -0,0 +1,8 @@ +[ + { + "id" :"1", + "created_at" : "2018-12-13T21:39:14.497Z", + "patient_document_root" : "root.d", + "error_response_reason" : "{\"data_format\":[\"can't be blank\",\"is not included in the list\"],\"source_last_modified_at\":[\"can't be blank\"]}" + } +] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec05e5f..bfa0089 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -118,6 +118,11 @@ def self.ingestion_errors self end + def self.ingestion_error + read_fixture('sample_ingestion_error.json') + self + end + def self.info_deployments read_fixture('sample_info_deployments.json') self