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
|
---|
4 | module 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 |
|
---|
19 | def initialize(parent = nil)
|
---|
20 | @parent = parent
|
---|
21 | end
|
---|
22 |
|
---|
23 | def item_at_path(path)
|
---|
24 | raise NotImplementError, "item_at_path must be implemented"
|
---|
25 | end
|
---|
26 |
|
---|
27 | def items_at_path(path)
|
---|
28 | raise NotImplementError, "items_at_path must be implemented"
|
---|
29 | end
|
---|
30 |
|
---|
31 | def path_exists?(path)
|
---|
32 | raise NotImplementError, "path_exists? must be implemented"
|
---|
33 | end
|
---|
34 |
|
---|
35 | def path_of_item(item)
|
---|
36 | raise NotImplementError, "path_of_item must be implemented"
|
---|
37 | end
|
---|
38 |
|
---|
39 | def path_unique(path)
|
---|
40 | raise NotImplementError, "path_unique must be implemented"
|
---|
41 | end
|
---|
42 | end
|
---|
43 |
|
---|
44 | class Locatable < Pathable
|
---|
45 | include Locater_Constants
|
---|
46 | attr_reader :archetype_node_id, :name, :links
|
---|
47 | attr_accessor :uid, :archetype_details, :feeder_audit
|
---|
48 |
|
---|
49 | def initialize(archetype_node_id, name, links, parent=nil, uid=nil, archetype_details=nil, feeder_audit=nil)
|
---|
50 | super(parent)
|
---|
51 | self.archetype_node_id = archetype_node_id
|
---|
52 | self.name = name
|
---|
53 | self.links = links
|
---|
54 | self.uid = uid
|
---|
55 | self.archetype_details = archetype_details
|
---|
56 | self.feeder_audit = feeder_audit
|
---|
57 | self.parent = parent
|
---|
58 | end
|
---|
59 |
|
---|
60 | def archetype_node_id=(archetype_node_id)
|
---|
61 | raise ArgumentError, 'archetype_node_id should not be nil' if archetype_node_id.nil?
|
---|
62 | @archetype_node_id = archetype_node_id
|
---|
63 | end
|
---|
64 |
|
---|
65 | def name=(name)
|
---|
66 | raise ArgumentError, 'name should not be empty' if name.nil? or name.value.empty?
|
---|
67 | @name = name
|
---|
68 | end
|
---|
69 | def links=(links)
|
---|
70 | raise ArgumentError, "links shoud not be empty" if !links.nil? and links.empty?
|
---|
71 | @links = links
|
---|
72 | end
|
---|
73 | def item_at_path(path)
|
---|
74 | if !@path.nil?
|
---|
75 | if @path == ""
|
---|
76 | raise ArgumentError, "path is not valid"
|
---|
77 | end
|
---|
78 | end
|
---|
79 | end
|
---|
80 | def items_at_path(path)
|
---|
81 | raise NotImplementError, "items_at_path must be implemented"
|
---|
82 | end
|
---|
83 | def path_exists?
|
---|
84 | raise NotImplementError, "path_exists? must be implemented"
|
---|
85 | end
|
---|
86 | def path_unique
|
---|
87 | raise NotImplementError, "path_unique must be implemented"
|
---|
88 | end
|
---|
89 | def concept
|
---|
90 | end
|
---|
91 | def is_archetype_root?
|
---|
92 | !archetype_details.nil?
|
---|
93 | end
|
---|
94 | end
|
---|
95 |
|
---|
96 | class Archetyped
|
---|
97 | attr_reader :archetype_id, :rm_version
|
---|
98 | attr_accessor :template_id
|
---|
99 | def initialize(archetype_id, rm_version, template_id = nil)
|
---|
100 | self.archetype_id = archetype_id
|
---|
101 | self.rm_version = rm_version
|
---|
102 | self.template_id = template_id
|
---|
103 | end
|
---|
104 | def archetype_id=(archetype_id)
|
---|
105 | raise ArgumentError, "invalid archetype_id" if archetype_id.nil?
|
---|
106 | @archetype_id = archetype_id
|
---|
107 | end
|
---|
108 | def rm_version=(rm_version)
|
---|
109 | raise ArgumentError, "invalid rm_version" if rm_version.nil? or rm_version.empty?
|
---|
110 | @rm_version = rm_version
|
---|
111 | end
|
---|
112 | end
|
---|
113 |
|
---|
114 | class Link
|
---|
115 | attr_reader :meaning, :target, :type
|
---|
116 | def initialize(meaning, target, type)
|
---|
117 | self.meaning = meaning
|
---|
118 | self.target = target
|
---|
119 | self.type = type
|
---|
120 | end
|
---|
121 | def meaning=(meaning)
|
---|
122 | raise ArgumentError, "meaning should not be nil" if meaning.nil?
|
---|
123 | @meaning = meaning
|
---|
124 | end
|
---|
125 | def target=(target)
|
---|
126 | raise ArgumentError, "target should not be nil" if target.nil?
|
---|
127 | @target = target
|
---|
128 | end
|
---|
129 | def type=(type)
|
---|
130 | raise ArgumentError, "type should not be nil" if type.nil?
|
---|
131 | @type = type
|
---|
132 | end
|
---|
133 | end # of Link
|
---|
134 | end # of Archetyped
|
---|
135 | end # of Common
|
---|
136 | end # of RM
|
---|
137 | end # OpenEHR
|
---|