From b8f6c85746bd698b2f284d9390e7ac8b09cbf788 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Mon, 25 Mar 2024 11:57:54 -0700 Subject: [PATCH] 78648 do not call refresh_appts for OH claims --- .../v2/patient_check_ins_controller.rb | 3 +- .../app/models/check_in/v2/session.rb | 3 +- .../app/services/v2/lorota/service.rb | 11 +++---- .../spec/models/check_in/v2/session_spec.rb | 4 +++ .../spec/services/v2/lorota/service_spec.rb | 30 +++++++++++++++++-- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/modules/check_in/app/controllers/check_in/v2/patient_check_ins_controller.rb b/modules/check_in/app/controllers/check_in/v2/patient_check_ins_controller.rb index 9a283417b16..582c0f6f63c 100644 --- a/modules/check_in/app/controllers/check_in/v2/patient_check_ins_controller.rb +++ b/modules/check_in/app/controllers/check_in/v2/patient_check_ins_controller.rb @@ -7,7 +7,8 @@ class PatientCheckInsController < CheckIn::ApplicationController after_action :after_logger, only: %i[show create] def show - check_in_session = CheckIn::V2::Session.build(data: { uuid: params[:id], handoff: handoff? }, + check_in_session = CheckIn::V2::Session.build(data: { uuid: params[:id], handoff: handoff?, + facility_type: params[:facilityType] }, jwt: low_auth_token) unless check_in_session.authorized? diff --git a/modules/check_in/app/models/check_in/v2/session.rb b/modules/check_in/app/models/check_in/v2/session.rb index 0678b23c931..a17d7efab75 100644 --- a/modules/check_in/app/models/check_in/v2/session.rb +++ b/modules/check_in/app/models/check_in/v2/session.rb @@ -25,7 +25,7 @@ class Session DOB_REGEX = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/ LAST_NAME_REGEX = /^.{1,600}$/ - attr_reader :uuid, :dob, :last_name, :settings, :jwt, :check_in_type, :handoff + attr_reader :uuid, :dob, :last_name, :settings, :jwt, :check_in_type, :handoff, :facility_type def_delegators :settings, :redis_session_prefix @@ -46,6 +46,7 @@ def initialize(opts) @last_name = opts.dig(:data, :last_name) @check_in_type = opts.dig(:data, :check_in_type) @handoff = opts.dig(:data, :handoff) + @facility_type = opts.dig(:data, :facility_type) end # diff --git a/modules/check_in/app/services/v2/lorota/service.rb b/modules/check_in/app/services/v2/lorota/service.rb index 6504b0cfcab..cc339b99b74 100644 --- a/modules/check_in/app/services/v2/lorota/service.rb +++ b/modules/check_in/app/services/v2/lorota/service.rb @@ -87,7 +87,7 @@ def check_in_data raw_data = if token.present? - chip_service.refresh_appointments if appointment_identifiers.present? + chip_service.refresh_appointments if refresh_appointments? lorota_client.data(token:) end @@ -101,15 +101,16 @@ def check_in_data patient_check_in.approved end - def appointment_identifiers - Rails.cache.read( + private + + def refresh_appointments? + appointment_identifiers = Rails.cache.read( "check_in_lorota_v2_appointment_identifiers_#{check_in.uuid}", namespace: 'check-in-lorota-v2-cache' ) + appointment_identifiers.present? && !'oh'.casecmp?(check_in.facility_type) end - private - def error_message_handler(e) case Oj.load(e.original_body).fetch('error').strip.downcase when *LOROTA_401_ERROR_MESSAGES diff --git a/modules/check_in/spec/models/check_in/v2/session_spec.rb b/modules/check_in/spec/models/check_in/v2/session_spec.rb index a2ecd3bc8e7..8d53eb70e0e 100644 --- a/modules/check_in/spec/models/check_in/v2/session_spec.rb +++ b/modules/check_in/spec/models/check_in/v2/session_spec.rb @@ -52,6 +52,10 @@ it 'responds to handoff' do expect(subject.build({}).respond_to?(:handoff)).to be(true) end + + it 'responds to facility_type' do + expect(subject.build({}).respond_to?(:facility_type)).to be(true) + end end describe '#valid?' do diff --git a/modules/check_in/spec/services/v2/lorota/service_spec.rb b/modules/check_in/spec/services/v2/lorota/service_spec.rb index 84ec3476305..500086b98f6 100644 --- a/modules/check_in/spec/services/v2/lorota/service_spec.rb +++ b/modules/check_in/spec/services/v2/lorota/service_spec.rb @@ -680,6 +680,10 @@ .and_return(Faraday::Response.new(response_body: appointment_data.to_json, status: 200)) end + it 'returns approved data' do + expect(subject.build(check_in: valid_check_in).check_in_data).to eq(approved_response) + end + context 'when check_in_type is preCheckIn' do let(:opts) { { data: { check_in_type: 'preCheckIn' } } } let(:pre_check_in) { CheckIn::V2::Session.build(opts) } @@ -702,8 +706,30 @@ end end - it 'returns approved data' do - expect(subject.build(check_in: valid_check_in).check_in_data).to eq(approved_response) + context 'when appt identifiers are not present' do + it 'does not call refresh_appts' do + expect_any_instance_of(::V2::Chip::Service).not_to receive(:refresh_appointments) + + expect(subject.build(check_in: valid_check_in).check_in_data).to eq(approved_response) + end + end + + context 'when appt identifiers are present and facility type is OH' do + let(:valid_check_in_oh) { CheckIn::V2::Session.build(opts.deep_merge!({ data: { facility_type: 'oh' } })) } + + before do + Rails.cache.write( + "check_in_lorota_v2_appointment_identifiers_#{id}", + '123', + namespace: 'check-in-lorota-v2-cache' + ) + end + + it 'does not call refresh_appts' do + expect_any_instance_of(::V2::Chip::Service).not_to receive(:refresh_appointments) + + expect(subject.build(check_in: valid_check_in_oh).check_in_data).to eq(approved_response) + end end end end