Skip to content

Commit

Permalink
Added excipiens and more_info
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Jul 8, 2015
1 parent a338c9d commit be3b62e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/model/activeagent.rb
Expand Up @@ -12,7 +12,7 @@ class ActiveAgentCommon
attr_accessor :substance
attr_accessor :chemical_substance, :equivalent_substance
attr_accessor :dose, :chemical_dose, :equivalent_dose, :sequence
attr_accessor :spagyric_dose, :spagyric_type, :composition
attr_accessor :spagyric_dose, :spagyric_type, :composition, :more_info, :is_active_agent
class << self
include AccessorCheckMethod
end
Expand All @@ -26,13 +26,18 @@ class << self
:sequence => 'ODDB::Sequence',
}
define_check_class_methods check_class_list
def initialize(substance_name)
def initialize(substance_name, is_active_agent = true)
super()
@substance_name = substance_name
@is_active_agent = is_active_agent
end
def init(app)
self.substance = app.substance(@substance_name)
end
def is_active_agent
return @is_active_agent unless @is_active_agent
true
end
def checkout
if(@substance.respond_to?(:remove_sequence))
@substance.remove_sequence(@sequence)
Expand Down
15 changes: 11 additions & 4 deletions src/model/composition.rb
Expand Up @@ -5,18 +5,24 @@

require 'util/persistence'
require 'model/activeagent'
require 'model/substance'

module ODDB
class Composition
include Persistence
include Comparable
attr_accessor :sequence, :source, :label
attr_reader :galenic_form, :active_agents
attr_reader :galenic_form, :active_agents, :excipiens
def initialize
@excipiens = nil
@active_agents = []
@parts = []
super
end
def add_excipiens(substance)
raise "can only add a substance as excipiens" unless substance.is_a?(ODDB::Substance)
@excipiens = substance
end
def init(app)
@pointer.append(@oid)
end
Expand All @@ -31,11 +37,11 @@ def checkout
}
@active_agents.odba_delete
end
def create_active_agent(substance_name)
def create_active_agent(substance_name, is_active_agent = true)
active = active_agent(substance_name)
return active unless active.nil?
active = ActiveAgent.new(substance_name)
active.composition = self
active = ActiveAgent.new(substance_name, is_active_agent)
composition = self
active.sequence = @sequence
@active_agents.push(active)
active
Expand Down Expand Up @@ -71,6 +77,7 @@ def to_s
if @galenic_form
str = "%s: %s" % [@galenic_form, str]
end
str = @label + ': ' + str if @label
str
end
def *(factor)
Expand Down
3 changes: 2 additions & 1 deletion src/model/substance.rb
Expand Up @@ -15,11 +15,12 @@ class Substance
include SequenceObserver
ODBA_SERIALIZABLE = [ '@descriptions', '@synonyms' ]
attr_reader :chemical_forms, :effective_form, :sequences
attr_accessor :swissmedic_code, :casrn
attr_accessor :swissmedic_code, :casrn, :more_info
include Comparable
include Language
def initialize
super()
@more_info = nil
@sequences = []
@chemical_forms = []
end
Expand Down
27 changes: 25 additions & 2 deletions test/test_model/composition.rb
Expand Up @@ -2,20 +2,22 @@
# encoding: utf-8
# ODDB::TestComposition -- oddb.org -- 20.04.2011 -- mhatakeyama@ywesee.com

#$: << File.expand_path('..', File.dirname(__FILE__))
$: << File.expand_path('..', File.dirname(__FILE__))
$: << File.expand_path("../../src", File.dirname(__FILE__))

gem 'minitest'
require 'minitest/autorun'
require 'flexmock'
require 'model/composition'
require 'stub/odba'

module ODDB
class TestComposition <Minitest::Test
include FlexMock::TestCase
def setup
flexmock(ODBA.cache, :next_id => 123)
@composition = ODDB::Composition.new
@tst_name = 'substance_name'
end
def test_init
pointer = flexmock('pointer', :append => 'append')
Expand All @@ -30,6 +32,11 @@ def test_active_agent__found
@composition.instance_eval('@active_agents = [active_agent]')
assert_equal(active_agent, @composition.active_agent('substance'))
end
def test_active_agent__found_substance
active_agent = flexmock('active_agent', :same_as? => true, :is_active_agent => false)
@composition.instance_eval('@active_agents = [active_agent]')
assert_equal(active_agent, @composition.active_agent('substance'))
end
def test_checkout
active_agent = flexmock('active_agent',
:checkout => 'checkout',
Expand All @@ -40,7 +47,14 @@ def test_checkout
assert_equal('odba_delete', @composition.checkout)
end
def test_create_active_agent
assert_kind_of(ODDB::ActiveAgent, @composition.create_active_agent('substance_name'))
result = @composition.create_active_agent('substance_name')
assert_kind_of(ODDB::ActiveAgent, result)
assert_equal(true, result.is_active_agent)
end
def test_create_substance
result = @composition.create_active_agent('substance_name', false)
assert_kind_of(ODDB::ActiveAgent, result)
assert_equal(false, result.is_active_agent)
end
def test_delete_active_agent
active_agent = flexmock('active_agent', :same_as? => true)
Expand Down Expand Up @@ -129,6 +143,15 @@ def test_replace_observer
value = flexmock('value', :add_sequence => 'add_sequence')
assert_equal(value, @composition.instance_eval('replace_observer(target, value)'))
end
def test_active_more_info
tst = 'more_info'
active = @composition.create_active_agent('substance')
assert_equal(ODDB::ActiveAgent, active.class)
active.more_info = tst
assert_equal(tst, active.more_info)
active.more_info = nil
assert_equal(nil, active.more_info)
end

end
end
8 changes: 8 additions & 0 deletions test/test_model/substance.rb
Expand Up @@ -29,6 +29,14 @@ def teardown
def test_initialize
refute_nil(@substance.oid)
end
def test_add_more_info
tstLabel = 'conserv.'
@substance.more_info = tstLabel
assert_equal(tstLabel, @substance.more_info)
end
def test_is_active_agent_true
assert_equal(false, @substance.is_active_agent)
end
def test_add_chemical_form
form1 = flexmock 'chemical form'
@substance.add_chemical_form form1
Expand Down

0 comments on commit be3b62e

Please sign in to comment.