Skip to content

Commit

Permalink
Extract reason code text fields from DS appointments (#17626)
Browse files Browse the repository at this point in the history
* Extract reason code text fields from DS appointments

* Fix naming after rebase
  • Loading branch information
JunTaoLuo authored Jul 25, 2024
1 parent 6b6c53a commit 5a0db5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class AppointmentsReasonCodeService
#
# @param appointment [Hash] the appointment to modify
def extract_reason_code_fields(appointment)
# Return if the appointment is a CC request or not a request.
# We consider appointments with requested_periods as requests.
return if appointment[:kind] == 'cc' || appointment[:requested_periods].blank?

# Retrieve the reason code text, or return if it is not present
reason_code_text = appointment&.dig(:reason_code, :text)
return if reason_code_text.nil?
Expand All @@ -39,10 +35,18 @@ def extract_reason_code_fields(appointment)
.to_h { |pair| pair.split(':').map!(&:strip) }
return if reason_code_hash.empty?

contact = extract_contact_fields(reason_code_hash)
comments = reason_code_hash['comments'] if reason_code_hash.key?('comments')
reason = extract_reason_for_appointment(reason_code_hash)
preferred_dates = extract_preferred_dates(reason_code_hash)
# Direct Scheduling appointments
if appointment[:kind] == 'clinic' && appointment[:status] == 'booked'
comments = reason_code_hash['comments'] if reason_code_hash.key?('comments')
reason = extract_reason_for_appointment(reason_code_hash)

# Appointment requests
elsif appointment[:requested_periods].present? && appointment[:kind] != 'cc'
contact = extract_contact_fields(reason_code_hash)
comments = reason_code_hash['comments'] if reason_code_hash.key?('comments')
reason = extract_reason_for_appointment(reason_code_hash)
preferred_dates = extract_preferred_dates(reason_code_hash)
end

appointment[:contact] = contact unless contact.nil?
appointment[:patient_comments] = comments unless comments.nil?
Expand Down
17 changes: 15 additions & 2 deletions modules/vaos/spec/factories/v2/appointment_forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@

trait :va_proposed_valid_reason_code_text do
va_proposed_base
kind { 'clinic' }
reason_code do
{ 'text': 'station id: 983|preferred modality: FACE TO FACE|phone number: 6195551234|email: myemail72585885@unattended.com|preferred dates:06/26/2024 AM,06/26/2024 PM|reason code:ROUTINEVISIT|comments:test' } # rubocop:disable Layout/LineLength
end
Expand Down Expand Up @@ -263,13 +264,26 @@
kind { 'phone' }
end

trait :with_direct_scheduling do
trait :with_direct_scheduling_base do
kind { 'cc' }
status { 'booked' }
location_id { '983' }
practitioner_ids { [{ system: 'HSRM', value: '1234567890' }] }
preferred_language { 'English' }
reason { 'Testing' }
service_type { 'CCPOD' }
end

trait :ds_cc_booked_valid_reason_code_text do
with_direct_scheduling_base

reason_code do
{ 'text': 'station id: 983|preferred modality: FACE TO FACE|phone number: 6195551234|email: myemail72585885@unattended.com|preferred dates:06/26/2024 AM,06/26/2024 PM|reason code:ROUTINEVISIT|comments:test' } # rubocop:disable Layout/LineLength
end
end

trait :with_direct_scheduling do
with_direct_scheduling_base

contact do
{
Expand All @@ -286,7 +300,6 @@
}
end

service_type { 'CCPOD' }
requested_periods do
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@
expect(appt[:preferred_dates]).to be_nil
end

it 'returns without modification for va booked' do
appt = FactoryBot.build(:appointment_form_v2, :va_booked_valid_reason_code_text).attributes
it 'returns without modification for cc booked' do
appt = FactoryBot.build(:appointment_form_v2, :ds_cc_booked_valid_reason_code_text).attributes
subject.extract_reason_code_fields(appt)
expect(appt[:contact]).to eq({})
expect(appt[:patient_comments]).to be_nil
expect(appt[:reason_for_appointment]).to be_nil
expect(appt[:preferred_dates]).to be_nil
end

it 'extract valid reason text for va request' do
it 'extract valid reason code fields for va direct scheduling appointments' do
appt = FactoryBot.build(:appointment_form_v2, :va_booked_valid_reason_code_text).attributes
subject.extract_reason_code_fields(appt)
expect(appt[:contact]).to eq({})
expect(appt[:patient_comments]).to eq('test')
expect(appt[:reason_for_appointment]).to eq('Routine/Follow-up')
expect(appt[:preferred_dates]).to be_nil
end

it 'extract valid reason code fields for va request' do
appt = FactoryBot.build(:appointment_form_v2, :va_proposed_valid_reason_code_text).attributes
subject.extract_reason_code_fields(appt)
expect(appt[:contact][:telecom][0]).to eq({ type: 'phone', value: '6195551234' })
Expand Down

0 comments on commit 5a0db5f

Please sign in to comment.