Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Namespaced models. #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ tmp
.DS_Store
.idea
.rvmrc

.ruby-version
.ruby-gemset
36 changes: 18 additions & 18 deletions lib/health-data-standards/export/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ def code_display(entry, options={})
code_string += "nullFlavor=\"UNK\" " unless options["exclude_null_flavor"]
code_string += "#{options['extra_content']}>"
end



if options["attribute"] == :codes && entry.respond_to?(:translation_codes)
code_string += "<originalText>#{ERB::Util.html_escape entry.description}</originalText>" if entry.respond_to?(:description)
entry.translation_codes(options['preferred_code_sets'], options['value_set_map']).each do |translation|
code_string += "<translation code=\"#{translation['code']}\" codeSystem=\"#{HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(translation['code_set'])}\"/>\n"
end
end

code_string += "</#{options['tag_name']}>"
code_string
end

def status_code_for(entry)
case entry.status.to_s.downcase
when 'active'
Expand All @@ -40,27 +40,27 @@ def status_code_for(entry)
end
end


def value_or_null_flavor(time)
if time
if time
return "value='#{Time.at(time).utc.to_formatted_s(:number)}'"
else
else
return "nullFlavor='UNK'"
end
end

def time_if_not_nil(*args)
args.compact.map {|t| Time.at(t).utc}.first
end

def is_num?(str)
Float(str || "")
rescue ArgumentError
false
else
true
end

def is_bool?(str)
return ["true","false"].include? (str || "").downcase
end
Expand All @@ -73,7 +73,7 @@ def convert_field_to_hash(field, codes)
codes = codes[0] if codes.is_a? Array
if (codes.is_a? Hash)
clean_hash = {}

if codes['codeSystem']
if codes['title']
clean_hash[codes['codeSystem']] = codes['code'] + " (#{codes['title']})"
Expand Down Expand Up @@ -101,26 +101,26 @@ def convert_field_to_hash(field, codes)
elsif codes['scalar']
return "#{codes['scalar']} #{codes['units']}"
else
return codes.map do |hashcode_set, hashcodes|
return codes.map do |hashcode_set, hashcodes|
if hashcodes.is_a? Hash
"#{hashcode_set}: #{convert_field_to_hash(hashcode_set, hashcodes)}"
else
"#{hashcode_set}: #{(hashcodes.respond_to? :join) ? hashcodes.join(', ') : hashcodes.to_s}"
end
end.join(' ')
end

clean_hash
else
if codes && (field.match(/Time$/) || field.match(/\_time$/) || field.match(/Date$/))
Entry.time_to_s(codes)
if codes && (field.match(/Time$/) || field.match(/\_time$/) || field.match(/Date$/))
HealthDataStandards::Entry.time_to_s(codes)
else
codes.to_s
end
end
end


end
end
end
end
10 changes: 5 additions & 5 deletions lib/health-data-standards/import/bulk_record_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.import_archive(file, failed_dir=nil)
#if there was a patient manifest, theres a patient id list we need to load
if patient_id_list
patient_id_list.split("\n").each do |id|
patient = Record.where(:medical_record_number => id).first
patient = HealthDataStandards::Record.where(:medical_record_number => id).first
if patient == nil
missing_patients << id
end
Expand Down Expand Up @@ -78,11 +78,11 @@ def self.import_file(name,data,failed_dir,provider_map={})

