Class: Entry
- Inherits:
-
Object
- Object
- Entry
- Includes:
- ActiveModel::MassAssignmentSecurity, Mongoid::Attributes::Dynamic, Mongoid::Document, ThingWithCodes
- Defined in:
- lib/health-data-standards/models/entry.rb
Direct Known Subclasses
AdverseEvent, Allergy, Assessment, CareExperience, CareGoal, Communication, Condition, Encounter, FamilyHistory, FunctionalStatus, Immunization, InsuranceProvider, LabResult, MedicalEquipment, Medication, Participation, Procedure, Support, TreatingProvider
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares hash values to determine equality.
- #add_reference(entry, type) ⇒ Object
-
#as_point_in_time ⇒ Object
Tries to find a single point in time for this entry.
-
#calculate_hash! ⇒ Object
Calculates a hash value for this entry.
-
#hash ⇒ Object
Returns the hash value, calculating it if not already done.
- #identifier ⇒ Object
-
#is_date_range? ⇒ true, false
Checks to see if this Entry can be used as a date range.
-
#is_in_code_set?(code_set) ⇒ true, false
Checks if a code is in the list of possible codes.
-
#set_value(scalar, units = nil) ⇒ Object
Sets the value for the entry.
- #shift_dates(date_diff) ⇒ Object
-
#status ⇒ Object
Entry previously had a status field that dropped the code set and converted the status to a String.
- #status=(status_text) ⇒ Object
- #times_to_s(nil_string = 'UNK') ⇒ Object
-
#to_hash ⇒ Hash
Creates a Hash for this Entry.
-
#usable? ⇒ true, false
Checks to see if this Entry is usable for measure calculation.
Methods included from ThingWithCodes
#add_code, #codes_in_code_set, #codes_to_s, convert_codes_to_s, included, #preferred_code, #single_code_value?, #translation_codes
Class Method Details
.from_event_hash(event) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/health-data-standards/models/entry.rb', line 86 def self.from_event_hash(event) entry = Entry.new if event['code'] entry.add_code(event['code'], event['code_set']) end entry.time = event['time'] if event['value'] entry.set_value(event['value'], event['unit']) end if event['description'] entry.description = event['description'] end if event['specifics'] entry.specifics = event['specifics'] end if event['status'] entry.status = event['status'] end entry end |
.time_to_s(input_time) ⇒ Object
49 50 51 |
# File 'lib/health-data-standards/models/entry.rb', line 49 def self.time_to_s(input_time) Time.at(input_time).utc.to_formatted_s(:long_ordinal) end |
Instance Method Details
#==(other) ⇒ Object
Compares hash values to determine equality
159 160 161 |
# File 'lib/health-data-standards/models/entry.rb', line 159 def ==(other) self.class==other.class && self.hash==other.hash end |
#add_reference(entry, type) ⇒ Object
35 36 37 |
# File 'lib/health-data-standards/models/entry.rb', line 35 def add_reference(entry, type) references.build(type: type, referenced_type: entry.class, referenced_id: entry.id) end |
#as_point_in_time ⇒ Object
Tries to find a single point in time for this entry. Will first return time if it is present, then fall back to start_time and finally end_time
135 136 137 138 139 140 141 142 143 |
# File 'lib/health-data-standards/models/entry.rb', line 135 def as_point_in_time if time time elsif start_time start_time else end_time end end |
#calculate_hash! ⇒ Object
Calculates a hash value for this entry
169 170 171 172 173 |
# File 'lib/health-data-standards/models/entry.rb', line 169 def calculate_hash! entry_hash = to_hash entry_hash['description']=nil @hash = entry_hash.hash end |
#hash ⇒ Object
Returns the hash value, calculating it if not already done
164 165 166 |
# File 'lib/health-data-standards/models/entry.rb', line 164 def hash @hash || calculate_hash! end |
#identifier ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/health-data-standards/models/entry.rb', line 213 def identifier if respond_to?(:cda_identifier) && self.cda_identifier.present? self.cda_identifier else self.id end end |
#is_date_range? ⇒ true, false
Checks to see if this Entry can be used as a date range
147 148 149 |
# File 'lib/health-data-standards/models/entry.rb', line 147 def is_date_range? start_time.present? && end_time.present? end |
#is_in_code_set?(code_set) ⇒ true, false
Checks if a code is in the list of possible codes
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/health-data-standards/models/entry.rb', line 120 def is_in_code_set?(code_set) codes.keys.each do |code_system| all_codes_in_system = code_set.find_all {|set| set['set'] == code_system} all_codes_in_system.each do |codes_in_system| matching_codes = codes_in_system['values'] & codes[code_system] if matching_codes.length > 0 return true end end end false end |
#set_value(scalar, units = nil) ⇒ Object
Sets the value for the entry
110 111 112 113 |
# File 'lib/health-data-standards/models/entry.rb', line 110 def set_value(scalar, units=nil) pq_value = PhysicalQuantityResultValue.new(scalar: scalar, units: units) self.values << pq_value end |
#shift_dates(date_diff) ⇒ Object
207 208 209 210 211 |
# File 'lib/health-data-standards/models/entry.rb', line 207 def shift_dates(date_diff) self.start_time = self.start_time.nil? ? nil : (self.start_time + date_diff) self.end_time = self.end_time.nil? ? nil : (self.end_time + date_diff) self.time = self.time.nil? ? nil : (self.time + date_diff) end |
#status ⇒ Object
Entry previously had a status field that dropped the code set and converted the status to a String. Entry now preserves the original code and code set. This method is here to maintain backwards compatibility.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/health-data-standards/models/entry.rb', line 56 def status if status_code.present? if status_code['HL7 ActStatus'] status_code['HL7 ActStatus'].first() elsif status_code['SNOMED-CT'] case status_code['SNOMED-CT'].first() when '55561003' 'active' when '73425007' 'inactive' when '413322009' 'resolved' end end end end |
#status=(status_text) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/health-data-standards/models/entry.rb', line 73 def status=(status_text) case status_text.to_s # makes sure that any Symbols passed in are stringified when 'active' self.status_code = {'SNOMED-CT' => ['55561003'], 'HL7 ActStatus' => ['active']} when 'inactive' self.status_code = {'SNOMED-CT' => ['73425007']} when 'resolved' self.status_code = {'SNOMED-CT' => ['413322009']} else self.status_code = {'HL7 ActStatus' => [status_text]} end end |
#times_to_s(nil_string = 'UNK') ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/health-data-standards/models/entry.rb', line 39 def times_to_s(nil_string='UNK') if start_time.present? || end_time.present? start_string = start_time ? Entry.time_to_s(start_time) : nil_string end_string = end_time ? Entry.time_to_s(end_time) : nil_string "#{start_string} - #{end_string}" elsif time.present? Time.at(time).utc.to_formatted_s(:long_ordinal) end end |
#to_hash ⇒ Hash
Creates a Hash for this Entry
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/health-data-standards/models/entry.rb', line 177 def to_hash entry_hash = {} entry_hash['codes'] = codes unless values.empty? entry_hash['value'] = values end if is_date_range? entry_hash['start_time'] = start_time entry_hash['end_time'] = end_time else entry_hash['time'] = as_point_in_time end if status entry_hash['status'] = status end if description entry_hash['description'] = description end if specifics entry_hash['specifics'] = specifics end entry_hash end |
#usable? ⇒ true, false
Checks to see if this Entry is usable for measure calculation. This means that it contains at least one code and has one of its time properties set (start, end or time)
154 155 156 |
# File 'lib/health-data-standards/models/entry.rb', line 154 def usable? codes.present? && (start_time.present? || end_time.present? || time.present?) end |