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
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
[221]50
51 def initialize(args = {})
52 self.code_string = args[:code_string]
53 self.terminology_id = args[:terminology_id]
[106]54 end
55
56 def terminology_id=(terminology_id)
[224]57 if terminology_id.nil?
58 raise ArgumentError, "terminology_id should not be nil"
59 end
[106]60 @terminology_id = terminology_id
61 end
62
63 def code_string=(code_string)
[224]64 if code_string.nil? or code_string.empty?
65 raise ArgumentError, "code_string should not be empty"
66 end
[4]67 @code_string = code_string
[106]68 end
[167]69 end # of CodePhrase
[4]70
[216]71 class DvText < OpenEHR::RM::DataTypes::Basic::DataValue
[220]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]
[4]81 end
[220]82
[4]83 def value=(value)
[220]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
[4]89 @value = value
90 end
[220]91
[4]92 def formatting=(formatting)
[221]93 if !formatting.nil? and formatting.empty?
[220]94 raise ArgumentError, "formatting is not valid"
95 end
[4]96 @formatting = formatting
97 end
[220]98
[4]99 def encoding=(encoding)
[224]100 if !encoding.nil? and encoding.code_string.empty?
[220]101 raise ArgumentError, "encoding is not valid"
102 end
[4]103 @encoding = encoding
104 end
105 def mappings=(mappings)
[220]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
[4]112 @mappings = mappings
113 end
114 def language=(language)
[221]115 if !@language.nil? and language.empty?
[220]116 raise ArgumentError, "langage is not valid"
117 end
[4]118 @language = language
119 end
120 end
121
[167]122 class DvCodedText < DvText
[4]123 attr_reader :defining_code
[124]124
[220]125 def initialize(args = {})
126 super(args)
127 self.defining_code = args[:defining_code]
[4]128 end
[124]129
[4]130 def defining_code=(defining_code)
[124]131 if defining_code.nil?
[220]132 raise ArgumentError, 'defiining code is mandatory'
[124]133 end
[4]134 @defining_code = defining_code
135 end
136 end
137
[216]138 class DvParagraph < OpenEHR::RM::DataTypes::Basic::DataValue
[4]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
[167]159 end # of DataTypes
[4]160 end # of RM
161end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.