Class: OpenEHR::RM::Common::ChangeControl::VersionedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/open_ehr/rm/common/change_control.rb

Direct Known Subclasses

Directory::VersionedFolder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = { }) ⇒ VersionedObject

Returns a new instance of VersionedObject.



164
165
166
167
168
169
# File 'lib/open_ehr/rm/common/change_control.rb', line 164

def initialize(args = { })
  self.uid = args[:uid]
  self.owner_id = args[:owner_id]
  self.time_created = args[:time_created]
  self.all_versions = args[:all_versions]
end

Instance Attribute Details

#all_versionsObject

Returns the value of attribute all_versions.



162
163
164
# File 'lib/open_ehr/rm/common/change_control.rb', line 162

def all_versions
  @all_versions
end

#owner_idObject

Returns the value of attribute owner_id.



162
163
164
# File 'lib/open_ehr/rm/common/change_control.rb', line 162

def owner_id
  @owner_id
end

#time_createdObject

Returns the value of attribute time_created.



162
163
164
# File 'lib/open_ehr/rm/common/change_control.rb', line 162

def time_created
  @time_created
end

#uidObject

Returns the value of attribute uid.



162
163
164
# File 'lib/open_ehr/rm/common/change_control.rb', line 162

def uid
  @uid
end

Instance Method Details

#all_version_idsObject



195
196
197
198
199
# File 'lib/open_ehr/rm/common/change_control.rb', line 195

def all_version_ids
  ids = []
  @all_versions.each{|id| ids << id.uid}
  return ids
end

#commit_attestation(args = { }) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
# File 'lib/open_ehr/rm/common/change_control.rb', line 317

def commit_attestation(args = { })
  if args[:attestation].nil?
    raise ArgumentError, 'attestation is mandatory'
  end
  if self.has_version_id?(args[:uid]) && self.is_original_version?(args[:uid])
    self.version_with_id(args[:uid]).attestations << args[:attestation]
    self.version_with_id(args[:uid]).signature = args[:signature]
  else
    raise ArgumentError, 'uid invalid'
  end
end

#commit_imported_version(args = { }) ⇒ Object



311
312
313
314
315
# File 'lib/open_ehr/rm/common/change_control.rb', line 311

def commit_imported_version(args = { })
  @all_versions << ImportedVersion.new(:item => args[:item],
                                       :contribution => args[:contribution],
                                       :commit_audit => args[:commit_audit])
end

#commit_original_merged_version(args = { }) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/open_ehr/rm/common/change_control.rb', line 299

def commit_original_merged_version(args = { })
  @all_versions << OriginalVersion.new(:uid => args[:uid],
                                        :contribution => args[:contribution],
                                    :preceding_version_uid => args[:preceding_version_uid],
                                    :commit_audit => args[:commit_audit],
                                    :lifecycle_state => args[:lifecycle_state],
                                    :data => args[:data],
                                    :attestations => args[:attestations],
                                    :other_input_version_uids => args[:other_input_version_uids],
                                    :signature => args[:signature])
end

#commit_original_version(args = { }) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/open_ehr/rm/common/change_control.rb', line 284

def commit_original_version(args={ })
  if has_version_id?(args[:preceding_version_uid]) or self.version_count == 0
    @all_versions << OriginalVersion.new(:uid => args[:uid],
                                         :preceding_version_uid => args[:preceding_version_uid],
                                         :contribution => args[:contribution],
                                         :commit_audit => args[:commit_audit],
                                         :lifecycle_state => args[:lifecycle_state],
                                         :data => args[:data],
                                         :attestations => args[:attestations],
                                         :signature => args[:signature])
  else
    raise ArgumentError, 'invalid preceding uid'
  end
end

#has_version_at_time?(a_time) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


217
218
219
220
221
222
223
224
225
# File 'lib/open_ehr/rm/common/change_control.rb', line 217

def has_version_at_time?(a_time)
  raise ArgumentError, 'argument mandatory' if a_time.nil?
  @all_versions.each do |ver|
    if ver.commit_audit.time_committed == a_time
      return true
    end
  end
  return false
end

#has_version_id?(a_ver_id) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


205
206
207
208
# File 'lib/open_ehr/rm/common/change_control.rb', line 205

def has_version_id?(a_ver_id)
  raise ArgumentError, 'argument is mandatory' if a_ver_id.nil?
  return self.all_version_ids.include?(a_ver_id)
end

#is_original_version?(a_ver_id) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
213
214
215
# File 'lib/open_ehr/rm/common/change_control.rb', line 210

def is_original_version?(a_ver_id)
  if a_ver_id.nil? || !self.has_version_id?(a_ver_id)
    raise ArgumentError, 'invalid a_ver_id'
  end
  return @all_versions[self.all_version_ids.index(a_ver_id)].instance_of? OriginalVersion
end

#latest_trunk_versionObject



252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/open_ehr/rm/common/change_control.rb', line 252

def latest_trunk_version
  trunk_versions = [ ]
  @all_versions.each do |ver|
    if ver.uid.version_tree_id.trunk_version == '1'
      trunk_versions << ver
    end
  end
  sorted_trunk_version = trunk_versions.sort do |a,b|
    a.commit_audit.time_committed <=> b.commit_audit.time_committed
  end
  return sorted_trunk_version.last
end

#latest_versionObject



245
246
247
248
249
250
# File 'lib/open_ehr/rm/common/change_control.rb', line 245

def latest_version
  time_sorted_version = @all_versions.sort do |a,b|
    a.commit_audit.time_committed <=> b.commit_audit.time_committed
  end
  return time_sorted_version.last
end

#revision_historyObject



269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/open_ehr/rm/common/change_control.rb', line 269

def revision_history
  revision_history_items = [ ]
  @all_versions.each do |ver|
    audits = [ ]
    if ver.instance_of? OriginalVersion
      audits << ver.attestations
    end
    audits << ver.commit_audit
    revision_history_items << RevisionHistoryItem.new(
                                :audits => audits,
                                :version_id => ver.uid)
  end
  return RevisionHistory.new(:items => revision_history_items)
end

#trunk_lifecycle_stateObject



265
266
267
# File 'lib/open_ehr/rm/common/change_control.rb', line 265

def trunk_lifecycle_state
  return self.latest_trunk_version.lifecycle_state
end

#version_at_time(a_time) ⇒ Object



234
235
236
237
238
239
240
241
242
243
# File 'lib/open_ehr/rm/common/change_control.rb', line 234

def version_at_time(a_time)
  if a_time.nil? || !self.has_version_at_time?(a_time)
    raise ArgumentError, 'argument invalid'
  end
  @all_versions.each do |ver|
    if ver.commit_audit.time_committed == a_time
      return ver
    end
  end
end

#version_countObject



201
202
203
# File 'lib/open_ehr/rm/common/change_control.rb', line 201

def version_count
  return all_versions.size
end

#version_with_id(a_ver_id) ⇒ Object



227
228
229
230
231
232
# File 'lib/open_ehr/rm/common/change_control.rb', line 227

def version_with_id(a_ver_id)
  if a_ver_id.nil? || !self.has_version_id?(a_ver_id)
    raise ArgumentError, 'argument invalid'
  end
  return @all_versions[self.all_version_ids.index(a_ver_id)]
end