Class: ODDB::Composition

Inherits:
Object show all
Includes:
Comparable, OddbYaml, Persistence
Defined in:
src/model/composition.rb,
ext/export/src/oddb_yaml.rb

Constant Summary

EXPORT_PROPERTIES =
[
  '@galenic_form', '@active_agents'
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Methods included from PersistenceMethods

#data_origin, #data_origins, #diff, #nil_if_empty, #parent, #pointer_descr, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (Composition) initialize

A new instance of Composition



13
14
15
16
17
# File 'src/model/composition.rb', line 13

def initialize
  @active_agents = []
  @parts = []
  super
end

Instance Attribute Details

- (Object) active_agents

Returns the value of attribute active_agents



12
13
14
# File 'src/model/composition.rb', line 12

def active_agents
  @active_agents
end

- (Object) galenic_form

Returns the value of attribute galenic_form



12
13
14
# File 'src/model/composition.rb', line 12

def galenic_form
  @galenic_form
end

- (Object) label

Returns the value of attribute label



11
12
13
# File 'src/model/composition.rb', line 11

def label
  @label
end

- (Object) sequence

Returns the value of attribute sequence



11
12
13
# File 'src/model/composition.rb', line 11

def sequence
  @sequence
end

- (Object) source

Returns the value of attribute source



11
12
13
# File 'src/model/composition.rb', line 11

def source
  @source
end

Instance Method Details

- (Object) *(factor)



70
71
72
73
74
75
76
77
78
# File 'src/model/composition.rb', line 70

def *(factor)
  result = dup
  result.active_agents = @active_agents.collect do |act|
    factored = act.dup
    factored.dose = act.dose * factor
    factored
  end
  result
end

- (Object) <=>(other)



88
89
90
91
92
93
94
95
# File 'src/model/composition.rb', line 88

def <=>(other)
  if other.is_a? Composition
    [@active_agents.sort, @galenic_form] \
      <=> [other.active_agents.sort, other.galenic_form]
  else
    1
  end
end

- (Object) ==(other)



79
80
81
82
83
84
85
86
87
# File 'src/model/composition.rb', line 79

def ==(other)
  other.object_id == object_id \
    || other.is_a?(Composition) \
    && !@galenic_form.nil? \
    && !other.galenic_form.nil? \
    && other.galenic_form.equivalent_to?(@galenic_form) \
    && other.active_agents.size == @active_agents.size \
    && other.active_agents.sort == @active_agents.sort
end

- (Object) active_agent(substance_or_oid, spag = nil)



21
22
23
# File 'src/model/composition.rb', line 21

def active_agent(substance_or_oid, spag=nil)
  @active_agents.find { |active| active.same_as?(substance_or_oid, spag) }
end

- (Object) checkout



24
25
26
27
28
29
30
31
# File 'src/model/composition.rb', line 24

def checkout
  self.galenic_form = nil
  @active_agents.dup.each { |act|
    act.checkout
    act.odba_delete
  }
  @active_agents.odba_delete
end

- (Object) create_active_agent(substance_name)



32
33
34
35
36
37
38
39
40
# File 'src/model/composition.rb', line 32

def create_active_agent(substance_name)
  active = active_agent(substance_name)
  return active unless active.nil?
  active = ActiveAgent.new(substance_name)
  active.composition = self
  active.sequence = @sequence
  @active_agents.push(active)
  active
end

- (Object) delete_active_agent(substance)



41
42
43
44
45
46
47
# File 'src/model/composition.rb', line 41

def delete_active_agent(substance)
  if(active = active_agent(substance))
    @active_agents.delete(active)
    @active_agents.odba_isolated_store
    active
  end
end

- (Object) doses



48
49
50
# File 'src/model/composition.rb', line 48

def doses
  @active_agents.collect { |agent| agent.dose }
end

- (Object) galenic_group



54
55
56
# File 'src/model/composition.rb', line 54

def galenic_group
  @galenic_form.galenic_group if(@galenic_form)
end

- (Object) init(app)



18
19
20
# File 'src/model/composition.rb', line 18

def init(app)
  @pointer.append(@oid)
end

- (Object) route_of_administration



57
58
59
# File 'src/model/composition.rb', line 57

def route_of_administration
  @galenic_form.route_of_administration if(@galenic_form)
end

- (Object) substances



60
61
62
# File 'src/model/composition.rb', line 60

def substances
  @active_agents.collect { |agent| agent.substance }
end

- (Object) to_s



63
64
65
66
67
68
69
# File 'src/model/composition.rb', line 63

def to_s
  str = @active_agents.join(', ')
  if @galenic_form
    str = "%s: %s" % [@galenic_form, str]
  end
  str
end