Skip to content

Commit

Permalink
support QRDA upload too
Browse files Browse the repository at this point in the history
  • Loading branch information
dczulada committed Jan 16, 2024
1 parent d9b0651 commit 49c2084
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 57 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/templates/measure.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
{{#button "importJsonPatients" class="btn btn-default export-patients"}}
<i class="fa fa-upload" aria-hidden="true"></i> IMPORT <span class="sr-only">Import Patients</span>
{{/button}}
{{#button "importQrdaPatients" class="btn btn-default export-patients"}}
<i class="fa fa-upload" aria-hidden="true"></i> IMPORT QRDA <span class="sr-only">Import QRDA Patients</span>
{{/button}}

<a data-title="Not available for QDM 5.6" data-toggle="tooltip" data-placement="bottom">
{{#button "convertQdmPatients" class="btn btn-default export-patients" disabled="true"}}
Expand Down
45 changes: 45 additions & 0 deletions app/assets/javascripts/templates/measure/import_qrda_patients.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="modal fade" id="importQdaPatientInProgressDialog" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1>Importing Patients...</h1>
</div>
<div class="modal-body">
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
<span class="sr-only">Importing Patients...</span>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="modal fade" id="importQrdaPatientsDialog" tabindex="-1" aria-hidden="true">
<div class="modal-dialog" role="dialog" aria-labelledby="modalTitle">
<div class="modal-content">
<form role="form" method="post" enctype="multipart/form-data" action="/patients/qrda_import">
<input name="authenticity_token" type="hidden" value="{{token}}">
<input name="measure_id" type="hidden" value="{{measure.id}}">
<input name="hqmf_set_id" type="hidden" value="{{measure.hqmf_set_id}}">
<div class="modal-header">
<h1 class="modal-title" id="modalTitle">Import patients into measure {{measure.title}}</h1>
</div>
<div class="modal-body">
<div class="alert alert-info">Please select a patient zip file exported from Bonnie QDM. By clicking Submit you agree to not upload any Protected Health Information (PHI) or Personally Identifiable Information (PII) while using this feature.</div>
<div class="form-group">
<label for="measureFileInput" class="control-label">Patient zip file</label>
<div>
<input class="file nice_input" type="file" id="patientFileInput" name="patient_import_file">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" id="importPatientsSubmit" class="btn btn-primary" disabled>Submit</button>
<button type="button" id="importPatientsCancel" class="btn btn-default">Cancel</button>
</div>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
41 changes: 41 additions & 0 deletions app/assets/javascripts/views/import_qrda_patients_view.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Thorax.Views.ImportQrdaPatients extends Thorax.Views.BonnieView
template: JST['measure/import_qrda_patients']

initialize: ->
@measure = @model.get('cqmMeasure');


context: ->
_(super).extend
token: $('meta[name="csrf-token"]').attr('content')

setup: ->
@importQrdaPatientsDialog = @$("#importQrdaPatientsDialog")

events:
rendered: ->
@$el.on 'hidden.bs.modal', -> @remove() unless $('#importQrdaPatientsDialog').is(':visible')
'click #importPatientsCancel': 'cancel'
'click #importPatientsSubmit': 'submit'
'change #patientFileInput': 'fileChanged'
'ready': 'setup'


display: ->
@importQrdaPatientsDialog.modal(
"backdrop" : "static",
"keyboard" : true,
"show" : true)

cancel: ->
@importQrdaPatientsDialog.modal('hide')

submit: (e) ->
e.preventDefault()
$(e.target).prop('disabled', true)
@$('form').submit()
@importQrdaPatientsDialog.modal('hide')
@$("#importQrdaPatientInProgressDialog").modal backdrop: 'static'

fileChanged: (e) ->
@$('#importPatientsSubmit').prop('disabled', !fileName = $(e.target).val())
5 changes: 5 additions & 0 deletions app/assets/javascripts/views/measure_view.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class Thorax.Views.Measure extends Thorax.Views.BonnieView
importJsonPatients.appendTo(@$el)
importJsonPatients.display()

importQrdaPatients: (e) ->
importQrdaPatients = new Thorax.Views.ImportQrdaPatients(model: @model, measures: new Thorax.Collections.Measures(@model.collection))
importQrdaPatients.appendTo(@$el)
importQrdaPatients.display()

exportQrdaPatients: (e) ->
@exportPatientsView.exporting()

Expand Down
114 changes: 57 additions & 57 deletions app/controllers/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,63 +250,6 @@ def json_export
end
end

# def json_import
# virus_scan params[:patient_import_file]
# is_zip_file params[:patient_import_file]

# # Verify target measure exists
# measure = CQM::Measure.where(id: params[:measure_id]).first
# raise MeasureUpdateMeasureNotFound if measure.nil?

# # Get the JSON files from the zip:
# # meta - contains measure population, patient signature, and troubleshooting meta data.
# # patients - contains the CQM Patients array.
# json = unzip_patient_import_files(params[:patient_import_file])
# meta = JSON.parse(json[:meta])
# raise PatientsModified if meta["patients_signature"].nil?
# raise IncompatibleQdmVersion unless meta["qdm_version"].eql?(APP_CONFIG['support_qdm_version'].to_s)

# # Verify Patients signature hash
# signature = Digest::MD5.hexdigest("#{meta['qdm_version']}#{json[:patients]}")
# raise PatientsModified unless signature.eql?(meta["patients_signature"])

# # Deserialize patients json array to CQM Patient model
# cqm_patients = JSON.parse(json[:patients]).map { |p| CQM::Patient.new.from_json JSON.generate p }

# # Check whether the provided measure populations match the populations in the target measure
# matching_populations = meta["measure_populations"] == measure.population_criteria.keys

# # Prepare patients for insert
# cqm_patients.each do |patient|
# patient[:id] = BSON::ObjectId.new
# patient[:group_id] = current_user.current_group.id
# patient['measure_ids'] = [measure.hqmf_set_id]
# # If the provided populations match the populations in the target measure, include them in the import
# if matching_populations
# patient[:expectedValues].each do |ev|
# ev["measure_id"] = measure.hqmf_set_id
# end
# else
# patient[:expectedValues] = [] # The measure population docs will be inserted when the user saves the patient.
# end
# # Validate patient so we don't have partial inserts
# raise MeasureLoadingOther unless patient.validate
# end

# cqm_patients.each(&:upsert)
# flash[:msg] = {
# title: "QDM PATIENT IMPORT COMPLETED",
# summary: "",
# body: "Your patients have been successfully added to the measure.
# #{'Due to mismatching populations, the Expected Values have been cleared from imported patients.' unless matching_populations}"
# }
# rescue StandardError => e
# puts e.backtrace
# flash[:error] = turn_exception_into_shared_error_if_needed(e).front_end_version
# ensure
# redirect_to "#{root_path}#measures/#{params[:hqmf_set_id]}"
# end

def json_import
virus_scan params[:patient_import_file]
is_zip_file params[:patient_import_file]
Expand All @@ -315,6 +258,63 @@ def json_import
measure = CQM::Measure.where(id: params[:measure_id]).first
raise MeasureUpdateMeasureNotFound if measure.nil?

# Get the JSON files from the zip:
# meta - contains measure population, patient signature, and troubleshooting meta data.
# patients - contains the CQM Patients array.
json = unzip_patient_import_files(params[:patient_import_file])
meta = JSON.parse(json[:meta])
raise PatientsModified if meta["patients_signature"].nil?
raise IncompatibleQdmVersion unless meta["qdm_version"].eql?(APP_CONFIG['support_qdm_version'].to_s)

# Verify Patients signature hash
signature = Digest::MD5.hexdigest("#{meta['qdm_version']}#{json[:patients]}")
raise PatientsModified unless signature.eql?(meta["patients_signature"])

# Deserialize patients json array to CQM Patient model
cqm_patients = JSON.parse(json[:patients]).map { |p| CQM::Patient.new.from_json JSON.generate p }

# Check whether the provided measure populations match the populations in the target measure
matching_populations = meta["measure_populations"] == measure.population_criteria.keys

# Prepare patients for insert
cqm_patients.each do |patient|
patient[:id] = BSON::ObjectId.new
patient[:group_id] = current_user.current_group.id
patient['measure_ids'] = [measure.hqmf_set_id]
# If the provided populations match the populations in the target measure, include them in the import
if matching_populations
patient[:expectedValues].each do |ev|
ev["measure_id"] = measure.hqmf_set_id
end
else
patient[:expectedValues] = [] # The measure population docs will be inserted when the user saves the patient.
end
# Validate patient so we don't have partial inserts
raise MeasureLoadingOther unless patient.validate
end

cqm_patients.each(&:upsert)
flash[:msg] = {
title: "QDM PATIENT IMPORT COMPLETED",
summary: "",
body: "Your patients have been successfully added to the measure.
#{'Due to mismatching populations, the Expected Values have been cleared from imported patients.' unless matching_populations}"
}
rescue StandardError => e
puts e.backtrace
flash[:error] = turn_exception_into_shared_error_if_needed(e).front_end_version
ensure
redirect_to "#{root_path}#measures/#{params[:hqmf_set_id]}"
end

def qrda_import
virus_scan params[:patient_import_file]
is_zip_file params[:patient_import_file]

# Verify target measure exists
measure = CQM::Measure.where(id: params[:measure_id]).first
raise MeasureUpdateMeasureNotFound if measure.nil?

vendor_patient_file = File.new(params[:patient_import_file].path)
artifact = Artifact.new(file: vendor_patient_file)

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
post 'convert_patients'
post 'json_export'
post 'json_import'
post 'qrda_import'
post 'delete_all_patients'
end
end
Expand Down

0 comments on commit 49c2084

Please sign in to comment.