source: ruby/trunk/lib/models/rm/data_types/quantity.rb@ 142

Last change on this file since 142 was 142, checked in by KOBAYASHI, Shinji, 15 years ago

ref #50

File size: 5.2 KB
Line 
1# This modules are implemented from the UML shown bellow
2# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109599337877_94556_1510Report.html
3# Ticket refs #50
4require 'assumed_library_types'
5module OpenEHR
6 module RM
7 module Data_Types
8 module Quantity
9
10 autoload :Date_Time, "rm/data_types/quantity/date_time.rb"
11
12 class DV_Ordered < OpenEHR::RM::Data_Types::Basic::Data_Value
13 include Comparable
14 attr_accessor :normal_range, :other_refference_ranges, :normal_status
15
16 def initialize(normal_range=nil, normal_status = nil,
17 other_reference_ranges=nil)
18 self.normal_range = normal_range
19 self.normal_status = normal_status
20 self.other_reference_ranges = other_reference_ranges
21 end
22
23 def is_normal?
24 if @normal_range.nil? and @normal_status.nil?
25 return false
26 elsif !@normal_range.nil?
27 return @normal_range.has(@value)
28 elsif !@normal_status.nil?
29 return @normal_status.code_string == 'N'
30 end
31 end
32
33 def is_simple?
34 normal_status.nil? and other_refference_ranges.nil?
35 end
36
37 def <=>(other)
38 raise NotImplementedError, 'This method should be implemented'
39 end
40
41 def other_reference_ranges=(other_reference_ranges)
42 unless other_reference_ranges.nil? or !other_reference_ranges.is_empty?
43 raise ArgumentError, "Other reference ranges validity error"
44 end
45 @other_reference_ranges = other_reference_ranges
46 end
47
48 def is_strictly_comparable_to?(other)
49 raise NotImplementedError, 'this method should be implemented'
50 end
51 end
52
53 class DV_Interval < OpenEHR::Assumed_Library_Types::Interval
54
55 end
56
57 class DV_Quantified < DV_Ordered
58
59 def initialize(normal_range=nil, normal_status = nil,
60 other_reference_ranges=nil)
61 super(normal_range, normal_status, other_reference_ranges)
62 end
63
64 def magnitude
65
66 end
67
68 def <=>(others)
69 @value <=> others.value
70 end
71
72 def valid_magnitude_status(s)
73
74 end
75 end
76
77 class DV_Ordinal < DV_Ordered
78 attr_reader :value, :symbol, :limits
79
80 def initialize(value, symbol, limits=nil, normal_range=nil,
81 normal_status = nil, other_reference_ranges=nil)
82 self.value = value
83 self.symbol = symbol
84 self.limits = limits
85 super(normal_range, normal_status, other_reference_ranges)
86 end
87
88 def value=(value)
89 raise ArgumentError, 'value should not be nil' if value.nil?
90 @value = value
91 end
92
93 def symbol=(symbol)
94 raise ArgumentError,'symbol should not be nil' if symbol.nil?
95 @symbol = symbol
96 end
97
98 def is_strictly_comparable_to?(others)
99 unless others.instance_of? OpenEHR::RM::Data_Types::Quantity::DV_Ordinal
100 return false
101 end
102 unless others.symbol.defining_code.terminology_id.value ==
103 @symbol.defining_code.terminology_id.value
104 return false
105 end
106 return true
107 end
108
109 def <=>(other)
110 @value <=> other.value
111 end
112
113 def limits=(limits)
114 unless limits.nil? or limits.meaning.value == 'limits'
115 raise ArgumentError, 'invalid limits'
116 else
117 @limits = limits
118 end
119 end
120 end
121
122 class DV_Absolute_Quantity < DV_Quantified
123 attr_reader :accuracy
124
125 def add(a_diff)
126 raise NotImplementError, 'add must be implemented'
127 end
128
129 def diff(other)
130 raise NotImplementError, 'diff must be implemented'
131 end
132
133 def subtract(a_diff)
134 raise NotImplementError, 'subtract must be implemented'
135 end
136 end
137
138 class DV_Amount < DV_Quantified
139 attr_reader :accuracy, :accuracy_is_percent
140
141 def infix(dv_amount, op)
142 raise NotImplementError, 'infix must be implemented'
143 end
144
145 def accuracy=(accuracy)
146 raise ArgumentError, 'accuracy invalid'
147 end
148 end
149
150 class DV_Quantity < DV_Amount
151
152 end
153
154 class Reference_Range
155 attr_reader :meaning
156
157 def initialize(meaning)
158 self.meaning = meaning
159 end
160
161 def meaning=(meaning)
162 if meaning.nil?
163 raise ArgumentError, 'meaning should not be nil'
164 end
165 @meaning = meaning
166 end
167 end
168
169 module Proportion_Kind
170 PK_RATIO = 0
171 PK_UNITARY = 1
172 PK_PERCENT = 2
173 PK_FRACTION = 3
174 PK_INTEGER_FRACTION = 4
175
176 def Proportion_Kind.valid_proportion_kind?(kind)
177 return true if kind >= 0 && kind <= 4
178 return false
179 end
180 end # end of Proportion_Kind
181 end # of Quantity
182 end # of Data_Types
183 end # of RM
184end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.