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
RevLine 
[88]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
[141]4require 'assumed_library_types'
[4]5module OpenEHR
6 module RM
7 module Data_Types
8 module Quantity
[137]9
10 autoload :Date_Time, "rm/data_types/quantity/date_time.rb"
11
[104]12 class DV_Ordered < OpenEHR::RM::Data_Types::Basic::Data_Value
[4]13 include Comparable
[138]14 attr_accessor :normal_range, :other_refference_ranges, :normal_status
[122]15
[124]16 def initialize(normal_range=nil, normal_status = nil,
17 other_reference_ranges=nil)
[123]18 self.normal_range = normal_range
[124]19 self.normal_status = normal_status
[123]20 self.other_reference_ranges = other_reference_ranges
[4]21 end
[122]22
[4]23 def is_normal?
[124]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
[4]31 end
[122]32
[4]33 def is_simple?
[88]34 normal_status.nil? and other_refference_ranges.nil?
[4]35 end
[122]36
37 def <=>(other)
[124]38 raise NotImplementedError, 'This method should be implemented'
[122]39 end
40
41 def other_reference_ranges=(other_reference_ranges)
[123]42 unless other_reference_ranges.nil? or !other_reference_ranges.is_empty?
[4]43 raise ArgumentError, "Other reference ranges validity error"
44 end
[123]45 @other_reference_ranges = other_reference_ranges
[4]46 end
[123]47
[142]48 def is_strictly_comparable_to?(other)
[137]49 raise NotImplementedError, 'this method should be implemented'
50 end
[4]51 end
[88]52
[141]53 class DV_Interval < OpenEHR::Assumed_Library_Types::Interval
54
55 end
[142]56
[104]57 class DV_Quantified < DV_Ordered
[137]58
[138]59 def initialize(normal_range=nil, normal_status = nil,
60 other_reference_ranges=nil)
[139]61 super(normal_range, normal_status, other_reference_ranges)
[137]62 end
63
[4]64 def magnitude
[137]65
[4]66 end
[137]67
68 def <=>(others)
[140]69 @value <=> others.value
[137]70 end
71
[4]72 def valid_magnitude_status(s)
[140]73
[4]74 end
75 end
[88]76
[104]77 class DV_Ordinal < DV_Ordered
[142]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)
[140]86 end
[137]87
[142]88 def value=(value)
89 raise ArgumentError, 'value should not be nil' if value.nil?
90 @value = value
91 end
[140]92
[142]93 def symbol=(symbol)
94 raise ArgumentError,'symbol should not be nil' if symbol.nil?
95 @symbol = symbol
[88]96 end
[137]97
[142]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
[139]109 def <=>(other)
[142]110 @value <=> other.value
[139]111 end
[140]112
[142]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
[88]119 end
120 end
121
[104]122 class DV_Absolute_Quantity < DV_Quantified
[88]123 attr_reader :accuracy
124
125 def add(a_diff)
[122]126 raise NotImplementError, 'add must be implemented'
[88]127 end
128
129 def diff(other)
[122]130 raise NotImplementError, 'diff must be implemented'
[88]131 end
132
133 def subtract(a_diff)
[122]134 raise NotImplementError, 'subtract must be implemented'
[88]135 end
136 end
[120]137
[122]138 class DV_Amount < DV_Quantified
139 attr_reader :accuracy, :accuracy_is_percent
[140]140
[122]141 def infix(dv_amount, op)
142 raise NotImplementError, 'infix must be implemented'
143 end
[140]144
[122]145 def accuracy=(accuracy)
146 raise ArgumentError, 'accuracy invalid'
147 end
148 end
149
[140]150 class DV_Quantity < DV_Amount
151
152 end
153
[124]154 class Reference_Range
[141]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
[124]167 end
[139]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
[140]180 end # end of Proportion_Kind
[4]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.