def self.import_json(data,provider_map = {})
json = JSON.parse(data,:max_nesting=>100)
record = Record.update_or_create(Record.new(json))
record = HealthDataStandards::Record.update_or_create(Record.new(json))
providers = record.provider_performances
providers.each do |prov|
prov.provider.ancestors.each do |ancestor|
record.provider_performances.push(ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
record.provider_performances.push(HealthDataStandards::ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
end
end
record.save!
Expand All @@ -109,7 +109,7 @@ def self.import(xml_data, provider_map = {})
return {status: 'error', message: "Document templateId does not identify it as a C32 or CCDA", status_code: 400}
end

record = Record.update_or_create(patient_data)
record = HealthDataStandards::Record.update_or_create(patient_data)

begin
providers = CDA::ProviderImporter.instance.extract_providers(doc, record)
Expand All @@ -123,7 +123,7 @@ def self.import(xml_data, provider_map = {})
record.provider_performances = providers
providers.each do |prov|
prov.provider.ancestors.each do |ancestor|
record.provider_performances.push(ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
record.provider_performances.push(HealthDataStandards::ProviderPerformance.new(start_date: prov.start_date, end_date: prov.end_date, provider: ancestor))
end
end
record.save
Expand Down
4 changes: 2 additions & 2 deletions lib/health-data-standards/import/bundle/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def self.unpack_and_store_measures(zip, type, bundle, update_measures)
def self.unpack_and_store_patients(zip, type, bundle)
entries = zip.glob(File.join(SOURCE_ROOTS[:patients],type || '**','json','*.json'))
entries.each_with_index do |entry, index|
patient = Record.new(unpack_json(entry))
patient = HealthDataStandards::Record.new(unpack_json(entry))
patient['bundle_id'] = bundle.id
patient.save
report_progress('patients', (index*100/entries.length)) if index%10 == 0
Expand Down Expand Up @@ -166,7 +166,7 @@ def self.unpack_and_store_results(zip, type, measure_ids, bundle)
# Set the patient_id to the actual _id of
# newly created patient record
medical_record_id = document['value']['medical_record_id']
if patient = Record.by_patient_id(medical_record_id).first
if patient = HealthDataStandards::Record.by_patient_id(medical_record_id).first
document['value']['patient_id'] = patient.id
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/health-data-standards/import/c32/immunization_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(entry_finder=CDA::EntryFinder.new("//cda:section[cda:templateId/@
super(entry_finder)
@code_xpath = "./cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
@description_xpath = "./cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code/cda:originalText/cda:reference[@value]"
@entry_class = Immunization
@entry_class = HealthDataStandards::Immunization
end

def create_entry(entry_element, nrh = CDA::NarrativeReferenceHandler.new)
Expand All @@ -16,9 +16,9 @@ def create_entry(entry_element, nrh = CDA::NarrativeReferenceHandler.new)
extract_performer(entry_element, immunization)
immunization
end

private

def extract_performer(parent_element, immunization)
performer_element = parent_element.at_xpath("./cda:performer")
immunization.performer = import_actor(performer_element) if performer_element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module HealthDataStandards
module Import
module C32
class InsuranceProviderImporter < CDA::SectionImporter

def initialize(entry_finder=CDA::EntryFinder.new("//cda:act[cda:templateId/@root='2.16.840.1.113883.10.20.1.26']"))
super(entry_finder)
@check_for_usable = false # needs to be this way becase InsuranceProvider does not respond
# to usable?
end

def create_entry(payer_element, nrh = CDA::NarrativeReferenceHandler.new)
ip = InsuranceProvider.new
ip = HealthDataStandards::InsuranceProvider.new
type = extract_code(payer_element, "./cda:code")
ip.type = type['code'] if type
ip.payer = import_organization(payer_element.at_xpath("./cda:performer/cda:assignedEntity[cda:code[@code='PAYOR']]"))
Expand All @@ -26,20 +26,20 @@ def create_entry(payer_element, nrh = CDA::NarrativeReferenceHandler.new)
ip.financial_responsibility_type = extract_code(payer_element, "./cda:performer/cda:assignedEntity/cda:code")
ip
end

def extract_guarantors(guarantor_elements)
guarantor_elements.map do |guarantor_element|
guarantor = Guarantor.new
guarantor = HealthDataStandards::Guarantor.new
extract_dates(guarantor_element, guarantor, element_name="time")
guarantor_entity = guarantor_element.at_xpath("./cda:assignedEntity")
guarantor.person = import_person(guarantor_entity.at_xpath("./cda:assignedPerson"))
guarantor.organization = import_organization(guarantor_entity.at_xpath("./cda:representedOrganization"))
guarantor
end
end

end
end
end

end
16 changes: 8 additions & 8 deletions lib/health-data-standards/import/c32/patient_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PatientImporter
include HealthDataStandards::Util
include HealthDataStandards::Import::CDA::LocatableImportUtils

# Creates a new PatientImporter with the following XPath expressions used to find content in
# Creates a new PatientImporter with the following XPath expressions used to find content in
# a HITSP C32:
#
# Encounter entries
Expand Down Expand Up @@ -69,7 +69,7 @@ def initialize(check_usable = true)
@section_importers[:insurance_providers] = InsuranceProviderImporter.new
end

# @param [boolean] value for check_usable_entries...importer uses true, stats uses false
# @param [boolean] value for check_usable_entries...importer uses true, stats uses false
def check_usable(check_usable_entries)
@section_importers.each_pair do |section, importer|
importer.check_for_usable = check_usable_entries
Expand All @@ -82,14 +82,14 @@ def check_usable(check_usable_entries)
# will have the "cda" namespace registered to "urn:hl7-org:v3"
# @return [Record] a Mongoid model representing the patient
def parse_c32(doc)
c32_patient = Record.new
c32_patient = HealthDataStandards::Record.new
get_demographics(c32_patient, doc)
create_c32_hash(c32_patient, doc)
check_for_cause_of_death(c32_patient)

c32_patient
end

# Checks the conditions to see if any of them have a cause of death set. If they do,
# it will set the expired field on the Record. This is done here rather than replacing
# the expried method on Record because other formats may actully tell you whether
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_demographics(patient, doc)
patient.gender = gender_node['code']
id_node = patient_role_element.at_xpath('./cda:id')
patient.medical_record_number = id_node['extension']

# parse race, ethnicity, and spoken language
race_node = patient_element.at_xpath('cda:raceCode')
patient.race = { code: race_node['code'], code_set: 'CDC-RE' } if race_node
Expand All @@ -150,10 +150,10 @@ def get_demographics(patient, doc)
patient.religious_affiliation = {code: ra_node['code'], code_set: "Religious Affiliation"} if ra_node
languages = patient_element.search('languageCommunication').map {|lc| lc.at_xpath('cda:languageCode')['code'] }
patient.languages = languages unless languages.empty?

patient.addresses = patient_role_element.xpath("./cda:addr").map { |addr| import_address(addr) }
patient.telecoms = patient_role_element.xpath("./cda:telecom").map { |tele| import_telecom(tele) }

end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cat1
class DiagnosticStudyOrderImporter < CDA::SectionImporter
def initialize(entry_finder=CDA::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.17']"))
super(entry_finder)
@entry_class = Procedure
@entry_class = HealthDataStandards::Procedure
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
def extract_reason(parent_element, encounter, nrh)
reason_element = parent_element.at_xpath(@reason_xpath)
if reason_element
reason = Entry.new
reason = HealthDataStandards::Entry.new
extract_codes(reason_element, reason)
extract_reason_description(reason_element, reason, nrh)
extract_status(reason_element, reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module HealthDataStandards
module Import
module Cat1
class InsuranceProviderImporter < CDA::SectionImporter

def initialize
super(CDA::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.55']"))
@check_for_usable = false # needs to be this way becase InsuranceProvider does not respond
# to usable?
end

def create_entry(payer_element, nrh = CDA::NarrativeReferenceHandler.new)
ip = InsuranceProvider.new
ip = HealthDataStandards::InsuranceProvider.new
value_element = payer_element.at_xpath('cda:value')
ip.codes = { 'SOP' => [value_element['code']] } if value_element
extract_dates(payer_element, ip)
Expand Down
4 changes: 2 additions & 2 deletions lib/health-data-standards/import/cat1/lab_order_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Cat1
class LabOrderImporter < CDA::SectionImporter
def initialize(entry_finder=CDA::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.37']"))
super(entry_finder)
@entry_class = LabResult
@entry_class = HealthDataStandards::LabResult
end

private

def extract_dates(parent_element, entry, element_name="author")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cat1
class LabResultImporter < CDA::SectionImporter
def initialize(entry_finder=CDA::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.40']"))
super(entry_finder)
@entry_class = LabResult
@entry_class = HealthDataStandards::LabResult
end

def create_entry(entry_element, nrh = CDA::NarrativeReferenceHandler.new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class MedicationDispensedImporter < CDA::SectionImporter
def initialize(entry_finder=CDA::EntryFinder.new("./cda:entry/cda:supply[cda:templateId/@root='2.16.840.1.113883.10.20.24.3.45']"))
super(entry_finder)
@code_xpath = "./cda:product/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
@entry_class = Medication
@entry_class = HealthDataStandards::Medication
end
end
end
Expand Down
Loading