Skip to content

Commit

Permalink
58400 appointment details comment logging (#12848)
Browse files Browse the repository at this point in the history
* appointment details comment logging
  • Loading branch information
cferris32 authored May 31, 2023
1 parent 7ec7ae1 commit 8bb4baa
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 4 deletions.
38 changes: 34 additions & 4 deletions modules/vaos/app/controllers/vaos/v2/appointments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ module VAOS
module V2
class AppointmentsController < VAOS::BaseController
STATSD_KEY = 'api.vaos.va_mobile.response.partial'
NPI_NOT_FOUND_MSG = "We're sorry, we can't display your provider's information right now."
PAP_COMPLIANCE_TELE = 'PAP COMPLIANCE/TELE'
PAP_COMPLIANCE_TELE_KEY = 'PAP COMPLIANCE/TELE Appointment Details'
FACILITY_ERROR_MSG = 'Error fetching facility details'
APPT_INDEX = 'Appointment Index'
APPT_SHOW = 'Appointment Show'
APPT_CREATE = 'Appointment Create'

# cache utilized by the controller to store key/value pairs of provider name and npi
# in order to prevent duplicate service call lookups during index/show/create
Expand All @@ -24,6 +31,10 @@ def index
_include&.include?('clinics') && merge_clinics(appointments[:data])
_include&.include?('facilities') && merge_facilities(appointments[:data])

appointments[:data].each do |appt|
log_pap_compliance_appt_data(appt, APPT_INDEX) if appt&.[](:reason)&.include? PAP_COMPLIANCE_TELE
end

serializer = VAOS::V2::VAOSSerializer.new
serialized = serializer.serialize(appointments[:data], 'appointments')

Expand Down Expand Up @@ -51,6 +62,10 @@ def show

appointment[:location] = get_facility(appointment[:location_id]) unless appointment[:location_id].nil?

if appointment&.[](:reason_code)&.[](:text)&.include? PAP_COMPLIANCE_TELE
log_pap_compliance_appt_data(appointment, APPT_SHOW)
end

serializer = VAOS::V2::VAOSSerializer.new
serialized = serializer.serialize(appointment, 'appointments')
render json: { data: serialized }
Expand All @@ -72,6 +87,11 @@ def create
unless new_appointment[:location_id].nil?
new_appointment[:location] = get_facility(new_appointment[:location_id])
end

if new_appointment&.[](:reason_code)&.[](:text)&.include? PAP_COMPLIANCE_TELE
log_pap_compliance_appt_data(new_appointment, APPT_CREATE)
end

serializer = VAOS::V2::VAOSSerializer.new
serialized = serializer.serialize(new_appointment, 'appointments')
render json: { data: serialized }, status: :created
Expand Down Expand Up @@ -142,8 +162,6 @@ def updated_appointment
# will cache at the class level the key value pair of npi and provider name to avoid
# duplicate get_provider_with_cache calls

NPI_NOT_FOUND_MSG = "We're sorry, we can't display your provider's information right now."

def find_and_merge_provider_name(appt)
found_npi = find_npi(appt)
if found_npi
Expand Down Expand Up @@ -225,8 +243,6 @@ def add_timezone_offset(date, tz)
utc_date.change(offset: timezone_offset).to_datetime
end

FACILITY_ERROR_MSG = 'Error fetching facility details'

# Returns the facility timezone id (eg. 'America/New_York') associated with facility id (location_id)
def get_facility_timezone(facility_location_id)
facility_info = get_facility(facility_location_id)
Expand Down Expand Up @@ -294,6 +310,20 @@ def get_facility(location_id)
FACILITY_ERROR_MSG
end

def log_pap_compliance_appt_data(appt, appt_method)
pap_compliance_entry = { PAP_COMPLIANCE_TELE_KEY => pap_compliance_details(appt[:location_id], appt[:clinic],
appt_method) }
Rails.logger.info('Details for PAP COMPLIANCE/TELE appointment', pap_compliance_entry.to_json)
end

def pap_compliance_details(location_id, clinic, appt_method)
{
endpoint_method: appt_method,
location_id:,
clinic:
}
end

def update_appt_id
params.require(:id)
end
Expand Down
42 changes: 42 additions & 0 deletions modules/vaos/spec/request/v2/appointments_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end

it 'creates the va appointment and logs appointment details when there is a PAP COMPLIANCE comment' do
VCR.use_cassette('vaos/v2/appointments/post_appointments_va_booked_200_and_log_facility',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
post '/vaos/v2/appointments', params: va_booked_request_body, headers: inflection_header
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
expect(Rails.logger).to have_received(:info).with('Details for PAP COMPLIANCE/TELE appointment',
any_args).at_least(:once)
end
end
end

describe 'GET appointments' do
Expand Down Expand Up @@ -177,6 +189,19 @@
end
end

it 'returns va appointments and logs details when there is a PAP COMPLIANCE comment' do
VCR.use_cassette('vaos/v2/appointments/get_appointments_200_with_facilities_200_and_log_pap_comp',
match_requests_on: %i[method path query], allow_playback_repeats: true) do
allow(Rails.logger).to receive(:info).at_least(:once)
get '/vaos/v2/appointments', params:, headers: inflection_header
expect(response).to have_http_status(:ok)
expect(response.body).to be_a(String)
expect(Rails.logger).to have_received(:info).with('Details for PAP COMPLIANCE/TELE appointment',
any_args).at_least(:once)
expect(response).to match_camelized_response_schema('vaos/v2/appointments', { strict: false })
end
end

it 'has access and returns a va appointments with no location id' do
VCR.use_cassette('vaos/v2/appointments/get_appointments_200_no_location_id',
match_requests_on: %i[method path query], allow_playback_repeats: true) do
Expand Down Expand Up @@ -319,6 +344,23 @@
end
end

it 'returns appointment and logs PAP COMPLIANCE details' do
VCR.use_cassette('vaos/v2/appointments/get_appointment_200_with_facility_200_and_log_pap_comp',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
get '/vaos/v2/appointments/70060', headers: inflection_header
expect(response).to have_http_status(:ok)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
data = JSON.parse(response.body)['data']

expect(data['id']).to eq('70060')
expect(data['attributes']['kind']).to eq('clinic')
expect(data['attributes']['status']).to eq('proposed')
expect(Rails.logger).to have_received(:info).with('Details for PAP COMPLIANCE/TELE appointment',
any_args).at_least(:once)
end
end

# TODO: verify this cc request spec with NPI changes
it 'has access and returns appointment - cc proposed' do
VCR.use_cassette('vaos/v2/appointments/get_appointment_200_cc_proposed_with_facility_200',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8bb4baa

Please sign in to comment.