Skip to content

Commit

Permalink
Update Vaos appointment type determination logic (#19710)
Browse files Browse the repository at this point in the history
* update type logic

* rubocop formatting

* more lint refactoring

* set type to cc request or appointment if kind is cc

* linting and tests
  • Loading branch information
drewconnelly authored Dec 16, 2024
1 parent d6f9b1a commit 8cd2071
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 12 deletions.
63 changes: 51 additions & 12 deletions modules/vaos/app/services/vaos/v2/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,20 @@ def filter_reason_code_text(request_object_body)
VAOS::Strings.filter_ascii_characters(text) if text.present?
end

# Determines if the appointment is a Cerner (Oracle Health) appointment.
# This is determined by the presence of a 'CERN' prefix in the appointment's id.
#
# @param appt [Hash] the appointment to check
# @return [Boolean] true if the appointment is a Cerner appointment, false otherwise
#
# @raise [ArgumentError] if the appointment is nil
#
def cerner?(appt)
raise ArgumentError, 'Appointment cannot be nil' if appt.nil?

appt[:id].start_with?('CERN')
end

# Checks if the appointment is booked.
#
# @param appt [Hash] the appointment to check
Expand Down Expand Up @@ -691,22 +705,47 @@ def log_direct_schedule_submission_errors(e)
end

def set_type(appointment)
type = APPOINTMENT_TYPES[:request] if appointment[:kind] != 'cc' && appointment[:request_periods].present?

type ||= case appointment[:kind]
when 'cc'
if appointment[:start]
APPOINTMENT_TYPES[:cc_appointment]
else
APPOINTMENT_TYPES[:cc_request]
end
else
APPOINTMENT_TYPES[:va]
end
type = if cerner?(appointment)
cerner_type(appointment)
else
non_cerner_type(appointment)
end

appointment[:type] = type
end

# Determines the type of appointment for Cerner appointments.
# @param appointment [Hash] the appointment to determine the type for
#
# @return [String] the type of appointment
#
def cerner_type(appointment)
if appointment[:end].present?
appointment[:kind] == 'cc' ? APPOINTMENT_TYPES[:cc_appointment] : APPOINTMENT_TYPES[:va]
else
appointment[:kind] == 'cc' ? APPOINTMENT_TYPES[:cc_request] : APPOINTMENT_TYPES[:request]
end
end

# Determines the type of appointment for non-Cerner appointments.
# @param appointment [Hash] the appointment to determine the type for
#
# @return [String] the type of appointment
#
def non_cerner_type(appointment)
if appointment[:kind] == 'cc'
if appointment[:requested_periods].present?
APPOINTMENT_TYPES[:cc_request]
else
APPOINTMENT_TYPES[:cc_appointment]
end
elsif appointment[:requested_periods].present?
APPOINTMENT_TYPES[:request]
else
APPOINTMENT_TYPES[:va]
end
end

# Modifies the appointment, setting the cancellable flag to false
#
# @param appointment [Hash] the appointment to modify
Expand Down
80 changes: 80 additions & 0 deletions modules/vaos/spec/services/v2/appointment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,20 @@
end
end

describe '#cerner?' do
it 'raises an ArgumentError if appt is nil' do
expect { subject.send(:cerner?, nil) }.to raise_error(ArgumentError, 'Appointment cannot be nil')
end

it 'returns true for appointments with a "CERN" prefix' do
expect(subject.send(:cerner?, { id: 'CERN99999' })).to eq(true)
end

it 'returns false for appointments without a "CERN" prefix' do
expect(subject.send(:cerner?, { id: '99999' })).to eq(false)
end
end

describe '#no_service_cat?' do
it 'raises an ArgumentError if appt is nil' do
expect { subject.send(:no_service_cat?, nil) }.to raise_error(ArgumentError, 'Appointment cannot be nil')
Expand Down Expand Up @@ -1643,4 +1657,70 @@
expect(appt[:preferred_dates]).not_to be_nil
end
end

describe '#set_type' do
it 'has a type of request for Cerner appointments without end dates' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = 'CERN1234'
appt[:end] = nil
subject.send(:set_type, appt)
expect(appt[:type]).to eq('REQUEST')
end

it 'is a VA appointment for Cerner appointments with a valid end date' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = 'CERN1234'
appt[:end] = :end_date
subject.send(:set_type, appt)
expect(appt[:type]).to eq('VA')
end

it 'is a cc appointment for appointments with kind = "cc" and a valid start date' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = :id
appt[:start] = :start_date
appt[:requested_periods] = []
appt[:kind] = 'cc'
subject.send(:set_type, appt)
expect(appt[:type]).to eq('COMMUNITY_CARE_APPOINTMENT')
end

it 'is a cc request for appointments with kind = "cc" and at least one requested period' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = :id
appt[:kind] = 'cc'
appt[:requested_periods] = [{ start: '2024-06-26T12:00:00Z', end: '2024-06-26T13:00:00Z' }]
subject.send(:set_type, appt)
expect(appt[:type]).to eq('COMMUNITY_CARE_REQUEST')
end

it 'is a request for appointments with kind other than "cc" and at least one requested period' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = :id
appt[:kind] = 'telehealth'
appt[:requested_periods] = [{ start: '2024-06-26T12:00:00Z', end: '2024-06-26T13:00:00Z' }]
subject.send(:set_type, appt)
expect(appt[:type]).to eq('REQUEST')
end

it 'is a request for appointments with kind = "cc" and no start date or requested periods' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = :id
appt[:kind] = 'cc'
appt[:start] = nil
appt[:requested_periods] = []
subject.send(:set_type, appt)
expect(appt[:type]).to eq('COMMUNITY_CARE_APPOINTMENT')
end

it 'is a cc request for Cerner with no start date or requested periods' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
appt[:id] = 'CERN1234'
appt[:kind] = 'cc'
appt[:start] = nil
appt[:requested_periods] = []
subject.send(:set_type, appt)
expect(appt[:type]).to eq('COMMUNITY_CARE_REQUEST')
end
end
end

0 comments on commit 8cd2071

Please sign in to comment.