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

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

refs #48, #52, #39

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