source: ruby/trunk/models/rm/data_types/text.rb@ 4

Last change on this file since 4 was 4, checked in by KOBAYASHI, Shinji, 16 years ago

restructuring repository tree

File size: 5.7 KB
Line 
1module OpenEHR
2 module RM
3 module Data_Types
4 module Text
5 class Term_Mapping
6 attr_reader :match, :purpose, :target
7 def initialize(match, purpose, target)
8 match_valid(match)
9 purpose_valid(purpose)
10 target_valid(target)
11 @match, @purpose, @target = match, purpose, target
12 end
13 def broader?
14 match == '>'
15 end
16 def equivalent?
17 match == '='
18 end
19 def narrower?
20 match == '<'
21 end
22 def unknown?
23 match == '?'
24 end
25 def Term_Mapping.is_valid_mach_code?(c)
26 c == '>' or c == '=' or c == '<' or c == '?'
27 end
28 private
29 def match_valid(mach)
30 raise ArgumentError, "match is not valid" if self.is_valid_mach_code? match
31 end
32 def purpose_valid(purpose)
33 if !purpose.nil? and !purpose.instance_of? DV_Coded_Text
34 raise ArgumentError, "purpose is not valid"
35 end
36 # should be settled after terminology service implemented
37 end
38 def target_valid(target)
39 raise ArgumentError, "target must not be nil" if target.nil?
40 end
41 end
42
43 class Code_Phrase
44 attr_reader :terminology_id, :code_string
45 def initialize(terminology_id, code_string)
46 if terminlogyID == nil
47 raise Exception.new("nil terminology")
48 end
49 if code_string == nil
50 raise Exception.new("empty codeString")
51 end
52 if terminology_id.instance_of?(Terminology_ID)
53 @terminology_id = terminology_id
54 else
55 @terminologyID = Terminology_ID.new(terminology_id)
56 end
57 @code_string = code_string
58 end
59 end # of Code_Phrase
60
61 class DV_Text < OpenEHR::RM::Data_Types::Basic::Data_Value
62 attr_reader :value, :formatting, :hyperlink, :mappings
63 attr_reader :language, :encoding
64 def initialize(value, formatting = nil, hyperlink = nil,
65 mappings = nil, language = nil, encoding = nil)
66 value_valid(value)
67 DV_Text.formatting_valid(formatting)
68 DV_Text.encoding_valid(encoding)
69 DV_Text.mapping_valid(mappings)
70 DV_Text.language_valid(language)
71 @value, @formatting, @encoding = value, formatting, encoding
72 @mappings, @language = mappings, language
73 end
74 def value=(value)
75 value_valid(value)
76 @value = value
77 end
78 def formatting=(formatting)
79 DV_Text.formatting_valid(formatting)
80 @formatting = formatting
81 end
82 def encoding=(encoding)
83 DV_Text.encoding_valid(encoding)
84 @encoding = encoding
85 end
86 def mappings=(mappings)
87 DV_Text.mapping_valid(mappings)
88 @mappings = mappings
89 end
90 def language=(language)
91 DV_Text.language_valid(language)
92 @language = language
93 end
94 private
95 def value_valid(value)
96 if value.nil? or value.empty? or value.include? CR or value.include? LF
97 raise ArgumentError, "value is not valid"
98 # CR and LF are defined in Basic_Definition inherited Data_Value.
99 end
100 end
101
102 class << self
103
104 def formatting_valid(formatting)
105 raise ArgumentError, "formatting is not valid" if formatting != nil and formatting.empty?
106 end
107
108 def encoding_valid(encoding)
109 raise ArgumentError, "encoding is not valid" if encoding != nil and encoding.empty?
110 end
111
112 def mapping_valid(mapping)
113 if !mapping.nil? and !mapping.instance_of? Set
114 raise ArgumentError, "mapping(s) is(are) not valid"
115 elsif !mapping.nil? and mapping.instance_of? Set
116 raise ArgumentError, "mapping(s) is(are) not valid" if mapping.empty?
117 end
118 end
119
120 def language_valid(language)
121 raise ArgumentError, "langage is not valid" if language != nil and language.empty?
122 end
123 end
124
125 end
126
127 class DV_Coded_Text < DV_Text
128 attr_reader :defining_code
129 def initialize(value, defining_code, formatting = nil,
130 hyperlink = nil, mappings = nil, language = nil,
131 encoding = nil)
132 super(value, formatting, hyperlink, mappings, language, encoding)
133 definition_exists(defining_code)
134 @defining_code = defining_code
135 end
136 def defining_code=(defining_code)
137 definition_exists(defining_code)
138 @defining_code = defining_code
139 end
140 private
141 def definition_exists(defining_code)
142 raise ArgumentError, "Defiinition must be exist" if defining_code.nil?
143 end
144 end
145
146 class DV_Paragraph < OpenEHR::RM::Data_Types::Basic::Data_Value
147 attr_reader :items
148 def initialize(items)
149 items_exists(items)
150 @items = items
151 end
152 def items=(items)
153 items_exists(items)
154 @items = items
155 end
156 private
157 def items_exists(items)
158 if !items.nil? and !items.instance_of? Set
159 raise ArgumentError, "Items are not valid"
160 elsif !items.nil? and items.instance_of? Set
161 raise ArgumentError, "Items must be exist" if items.empty?
162 end
163 end
164 end
165
166 end # of Text
167 end # of Data_Type
168 end # of RM
169end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.