Skip to content

Commit

Permalink
Mhv 65100 add grouping to single rx call (#19931)
Browse files Browse the repository at this point in the history
* [MHV 65100] added single rx get for grouped medications, subject to grouping feature flag

* [MHV 65100] spec for single grouped medication get request.

* [MHV 65100] addressed rubocop findings.

* [MHV 65100] addressed rubocop findings.
  • Loading branch information
robertbylight authored Dec 17, 2024
1 parent b926efc commit cb209cf
Show file tree
Hide file tree
Showing 5 changed files with 17,371 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ def index

def show
id = params[:id].try(:to_i)
resource = client.get_rx_details(id)
resource = if Flipper.enabled?(:mhv_medications_display_grouping)
get_single_rx_from_grouped_list(collection_resource.data, id)
else
client.get_rx_details(id)
end
raise Common::Exceptions::RecordNotFound, id if resource.blank?

options = { meta: resource.metadata }
options = if Flipper.enabled?(:mhv_medications_display_grouping)
{ meta: client.get_rx_details(id).metadata }
else
{ meta: resource.metadata }
end
render json: MyHealth::V1::PrescriptionDetailsSerializer.new(resource, options)
end

Expand Down
5 changes: 5 additions & 0 deletions modules/my_health/app/helpers/my_health/rx_grouping_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def group_prescriptions(prescriptions)
grouped_prescriptions
end

def get_single_rx_from_grouped_list(prescriptions, id)
grouped_list = group_prescriptions(prescriptions)
grouped_list.find { |rx| rx['prescription_id'] == id }
end

private

def add_solo_med_and_delete(grouped_prescriptions, prescriptions, prescription)
Expand Down
25 changes: 25 additions & 0 deletions modules/my_health/spec/requests/my_health/v1/prescriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@
expect(find_grouped_rx_in_base_list).to be_falsey
end

it 'responds to GET #show with a single grouped medication' do
prescription_id = '24891624'
VCR.use_cassette('rx_client/prescriptions/gets_a_single_grouped_prescription') do
get "/my_health/v1/prescriptions/#{prescription_id}"
end

expect(response).to be_successful
expect(response.body).to be_a(String)
expect(response).to match_response_schema('my_health/prescriptions/v1/prescription_single')
data = JSON.parse(response.body)['data']
expect(data).to be_truthy
expect(data['attributes']['prescription_id']).to eq(prescription_id.to_i)
end

it 'responds to GET #show with record not found when prescription_id is a part of a grouped medication' do
prescription_id = '22565799'
VCR.use_cassette('rx_client/prescriptions/gets_grouped_med_record_not_found') do
get "/my_health/v1/prescriptions/#{prescription_id}"
end

errors = JSON.parse(response.body)['errors'][0]
expect(errors).to be_truthy
expect(errors['detail']).to eq("The record identified by #{prescription_id} could not be found")
end

Flipper.disable('mhv_medications_display_grouping')
end

Expand Down
Loading

0 comments on commit cb209cf

Please sign in to comment.