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
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
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
[167]30 def TermMapping.is_valid_mach_code?(c)
[4]31 c == '>' or c == '=' or c == '<' or c == '?'
32 end
33 private
[90]34 def match_valid(match)
[167]35 raise ArgumentError, "match is not valid" if !TermMapping.is_valid_mach_code? match
[4]36 end
37 def purpose_valid(purpose)
[167]38 if purpose.nil? or !purpose.instance_of? DvCodedText
[4]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
[167]48 class CodePhrase
[4]49 attr_reader :terminology_id, :code_string
[107]50 def initialize(code_string, terminology_id)
51 self.code_string = code_string
[106]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?
[4]62 @code_string = code_string
[106]63 end
[167]64 end # of CodePhrase
[4]65
[216]66 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue
[220]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]
[4]76 end
[220]77
[4]78 def value=(value)
[220]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
[4]84 @value = value
85 end
[220]86
[4]87 def formatting=(formatting)
[220]88 unless formatting.nil? or formatting.empty?
89 raise ArgumentError, "formatting is not valid"
90 end
[4]91 @formatting = formatting
92 end
[220]93
[4]94 def encoding=(encoding)
[220]95 unless encoding.nil? or encoding.empty?
96 raise ArgumentError, "encoding is not valid"
97 end
[4]98 @encoding = encoding
99 end
100 def mappings=(mappings)
[220]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
[4]107 @mappings = mappings
108 end
109 def language=(language)
[220]110 unless language.nil? or language.empty?
111 raise ArgumentError, "langage is not valid"
112 end
[4]113 @language = language
114 end
115 end
116
[167]117 class DvCodedText < DvText
[4]118 attr_reader :defining_code
[124]119
[220]120 def initialize(args = {})
121 super(args)
122 self.defining_code = args[:defining_code]
[4]123 end
[124]124
[4]125 def defining_code=(defining_code)
[124]126 if defining_code.nil?
[220]127 raise ArgumentError, 'defiining code is mandatory'
[124]128 end
[4]129 @defining_code = defining_code
130 end
131 end
132
[216]133 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue
[4]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
[167]154 end # of DataTypes
[4]155 end # of RM
156end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.