Class: Record
- Inherits:
-
Object
- Object
- Record
- Extended by:
- Memoist
- Includes:
- Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/health-data-standards/models/record.rb
Constant Summary collapse
- Sections =
[:allergies, :care_goals, :conditions, :encounters, :immunizations, :medical_equipment, :medications, :procedures, :results, :social_history, :vital_signs, :support, :advance_directives, :insurance_providers, :functional_statuses]
Class Method Summary collapse
Instance Method Summary collapse
- #dedup_record! ⇒ Object
- #dedup_section!(section) ⇒ Object
-
#dedup_section_ignoring_content!(section) ⇒ Object
Remove duplicate entries from a section based on cda_identifier or id.
- #dedup_section_merging_codes_and_values!(section) ⇒ Object
- #entries ⇒ Object
- #entries_for_oid(oid) ⇒ Object
- #over_18? ⇒ Boolean
- #providers ⇒ Object
- #shift_dates(date_diff) ⇒ Object
Class Method Details
.update_or_create(data) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/health-data-standards/models/record.rb', line 59 def self.update_or_create(data) existing = Record.where(medical_record_number: data.medical_record_number).first if existing existing.update_attributes!(data.attributes.except('_id')) existing else data.save! data end end |
Instance Method Details
#dedup_record! ⇒ Object
126 127 128 |
# File 'lib/health-data-standards/models/record.rb', line 126 def dedup_record! Record::Sections.each {|section| self.dedup_section!(section)} end |
#dedup_section!(section) ⇒ Object
123 124 125 |
# File 'lib/health-data-standards/models/record.rb', line 123 def dedup_section!(section) [:encounters, :procedures, :results].include?(section) ? dedup_section_merging_codes_and_values!(section) : dedup_section_ignoring_content!(section) end |
#dedup_section_ignoring_content!(section) ⇒ Object
Remove duplicate entries from a section based on cda_identifier or id. This method may lose information because it does not compare entries based on clinical content
104 105 106 107 108 109 |
# File 'lib/health-data-standards/models/record.rb', line 104 def dedup_section_ignoring_content!(section) unique_entries = self.send(section).uniq do |entry| entry.identifier end self.send("#{section}=", unique_entries) end |
#dedup_section_merging_codes_and_values!(section) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/health-data-standards/models/record.rb', line 110 def dedup_section_merging_codes_and_values!(section) unique_entries = {} self.send(section).each do |entry| if unique_entries[entry.identifier] unique_entries[entry.identifier].codes = unique_entries[entry.identifier].codes.deep_merge(entry.codes){ |key, old, new| Array.wrap(old) + Array.wrap(new) } unique_entries[entry.identifier].values.concat(entry.values) else unique_entries[entry.identifier] = entry end end self.send("#{section}=", unique_entries.values) end |
#entries ⇒ Object
90 91 92 93 94 |
# File 'lib/health-data-standards/models/record.rb', line 90 def entries Sections.map do |section| self.send(section) end.flatten end |
#entries_for_oid(oid) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/health-data-standards/models/record.rb', line 78 def entries_for_oid(oid) matching_entries_by_section = Sections.map do |section| section_entries = self.send(section) if section_entries.present? section_entries.find_all { |entry| (entry.respond_to? :oid) ? entry.oid == oid : false} else [] end end matching_entries_by_section.flatten end |
#over_18? ⇒ Boolean
74 75 76 |
# File 'lib/health-data-standards/models/record.rb', line 74 def over_18? Time.at(birthdate) < Time.now.years_ago(18) end |
#providers ⇒ Object
70 71 72 |
# File 'lib/health-data-standards/models/record.rb', line 70 def providers provider_performances.map {|pp| pp.provider } end |
#shift_dates(date_diff) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/health-data-standards/models/record.rb', line 130 def shift_dates(date_diff) self.birthdate = (self.birthdate.nil?) ? nil : self.birthdate + date_diff self.deathdate = (self.deathdate.nil?) ? nil : self.deathdate + date_diff self.provider_performances.each {|pp| pp.shift_dates(date_diff)} Sections.each do |sec| (self.send sec || []).each do |ent| ent.shift_dates(date_diff) end end end |