source: ruby/trunk/lib/models/rm/common/archetyped.rb@ 112

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

refs #63, #65

File size: 4.4 KB
Line 
1# This module is based on the UML,
2# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109318114715_211173_0Report.html
3# Ticket refs #65
4module OpenEHR
5 module RM
6 module Common
7 module Archetyped
8 module Locater_Constants
9 CURRENT_TRANSACTION_ID = "current"
10 FRAGMENT_SEPARATOR = "#"
11 CONTENT_PATH_SEPARATOR = "|"
12 ORGANIZER_PATH_SEPARATOR = "/"
13 MULTIPART_ID_DELIMITER = "::"
14 end
15
16 class Pathable
17 attr_accessor :parent
18 def initialize(parent = nil)
19 @parent = parent
20 end
21 def item_at_path(path)
22 raise NotImplementError, "item_at_path must be implemented"
23 end
24 def items_at_path(path)
25 raise NotImplementError, "items_at_path must be implemented"
26 end
27 def path_exists?(path)
28 raise NotImplementError, "path_exists? must be implemented"
29 end
30 def path_of_item(item)
31 raise NotImplementError, "path_of_item must be implemented"
32 end
33 def path_unique(path)
34 raise NotImplementError, "path_unique must be implemented"
35 end
36 end
37
38 class Locatable < Pathable
39 include Locater_Constants
40 attr_reader :archetype_node_id, :name, :links
41 attr_accessor :uid, :archetype_details, :feeder_audit
42 def initialize(archetype_node_id, name, links, parent=nil, uid=nil, archetype_details=nil, feeder_audit=nil)
43 super(parent)
44 self.archetype_node_id = archetype_node_id
45 self.name = name
46 self.links = links
47 self.uid = uid
48 self.archetype_details = archetype_details
49 self.feeder_audit = feeder_audit
50 self.parent = parent
51 end
52
53 def archetype_node_id=(archetype_node_id)
54 raise ArgumentError, 'archetype_node_id should not be nil' if archetype_node_id.nil?
55 @archetype_node_id = archetype_node_id
56 end
57
58 def name=(name)
59 raise ArgumentError, 'name should not be empty' if name.nil? or name.value.empty?
60 @name = name
61 end
62 def links=(links)
63 raise ArgumentError, "links shoud not be empty" if !links.nil? and links.empty?
64 @links = links
65 end
66 def item_at_path(path)
67 if !@path.nil?
68 if @path == ""
69 raise ArgumentError, "path is not valid"
70 end
71 end
72 end
73 def items_at_path(path)
74 raise NotImplementError, "items_at_path must be implemented"
75 end
76 def path_exists?
77 raise NotImplementError, "path_exists? must be implemented"
78 end
79 def path_unique
80 raise NotImplementError, "path_unique must be implemented"
81 end
82 def concept
83 end
84 def is_archetype_root?
85 !archetype_details.nil?
86 end
87 end
88
89 class Archetyped
90 attr_reader :archetype_id, :rm_version
91 attr_accessor :template_id
92 def initialize(archetype_id, rm_version, template_id = nil)
93 self.archetype_id = archetype_id
94 self.rm_version = rm_version
95 self.template_id = template_id
96 end
97 def archetype_id=(archetype_id)
98 raise ArgumentError, "invalid archetype_id" if archetype_id.nil?
99 @archetype_id = archetype_id
100 end
101 def rm_version=(rm_version)
102 raise ArgumentError, "invalid rm_version" if rm_version.nil? or rm_version.empty?
103 @rm_version = rm_version
104 end
105 end
106
107 class Link
108 attr_reader :meaning, :target, :type
109 def initialize(meaning, target, type)
110 self.meaning = meaning
111 self.target = target
112 self.type = type
113 end
114 def meaning=(meaning)
115 raise ArgumentError, "meaning should not be nil" if meaning.nil?
116 @meaning = meaning
117 end
118 def target=(target)
119 raise ArgumentError, "target should not be nil" if target.nil?
120 @target = target
121 end
122 def type=(type)
123 raise ArgumentError, "type should not be nil" if type.nil?
124 @type = type
125 end
126 end # of Link
127 end # of Archetyped
128 end # of Common
129 end # of RM
130end # OpenEHR
Note: See TracBrowser for help on using the repository browser.