Changeset 298
- Timestamp:
- Sep 25, 2009, 12:27:29 PM (15 years ago)
- Location:
- ruby/trunk/lib/open_ehr
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/trunk/lib/open_ehr/rm/data_types/quantity.rb
r297 r298 2 2 # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109599337877_94556_1510Report.html 3 3 # Ticket refs #50 4 require 'assumed_library_types'4 #require 'assumed_library_types' 5 5 module OpenEHR 6 6 module RM 7 7 module DataTypes 8 8 module Quantity 9 10 autoload :Date_Time, "rm/data_types/quantity/date_time.rb"11 12 9 class DvOrdered < OpenEHR::RM::DataTypes::Basic::DataValue 13 10 include Comparable 14 11 attr_accessor :normal_range, :other_refference_ranges, :normal_status 15 12 16 def initialize( normal_range=nil, normal_status = nil,17 other_reference_ranges=nil)18 self.normal_range = normal_range19 self.normal_status = normal_status20 self.other_reference_ranges = other_reference_ranges13 def initialize(args = {}) 14 super(args) 15 self.normal_range = args[:normal_range] 16 self.normal_status = args[:normal_status] 17 self.other_reference_ranges = args[:other_reference_ranges] 21 18 end 22 19 … … 32 29 33 30 def is_simple? 34 normal_status.nil? and other_refference_ranges.nil?31 return @other_reference_ranges.nil? 35 32 end 36 33 … … 40 37 41 38 def other_reference_ranges=(other_reference_ranges) 42 unless other_reference_ranges.nil? or !other_reference_ranges.is_empty?39 if !other_reference_ranges.nil? && other_reference_ranges.empty? 43 40 raise ArgumentError, "Other reference ranges validity error" 44 41 end … … 46 43 end 47 44 48 def is_strictly_comparable_to?(other) 49 raise NotImplementedError, 'this method should be implemented' 45 def is_strictly_comparable_to?(others) 46 if others.instance_of? self.class 47 return true 48 else 49 return false 50 end 50 51 end 51 52 end … … 58 59 attr_reader :magnitude, :magnitude_status 59 60 60 def initialize(magnitude, magnitude_status=nil, 61 normal_range=nil, normal_status = nil, 62 other_reference_ranges=nil) 63 super(normal_range, normal_status, other_reference_ranges) 64 self.magnitude = magnitude 65 self.magnitude_status = magnitude_status 61 def initialize(args = {}) 62 super(args) 63 self.magnitude = args[:magnitude] 64 self.magnitude_status = args[:magnitude_status] 66 65 end 67 66 68 67 def <=>(others) 69 @ value <=> others.value68 @magnitude <=> others.magnitude 70 69 end 71 70 … … 102 101 attr_reader :value, :symbol, :limits 103 102 104 def initialize(value, symbol, limits=nil, normal_range=nil, 105 normal_status = nil, other_reference_ranges=nil) 106 self.value = value 107 self.symbol = symbol 108 self.limits = limits 109 super(normal_range, normal_status, other_reference_ranges) 103 def initialize(args = {}) 104 super(args) 105 self.symbol = args[:symbol] 106 self.limits = args[:limits] 110 107 end 111 108 … … 120 117 end 121 118 122 def is_strictly_comparable_to?(others)123 unless others.instance_of? OpenEhr::RM::DataTypes::Quantity::DvOrdinal124 return false125 end126 unless others.symbol.defining_code.terminology_id.value ==127 @symbol.defining_code.terminology_id.value128 return false129 end130 return true131 end132 133 119 def <=>(other) 134 120 @value <=> other.value … … 142 128 end 143 129 end 130 def is_strictly_comparable_to?(others) 131 unless super(others) 132 return false 133 end 134 unless others.symbol.defining_code.terminology_id.value == 135 @symbol.defining_code.terminology_id.value 136 return false 137 else 138 return true 139 end 140 end 144 141 end 145 142 … … 147 144 attr_accessor :accuracy 148 145 149 def initialize(magnitude, magnitude_status=nil, accuracy=nil, 150 normal_range=nil, normal_status = nil, 151 other_reference_ranges=nil) 152 super(magnitude, magnitude_status, normal_range, 153 normal_status, other_reference_ranges) 154 self.accuracy = accuracy 146 def initialize(args = {}) 147 super(args) 148 self.accuracy = args[:accuracy] 155 149 end 156 150 157 151 def add(a_diff) 158 raise NotImplementedError, 'add must be implemented' 152 type_check(a_diff) 153 return result_builder(DvAbsoluteQuantity, 154 @magnitude+a_diff.magnitude) 159 155 end 160 156 161 157 def diff(other) 162 raise NotImplementedError, 'diff must be implemented' 158 type_check(other) 159 return result_builder(DvAmount, 160 (@magnitude-other.magnitude).abs) 163 161 end 164 162 165 163 def subtract(a_diff) 166 raise NotImplementedError, 'subtract must be implemented' 164 type_check(a_diff) 165 return result_builder(DvAbsoluteQuantity, 166 @magnitude-a_diff.magnitude) 167 end 168 private 169 def type_check(other) 170 unless self.is_strictly_comparable_to? other 171 raise ArgumentError, 'type mismatch' 172 end 173 end 174 175 def result_builder(klass, magnitude) 176 return klass.new(:magnitude => magnitude, 177 :magnitude_status => @magnitude_status, 178 :accuracy => @accuracy, 179 :accuracy_percent => @accuracy_percent, 180 :normal_range => @normal_range, 181 :normal_status => @normal_status, 182 :other_reference_ranges => @other_reference_ranges) 167 183 end 168 184 end … … 170 186 class DvAmount < DvQuantified 171 187 attr_reader :accuracy, :accuracy_percent 172 def initialize(magnitude, magnitude_status=nil, accuracy=nil, 173 accuracy_percent=nil, normal_range=nil, 174 normal_status = nil, other_reference_ranges=nil) 175 super(magnitude, magnitude_status, normal_range, 176 normal_status, other_reference_ranges) 177 unless accuracy.nil? 178 set_accuracy(accuracy, accuracy_percent) 188 189 def initialize(args = {}) 190 super(args) 191 unless args[:accuracy].nil? 192 set_accuracy(args[:accuracy], args[:accuracy_percent]) 179 193 else 180 194 @accuracy, @accuracy_percent = nil, nil … … 183 197 184 198 def +(other) 185 unless self.is_strictly_comparable_to? (other)199 unless self.is_strictly_comparable_to? other 186 200 raise ArgumentError, 'type mismatch' 187 201 end 188 re turn DvAmount.new(@magnitude+other.magnitude, @magnitude_status,189 @accuracy, @accuracy_percent, @normal_range,190 @normal_status, @other_reference_ranges)191 end 192 193 def -(other) 202 result = self.dup 203 result.magnitude = @magnitude + other.magnitude 204 return result 205 end 206 207 def -(other) 194 208 other.magnitude = - other.magnitude 195 209 self+(other) … … 212 226 class DvQuantity < DvAmount 213 227 attr_reader :units, :precision 214 def initialize(magnitude, units, magnitude_status=nil, precision=nil, 215 accuracy=nil, accuracy_percent=nil, normal_range=nil, 216 normal_status = nil, other_reference_ranges=nil) 217 super(magnitude, magnitude_status, accuracy, accuracy_percent, 218 normal_range, normal_status, other_reference_ranges) 219 self.units = units 220 self.precision = precision 228 229 def initialize(args = {}) 230 super(args) 231 self.units = args[:units] 232 self.precision = args[:precision] 221 233 end 222 234 … … 234 246 235 247 def is_strictly_comparable_to?(others) 236 return false if others.nil? 237 if others.instance_of?(DvQuantity) && others.units == @units 248 unless super(others) 249 return false 250 end 251 if others.units == @units 238 252 return true 239 253 else … … 249 263 end 250 264 end 251 # accuracy???252 def +(other)253 dv_amount = super(other)254 return DvQuantity.new(dv_amount.magnitude, @units,255 @magnitude_status, @precision,256 @accuracy, @accuracy_percent, @normal_range,257 @normal_status, @other_reference_ranges)258 end259 265 end 260 266 261 267 class DvCount < DvAmount 262 def is_strictly_comparable_to?(others) 263 return false if others.nil? 264 if others.instance_of?(DvCount) 265 return true 266 else 267 return false 268 end 269 end 268 270 269 end 271 270 … … 273 272 attr_reader :meaning, :range 274 273 275 def initialize( meaning, range)276 self.meaning = meaning277 self.range = range274 def initialize(args = {}) 275 self.meaning = args[:meaning] 276 self.range = args[:range] 278 277 end 279 278 … … 314 313 attr_reader :numerator, :denominator, :type, :precision 315 314 316 def initialize(numerator, denominator, type, precision=nil, 317 magnitude_status=nil, accuracy=nil, 318 accuracy_percent=nil, normal_range=nil, 319 normal_status = nil, other_reference_ranges=nil) 320 self.type = type 321 self.numerator = numerator 322 self.denominator = denominator 323 self.precision = precision 324 self.magnitude_status = magnitude_status 325 unless accuracy.nil? 326 set_accuracy(accuracy, accuracy_percent) 315 def initialize(args = {}) 316 self.type = args[:type] 317 self.numerator = args[:numerator] 318 self.denominator = args[:denominator] 319 self.precision = args[:precision] 320 self.magnitude_status =args[:magnitude_status] 321 unless args[:accuracy].nil? 322 set_accuracy(args[:accuracy], args[:accuracy_percent]) 327 323 else 328 324 @accuracy, @accuracy_percent = nil, nil 329 325 end 330 self.normal_range = normal_range331 self.normal_status = normal_status332 self.other_reference_ranges = other_reference_ranges326 self.normal_range = args[:normal_range] 327 self.normal_status = args[:normal_status] 328 self.other_reference_ranges = args[:other_reference_ranges] 333 329 end 334 330 … … 343 339 344 340 def denominator=(denominator) 345 if denominator.nil? or denominator == PK_RATIO 346 raise ArgumentError, 'denominator invalid' 347 end 348 if (@type == PK_FRACTION || @type == PK_INTEGER_FRACTION) && 349 !denominator.integer? 350 raise ArgumentError, 'denominator invalid for type' 351 end 352 if @type == PK_UNITARY && denominator != 1 353 raise ArgumentError, 'denominator invalid for type' 354 end 355 if @type == PK_PERCENT && denominator != 100 356 raise ArgumentError, 'denominator invaild for type' 341 case @type 342 when PK_UNITARY 343 unless denominator == 1 344 raise ArgumentError, 'Unitary denominator must be 1' 345 end 346 when PK_PERCENT 347 unless denominator == 100 348 raise ArgumentError, 'Percent denominator must be 100' 349 end 350 when PK_FRACTION, PK_INTEGER_FRACTION 351 unless denominator.integer? and @numerator.integer? 352 raise ArgumentError, 'Fraction numerator/denominator must be integer' 353 end 357 354 end 358 355 @denominator = denominator … … 373 370 def precision=(precision) 374 371 unless precision.nil? 375 unless precision == 0 || self.is_integral? 376 @precision = precision 377 else 372 if (self.is_integral? && precision !=0) 378 373 raise ArgumentError, 'precision invalid' 379 374 end 380 375 end 376 @precision = precision 381 377 end 382 378 … … 386 382 387 383 def is_strictly_comparable_to?(other) 388 unless other.instance_of?(DvProportion)384 unless super(other) 389 385 return false 390 386 end -
ruby/trunk/lib/open_ehr/rm/data_types/text.rb
r297 r298 2 2 # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109067605961_209522_3179Report.html 3 3 # Ticket refs #48 4 include OpenEHR::RM::DataTypes::Basic 5 4 6 module OpenEHR 5 7 module RM … … 8 10 class TermMapping 9 11 attr_reader :match, :purpose, :target 10 def initialize(match, purpose, target) 11 match_valid(match)12 purpose_valid(purpose)13 target_valid(target)14 @match, @purpose, @target = match, purpose, target12 13 def initialize(args ={}) 14 self.match = args[:match] 15 self.purpose = args[:purpose] 16 self.target = args[:target] 15 17 end 18 19 def match=(match) 20 unless TermMapping.is_valid_mach_code? match 21 raise ArgumentError, 'invalid match character' 22 end 23 @match = match 24 end 25 26 def purpose=(purpose) 27 # if !purpose.nil? and !purpose.instance_of?(DvCodedText) 28 # raise ArgumentError, "purpose is not valid" 29 # end 30 # should be settled after terminology service implemented 31 @purpose = purpose 32 end 33 34 def target=(target) 35 raise ArgumentError, "target must not be nil" if target.nil? 36 @target = target 37 end 38 16 39 def broader? 17 40 match == '>' 18 41 end 42 19 43 def equivalent? 20 44 match == '=' 21 45 end 46 22 47 def narrower? 23 48 match == '<' 24 49 end 50 25 51 def unknown? 26 52 match == '?' 27 53 end 54 28 55 def TermMapping.is_valid_mach_code?(c) 29 56 c == '>' or c == '=' or c == '<' or c == '?' 30 end31 private32 def match_valid(match)33 raise ArgumentError, "match is not valid" if !TermMapping.is_valid_mach_code? match34 end35 def purpose_valid(purpose)36 if purpose.nil? or !purpose.instance_of? DvCodedText37 raise ArgumentError, "purpose is not valid"38 end39 # should be settled after terminology service implemented40 end41 def target_valid(target)42 raise ArgumentError, "target must not be nil" if target.nil?43 57 end 44 58 end … … 46 60 class CodePhrase 47 61 attr_reader :terminology_id, :code_string 48 def initialize(code_string, terminology_id) 49 self.code_string = code_string 50 self.terminology_id = terminology_id 62 63 def initialize(args = {}) 64 self.code_string = args[:code_string] 65 self.terminology_id = args[:terminology_id] 51 66 end 52 67 53 68 def terminology_id=(terminology_id) 54 raise ArgumentError, "terminology_id should not be nil" if terminology_id.nil? 69 if terminology_id.nil? 70 raise ArgumentError, "terminology_id should not be nil" 71 end 55 72 @terminology_id = terminology_id 56 73 end 57 74 58 75 def code_string=(code_string) 59 raise ArgumentError, "code_string should not be empty" if code_string.nil? or code_string.empty? 76 if code_string.nil? or code_string.empty? 77 raise ArgumentError, "code_string should not be empty" 78 end 60 79 @code_string = code_string 61 80 end … … 63 82 64 83 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue 65 attr_reader :value, :formatting, :hyperlink, :mappings 66 attr_reader :language, :encoding 67 def initialize(value, formatting = nil, hyperlink = nil, 68 mappings = nil, language = nil, encoding = nil) 69 value_valid(value) 70 DvText.formatting_valid(formatting) 71 DvText.encoding_valid(encoding) 72 DvText.mapping_valid(mappings) 73 DvText.language_valid(language) 74 @value, @formatting, @encoding = value, formatting, encoding 75 @mappings, @language = mappings, language 84 attr_reader :formatting, :hyperlink, :mappings, 85 :language, :encoding 86 87 def initialize(args = {}) 88 super(args) 89 self.formatting = args[:formatting] 90 self.encoding = args[:encoding] 91 self.mappings = args[:mappings] 92 self.language = args[:language] 76 93 end 94 77 95 def value=(value) 78 value_valid(value) 96 if value.nil? or value.empty? or 97 value.include? CR or value.include? LF 98 raise ArgumentError, "value is not valid" 99 # CR and LF are defined in Basic_Definition inherited DataValue. 100 end 79 101 @value = value 80 102 end 103 81 104 def formatting=(formatting) 82 DvText.formatting_valid(formatting) 105 if !formatting.nil? and formatting.empty? 106 raise ArgumentError, "formatting is not valid" 107 end 83 108 @formatting = formatting 84 109 end 110 85 111 def encoding=(encoding) 86 DvText.encoding_valid(encoding) 112 if !encoding.nil? and encoding.code_string.empty? 113 raise ArgumentError, "encoding is not valid" 114 end 87 115 @encoding = encoding 88 116 end 89 117 def mappings=(mappings) 90 DvText.mapping_valid(mappings) 118 if !mappings.nil? and !mappings.instance_of? Set 119 raise ArgumentError, "mapping(s) is(are) not valid" 120 elsif !mappings.nil? and mappings.instance_of? Set and 121 mappings.empty? 122 raise ArgumentError, "mapping(s) is(are) not valid" 123 end 91 124 @mappings = mappings 92 125 end 93 126 def language=(language) 94 DvText.language_valid(language) 127 if !@language.nil? and language.empty? 128 raise ArgumentError, "langage is not valid" 129 end 95 130 @language = language 96 131 end 97 private98 def value_valid(value)99 if value.nil? or value.empty? or value.include? CR or value.include? LF100 raise ArgumentError, "value is not valid"101 # CR and LF are defined in Basic_Definition inherited DataValue.102 end103 end104 105 class << self106 107 def formatting_valid(formatting)108 raise ArgumentError, "formatting is not valid" if formatting != nil and formatting.empty?109 end110 111 def encoding_valid(encoding)112 raise ArgumentError, "encoding is not valid" if encoding != nil and encoding.empty?113 end114 115 def mapping_valid(mapping)116 if !mapping.nil? and !mapping.instance_of? Set117 raise ArgumentError, "mapping(s) is(are) not valid"118 elsif !mapping.nil? and mapping.instance_of? Set119 raise ArgumentError, "mapping(s) is(are) not valid" if mapping.empty?120 end121 end122 123 def language_valid(language)124 raise ArgumentError, "langage is not valid" if language != nil and language.empty?125 end126 end127 128 132 end 129 133 … … 131 135 attr_reader :defining_code 132 136 133 def initialize(value, defining_code, formatting = nil, 134 hyperlink = nil, mappings = nil, language = nil, 135 encoding = nil) 136 super(value, formatting, hyperlink, mappings, language, encoding) 137 self.defining_code = defining_code 137 def initialize(args = {}) 138 super(args) 139 self.defining_code = args[:defining_code] 138 140 end 139 141 140 142 def defining_code=(defining_code) 141 143 if defining_code.nil? 142 raise ArgumentError, "Defiinition must be exist"144 raise ArgumentError, 'defiining code is mandatory' 143 145 end 144 146 @defining_code = defining_code … … 148 150 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue 149 151 attr_reader :items 150 def initialize(items) 151 items_exists(items) 152 153 def initialize(args ={}) 154 self.items = args[:items] 155 end 156 157 def items=(items) 158 if items.nil? or items.empty? 159 raise ArgumentError, "Items are not valid" 160 end 152 161 @items = items 153 end154 def items=(items)155 items_exists(items)156 @items = items157 end158 private159 def items_exists(items)160 if !items.nil? and !items.instance_of? Set161 raise ArgumentError, "Items are not valid"162 elsif !items.nil? and items.instance_of? Set163 raise ArgumentError, "Items must be exist" if items.empty?164 end165 162 end 166 163 end -
ruby/trunk/lib/open_ehr/rm/support/terminology.rb
r167 r298 1 1 2 module OpenE hr2 module OpenEHR 3 3 module RM 4 4 module Support … … 8 8 raise NotImplementedError, "all_codes must be implemented" 9 9 end 10 10 11 def has_code(a_code) 11 12 raise NotImplementedError, "has_code must be implemented" 12 13 end 14 13 15 def has_lang(a_lang) 14 16 raise NotImplementedError, "has_lang must be implemented" 15 17 end 18 16 19 def id 17 20 raise NotImplementedError, "id must be returned" 18 21 end 19 22 end 20 module OpenEhrCodeSetIdentifier 23 24 module OpenEHRCodeSetIdentifier 21 25 CODE_SET_ID_CHARACER_SETS = "character sets".freeze 22 26 CODE_SET_ID_COMPRESSION_ALGORITHMS = "compression algorithms".freeze … … 29 33 end 30 34 end 31 module OpenEhrTerminologyGroupIdentifiers 35 36 module OpenEHRTerminologyGroupIdentifiers 32 37 GROUP_ID_ATTESTATION_REASON = "attestation reason".freeze 33 38 GROUP_ID_AUDIT_CHANGE_TYPE = "audit change type".freeze … … 46 51 TERMINOLOGY_ID = "openehr".freeze 47 52 end 53 48 54 class TerminologyAccess 55 attr_reader :id 56 57 def initialize(args = {}) 58 self.id = args[:id] 59 end 60 49 61 def all_codes 50 62 raise NotImplementedError, "all_codes is not implemented" 51 63 end 64 52 65 def codes_for_group_id(group_id) 53 66 raise NotImplementedError, "codes_for_group_id is not implemented" 54 67 end 68 55 69 def codes_for_group_name(name, lang) 56 70 raise NotImplementedError, "codes_for_group_name is not implemented" 57 71 end 72 58 73 def has_code_for_group_id(group_id, a_code) 59 raise NotImplementedError, "has_code_for_group_id is not implemented"74 60 75 end 61 def id 62 raise NotImplementedError, "id is not implemented" 76 77 def id=(id) 78 @terminology = Terminology.find_all_by_name(id) 79 @id = id 63 80 end 81 64 82 def rubric_for_code(code, lang) 65 raise NotImplementedError, "rubic_for_code is not implemented" 83 return Terminology.find(:first, :conditions => {:code => code, 84 :lang => lang}) 66 85 end 86 67 87 private 68 88 def id_exists … … 74 94 end 75 95 end 96 76 97 class TerminologyService 77 include OpenEhrCodeSetIdentifier, OpenEhrTerminologyGroupIdentifiers 98 include OpenEHRCodeSetIdentifier, OpenEHRTerminologyGroupIdentifiers 99 78 100 def code_set(name) 79 101 raise NotImplementedError, "code_set is not implemented" 80 102 end 103 81 104 def code_set_for_id(id) 82 105 raise NotImplementedError, "code_set_for_id is not implemented" 83 106 end 107 84 108 def code_set_identifiers 85 109 raise NotImplementedError, "code_set_for_identifiers is not implemented" 86 110 end 111 87 112 def has_code_set(name) 88 113 raise NotImplementedError, "has_code_set is not implemented" 89 114 end 115 90 116 def has_terminology?(name) 91 117 raise NotImplementedError, "has_terminology is not implemented" 92 118 end 119 93 120 def openehr_code_sets 94 121 raise NotImplementedError, "openehr_code_set is not implemented" 95 122 end 123 96 124 def terminology(name) 97 r aise NotImplementedError, "terminology is not implemented"125 return TerminologyAccess.new(:id => name) 98 126 end 127 99 128 def terminology_identifiers 100 129 raise NotImplementedError, "terminology_identiferes is not implemented"
Note:
See TracChangeset
for help on using the changeset viewer.