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

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

terminology service (encoding) should be implemented. hmmmm

File size: 5.0 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 def initialize(match, purpose, target)
13 match_valid(match)
14 purpose_valid(purpose)
15 target_valid(target)
16 @match, @purpose, @target = match, purpose, target
17 end
18 def broader?
19 match == '>'
20 end
21 def equivalent?
22 match == '='
23 end
24 def narrower?
25 match == '<'
26 end
27 def unknown?
28 match == '?'
29 end
30 def TermMapping.is_valid_mach_code?(c)
31 c == '>' or c == '=' or c == '<' or c == '?'
32 end
33 private
34 def match_valid(match)
35 raise ArgumentError, "match is not valid" if !TermMapping.is_valid_mach_code? match
36 end
37 def purpose_valid(purpose)
38 if purpose.nil? or !purpose.instance_of? DvCodedText
39 raise ArgumentError, "purpose is not valid"
40 end
41 # should be settled after terminology service implemented
42 end
43 def target_valid(target)
44 raise ArgumentError, "target must not be nil" if target.nil?
45 end
46 end
47
48 class CodePhrase
49 attr_reader :terminology_id, :code_string
50
51 def initialize(args = {})
52 self.code_string = args[:code_string]
53 self.terminology_id = args[:terminology_id]
54 end
55
56 def terminology_id=(terminology_id)
57 if terminology_id.nil?
58 raise ArgumentError, "terminology_id should not be nil"
59 end
60 @terminology_id = terminology_id
61 end
62
63 def code_string=(code_string)
64 if code_string.nil? or code_string.empty?
65 raise ArgumentError, "code_string should not be empty"
66 end
67 @code_string = code_string
68 end
69 end # of CodePhrase
70
71 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue
72 attr_reader :formatting, :hyperlink, :mappings,
73 :language, :encoding
74
75 def initialize(args = {})
76 super(args)
77 self.formatting = args[:formatting]
78 self.encoding = args[:encoding]
79 self.mappings = args[:mappings]
80 self.language = args[:language]
81 end
82
83 def value=(value)
84 if value.nil? or value.empty? or
85 value.include? CR or value.include? LF
86 raise ArgumentError, "value is not valid"
87 # CR and LF are defined in Basic_Definition inherited DataValue.
88 end
89 @value = value
90 end
91
92 def formatting=(formatting)
93 if !formatting.nil? and formatting.empty?
94 raise ArgumentError, "formatting is not valid"
95 end
96 @formatting = formatting
97 end
98
99 def encoding=(encoding)
100 if !encoding.nil? and encoding.code_string.empty?
101 raise ArgumentError, "encoding is not valid"
102 end
103 @encoding = encoding
104 end
105 def mappings=(mappings)
106 if !mappings.nil? and !mappings.instance_of? Set
107 raise ArgumentError, "mapping(s) is(are) not valid"
108 elsif !mappings.nil? and mappings.instance_of? Set and
109 mappings.empty?
110 raise ArgumentError, "mapping(s) is(are) not valid"
111 end
112 @mappings = mappings
113 end
114 def language=(language)
115 if !@language.nil? and language.empty?
116 raise ArgumentError, "langage is not valid"
117 end
118 @language = language
119 end
120 end
121
122 class DvCodedText < DvText
123 attr_reader :defining_code
124
125 def initialize(args = {})
126 super(args)
127 self.defining_code = args[:defining_code]
128 end
129
130 def defining_code=(defining_code)
131 if defining_code.nil?
132 raise ArgumentError, 'defiining code is mandatory'
133 end
134 @defining_code = defining_code
135 end
136 end
137
138 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue
139 attr_reader :items
140 def initialize(items)
141 items_exists(items)
142 @items = items
143 end
144 def items=(items)
145 items_exists(items)
146 @items = items
147 end
148 private
149 def items_exists(items)
150 if !items.nil? and !items.instance_of? Set
151 raise ArgumentError, "Items are not valid"
152 elsif !items.nil? and items.instance_of? Set
153 raise ArgumentError, "Items must be exist" if items.empty?
154 end
155 end
156 end
157
158 end # of Text
159 end # of DataTypes
160 end # of RM
161end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.