diff --git a/lib/rx/client.rb b/lib/rx/client.rb index 4e62136e59a..830efd47923 100644 --- a/lib/rx/client.rb +++ b/lib/rx/client.rb @@ -135,7 +135,8 @@ def post_refill_rxs(ids) # def post_refill_rx(id) if (result = perform(:post, "prescription/rxrefill/#{id}", nil, token_headers)) - Common::Collection.bust([cache_key('getactiverx'), cache_key('gethistoryrx')]) + keys = [cache_key('getactiverx'), cache_key('gethistoryrx')].compact + Common::Collection.bust(keys) unless keys.empty? end result end diff --git a/modules/my_health/app/controllers/my_health/v1/prescriptions_controller.rb b/modules/my_health/app/controllers/my_health/v1/prescriptions_controller.rb index f1187aa11bd..435947a17d9 100644 --- a/modules/my_health/app/controllers/my_health/v1/prescriptions_controller.rb +++ b/modules/my_health/app/controllers/my_health/v1/prescriptions_controller.rb @@ -50,14 +50,16 @@ def refill def refill_prescriptions ids = params[:ids] - begin - ids.each do |id| - client.post_refill_rx(id) - end + successful_ids = [] + failed_ids = [] + ids.each do |id| + client.post_refill_rx(id) + successful_ids << id rescue => e - puts "Error refilling prescription: #{e.message}" + puts "Error refilling prescription with ID #{id}: #{e.message}" + failed_ids << id end - head :no_content + render json: { successful_ids:, failed_ids: } end def list_refillable_prescriptions diff --git a/spec/lib/rx/client_spec.rb b/spec/lib/rx/client_spec.rb index 32f54fdaec5..4caef3f48d9 100644 --- a/spec/lib/rx/client_spec.rb +++ b/spec/lib/rx/client_spec.rb @@ -94,7 +94,7 @@ if caching_enabled expect(Common::Collection).to receive(:bust).with(cache_keys) else - expect(Common::Collection).to receive(:bust).with([nil, nil]) + expect(Common::Collection).not_to receive(:bust).with([nil, nil]) end client_response = client.post_refill_rx(13_650_545)