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

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

move from test to rspec

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