source: ruby/branches/0.5/lib/open_ehr/rm/data_structures/history.rb@ 344

Last change on this file since 344 was 344, checked in by KOBAYASHI, Shinji, 14 years ago

ref #55
time calculation might be refactored

File size: 3.3 KB
Line 
1# rm::data_structures::history
2# history module
3# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109157527311_729550_7234Report.html
4# refs #55
5require 'time'
6include OpenEHR::RM::DataStructures
7include OpenEHR::RM::Common::Archetyped
8
9module OpenEHR
10 module RM
11 module DataStructures
12 module History
13 class History < DataStructure
14 attr_reader :origin, :events
15 attr_accessor :duration, :period, :summary
16
17 def initialize(args = { })
18 super(args)
19 self.origin = args[:origin]
20 self.duration = args[:duration]
21 self.period = args[:period]
22 self.events = args[:events]
23 self.summary = args[:summary]
24 end
25
26 def origin=(origin)
27 raise ArgumentError, 'origin is mandatory' if origin.nil?
28 @origin = origin
29 end
30
31 def events=(events)
32 if !events.nil? and events.empty?
33 raise ArgumentError, 'events should not be empty'
34 end
35 @events = events
36 end
37
38 def is_periodic?
39 return !@period.nil?
40 end
41 end
42
43 class Event < Locatable
44 attr_reader :data, :time
45 attr_accessor :state
46
47 def initialize(args = { })
48 super(args)
49 self.data = args[:data]
50 self.time = args[:time]
51 self.state = args[:state]
52 end
53
54 def data=(data)
55 raise ArgumentError, 'data is mandatory' if data.nil?
56 @data = data
57 end
58
59 def time=(time)
60 raise ArgumentError, 'time is mandatory' if time.nil?
61 @time = time
62 end
63
64 def offset
65 return @time.diff(@parent.origin)
66 end
67 end
68
69 class PointEvent < Event
70
71 end
72
73 class IntervalEvent < Event
74 attr_reader :width, :math_function
75 attr_accessor :sample_count
76
77 def initialize(args = { })
78 super(args)
79 self.width = args[:width]
80 self.math_function = args[:math_function]
81 self.sample_count = args[:sample_count]
82 end
83
84 def width=(width)
85 raise ArgumentError, 'width is mandatory' if width.nil?
86 @width = width
87 end
88
89 def math_function=(math_function)
90 if math_function.nil?
91 raise ArgumentError, 'math_function is mandatory'
92 end
93 @math_function = math_function
94 end
95
96 def interval_start_time
97 date_time = ::Time.iso8601(time.as_string)
98 start_time = (@width.years).years.ago date_time
99 start_time = (@width.months).months.ago start_time
100 start_time = (@width.days).days.ago start_time
101 start_time = (@width.hours).hours.ago start_time
102 start_time = (@width.minutes).minutes.ago start_time
103 seconds = @width.seconds
104 unless @width.fractional_second.nil?
105 seconds += @width.fractional_second
106 end
107 start_time = seconds.ago start_time
108 return DvDateTime.new(:value => start_time.iso8601)
109 end
110 end
111 end # end of History
112 end # end of DataStructure
113 end # end of RM
114end # end of OpenEHR
Note: See TracBrowser for help on using the repository browser.