Skip to content

Commit

Permalink
Mhv 63375 ccd generate and download (#19059)
Browse files Browse the repository at this point in the history
* MHV-42363 Initial cut at radiology imaging

* MHV-42363 More work on imaging

* MHV-42363 Imaging work mostly complete

* MHV-42363 Capture headers for DICOM

* MHV-42363 Refactored controller

* MHV-42363 Added spec tests for new client functions

* MHV-42363 BBInternal now expects ICN

* MHV-42363 Fixed header pass-through

* MHV-42363 Fixed data for broken spec test

* MHV-42363 Removed "new_episodes"

* MHV-63375: generate and download ccd work done

* MHV-63375: Shortened comment

* MHV-63375: Added new routes and moved controller

---------

Co-authored-by: Mike Moyer <michael.moyer@va.gov>
Co-authored-by: Mike Moyer <87040148+mmoyer-va@users.noreply.github.com>
Co-authored-by: Matthew Wright <matwright2010@gmail.com>
  • Loading branch information
4 people authored Oct 25, 2024
1 parent 048a7a3 commit f401602
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 0 deletions.
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
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
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 f401602

Please sign in to comment.