Class: TPG::Exporter
- Inherits:
-
Object
- Object
- TPG::Exporter
- Defined in:
- lib/tpg/generation/exporter.rb
Class Method Summary collapse
-
.html_contents(patient, exporter = HealthDataStandards::Export::HTML.new) ⇒ Object
Generate the HTML output for a Record from Health Data Standards.
-
.patient_filename(patient) ⇒ Object
Join the first and last name with an underscore and replace any other punctuation that might interfere with file names.
-
.zip(patients, format) ⇒ Object
Export a list of patients to a zip file.
-
.zip_qrda_cat_1_patients(measure_patients, measures) ⇒ Object
Export QRDA Category 1 patients to a zip file.
-
.zip_qrda_html_patients(measure_patients) ⇒ Object
Export QRDA Category 1 patients to a zip file.
Class Method Details
.html_contents(patient, exporter = HealthDataStandards::Export::HTML.new) ⇒ Object
Generate the HTML output for a Record from Health Data Standards.
87 88 89 |
# File 'lib/tpg/generation/exporter.rb', line 87 def self.html_contents(patient, exporter = HealthDataStandards::Export::HTML.new) exporter.export(patient) end |
.patient_filename(patient) ⇒ Object
Join the first and last name with an underscore and replace any other punctuation that might interfere with file names.
95 96 97 98 99 100 |
# File 'lib/tpg/generation/exporter.rb', line 95 def self.patient_filename(patient) safe_first_name = patient.first.gsub("'", "") safe_last_name = patient.last.gsub("'", "") "#{safe_first_name}_#{safe_last_name}" end |
.zip(patients, format) ⇒ Object
Export a list of patients to a zip file. Contains nothing but patient records.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tpg/generation/exporter.rb', line 8 def self.zip(patients, format) file = Tempfile.new("patients-#{Time.now.to_i}") html_exporter = HealthDataStandards::Export::HTML.new Zip::ZipOutputStream.open(file.path) do |z| xslt = Nokogiri::XSLT(File.read("public/cda.xsl")) patients.each do |patient| next_entry_path = patient_filename(patient) if format == "c32" z.put_next_entry("#{next_entry_path}.xml") z << HealthDataStandards::Export::C32.new.export(patient) elsif format == "ccr" z.put_next_entry("#{next_entry_path}.xml") z << HealthDataStandards::Export::CCR.export(patient) elsif format == "ccda" z.put_next_entry("#{next_entry_path}.xml") z << HealthDataStandards::Export::CCDA.new.export(patient) elsif format == "html" z.put_next_entry("#{next_entry_path}.html") z << html_contents(patient, html_exporter) elsif format == "json" z.put_next_entry("#{next_entry_path}.json") z << JSON.pretty_generate(JSON.parse(patient.to_json)) end end end file.close file end |
.zip_qrda_cat_1_patients(measure_patients, measures) ⇒ Object
Export QRDA Category 1 patients to a zip file. Contents are organized with a directory for each measure containing one patient for validation.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tpg/generation/exporter.rb', line 65 def self.zip_qrda_cat_1_patients(measure_patients, measures) file = Tempfile.new("patients-#{Time.now.to_i}") Zip::ZipOutputStream.open(file.path) do |zip| measure_patients.each do |nqf_id, patients| measure_defs = measures.find {|m| m.id == nqf_id} patients = [patients] unless patients.is_a? Array # we should be able to support multiple patients... however, the qrda patient generation just passes a single patient... lame. patients.each do |patient| # Create a directory for this measure and insert the HTML for this patient. zip.put_next_entry(File.join(measure_defs.hqmf_id, "#{patient_filename(patient)}.xml")) zip << HealthDataStandards::Export::Cat1.new.export(patient, [measure_defs], Time.gm(2011, 1, 1), Time.gm(2011, 12, 31)) end end end file.close file end |
.zip_qrda_html_patients(measure_patients) ⇒ Object
Export QRDA Category 1 patients to a zip file. Contents are organized with a directory for each measure containing one patient for validation.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tpg/generation/exporter.rb', line 44 def self.zip_qrda_html_patients(measure_patients) file = Tempfile.new("patients-#{Time.now.to_i}") html_exporter = HealthDataStandards::Export::HTML.new Zip::ZipOutputStream.open(file.path) do |zip| xslt = Nokogiri::XSLT(File.read("public/cda.xsl")) measure_patients.each do |measure, patient| # Create a directory for this measure and insert the HTML for this patient. zip.put_next_entry(File.join(measure, "#{patient_filename(patient)}.html")) zip << html_contents(patient, html_exporter) end end file.close file end |