Skip to content

Commit

Permalink
Merge pull request #133 from raj209/master
Browse files Browse the repository at this point in the history
Updated Logging Features, QRDA CAT1 Versions to Support R4 and measure bundle 2017
  • Loading branch information
peter li authored Mar 2, 2018
2 parents 325621b + 44fab21 commit 428f440
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 18 additions & 5 deletions lib/c4_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Cat1Exporter
attr_accessor :end_time
# note bad redundancy: have to declare version on init
# (don't know if call on export matters at all -- should be one or the other)
CAT1EXPORTER = HealthDataStandards::Export::Cat1.new('r3_1')
CAT1EXPORTER = HealthDataStandards::Export::Cat1.new('r4')

def initialize
# define @measures, @start_time @end_time from query_cache use pushnew? with measures
Expand All @@ -22,7 +22,7 @@ def export(patient)
# don't know about this one; try both ways
cms_compatible = true # if patient.product_test && patient.product_test.product.c3_test
# qrda version is hard coded right now!!!
CAT1EXPORTER.export(patient, @measures, @start_time, @end_time, nil, 'r3_1', #patient.bundle.qrda_version,
CAT1EXPORTER.export(patient, @measures, @start_time, @end_time, nil, 'r4', #patient.bundle.qrda_version,
cms_compatible)
end

Expand Down Expand Up @@ -64,12 +64,25 @@ class Cat1ZipFilter
attr_accessor :exporter

def initialize(measures_in, start_date_in, end_date_in)
@exporter = HealthDataStandards::Export::Cat1.new 'r3_1'
@exporter = HealthDataStandards::Export::Cat1.new(get_bundleversion)
@measures=measures_in
@start_date=start_date_in
@end_date=end_date_in
end

def get_bundleversion
bndl = (b = HealthDataStandards::CQM::Bundle.all.sort(:version => :desc).first) ? b.version : 'n/a'
cat1ver=nil
case bndl
when /2016/
cat1ver='r3_1'
when /2017/
cat1ver='r4'
else
cat1ver='r3'
end
cat1ver
end

def make_name(p)
"#{p['first']}_#{p['last']}"
end
Expand All @@ -82,7 +95,7 @@ def pluck(outfilepath, patients)
patient=patient_hash[:record]
pmeas=@measures.select { |m| patient_hash[:sub_id].include?(m[:sub_id]) }
zout.put_next_entry(make_name(patient)+'.xml')
zout.puts(@exporter.export(patient, pmeas, @start_date, @end_date, nil, 'r3_1'))
zout.puts(@exporter.export(patient, pmeas, @start_date, @end_date, nil, get_bundleversion))
end
zout.close
end
Expand Down
12 changes: 11 additions & 1 deletion lib/hds/bulk_record_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,17 @@ def self.import(xml_data, provider_map = {}, practice_id=nil)
elsif doc.at_xpath("/cda:ClinicalDocument/cda:templateId[@root='2.16.840.1.113883.10.20.22.1.2']")
patient_data = HealthDataStandards::Import::CCDA::PatientImporter.instance.parse_ccda(doc)
elsif doc.at_xpath("/cda:ClinicalDocument/cda:templateId[@root='2.16.840.1.113883.10.20.24.1.2']")
patient_data = HealthDataStandards::Import::Cat1::PatientImporter.instance.parse_cat1(doc)
begin
patient_data = HealthDataStandards::Import::Cat1::PatientImporter.instance.parse_cat1(doc)
rescue Exception => e
patient_role_element = doc.at_xpath('/cda:ClinicalDocument/cda:recordTarget/cda:patientRole')
patient_element = patient_role_element.at_xpath('./cda:patient')
first = patient_element.at_xpath('cda:name/cda:given').text.upcase
last = patient_element.at_xpath('cda:name/cda:family').text.upcase
puts "UNABLE TO IMPORT PATIENT RECORD FOR #{first} #{last}"
Delayed::Worker.logger.info("UNABLE TO IMPORT PATIENT RECORD FOR #{first} #{last}")
Delayed::Worker.logger.info(e.message)
end
else
STDERR.puts("Unable to determinate document template/type of CDA document")
return {status: 'error', message: "Document templateId does not identify it as a C32 or CCDA", status_code: 400}
Expand Down
3 changes: 2 additions & 1 deletion lib/hds/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Record
scope :without_provider, ->{any_of({provider_performances: nil}, {provider_performances: []})}
scope :provider_performance_between, ->(effective_date) { where("provider_performances.start_date" => {"$lt" => effective_date}).and('$or' => [{'provider_performances.end_date' => nil}, 'provider_performances.end_date' => {'$gt' => effective_date}]) }

Valid_Sections = [:allergies, :conditions, :encounters, :immunizations, :medications, :procedures, :results, :vital_signs, :socialhistories, :communications]
Valid_Sections = [:allergies, :conditions, :encounters, :immunizations, :medications, :procedures, :results, :vital_signs, :socialhistories, :communications, :assessments]

def language_names
lang_codes = (languages.nil?) ? [] : languages.map { |l| l.gsub(/\-[A-Z]*$/, "") }
Expand Down Expand Up @@ -88,6 +88,7 @@ def self.update_or_create(data, practice_id=nil)
data.medical_record_number = mrn_p
end
data.save!
Delayed::Worker.logger.info("Record for #{data.first} #{data.last} imported")
data
end
end
Expand Down

0 comments on commit 428f440

Please sign in to comment.