Skip to content

Commit

Permalink
Merge branch 'pbp-95481-va-email-notification' of github.com:departme…
Browse files Browse the repository at this point in the history
…nt-of-veterans-affairs/vets-api into pbp-95481-va-email-notification
  • Loading branch information
wayne-weibel committed Oct 25, 2024
2 parents db75eab + fb3c8c3 commit 95be20f
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
permissions: write-all
runs-on: ubuntu-16-cores-latest
runs-on: ubuntu-32-cores-latest
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
permissions: write-all
runs-on: ubuntu-16-cores-latest
runs-on: ubuntu-32-cores-latest
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -131,13 +131,13 @@ jobs:
max_attempts: 3
command: |
docker compose -f docker-compose.test.yml run web bash \
-c "CI=true RAILS_ENV=test DISABLE_BOOTSNAP=true bundle exec parallel_test -n 13 -e 'bin/rails db:reset'"
-c "CI=true RAILS_ENV=test DISABLE_BOOTSNAP=true bundle exec parallel_test -n 24 -e 'bin/rails db:reset'"
- name: Run Specs
timeout-minutes: 20
run: |
docker compose -f docker-compose.test.yml run web bash \
-c "CI=true DISABLE_BOOTSNAP=true bundle exec parallel_rspec spec/ modules/ -n 13 -o '--color --tty'"
-c "CI=true DISABLE_BOOTSNAP=true bundle exec parallel_rspec spec/ modules/ -n 24 -o '--color --tty'"
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
Expand Down
24 changes: 21 additions & 3 deletions app/controllers/concerns/form_attachment_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,39 @@ def validate_file_upload_class!
raise Common::Exceptions::InvalidFieldValue.new('file_data', filtered_params[:file_data].class.name)
end
rescue => e
log_exception_to_sentry(e, { context: 'FAC_validate', class: filtered_params[:file_data].class.name })
log_message_to_sentry(
'form attachment error 1',
:info,
phase: 'FAC_validate',
klass: filtered_params[:file_data].class.name,
exception: e.message
)
raise e
end

def save_attachment_to_cloud!
form_attachment.set_file_data!(filtered_params[:file_data], filtered_params[:password])
rescue => e
log_exception_to_sentry(e, { context: 'FAC_cloud' })
log_message_to_sentry(
'form attachment error 2',
:info,
phase: 'FAC_cloud',
exception: e.message
)
raise e
end

def save_attachment_to_db!
form_attachment.save!
rescue => e
log_exception_to_sentry(e, { context: 'FAC_db', errors: form_attachment.errors })
log_message_to_sentry(
'form attachment error 3',
:info,
phase: 'FAC_db',
errors: form_attachment.errors,
exception: e.message
)

raise e
end

Expand Down
20 changes: 20 additions & 0 deletions lib/medical_records/bb_internal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ def get_dicom(study_id, header_callback, yielder)
end

##
# @param icn - user icn
# @param last_name - user last name
# @return JSON [{ dateGenerated, status, patientId }]
#
def get_generate_ccd(icn, last_name)
response = perform(:get, "bluebutton/healthsummary/#{icn}/#{last_name}/xml", nil, token_headers)
response.body
end

##
# @param date - receieved from get_generate_ccd call property dateGenerated (e.g. 2024-10-18T09:55:58.000-0400)
# @return - Continuity of Care Document in XML format
#
def get_download_ccd(date)
token_headers['Accept'] = 'application/xml'

response = perform(:get, "bluebutton/healthsummary/#{date}/fileFormat/XML/ccdType/XML", nil, token_headers)
response.body
end

# check the status of a study job
# @return [Array] - [{ status: "COMPLETE", studyIdUrn: "111-1234567" percentComplete: 100, fileSize: "1.01 MB",
# startDate: 1729777818853, endDate}]
Expand Down
2 changes: 1 addition & 1 deletion modules/check_in/app/services/travel_claim/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def token

resp = client.token

