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

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

refs #50

File size: 4.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
[137]48 def is_strictry_comparable_to?(other)
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
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
[140]78 attr_reader :value, :symbol
79 def initialize(value, symbol, normal_range=nil, normal_status = nil,
80 other_reference_ranges=nil)
81 end
[137]82
[88]83 def is_strictly_comparable_to?
[140]84
[88]85 end
[137]86
[139]87 def <=>(other)
[140]88 @value <=> other.value
[139]89 end
[140]90
[88]91 def limits
[140]92
[88]93 end
94 end
95
[104]96 class DV_Absolute_Quantity < DV_Quantified
[88]97 attr_reader :accuracy
98
99 def add(a_diff)
[122]100 raise NotImplementError, 'add must be implemented'
[88]101 end
102
103 def diff(other)
[122]104 raise NotImplementError, 'diff must be implemented'
[88]105 end
106
107 def subtract(a_diff)
[122]108 raise NotImplementError, 'subtract must be implemented'
[88]109 end
110 end
[120]111
[122]112 class DV_Amount < DV_Quantified
113 attr_reader :accuracy, :accuracy_is_percent
[140]114
[122]115 def infix(dv_amount, op)
116 raise NotImplementError, 'infix must be implemented'
117 end
[140]118
[122]119 def accuracy=(accuracy)
120 raise ArgumentError, 'accuracy invalid'
121 end
122 end
123
[140]124 class DV_Quantity < DV_Amount
125
126 end
127
[124]128 class Reference_Range
[141]129 attr_reader :meaning
130
131 def initialize(meaning)
132 self.meaning = meaning
133 end
134
135 def meaning=(meaning)
136 if meaning.nil?
137 raise ArgumentError, 'meaning should not be nil'
138 end
139 @meaning = meaning
140 end
[124]141 end
[139]142
143 module Proportion_Kind
144 PK_RATIO = 0
145 PK_UNITARY = 1
146 PK_PERCENT = 2
147 PK_FRACTION = 3
148 PK_INTEGER_FRACTION = 4
149
150 def Proportion_Kind.valid_proportion_kind?(kind)
151 return true if kind >= 0 && kind <= 4
152 return false
153 end
[140]154 end # end of Proportion_Kind
[4]155 end # of Quantity
156 end # of Data_Types
157 end # of RM
158end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.