source: ruby/branches/0.5.0/lib/open_ehr/rm/data_types/text.rb@ 167

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

adjust for rails

File size: 5.8 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 DataTypes
7 module Text
8 class TermMapping
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 TermMapping.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 !TermMapping.is_valid_mach_code? match
34 end
35 def purpose_valid(purpose)
36 if purpose.nil? or !purpose.instance_of? DvCodedText
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 CodePhrase
47 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
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 CodePhrase
63
64 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
76 end
77 def value=(value)
78 value_valid(value)
79 @value = value
80 end
81 def formatting=(formatting)
82 DvText.formatting_valid(formatting)
83 @formatting = formatting
84 end
85 def encoding=(encoding)
86 DvText.encoding_valid(encoding)
87 @encoding = encoding
88 end
89 def mappings=(mappings)
90 DvText.mapping_valid(mappings)
91 @mappings = mappings
92 end
93 def language=(language)
94 DvText.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 DataValue.
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 DvCodedText < DvText
131 attr_reader :defining_code
132
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
138 end
139
140 def defining_code=(defining_code)
141 if defining_code.nil?
142 raise ArgumentError, "Defiinition must be exist"
143 end
144 @defining_code = defining_code
145 end
146 end
147
148 class DvParagraph < OpenEhr::RM::DataTypes::Basic::DataValue
149 attr_reader :items
150 def initialize(items)
151 items_exists(items)
152 @items = items
153 end
154 def items=(items)
155 items_exists(items)
156 @items = items
157 end
158 private
159 def items_exists(items)
160 if !items.nil? and !items.instance_of? Set
161 raise ArgumentError, "Items are not valid"
162 elsif !items.nil? and items.instance_of? Set
163 raise ArgumentError, "Items must be exist" if items.empty?
164 end
165 end
166 end
167
168 end # of Text
169 end # of DataTypes
170 end # of RM
171end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.