[190] | 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
|
---|
[192] | 30 |
|
---|
| 31 | class ItemList < ItemStructure
|
---|
[194] | 32 | attr_accessor :items
|
---|
| 33 |
|
---|
[195] | 34 | def initialize(args = {})
|
---|
| 35 | super(args)
|
---|
| 36 | self.items = args[:items]
|
---|
| 37 | end
|
---|
| 38 |
|
---|
[194] | 39 | def item_count
|
---|
| 40 | unless @items.nil?
|
---|
| 41 | return @items.size
|
---|
| 42 | else
|
---|
| 43 | return 0
|
---|
| 44 | end
|
---|
| 45 | end
|
---|
[195] | 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)
|
---|
[207] | 59 | raise ArgumentError, 'index invalid' if i <= 0
|
---|
| 60 | return @items[i - 1]
|
---|
[195] | 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
|
---|
[192] | 68 | end
|
---|
[203] | 69 |
|
---|
[200] | 70 | class ItemTable < ItemStructure
|
---|
| 71 | attr_accessor :rows
|
---|
| 72 |
|
---|
[203] | 73 | def initialize(args = {})
|
---|
[200] | 74 | super(args)
|
---|
| 75 | self.rows = args[:rows]
|
---|
| 76 | end
|
---|
[203] | 77 |
|
---|
| 78 | def row_count
|
---|
| 79 | if @rows.nil?
|
---|
| 80 | return 0
|
---|
| 81 | else
|
---|
| 82 | return @rows.size
|
---|
| 83 | end
|
---|
| 84 | end
|
---|
[207] | 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
|
---|
[208] | 118 |
|
---|
| 119 | def has_row_with_name?(key)
|
---|
| 120 | raise ArgumentError, 'invalid argument' if key.nil? or key.empty?
|
---|
| 121 | @rows.each do |row|
|
---|
| 122 | return true if row.items[0].name.value == key
|
---|
| 123 | end
|
---|
| 124 | return false
|
---|
| 125 | end
|
---|
| 126 |
|
---|
| 127 | def has_column_with_name?(key)
|
---|
| 128 | raise ArgumentError, 'invalid argument' if key.nil? or key.empty?
|
---|
| 129 | self.column_names.each do |name|
|
---|
| 130 | return true if name.value == key
|
---|
| 131 | end
|
---|
| 132 | return false
|
---|
| 133 | end
|
---|
| 134 |
|
---|
| 135 | def named_row(key)
|
---|
| 136 | raise ArgumentError, 'invalid argument' unless has_row_with_name?(key)
|
---|
| 137 | @rows.each do |row|
|
---|
| 138 | return row if row.items[0].name.value = key
|
---|
| 139 | end
|
---|
| 140 | return []
|
---|
| 141 | end
|
---|
[200] | 142 | end
|
---|
[190] | 143 | end # of ItemStructure
|
---|
| 144 | end # of DataStructures
|
---|
| 145 | end # of RM
|
---|
| 146 | end # of OpenEhr
|
---|