-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:department-of-veterans-affairs/ve…
…ts-api into ndbex/69209-ch36-to-benefits-intake
- Loading branch information
Showing
155 changed files
with
4,939 additions
and
1,750 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
db/migrate/20240411153910_create_accredited_individuals.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAccreditedIndividuals < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :accredited_individuals, id: :uuid do |t| | ||
t.uuid :ogc_id, null: false | ||
t.string :registration_number, null: false | ||
t.string :poa_code, limit: 3, index: true | ||
t.string :individual_type, null: false | ||
t.string :first_name | ||
t.string :middle_initial | ||
t.string :last_name | ||
t.string :full_name, index: true | ||
t.string :email | ||
t.string :phone | ||
t.string :address_type | ||
t.string :address_line1 | ||
t.string :address_line2 | ||
t.string :address_line3 | ||
t.string :city | ||
t.string :country_code_iso3 | ||
t.string :country_name | ||
t.string :county_name | ||
t.string :county_code | ||
t.string :international_postal_code | ||
t.string :province | ||
t.string :state_code | ||
t.string :zip_code | ||
t.string :zip_suffix | ||
t.jsonb :raw_address | ||
t.float :lat | ||
t.float :long | ||
t.geography :location, limit: { srid: 4326, type: 'st_point', geographic: true } | ||
t.timestamps | ||
|
||
t.index :location, using: :gist | ||
t.index %i[ registration_number individual_type ], name: 'index_on_reg_num_and_type_for_accredited_individuals', unique: true | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# frozen_string_literal: true | ||
|
||
module BenefitsIntake | ||
## | ||
# Validate the required metadata which must accompany an upload: | ||
# | ||
# { | ||
# 'veteranFirstName': String, | ||
# 'veteranLastName': String, | ||
# 'fileNumber': String, # 8-9 digits | ||
# 'zipCode': String, # 5 or 9 digits | ||
# 'source': String, | ||
# 'docType': String, | ||
# 'businessLine': String, # optional; enum in BUSINESS_LINE | ||
# } | ||
# | ||
# https://developer.va.gov/explore/api/benefits-intake/docs | ||
# | ||
class Metadata | ||
BUSINESS_LINE = { | ||
CMP: 'Compensation requests such as those related to disability, unemployment, and pandemic claims', | ||
PMC: 'Pension requests including survivor’s pension', | ||
INS: 'Insurance such as life insurance, disability insurance, and other health insurance', | ||
EDU: 'Education benefits, programs, and affiliations', | ||
VRE: 'Veteran Readiness & Employment such as employment questionnaires, ' \ | ||
'employment discrimination, employment verification', | ||
BVA: 'Board of Veteran Appeals', | ||
FID: 'Fiduciary / financial appointee, including family member benefits', | ||
NCA: 'National Cemetery Administration', | ||
OTH: 'Other (this value if used, will be treated as CMP)' | ||
}.freeze | ||
|
||
# rubocop:disable Metrics/ParameterLists | ||
def self.generate(first_name, last_name, file_number, zip_code, source, doc_type, business_line = nil) | ||
validate({ | ||
'veteranFirstName' => first_name, | ||
'veteranLastName' => last_name, | ||
'fileNumber' => file_number, | ||
'zipCode' => zip_code, | ||
'source' => source, | ||
'docType' => doc_type, | ||
'businessLine' => business_line | ||
}) | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
def self.validate(metadata) | ||
validate_first_name(metadata) | ||
.then { |m| validate_last_name(m) } | ||
.then { |m| validate_file_number(m) } | ||
.then { |m| validate_zip_code(m) } | ||
.then { |m| validate_source(m) } | ||
.then { |m| validate_doc_type(m) } | ||
.then { |m| validate_business_line(m) } | ||
end | ||
|
||
def self.validate_first_name(metadata) | ||
validate_presence_and_stringiness(metadata['veteranFirstName'], 'veteran first name') | ||
|
||
first_name = I18n.transliterate(metadata['veteranFirstName']).gsub(%r{[^a-zA-Z\-\/\s]}, '').strip.first(50) | ||
validate_nonblank(first_name, 'veteran first name') | ||
|
||
metadata['veteranFirstName'] = first_name | ||
metadata | ||
end | ||
|
||
def self.validate_last_name(metadata) | ||
validate_presence_and_stringiness(metadata['veteranLastName'], 'veteran last name') | ||
|
||
last_name = I18n.transliterate(metadata['veteranLastName']).gsub(%r{[^a-zA-Z\-\/\s]}, '').strip.first(50) | ||
validate_nonblank(last_name, 'veteran last name') | ||
|
||
metadata['veteranLastName'] = last_name | ||
metadata | ||
end | ||
|
||
def self.validate_file_number(metadata) | ||
validate_presence_and_stringiness(metadata['fileNumber'], 'file number') | ||
unless metadata['fileNumber'].match?(/^\d{8,9}$/) | ||
raise ArgumentError, 'file number is invalid. It must be 8 or 9 digits' | ||
end | ||
|
||
metadata | ||
end | ||
|
||
def self.validate_zip_code(metadata) | ||
validate_presence_and_stringiness(metadata['zipCode'], 'zip code') | ||
|
||
zip_code = metadata['zipCode'].dup.gsub(/[^0-9]/, '') | ||
zip_code.insert(5, '-') if zip_code.match?(/\A[0-9]{9}\z/) | ||
zip_code = '00000' unless zip_code.match?(/\A[0-9]{5}(-[0-9]{4})?\z/) | ||
|
||
metadata['zipCode'] = zip_code | ||
|
||
metadata | ||
end | ||
|
||
def self.validate_source(metadata) | ||
validate_presence_and_stringiness(metadata['source'], 'source') | ||
|
||
metadata | ||
end | ||
|
||
def self.validate_doc_type(metadata) | ||
validate_presence_and_stringiness(metadata['docType'], 'doc type') | ||
|
||
metadata | ||
end | ||
|
||
def self.validate_business_line(metadata) | ||
bl = metadata['businessLine'] | ||
if bl | ||
bl = bl.dup.to_s.upcase.to_sym | ||
bl = :OTH unless BUSINESS_LINE.key?(bl) | ||
metadata['businessLine'] = bl.to_s | ||
else | ||
metadata.delete('businessLine') | ||
end | ||
|
||
metadata | ||
end | ||
|
||
def self.validate_presence_and_stringiness(value, error_label) | ||
raise ArgumentError, "#{error_label} is missing" unless value | ||
raise ArgumentError, "#{error_label} is not a string" if value.class != String | ||
end | ||
|
||
def self.validate_nonblank(value, error_label) | ||
raise ArgumentError, "#{error_label} is blank" if value.blank? | ||
end | ||
end | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
modules/check_in/spec/services/check_in/vaos/appointment_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe CheckIn::VAOS::AppointmentService do | ||
subject { described_class.new(patient_icn:) } | ||
|
||
let(:patient_icn) { '123' } | ||
let(:token) { 'test_token' } | ||
let(:request_id) { SecureRandom.uuid } | ||
|
||
describe '#initialize' do | ||
it 'returns an instance of service' do | ||
service_obj = subject | ||
expect(service_obj).to be_an_instance_of(CheckIn::VAOS::AppointmentService) | ||
expect(service_obj.token_service).to be_an_instance_of(CheckIn::Map::TokenService) | ||
end | ||
end | ||
|
||
describe '#perform' do | ||
let(:token) { 'test-token-123' } | ||
let(:start_date) { '2023-11-10T17:12:30Z' } | ||
let(:end_date) { '2023-12-12T17:12:30Z' } | ||
let(:statuses) { 'confirmed' } | ||
let(:appointments_response) do | ||
{ | ||
data: [ | ||
{ | ||
id: '180765', | ||
kind: 'clinic', | ||
status: 'booked', | ||
patientIcn: 'icn', | ||
locationId: '983GC', | ||
clinic: '1081', | ||
start: '2023-11-02T17:12:30.174Z', | ||
end: '2023-12-12T17:12:30.174Z', | ||
minutesDuration: 30 | ||
} | ||
] | ||
}.with_indifferent_access | ||
end | ||
let(:faraday_response) { double('Faraday::Response') } | ||
let(:faraday_env) { double('Faraday::Env', status: 200, body: appointments_response.to_json) } | ||
|
||
context 'when vaos returns successful response' do | ||
before do | ||
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token) | ||
.and_return(token) | ||
allow_any_instance_of(Faraday::Connection).to receive(:get).with('/vaos/v1/patients/123/appointments', | ||
{ start: start_date, end: end_date, | ||
statuses: }) | ||
.and_return(faraday_response) | ||
allow(faraday_response).to receive(:env).and_return(faraday_env) | ||
end | ||
|
||
it 'returns appointments' do | ||
response = subject.get_appointments(DateTime.parse(start_date).in_time_zone, | ||
DateTime.parse(end_date).in_time_zone, | ||
statuses) | ||
expect(response).to eq(appointments_response) | ||
end | ||
end | ||
|
||
context 'when vaos returns server error' do | ||
let(:resp) { Faraday::Response.new(body: { error: 'Internal server error' }, status: 500) } | ||
let(:exception) { Common::Exceptions::BackendServiceException.new(nil, {}, resp.status, resp.body) } | ||
|
||
before do | ||
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token) | ||
.and_return(token) | ||
allow_any_instance_of(Faraday::Connection).to receive(:get).with('/vaos/v1/patients/123/appointments', | ||
{ start: start_date, end: end_date, | ||
statuses: }) | ||
.and_raise(exception) | ||
end | ||
|
||
it 'throws exception' do | ||
expect do | ||
subject.get_appointments(DateTime.parse(start_date).in_time_zone, | ||
DateTime.parse(end_date).in_time_zone, | ||
statuses) | ||
end.to(raise_error do |error| | ||
expect(error).to be_a(Common::Exceptions::BackendServiceException) | ||
end) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.