Changeset 298 for ruby/trunk/lib/open_ehr/rm/data_types/text.rb
- Timestamp:
- Sep 25, 2009, 12:27:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.