source: ruby/branches/0.5/lib/open_ehr/rm/data_types/text.rb

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

move from test to rspec

File size: 4.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
4include OpenEHR::RM::DataTypes::Basic
5
6module OpenEHR
7 module RM
8 module DataTypes
9 module Text
10 class TermMapping
11 attr_reader :match, :purpose, :target
12
13 def initialize(args ={})
14 self.match = args[:match]
15 self.purpose = args[:purpose]
16 self.target = args[:target]
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
39 def broader?
40 match == '>'
41 end
42
43 def equivalent?
44 match == '='
45 end
46
47 def narrower?
48 match == '<'
49 end
50
51 def unknown?
52 match == '?'
53 end
54
55 def TermMapping.is_valid_mach_code?(c)
56 c == '>' or c == '=' or c == '<' or c == '?'
57 end
58 end
59
60 class CodePhrase
61 attr_reader :terminology_id, :code_string
62
63 def initialize(args = {})
64 self.code_string = args[:code_string]
65 self.terminology_id = args[:terminology_id]
66 end
67
68 def terminology_id=(terminology_id)
69 if terminology_id.nil?
70 raise ArgumentError, "terminology_id should not be nil"
71 end
72 @terminology_id = terminology_id
73 end
74
75 def code_string=(code_string)
76 if code_string.nil? or code_string.empty?
77 raise ArgumentError, "code_string should not be empty"
78 end
79 @code_string = code_string
80 end
81 end # of CodePhrase
82
83 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue
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]
93 end
94
95 def value=(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
101 @value = value
102 end
103
104 def formatting=(formatting)
105 if !formatting.nil? and formatting.empty?
106 raise ArgumentError, "formatting is not valid"
107 end
108 @formatting = formatting
109 end
110
111 def encoding=(encoding)
112 if !encoding.nil? and encoding.code_string.empty?
113 raise ArgumentError, "encoding is not valid"
114 end
115 @encoding = encoding
116 end
117 def mappings=(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
124 @mappings = mappings
125 end
126 def language=(language)
127 if !@language.nil? and language.empty?
128 raise ArgumentError, "langage is not valid"
129 end
130 @language = language
131 end
132 end
133
134 class DvCodedText < DvText
135 attr_reader :defining_code
136
137 def initialize(args = {})
138 super(args)
139 self.defining_code = args[:defining_code]
140 end
141
142 def defining_code=(defining_code)
143 if defining_code.nil?
144 raise ArgumentError, 'defiining code is mandatory'
145 end
146 @defining_code = defining_code
147 end
148 end
149
150 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue
151 attr_reader :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
161 @items = items
162 end
163 end
164
165 end # of Text
166 end # of DataTypes
167 end # of RM
168end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.