Oj.load(resp.body)&.fetch('access_token').tap do |access_token|
Oj.safe_load(resp.body)&.fetch('access_token').tap do |access_token|
redis_client.save_token(token: access_token)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module MyHealth
module V1
module MedicalRecords
class CcdController < MrController
# Generates a CCD
# @return [Array] of objects with CCDs generated date and status (COMPLETE or not)
def generate
resource = bb_client.get_generate_ccd(@current_user.icn, @current_user.last_name)
render json: resource.to_json
end

# Downloads the CCD once it has been generated
# @param generated_datetime [String] date receieved from get_generate_ccd call property dateGenerated
# @return [XML] Continuity of Care Document
def download
resource = bb_client.get_download_ccd(generated_datetime)
send_data resource, type: 'application/xml'
end
end
end
end
end
6 changes: 6 additions & 0 deletions modules/my_health/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
resources :session, only: %i[create], controller: 'mr_session', defaults: { format: :json } do
get :status, on: :collection
end
resources :ccd, only: [] do
collection do
get :generate, to: 'ccd#generate'
get :download, to: 'ccd#download'
end
end
resources :imaging, only: %i[index], defaults: { format: :json } do
get 'request', on: :member, action: :request_download
get :status, on: :collection, action: :request_status
Expand Down
24 changes: 21 additions & 3 deletions spec/concerns/form_attachment_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ def serializer_klass
klass: 'String',
debug_timestamp: anything
)
expect(@controller).to receive(:log_exception_to_sentry).twice
expect(@controller).to receive(:log_message_to_sentry).with(
'form attachment error 1',
:info,
phase: 'FAC_validate',
klass: 'String',
exception: 'Invalid field value'
)
post(:create, params: { hca_attachment: { file_data: } })
end

Expand All @@ -95,7 +101,12 @@ def serializer_klass
klass: 'ActionDispatch::Http::UploadedFile',
debug_timestamp: anything
)
expect(@controller).to receive(:log_exception_to_sentry).twice
expect(@controller).to receive(:log_message_to_sentry).with(
'form attachment error 2',
:info,
phase: 'FAC_cloud',
exception: 'Unprocessable Entity'
)

form_attachment = double(HCAAttachment)
expect(HCAAttachment).to receive(:new) { form_attachment }
Expand All @@ -116,12 +127,19 @@ def serializer_klass
klass: 'ActionDispatch::Http::UploadedFile',
debug_timestamp: anything
)
expect(@controller).to receive(:log_exception_to_sentry)
expect(@controller).to receive(:log_message_to_sentry).with(
'form attachment error 3',
:info,
phase: 'FAC_db',
errors: 'error text',
exception: 'Record invalid'
)

form_attachment = double(HCAAttachment)
expect(HCAAttachment).to receive(:new) { form_attachment }
expect(form_attachment).to receive(:set_file_data!)
expect(form_attachment).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(form_attachment).to receive(:errors).and_return('error text')

post(:create, params: { hca_attachment: { file_data: } })
end
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/medical_records/bb_internal/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@
end
end

describe '#get_generate_ccd' do
it 'requests a CCD be generated and returns the correct structure' do
VCR.use_cassette 'mr_client/bb_internal/generate_ccd' do
ccd_list = client.get_generate_ccd(client.session.icn, 'DOE')

expect(ccd_list).to be_an(Array)
expect(ccd_list).not_to be_empty

first_ccd = ccd_list.first
expect(first_ccd).to be_a(Hash)
expect(first_ccd).to have_key('dateGenerated')
expect(first_ccd['dateGenerated']).to be_a(String)

expect(first_ccd).to have_key('status')
expect(first_ccd['status']).to be_a(String)
end
end
end

describe '#get_download_ccd' do
it 'retrieves a previously generated CCD as XML' do
VCR.use_cassette 'mr_client/bb_internal/download_ccd' do
ccd = client.get_download_ccd('2024-10-23T12:42:48.000-0400')

expect(ccd).to be_a(String)
expect(ccd).to include('<ClinicalDocument')
end
end
end

describe '#get_study_status' do
it 'retrieves the status of all study jobs' do
VCR.use_cassette 'mr_client/bb_internal/study_status' do
Expand Down
Loading

0 comments on commit 95be20f

Please sign in to comment.