Skip to content

Commit

Permalink
Mhv 61572 add filter for rx vagov (#19313)
Browse files Browse the repository at this point in the history
* [MHV 61572] made disp_status a fitlerable attribute and overrited the filter_params method in Filterable moduleto permit the PrescriptionDetails model filterable attributes.

* [MHV 61572] added spec for a filtered list with pagination.
  • Loading branch information
robertbylight authored Nov 7, 2024
1 parent 9e324f7 commit 2ec7ecc
Show file tree
Hide file tree
Showing 5 changed files with 7,619 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/prescription_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PrescriptionDetails < Prescription
attribute :modified_date, Common::UTCTime, sortable: { order: 'ASC' }
attribute :institution_id, String
attribute :dial_cmop_division_phone, String
attribute :disp_status, String, sortable: { order: 'ASC' }
attribute :disp_status, String, sortable: { order: 'ASC' }, filterable: %w[eq not_eq]
attribute :ndc, String
attribute :reason, String
attribute :prescription_number_index, String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ def get_image_uri(cmop_ndc_number)
"#{image_root_uri + folder_name}/#{file_name}"
end

def filter_params
@filter_params ||= begin
valid_filter_params = params.require(:filter).permit(PrescriptionDetails.filterable_attributes)
raise Common::Exceptions::FilterNotAllowed, params[:filter] if valid_filter_params.empty?

valid_filter_params
end
end

def collection_resource
case params[:refill_status]
when nil
Expand Down
16 changes: 16 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 @@ -265,6 +265,22 @@
expect(response).to match_camelized_response_schema('my_health/prescriptions/v1/prescription_list_filtered')
end

it 'responds to GET #index with filter and pagination' do
VCR.use_cassette('rx_client/prescriptions/gets_a_list_of_all_prescriptions_vagov') do
get '/my_health/v1/prescriptions?page=1&per_page=100&filter[[disp_status][eq]]=Active: Refill in Process'
end

filtered_response = JSON.parse(response.body)['data'].select do |i|
i['attributes']['disp_status'] == 'Active: Refill in Process'
end

expect(response).to be_successful
expect(response.body).to be_a(String)
expect(response).to match_response_schema('my_health/prescriptions/v1/prescription_list_filtered_with_pagination')
expect(filtered_response.length).to eq(JSON.parse(response.body)['data'].length)
expect(filtered_response.length).to eq(JSON.parse(response.body)['meta']['pagination']['total_entries'])
end

it 'responds to POST #refill' do
VCR.use_cassette('rx_client/prescriptions/refills_a_prescription') do
patch '/my_health/v1/prescriptions/13650545/refill'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": ["data", "meta"],
"properties": {
"data": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"$ref": "prescription_details.json"
}
},
"meta": {
"type": "object",
"required": ["updated_at", "failed_station_list", "sort"],
"properties": {
"updated_at": { "type": "string" },
"failed_station_list": { "type": "string" },
"filter": {
"type": "object"
},
"sort": {
"type": "object"
},
"pagination": {
"type": "object",
"required": ["current_page", "per_page", "total_pages", "total_entries"],
"properties": {
"current_page": { "type": "integer" },
"per_page": { "type": "integer" },
"total_pages": { "type": "integer" },
"total_entries": { "type": "integer" }
}
}
}
},
"links": {
"type": "object",
"required": ["self", "first", "prev", "next", "last"],
"properties": {
"self": { "type": "string" },
"first": { "type": "string" },
"prev": { "type": ["string", "null"] },
"next": { "type": ["string", "null"] },
"last": { "type": "string" }
}
}
}
}
Loading

0 comments on commit 2ec7ecc

Please sign in to comment.