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

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

DvText modified

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 def initialize(code_string, terminology_id)
51 self.code_string = code_string
52 self.terminology_id = terminology_id
53 end
54
55 def terminology_id=(terminology_id)
56 raise ArgumentError, "terminology_id should not be nil" if terminology_id.nil?
57 @terminology_id = terminology_id
58 end
59
60 def code_string=(code_string)
61 raise ArgumentError, "code_string should not be empty" if code_string.nil? or code_string.empty?
62 @code_string = code_string
63 end
64 end # of CodePhrase
65
66 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue
67 attr_reader :formatting, :hyperlink, :mappings,
68 :language, :encoding
69
70 def initialize(args = {})
71 super(args)
72 self.formatting = args[:formatting]
73 self.encoding = args[:encoding]
74 self.mappings = args[:mappings]
75 self.language = args[:language]
76 end
77
78 def value=(value)
79 if value.nil? or value.empty? or
80 value.include? CR or value.include? LF
81 raise ArgumentError, "value is not valid"
82 # CR and LF are defined in Basic_Definition inherited DataValue.
83 end
84 @value = value
85 end
86
87 def formatting=(formatting)
88 unless formatting.nil? or formatting.empty?
89 raise ArgumentError, "formatting is not valid"
90 end
91 @formatting = formatting
92 end
93
94 def encoding=(encoding)
95 unless encoding.nil? or encoding.empty?
96 raise ArgumentError, "encoding is not valid"
97 end
98 @encoding = encoding
99 end
100 def mappings=(mappings)
101 if !mappings.nil? and !mappings.instance_of? Set
102 raise ArgumentError, "mapping(s) is(are) not valid"
103 elsif !mappings.nil? and mappings.instance_of? Set and
104 mappings.empty?
105 raise ArgumentError, "mapping(s) is(are) not valid"
106 end
107 @mappings = mappings
108 end
109 def language=(language)
110 unless language.nil? or language.empty?
111 raise ArgumentError, "langage is not valid"
112 end
113 @language = language
114 end
115 end
116
117 class DvCodedText < DvText
118 attr_reader :defining_code
119
120 def initialize(args = {})
121 super(args)
122 self.defining_code = args[:defining_code]
123 end
124
125 def defining_code=(defining_code)
126 if defining_code.nil?
127 raise ArgumentError, 'defiining code is mandatory'
128 end
129 @defining_code = defining_code
130 end
131 end
132
133 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue
134 attr_reader :items
135 def initialize(items)
136 items_exists(items)
137 @items = items
138 end
139 def items=(items)
140 items_exists(items)
141 @items = items
142 end
143 private
144 def items_exists(items)
145 if !items.nil? and !items.instance_of? Set
146 raise ArgumentError, "Items are not valid"
147 elsif !items.nil? and items.instance_of? Set
148 raise ArgumentError, "Items must be exist" if items.empty?
149 end
150 end
151 end
152
153 end # of Text
154 end # of DataTypes
155 end # of RM
156end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.