Line | |
---|
1 | # rm::data_structures::item_structure
|
---|
2 | # ItemStructure module
|
---|
3 | # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109346709572_859750_3810Report.html
|
---|
4 | # refs #54
|
---|
5 | include OpenEhr::RM::DataStructures
|
---|
6 | module OpenEhr
|
---|
7 | module RM
|
---|
8 | module DataStructures
|
---|
9 | module ItemStructure
|
---|
10 | class ItemStructure < DataStructure
|
---|
11 | end
|
---|
12 |
|
---|
13 | class ItemSingle < ItemStructure
|
---|
14 | attr_reader :item
|
---|
15 |
|
---|
16 | def initialize(args = {})
|
---|
17 | super(args)
|
---|
18 | self.item = args[:item]
|
---|
19 | end
|
---|
20 |
|
---|
21 | def as_hierarchy
|
---|
22 | return @item
|
---|
23 | end
|
---|
24 |
|
---|
25 | def item=(item)
|
---|
26 | raise ArgumentError, 'item is mandatory' if item.nil?
|
---|
27 | @item = item
|
---|
28 | end
|
---|
29 | end
|
---|
30 |
|
---|
31 | class ItemList < ItemStructure
|
---|
32 | attr_accessor :items
|
---|
33 |
|
---|
34 | def initialize(args = {})
|
---|
35 | super(args)
|
---|
36 | self.items = args[:items]
|
---|
37 | end
|
---|
38 |
|
---|
39 | def item_count
|
---|
40 | unless @items.nil?
|
---|
41 | return @items.size
|
---|
42 | else
|
---|
43 | return 0
|
---|
44 | end
|
---|
45 | end
|
---|
46 |
|
---|
47 | def names
|
---|
48 | return @items.collect{|item| item.name}
|
---|
49 | end
|
---|
50 |
|
---|
51 | def named_item(a_name)
|
---|
52 | @items.each do |item|
|
---|
53 | return item if item.name.value == a_name
|
---|
54 | end
|
---|
55 | retrun nil
|
---|
56 | end
|
---|
57 |
|
---|
58 | def ith_item(i)
|
---|
59 | raise ArgumentError, 'index invalid' if i <= 0
|
---|
60 | return @items[i - 1]
|
---|
61 | end
|
---|
62 |
|
---|
63 | def as_hierarchy
|
---|
64 | return Cluster.new(:name => @name,
|
---|
65 | :archetype_node_id => @archetype_node_id,
|
---|
66 | :items => @items)
|
---|
67 | end
|
---|
68 | end
|
---|
69 |
|
---|
70 | class ItemTable < ItemStructure
|
---|
71 | attr_accessor :rows
|
---|
72 |
|
---|
73 | def initialize(args = {})
|
---|
74 | super(args)
|
---|
75 | self.rows = args[:rows]
|
---|
76 | end
|
---|
77 |
|
---|
78 | def row_count
|
---|
79 | if @rows.nil?
|
---|
80 | return 0
|
---|
81 | else
|
---|
82 | return @rows.size
|
---|
83 | end
|
---|
84 | end
|
---|
85 |
|
---|
86 | def column_count
|
---|
87 | if @rows.nil?
|
---|
88 | return 0
|
---|
89 | else
|
---|
90 | return @rows[0].items.count
|
---|
91 | end
|
---|
92 | end
|
---|
93 |
|
---|
94 | def row_names
|
---|
95 | if @rows.nil?
|
---|
96 | return []
|
---|
97 | else
|
---|
98 | return @rows.collect{|r| r.name}
|
---|
99 | end
|
---|
100 | end
|
---|
101 |
|
---|
102 | def column_names
|
---|
103 | if @rows.nil?
|
---|
104 | return []
|
---|
105 | else
|
---|
106 | return @rows[0].items.collect{|i| i.name}
|
---|
107 | end
|
---|
108 | end
|
---|
109 |
|
---|
110 | def ith_row(i)
|
---|
111 | raise ArgumentError, 'invalid index' if i<=0 or i>@rows.size
|
---|
112 | if @rows.nil?
|
---|
113 | return []
|
---|
114 | else
|
---|
115 | return @rows[i - 1]
|
---|
116 | end
|
---|
117 | end
|
---|
118 | end
|
---|
119 | end # of ItemStructure
|
---|
120 | end # of DataStructures
|
---|
121 | end # of RM
|
---|
122 | end # of OpenEhr
|
---|
Note:
See
TracBrowser
for help on using the repository browser.