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

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

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