Changeset 369 for ruby


Ignore:
Timestamp:
Nov 20, 2009, 3:11:04 PM (14 years ago)
Author:
KOBAYASHI, Shinji
Message:

merge from branches/0.5

Location:
ruby/trunk
Files:
3 deleted
19 edited
86 copied

Legend:

Unmodified
Added
Removed
  • ruby/trunk

  • ruby/trunk/README

    r313 r369  
    2727instances.  The work is still in progress. The
    2828intention is to have complete implementation of openEHR
    29 Reference Model and Archetype Object Model, with
    30 support for archetype based object creation and validation.
     29Reference Model and some of the Archetype Object Models,
     30with support for archetype based object creation and
     31validation.
     32
     33Almost all classes passed the test constructed by rspec or
     34test/unit. This test cases are under /spec or /tests
     35
     36Some specifications are not well determined yet, such as
     37rm/security and so on. We postponed to implement such
     38classes.
     39
     40Terminology and Demographic server will be implemented in
     41next version, Miyajima release
    3142
    3243= Authors
  • ruby/trunk/lib/adl_parser/lib/adl_scanner.rb

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl

    r318 r369  
    1010        ["name"] = <"Thomas Beale">
    1111        ["organisation"] = <"Ocean Informatics">
    12         ["date"] = <"2005-10-10">
     12        ["date"] = <"10/10/2005">
    1313    >
    1414    details = <
  • ruby/trunk/lib/models/tests/rm

  • ruby/trunk/lib/models/tests/rm/test_common.rb

    r292 r369  
    8686class RM_Common_Archetyped_Test < Test::Unit::TestCase
    8787  def setup
    88 
    8988    @dv_text = OpenEhr::RM::DataTypes::Text::DvText.new('Test')
    9089    @uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.5')
  • ruby/trunk/lib/open_ehr/assumed_library_types.rb

    r297 r369  
    583583        self.minutes = $13.to_i
    584584        self.seconds = $15.to_i
    585         self.fractional_second = $16.to_f
     585        unless $16.nil?
     586          self.fractional_second = $16.to_f
     587        end
    586588      end
    587589    end # end of ISO8601Duration
  • ruby/trunk/lib/open_ehr/rm/common/directory.rb

    • Property svn:mergeinfo deleted
  • ruby/trunk/lib/open_ehr/rm/composition/content/entry.rb

    r167 r369  
    1 module OpenEhr
     1# rm::composition::content::entry
     2# entry module
     3# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109264528523_312165_346Report.html
     4# refs #56
     5include OpenEHR::RM::Composition::Content
     6
     7module OpenEHR
    28  module RM
    3     module Content
    4       module Entry
    5         class Entry < Content_Item
    6         end
    7         class CareEntry < Entry
    8         end
    9         class Action < CareEntry
    10           attr_accessor :description, :time
    11           attr_accessor :ism_transition, :instruction_details
    12           def initialize(description, time, ism_transition, instruction_details)
    13             raise Exception.new("invalid argument") if description == nil || time == nil || ism_transition == nil
    14             @description = description
    15             @time = time
    16             @ism_transition = ism_transition
    17             @instruction_details = instruction_details if instruction_details != nil
    18           end
    19         end # end of Action
    20       end # end of Entry
    21     end # end of Content
    22   end # end of RM
    23 end # end of OpenEHR
     9    module Composition
     10      module Content
     11        module Entry
     12          class Entry < ContentItem
     13            attr_reader :language, :encoding, :subject
     14            attr_accessor :provider, :other_participations, :workflow_id
     15            def initialize(args = { })
     16              super(args)
     17              self.language = args[:language]
     18              self.encoding = args[:encoding]
     19              self.subject = args[:subject]
     20              self.provider = args[:provider]
     21              self.other_participations = args[:other_participations]
     22              self.workflow_id = args[:workflow_id]
     23            end
     24
     25            def language=(language)
     26              raise ArgumentError, 'language is mandatory' if language.nil?
     27              @language = language
     28            end
     29
     30            def encoding=(encoding)
     31              raise ArgumentError, 'encoding is mandatory' if encoding.nil?
     32              @encoding = encoding
     33            end
     34
     35            def subject=(subject)
     36              raise ArgumentError, 'subject is mandatory' if subject.nil?
     37              @subject = subject
     38            end
     39
     40            def subject_is_self?
     41              return @subject.instance_of? PartySelf
     42            end
     43          end
     44
     45          class AdminEntry < Entry
     46            attr_reader :data
     47
     48            def initialize(args = { })
     49              super(args)
     50              self.data = args[:data]
     51            end
     52
     53            def data=(data)
     54              raise ArgumentError, 'data are mandatory' if data.nil?
     55              @data = data
     56            end
     57          end
     58          class CareEntry < Entry
     59            attr_accessor :protocol, :guideline_id
     60
     61            def initialize(args = { })
     62              super(args)
     63              self.protocol = args[:protocol]
     64              self.guideline_id = args[:guideline_id]
     65            end
     66          end
     67
     68          class Observation < CareEntry
     69            attr_reader :data
     70            attr_accessor :state
     71
     72            def initialize(args = { })
     73              super(args)
     74              self.data = args[:data]
     75              self.state = args[:state]
     76            end
     77
     78            def data=(data)
     79              raise ArgumentError, 'data are mandatory' if data.nil?
     80              @data = data
     81            end
     82          end
     83
     84          class Evaluation < CareEntry
     85            attr_reader :data
     86
     87            def initialize(args = { })
     88              super(args)
     89              self.data = args[:data]
     90            end
     91
     92            def data=(data)
     93              raise ArgumentError, 'data are mandatory' if data.nil?
     94              @data = data
     95            end
     96          end
     97
     98          class Instruction < CareEntry
     99            attr_reader :narrative, :activities
     100            attr_accessor :expiry_time, :wf_definition
     101
     102            def initialize(args = { })
     103              super(args)
     104              self.narrative = args[:narrative]
     105              self.activities = args[:activities]
     106              self.expiry_time = args[:expiry_time]
     107              self.wf_definition = args[:wf_definition]
     108            end
     109
     110            def narrative=(narrative)
     111              if narrative.nil?
     112                raise ArgumentError, 'narrative is mandatory'
     113              end
     114              @narrative = narrative
     115            end
     116
     117            def activities=(activities)
     118              if !activities.nil? && activities.empty?
     119                raise ArgumentError, 'activities should not be empty'
     120              end
     121              @activities = activities
     122            end
     123          end
     124
     125          class Activity < Locatable
     126            attr_reader :description, :timing, :action_archetype_id
     127
     128            def initialize(args = { })
     129              super(args)
     130              self.description = args[:description]
     131              self.timing = args[:timing]
     132              self.action_archetype_id = args[:action_archetype_id]
     133            end
     134
     135            def description=(description)
     136              if description.nil?
     137                raise ArgumentError, 'description is mandatory'
     138              end
     139              @description = description
     140            end
     141
     142            def timing=(timing)
     143              if timing.nil?
     144                raise ArgumentError, 'timing is mandatory'
     145              end
     146              @timing = timing
     147            end
     148          end
     149
     150          def action_archetype_id=(action_archetype_id)
     151            if action_archetype_id.nil? || action_archetype_id.empty?
     152              raise ArgumentError, 'action_archetype_id is mandatory'
     153            end
     154            @action_archetype_id = action_archetype_id
     155          end
     156
     157          class Action < CareEntry
     158            attr_reader :time, :description, :ism_transition
     159            attr_accessor :instruction_details
     160           
     161            def initialize(args = { })
     162              super(args)
     163              self.description = args[:description]
     164              self.time = args[:time]
     165              self.ism_transition = args[:ism_transition]
     166              self.instruction_details = args[:instruction_details]
     167            end
     168
     169            def time=(time)
     170              if time.nil?
     171                raise ArgumentError, 'time is mandatory'
     172              end
     173              @time = time
     174            end
     175
     176            def description=(description)
     177              if description.nil?
     178                raise ArgumentError, 'description is mandatory'
     179              end
     180              @description = description
     181            end
     182
     183            def ism_transition=(ism_transition)
     184              if ism_transition.nil?
     185                raise ArgumentError
     186              end
     187              @ism_transition = ism_transition
     188            end
     189          end
     190
     191          class InstructionDetails < Pathable
     192            attr_reader :instruction_id, :activity_id
     193            attr_accessor :wf_details
     194
     195            def initialize(args = { })
     196              super(args)
     197              self.instruction_id = args[:instruction_id]
     198              self.activity_id = args[:activity_id]
     199              self.wf_details = args[:wf_details]
     200            end
     201
     202            def instruction_id=(instruction_id)
     203              if instruction_id.nil?
     204                raise ArgumentError, 'instruction_id is mandatory'
     205              end
     206              @instruction_id = instruction_id
     207            end
     208
     209            def activity_id=(activity_id)
     210              if activity_id.nil? || activity_id.empty?
     211                raise ArgumentError, 'activity_id is mandatory'
     212              end
     213              @activity_id = activity_id
     214            end
     215          end
     216
     217          class IsmTransition < Pathable
     218            attr_reader :current_state, :transition
     219            attr_accessor :careflow_step
     220
     221            def initialize(args = { })
     222              super(args)
     223              self.current_state = args[:current_state]
     224              self.transition = args[:transition]
     225              self.careflow_step = args[:careflow_step]
     226            end
     227
     228            def current_state=(current_state)
     229              if current_state.nil?
     230                raise ArgumentError, 'current_state is mandatory'
     231              end
     232              @current_state = current_state
     233            end
     234
     235            def transition=(transition)
     236              if transition.nil?
     237                raise ArgumentError, 'transition is mandatory'
     238              end
     239              @transition = transition
     240            end
     241          end
     242        end # of Entry
     243      end # of Content
     244    end # of Composition
     245  end # of RM
     246end # of OpenEHR
  • ruby/trunk/lib/open_ehr/rm/data_structures/item_structure.rb

    r299 r369  
    5454              return item if item.name.value == a_name
    5555            end
    56             retrun nil
     56            return nil
    5757          end
    5858
     
    111111          def ith_row(i)
    112112            raise ArgumentError, 'invalid index' if i<=0 or i>@rows.size
    113             if @rows.nil?
    114               return []
    115             else
    116               return @rows[i - 1]
    117             end
     113            return @rows[i - 1]
    118114          end
    119115
     
    139135              return row if row.items[0].name.value == key
    140136            end
    141             return []
    142137          end
    143138
     
    191186            self.items = args[:items]
    192187          end
     188
     189          def has_element_path?(path)
     190            paths = [ ]
     191            @items.each do |item|
     192              paths << item.archetype_node_id
     193            end
     194            return paths.include? path
     195          end
     196
     197          def element_at_path(path)
     198            @items.each do |item|
     199              return item if item.archetype_node_id == path
     200            end
     201            return nil
     202          end
     203
     204          def as_hierarchy
     205            return Cluster.new(:name => @name,
     206                               :archetype_node_id => @archetype_node_id,
     207                               :items => @items)
     208          end
    193209        end
    194210      end # of ItemStructure
  • ruby/trunk/lib/open_ehr/rm/data_types/quantity.rb

    r298 r369  
    6666
    6767          def <=>(others)
    68             @magnitude <=> others.magnitude
     68            self.magnitude <=> others.magnitude
    6969          end
    7070
     
    151151          def add(a_diff)
    152152            type_check(a_diff)
    153             return result_builder(DvAbsoluteQuantity,
     153            return result_builder(self.class,
    154154                                  @magnitude+a_diff.magnitude)
    155155          end
     
    157157          def diff(other)
    158158            type_check(other)
    159             return result_builder(DvAmount,
     159            return result_builder(self.class,
    160160                                  (@magnitude-other.magnitude).abs)
    161161          end
     
    163163          def subtract(a_diff)
    164164            type_check(a_diff)
    165             return result_builder(DvAbsoluteQuantity,
     165            return result_builder(self.class,
    166166                                  @magnitude-a_diff.magnitude)
    167167          end
  • ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb

    r167 r369  
    44require 'assumed_library_types'
    55require 'date'
    6 
    7 module OpenEhr
     6include OpenEHR::RM::DataTypes::Quantity
     7include OpenEHR::AssumedLibraryTypes
     8
     9module OpenEHR
    810  module RM
    911    module DataTypes
    1012      module Quantity
    1113        module DateTime
    12           class DvTemporal < OpenEhr::RM::DataTypes::Quantity::DvAbsoluteQuantity
    13             include Comparable
    14             attr_reader :value
    15 
    16             def initialize(value, magnitude_status=nil, accuracy=nil,
    17                          normal_range=nil, normal_status=nil,
    18                          other_reference_ranges=nil)
    19               self.value = value
    20               self.magnitude_status = magnitude_status
    21               self.accuracy = accuracy
    22               self.normal_range = normal_range
    23               self.normal_status = normal_status
    24               self.other_reference_ranges = other_reference_ranges
     14          class DvTemporal < DvAbsoluteQuantity
     15            def initialize(args = {})
     16              self.value = args[:value]
     17              self.magnitude_status = args[:magnitude_status]
     18              self.accuracy = args[:accuracy]
     19              self.normal_range = args[:normal_range]
     20              self.normal_status = args[:normal_status]
     21              self.other_reference_ranges = args[:other_reference_ranges]
    2522            end
    2623
     
    3229            end
    3330
    34             def <=>(other)
    35               self.magnitude <=> other.magnitude
    36             end
     31            undef magnitude=
    3732          end
    3833
    3934          class DvDate < DvTemporal
    40             include OpenEhr::AssumedLibraryTypes::ISO8601_DATE_MODULE
     35            include ISO8601DateModule
    4136
    4237            DAYS_IN_MONTH = [0,31,28,31,30,31,30,31,31,30,31,30,31]
    4338
    44             def initialize(value, magnitude_status=nil, accuracy=nil,
    45                            normal_range=nil, normal_status=nil,
    46                            other_reference_range=nil)
    47               super(value, magnitude_status, accuracy, normal_range,
    48                     normal_status, other_reference_range)
    49             end
    50 
    5139            def value=(value)
    5240              super(value)
    53               iso8601_date = AssumedLibraryTypes::ISO8601_DATE.new(value)
     41              iso8601_date = ISO8601Date.new(value)
    5442              @year = iso8601_date.year
    5543              @month = iso8601_date.month
     
    5745            end
    5846
    59             undef magnitude=
    60 
    6147            def magnitude
    6248              return Date.new(@year, @month, @day)-Date.new(0000,1,1)
     
    7359                day = future.day - past.day
    7460              else
    75                 month -= 1
     61                month = -1
    7662                previous_month = future.month - 1
    77                 if previous_month <= 0
     63                if previous_month == 0
    7864                  previous_month = 12
    7965                end
     
    9076                month += future.month + 12 - past.month
    9177              end
     78              if month < 0
     79                year -= 1
     80                month += 12
     81              end
    9282              year += future.year - past.year
    93               return DvDuration.new(
     83              return DvDuration.new(:value =>
    9484                   'P' + year.to_s + 'Y' + month.to_s + 'M' +
    9585                         week.to_s + 'W' + day.to_s + 'D')
     
    9888         
    9989          class DvTime < DvTemporal
    100             include OpenEhr::AssumedLibraryTypes::ISO8601_TIME_MODULE
    101             def initialize(value, magnitude_status=nil, accuracy=nil,
    102                            normal_range=nil, normal_status=nil,
    103                            other_reference_range=nil)
    104               super(value, magnitude_status, accuracy, normal_range,
    105                     normal_status, other_reference_range)
    106             end
     90            include ISO8601TimeModule
    10791
    10892            def value=(value)
    10993              super(value)
    110               iso8601_time = AssumedLibraryTypes::ISO8601_TIME.new(value)
     94              iso8601_time = ISO8601Time.new(value)
    11195              @hour = iso8601_time.hour
    11296              @minute = iso8601_time.minute
     
    116100
    117101            def magnitude
    118               return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
     102              if @fractional_second.nil?
     103                return @hour * 60 * 60 + @minute * 60 + @second
     104              else
     105                return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
     106              end
    119107            end
    120108
     
    125113              second = (diff - hour * 60 *60 - minute * 60).to_i
    126114              fractional_second = ((diff - diff.to_i)*1000000.0).to_i/1000000.0
    127               return DvDuration.new('P0Y0M0W0DT' + hour.to_s + 'H' +
    128                         minute.to_s + 'M' +
    129                         second.to_s + fractional_second.to_s[1..-1] + 'S')
     115              str = 'P0Y0M0W0DT' + hour.to_s + 'H' +
     116                minute.to_s + 'M' + second.to_s
     117              if @fractional_second.nil?
     118                str += 'S'
     119              else
     120                str += fractional_second.to_s[1..-1] + 'S'
     121              end
     122              return DvDuration.new(:value => str)
    130123            end
    131124          end
    132125
    133126          class DvDateTime < DvTemporal
    134             include OpenEhr::AssumedLibraryTypes::ISO8601_DATE_TIME_MODULE
    135             attr_reader :value
    136 
    137             def initialize(value, magnitude_status=nil, accuracy=nil,
    138                            normal_range=nil, normal_status=nil,
    139                            other_reference_range=nil)
    140               super(value, magnitude_status, accuracy, normal_range,
    141                     normal_status, other_reference_range)
    142             end
     127            include OpenEHR::AssumedLibraryTypes::ISO8601DateTimeModule
    143128
    144129            def value=(value)             
    145130              super(value)
    146               iso8601date_time = AssumedLibraryTypes::ISO8601_DATE_TIME.new(value)
     131              iso8601date_time = AssumedLibraryTypes::ISO8601DateTime.new(value)
    147132              self.year = iso8601date_time.year
    148133              self.month = iso8601date_time.month
     
    156141
    157142            def magnitude
    158               seconds = DateTime.new(@year,@month,@day,@hour,@minute,@second) -
    159                 DateTime.new(0000,1,1,0,0,0)
     143              seconds = (((@year * 365.24 +
     144                           @month * 30.42 +
     145                           @day) * 24 + @hour) * 60 +
     146                         @minute) * 60 + @second
    160147              if @fractional_second.nil?
    161148                return seconds
     
    164151              end
    165152            end
    166 
    167             undef magnitude=
    168153
    169154            def diff(other)
     
    184169              minute = ((time_diff - hour*60*60)/60).to_i
    185170              second = (time_diff - hour * 60 *60 - minute * 60).to_i
    186               fractional_second = ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
    187 
    188               return DvDuration.new(date_duration.value + 'T' +
    189                         hour.to_s + 'H' +
    190                         minute.to_s + 'M' +
    191                         second.to_s + fractional_second.to_s[1..-1] + 'S')
    192                                    
     171              str = date_duration.value + 'T' + hour.to_s + 'H' +
     172                minute.to_s + 'M' + second.to_s
     173              if @fractional_second.nil?
     174                return DvDuration.new(:value => str +'S')
     175              else
     176                fractional_second =
     177                  ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
     178                return DvDuration.new(:value => str +
     179                                      fractional_second.to_s[1..-1] + 'S')
     180              end
    193181            end
    194182
     
    197185            def split_date_time(date_time)
    198186              /^(.*)T(.*)$/ =~ date_time.as_string
    199               return DvDate.new($1), DvTime.new($2)
     187              return DvDate.new(:value => $1), DvTime.new(:value => $2)
    200188            end
    201189          end
    202190
    203191          class DvDuration < DvAmount
    204             include AssumedLibraryTypes::ISO8601_DURATION_MODULE
     192            include AssumedLibraryTypes::ISO8601DurationModule
    205193            attr_reader :value
    206194           
    207             def initialize(value, magnitude_status=nil, accuracy=nil,
    208                          accuracy_percent=nil, normal_range=nil,
    209                          normal_status = nil, other_reference_ranges=nil)
    210               self.value = value
     195            def initialize(args = { })
     196              self.value = args[:value]
     197              self.magnitude_status = args[:magnitude_status]
     198              self.normal_range = args[:normal_range]
     199              self.normal_status = args[:normal_status]
     200              self.other_reference_ranges = args[:other_reference_ranges]
    211201            end
    212202
     
    214204              raise ArgumentError, 'value must be not nil' if value.nil?
    215205              @value = value
    216               iso8601_duration = AssumedLibraryTypes::ISO8601_DURATION.new(value)
     206              iso8601_duration = AssumedLibraryTypes::ISO8601Duration.new(value)
    217207              self.years = iso8601_duration.years
    218208              self.months = iso8601_duration.months
  • ruby/trunk/lib/open_ehr/rm/demographic.rb

    r167 r369  
    22# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_5_76d0249_1118674798473_6021_0Report.html
    33# Ticket refs #45
     4include OpenEHR::RM::Common::Archetyped
     5
    46module OpenEHR
    57  module RM
    6     module Demogrphic
    7       class Address < OpenEHR::RM::Common::Archetyped::Locatable
    8         attr_reader :details
    9 
    10         def as_string
    11 
    12         end
    13 
    14         def type
    15 
    16         end
    17       end
    18 
    19       class Capability < OpenEHR::RM::Common::Archetyped::Locatable
    20         attr_reader :credentials, :time_validity
    21 
    22       end
    23 
    24       class Party < OpenEHR::RM::Common::Archetyped::Locatable
    25         attr_reader :details, :reverse_relationships, :uid
    26         attr_reader :idetities, :contacts, :relationships
    27         def initialize(uid, archetype_node_id, name, archetype_details,
    28                        feeder_audit, links, identities, contacts,
    29                        relationships, reverse_relationships, details)
    30           super(uid, archetype_node_id, name, archetype_details,
    31                 feeder_audit, links, nil)
    32           uid_valid(uid)
     8    module Demographic
     9      class Party < Locatable
     10        attr_reader :uid, :identities, :contacts, :relationships,
     11                    :reverse_relationships
     12        attr_accessor :details
     13        alias :type :name
     14
     15        def initialize(args = { })
     16          super(args)
     17          self.uid = args[:uid]
     18          self.identities = args[:identities]
     19          self.contacts = args[:contacts]
     20          self.relationships = args[:relationships]
     21          self.reverse_relationships =
     22            args[:reverse_relationships]
     23          self.details = args[:details]
     24        end
     25
     26        def uid=(uid)
     27          raise ArgumentError, 'uid is mandatory' if uid.nil?
    3328          @uid = uid
    34           identities_vaild(identities)
     29        end
     30
     31        def identities=(identities)
     32          if identities.nil? || identities.empty?
     33            raise ArgumentError, 'identities are mandatory'
     34          end
    3535          @identities = identities
    36           contacts_valid(contacts)
     36        end
     37
     38        def contacts=(contacts)
     39          if !contacts.nil? && contacts.empty?
     40            raise ArgumentError, 'contacts should not be empty'
     41          end
    3742          @contacts = contacts
    38           relationships_valid(relationships)
    39         end
    40         def type
    41           return name
    42         end
    43         def uid=(uid)
    44           uid_valid(uid)
    45           @uid = uid
    46         end
    47         def identities=(identities)
    48           identities_vaild(identities)
    49           @identities = identities
    50         def contacts=(contacts)
    51           contacts_valid(contacts)
    52           @contacts = contacts
    53         end
     43        end
     44
    5445        def parent=(parent)
    5546          @parent = nil
    5647        end
    57         private
    58         def uid_valid(uid)
    59           raise ArgumentError, "uid is not valid" if uid.nil?
    60         end
    61         def identities_vaild(identities)
    62           if identities.nil?
    63             raise ArgumentError, "identities must not be nil"
    64           elsif identities.empty?
    65             raise ArgumentError, "identities must not be empty"
    66           end
    67         end
    68         def contacts_valid(contacts)
    69           if contacs.nil?
    70             raise ArgumentError, "contacts must not be nil"
    71           elsif contacts.empty?
    72             raise ArgumentError, "contacts must not be empty"
    73           end         
    74         end
    75       end
    76 
    77       class PartyIdentity < OpenEHR::RM::Common::Archetyped::Locatable
     48
     49        def relationships=(relationships)
     50          unless relationships.nil?
     51            if relationships.empty?
     52              raise ArgumentError, 'relationships should not be empty?'
     53            else
     54              relationships.each do |rel|
     55                if rel.source.id.value != @uid.value
     56                  raise ArgumentError, 'invalid source of relationships'
     57                end
     58              end
     59            end
     60          end
     61          @relationships = relationships
     62        end
     63
     64        def reverse_relationships=(reverse_relationships)
     65          if !reverse_relationships.nil? && reverse_relationships.empty?
     66            raise ArgumentError, 'reverse_relationships should not be empty'
     67          end
     68          @reverse_relationships = reverse_relationships
     69        end
     70      end
     71
     72      class PartyIdentity < Locatable
    7873        attr_reader :details
    7974
    80       end
    81 
    82       class PartyRelationship < OpenEHR::RM::Common::Archetyped::Locatable
    83 
    84       end
    85 
    86       class Versioned_Party < OpenEHR::RM::Common::Archetyped::Locatable
    87 
    88       end
    89 
    90       class Role < Party
    91 
     75        def initialize(args = { })
     76          super(args)
     77          self.details = args[:details]
     78        end
     79
     80        def details=(details)
     81          if details.nil?
     82            raise ArgumentError, 'details are mandatory'
     83          end
     84          @details = details
     85        end
     86
     87        def purpose
     88          return @name
     89        end
     90      end
     91
     92      class Contact < Locatable
     93        attr_accessor :time_validity
     94        attr_reader :addresses
     95
     96        def initialize(args = { })
     97          super(args)
     98          self.addresses = args[:addresses]
     99          self.time_validity = args[:time_validity]
     100        end
     101
     102        def purpose
     103          return @name
     104        end
     105
     106        def addresses=(addresses)
     107          if addresses.nil? || addresses.empty?
     108            raise ArgumentError, 'address is mandatory'
     109          end
     110          @addresses = addresses
     111        end
     112      end
     113
     114      class Address < Locatable
     115        attr_reader :details
     116
     117        def initialize(args = { })
     118          super(args)
     119          self.details = args[:details]
     120        end
     121
     122        def details=(details)
     123          if details.nil?
     124            raise ArgumentError, 'details are mandatory'
     125          end
     126          @details = details
     127        end
     128
     129        def type
     130          return @name
     131        end
    92132      end
    93133
    94134      class Actor < Party
    95         LEAGAL_IDENTITY = 'leagal identity'
    96         attr_reader :languages, :rules
    97         def initialize(uid, archetype_node_id, name, archetype_details,
    98                        feeder_audit, links, identities, contacts,
    99                        relationships, reverse_relationships, details,
    100                        languages, rules)
    101           super(uid, archetype_node_id, name, archetype_details,
    102                 feeder_audit, links, relationships, reverse_relationships,
    103                 details)
    104           has_legal_identity?
    105           set_languages(languages)
    106           set_rules(rules)
    107         end
     135        LEAGAL_IDENTITY = 'legal identity'
     136        attr_reader :languages, :roles
     137
     138        def initialize(args = { })
     139          super(args)
     140          self.roles = args[:roles]
     141          self.languages = args[:languages]
     142        end
     143
     144        def roles=(roles)
     145          if !roles.nil? && roles.empty?
     146            raise ArgumentError, 'roles should not be empty'
     147          end
     148          @roles = roles
     149        end
     150
    108151        def has_legal_identity?
    109           @identities.each {|identity|
    110             if (identity.purpose.value == LEAGAL_IDENTITY)
     152          @identities.each do |identity|
     153            if identity.purpose.value == LEAGAL_IDENTITY
    111154              return true
    112155            end
    113           }
    114           false
    115         end
     156          end
     157          return false
     158        end
     159
    116160        def languages=(languages)
    117           set_languages(languages)
    118         end
    119         def values=(values)
    120           set_values(values)
    121         end
    122         private
    123         def set_languages(languages)
    124           if languages.nil?
    125             raise ArgumentError, "languages should not be nil."
    126           elsif languages.empty?
    127             raise ArgumentError, "languages shouldnot be empty."
     161          if !languages.nil? && languages.empty?
     162            raise ArgumentError, 'languages should not be empty.'
    128163          end
    129164          @languages = languages
    130165        end
    131         def set_values(values)
    132           if values.nil?
    133             raise ArgumentError, "values should not be nil."
    134           elsif values.empty?
    135             raise ArgumentError, "values should not be nil."
    136           end
    137           @values = values
    138       end
    139       class Contact < OpenEHR::RM::Common::Archetyped::Locatable
     166      end
     167
     168      class Person < Actor
     169
     170      end
     171
     172      class Organisation < Actor
     173
     174      end
     175
     176      class Group < Actor
     177
     178      end
     179
     180      class Agent < Actor
     181
     182      end
     183
     184      class Role < Party
     185        attr_reader :performer, :capabilities
    140186        attr_accessor :time_validity
    141         attr_reader :addresses
    142         def initialize(uid, archetype_node_id, name, archetype_details,
    143                        feeder_audit, links, parent, time_validity, addresses)
    144           super(uid, archetype_node_id, name, archetype_details,
    145                 feeder_audit, links, parent)
    146           address_exists?(addresses)
    147           @addresses = addresses
    148           @time_validity = time_validity
    149         end
    150         def purpose
    151           @name
    152         end
    153         def purpose=(purpose)
    154           @name = purpose
    155         end
    156         def addresses=(addresses)
    157           address_exists?(addresses)
    158           @addresses = addresses
    159         end
    160         private
    161         def address_exists?(addresses)
    162           if addresses.nil?
    163             raise ArgumentError, "address must not be nil"
    164           elsif addresses.empty?
    165             raise ArgumentError, "address must not be empty"
    166           end
    167         end
    168       end
    169 
    170       class Agent < Actor
    171 
    172       end
    173 
    174       class Organisation < Actor
    175 
    176       end
    177 
    178       class Person < Actor
    179 
    180       end
    181 
    182       class Group < Actor
     187
     188        def initialize(args = { })
     189          super(args)
     190          self.performer = args[:performer]
     191          self.capabilities = args[:capabilities]
     192          self.time_validity = args[:time_validity]
     193        end
     194
     195        def performer=(performer)
     196          if performer.nil?
     197            raise ArgumentError, 'performer is mandatory'
     198          end
     199          @performer = performer
     200        end
     201
     202        def capabilities=(capabilities)
     203          if !capabilities.nil? && capabilities.empty?
     204            raise ArgumentError, 'capability should not be empty'
     205          end
     206          @capabilities = capabilities
     207        end
     208      end
     209
     210      class Capability < Locatable
     211        attr_reader :credentials
     212        attr_accessor :time_validity
     213
     214        def initialize(args = { })
     215          super(args)
     216          self.credentials = args[:credentials]
     217          self.time_validity = args[:time_validity]
     218        end
     219
     220        def credentials=(credentials)
     221          if credentials.nil?
     222            raise ArgumentError, 'credentials are mandatory'
     223          end
     224          @credentials = credentials
     225        end
     226      end
     227
     228      class PartyRelationship < Locatable
     229        attr_accessor :details, :time_validity
     230        attr_reader :source, :target
     231        alias :type :name
     232
     233        def initialize(args = { })
     234          super(args)
     235          self.uid = args[:uid]
     236          self.details = args[:details]
     237          self.time_validity = args[:time_validity]
     238          self.source = args[:source]
     239          self.target = args[:target]
     240        end
     241
     242        def uid=(uid)
     243          if uid.nil?
     244            raise ArgumentError, 'uid is mandatory'
     245          end
     246          @uid = uid
     247        end
     248
     249        def source=(source)
     250          if source.nil? or source.id.value != @uid.value
     251            raise ArgumentError, 'source is invalid'
     252          end
     253          @source = source
     254        end
     255
     256        def target=(target)
     257          if target.nil?
     258            raise ArgumentError, 'taraget is invalid'
     259          end
     260          @target = target
     261        end
     262      end
     263
     264      class VersionedParty < Locatable
    183265
    184266      end
  • ruby/trunk/lib/open_ehr/rm/support/measurement.rb

    • Property svn:mergeinfo deleted
  • ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb

    r220 r369  
    3636  end
    3737
    38   it 'retrieve the item with a name' do
     38  it 'should return the item with a name' do
    3939    @item_list.named_item('one').name.value.should == 'one'
     40  end
     41
     42  it 'should return nil when item is not exist' do
     43    @item_list.named_item('four').should be_nil
    4044  end
    4145
  • ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb

    r216 r369  
    66
    77describe ItemSingle do
    8   before(:all) do
    9     name =
    10     @element = Element.new(:name => DvText.new('item'),
    11                            :archetype_node_id => 'AT0000',
    12                            :value => DvQuantity.new())
    13     item_single_name = DvText.new('item single')
     8  before(:each) do
     9    element = stub(Element, :archetype_node_id => 'at0002')
     10    item_single_name = DvText.new(:value => 'item single')
    1411    @item_single = ItemSingle.new(:name => item_single_name,
    15                                   :archetype_node_id => 'test',
    16                                   :item => @element)
    17    
     12                                  :archetype_node_id => 'at0001',
     13                                  :item => element)
    1814  end
    1915
     16  it 'should be an instance of ItemSingle' do
     17    @item_single.should be_an_instance_of ItemSingle
     18  end
    2019
     20  it 'should raise ArgumentError with nil item' do
     21    lambda {
     22      @item_single.item = nil
     23    }.should raise_error ArgumentError
     24  end
     25
     26  it 'should return as_hierarchy' do
     27    @item_single.as_hierarchy.archetype_node_id.should == 'at0002'
     28  end
    2129end
  • ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb

    r220 r369  
    4545  end
    4646
     47  it 'column_count should be 0 when @rows == nil' do
     48    @item_table.rows = nil
     49    @item_table.column_count.should be_equal 0
     50  end
    4751
    4852  it 's row_names should be cluster cluster' do
     
    96100  end
    97101
     102  it 'should be false it has_column with name ten' do
     103    @item_table.has_column_with_name?('ten').should be_false
     104  end
     105
    98106  it 'second row should be named_row four' do
    99107    @item_table.named_row('four').items[1].name.value = 'five'
     
    126134
    127135  it 'should be two element at named cell by row column' do
    128     @item_table.element_at_named_cell('cluster', 'two').name.value == 'two'
     136    @item_table.element_at_named_cell('cluster', 'three').name.value == 'three'
     137  end
     138
     139  it 'should return nil when rows are nil' do
     140    @item_table.rows = nil
     141    @item_table.row_count.should be_equal 0
    129142  end
    130143
  • ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb

    r220 r369  
    77describe ItemTree do
    88  before(:each) do
    9     items = %w{one two}.collect do |name|
     9    i = 1
     10    items = %w{one two three}.collect do |name|
     11      i += 1
    1012      Element.new(:name => DvText.new(:value => name),
    11                   :archetype_node_id => 'test')
     13                  :archetype_node_id => 'at000' + i.to_s)
    1214    end
    1315    name = DvText.new(:value => 'item tree')
    1416    @item_tree = ItemTree.new(:name => name,
    15                               :archetype_node_id => 'test',
     17                              :archetype_node_id => 'at0001',
    1618                              :items => items)
    1719  end
     
    2628
    2729  it 'has valid element path' do
     30    @item_tree.has_element_path?('at0002').should be_true
     31  end
     32
     33  it 'should return false with wrong node' do
     34    @item_tree.has_element_path?('at0005').should be_false
     35  end
     36
     37  it 'path at002 should return two' do
     38    @item_tree.element_at_path('at0003').name.value.should == 'two'
     39  end
     40
     41  it 'path at005 should return nil' do
     42    @item_tree.element_at_path('at0005').should be_nil
     43  end
     44
     45  it 'should returns ItemTree as Cluster' do
     46    @item_tree.as_hierarchy.name.value.should == 'item tree'
    2847  end
    2948end
  • ruby/trunk/test/unit/open_ehr

Note: See TracChangeset for help on using the changeset viewer.