Skip to content

Commit

Permalink
Added new fields to import of swissmedic
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Jul 23, 2015
1 parent 10e1bbc commit 25a470a
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 61 deletions.
10 changes: 8 additions & 2 deletions src/model/composition.rb
Expand Up @@ -11,7 +11,7 @@ module ODDB
class Composition
include Persistence
include Comparable
attr_accessor :sequence, :source, :label
attr_accessor :sequence, :source, :label, :corresp
attr_reader :galenic_form, :active_agents, :excipiens
def initialize
@excipiens = nil
Expand All @@ -27,6 +27,12 @@ def add_excipiens(substance)
def init(app)
@pointer.append(@oid)
end
# fix_pointers is needed to enable calling @app.create(sequence.pointer + :composition) in
# plugin/swissmedic.rb when running UnitTests
def fix_pointers
@pointer = @sequence.pointer + [:composition, @oid]
odba_store
end
def active_agent(substance_or_oid, spag=nil)
@active_agents.find { |active| active.same_as?(substance_or_oid, spag) }
end
Expand Down Expand Up @@ -83,7 +89,7 @@ def to_s
if @galenic_form
str = "%s: %s" % [@galenic_form, str]
end
str = @label + ': ' + str if @label
str = str.length > 0 ? @label + ': ' + str : @label if @label
str
end
def *(factor)
Expand Down
12 changes: 6 additions & 6 deletions src/model/sequence.rb
Expand Up @@ -366,12 +366,12 @@ def adjust_types(values, app=nil)
values[key] = value.resolve(app)
else
case(key)
when :atc_class
values[key] = if(atc = app.atc_class(value))
atc
else
@atc_class
end
when :atc_class
values[key] = if(atc = app.atc_class(value))
atc
else
@atc_class
end
when :dose
values[key] = if(value.is_a? Dose)
value
Expand Down
123 changes: 96 additions & 27 deletions src/plugin/swissmedic.rb

Large diffs are not rendered by default.

Binary file modified test/data/xlsx/Packungen-2015.07.02.xlsx
Binary file not shown.
25 changes: 24 additions & 1 deletion test/test_model/composition.rb
Expand Up @@ -15,7 +15,6 @@ 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
Expand Down Expand Up @@ -153,5 +152,29 @@ def test_active_more_info
assert_equal(nil, active.more_info)
end

def test_composition_corresp
tst = 'corresp_tst'
assert_equal('', @composition.to_s)
@composition.corresp = tst
assert_equal(tst, @composition.corresp)
assert_equal('', @composition.to_s)
end

def test_composition_label
tst = 'label_tst'
assert_equal('', @composition.to_s)
@composition.label = tst
assert_equal(tst, @composition.to_s)
end

def test_composition_label_corresp
tst_label = 'label_tst'
tst_corresp = 'corresp'
@composition.corresp = tst_corresp
assert_equal(tst_corresp, @composition.corresp)
@composition.label = tst_label
assert_equal(tst_label, @composition.label)
assert_equal(tst_label, @composition.to_s)
end
end
end
3 changes: 0 additions & 3 deletions test/test_model/substance.rb
Expand Up @@ -34,9 +34,6 @@ def test_add_more_info
@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
63 changes: 41 additions & 22 deletions test/test_plugin/swissmedic.rb
Expand Up @@ -23,11 +23,16 @@
require 'util/oddbconfig'
require 'stub/oddbapp'

begin
require 'pry';
rescue LoadError
end

class FlexMock::TestUnitFrameworkAdapter
attr_accessor :assertions
end

RUN_ALL = true
RUN_ALL = false
module ODDB
class SwissmedicPluginTest < Minitest::Test
include FlexMock::TestCase
Expand All @@ -40,6 +45,8 @@ class SwissmedicPluginTest < Minitest::Test
ROW_AXOTIDE = 19
IKSNR_WELEDA = "09232"
EXPIRATION_DATE_ASPIRIN = Date.new(2017,5,9)
COMPOSITION_LABEL = 'aCompLabel'

def setup_app(app = flexmock('app'))
@app = app
@archive = File.expand_path('../var', File.dirname(__FILE__))
Expand Down Expand Up @@ -85,6 +92,8 @@ def setup_index_page

def setup_simple_seq(iksnr = '12345', seqnr='01')
@ptr = Persistence::Pointer.new([:registration, iksnr], [:sequence, seqnr])
@composition = Composition.new
@composition.label = COMPOSITION_LABEL
seq = flexmock 'sequence'
seq.should_receive(:pointer).and_return @ptr
seq.should_receive(:seqnr).and_return seqnr
Expand All @@ -94,6 +103,7 @@ def setup_simple_seq(iksnr = '12345', seqnr='01')
seq.should_receive(:composition_text=)
seq.should_receive(:composition_text).and_return "composition_text #{iksnr} #{seqnr}"
seq.should_receive(:delete_composition)
seq.should_receive(:create_composition).and_return(@composition)
seq
end

Expand Down Expand Up @@ -846,6 +856,7 @@ def test_update_composition__focus_on_doses_percent
parsed_comps = ParseUtil.parse_compositions(composition_text, active_agents_text)
result = @plugin.update_compositions(seq, row, {}, composition_text, parsed_comps)
assert_equal([comp, comp, comp, comp, comp], result)
# assert_equal("[aCompLabel, aCompLabel, aCompLabel, aCompLabel, aCompLabel]", result.to_s)
end

def test_update_composition__focus_on_doses_qty_in_scale
Expand All @@ -858,7 +869,7 @@ def test_update_composition__focus_on_doses_qty_in_scale
seq.should_receive(:pointer).and_return ptr
seq.should_receive(:oid).and_return 'oid'
seq.should_receive(:iksnr).and_return 'iksnr'
seq.should_receive(:seqnr).and_return 'seqnr'
seq.should_receive(:seqnr).and_return 1
seq.should_receive(:active_agents).and_return []
seq.should_receive(:composition_text).and_return composition_text
seq.should_receive(:compositions).and_return []
Expand All @@ -880,6 +891,7 @@ def test_update_composition__focus_on_doses_qty_in_scale
comp.should_receive(:substances).and_return []
cptr = ptr + [:composition, 'id']
comp.should_receive(:pointer).and_return(cptr)
seq.should_receive(:create_composition).and_return []
@app.should_receive(:create).with(ptr + :composition).and_return comp
args = {
:label => nil,
Expand Down Expand Up @@ -1167,16 +1179,17 @@ def test_diff
reg.should_receive(:package).and_return pac
@app.should_receive(:registration).and_return reg
result = @plugin.diff(@current, @older)
assert_equal 9, result.news.size
assert_equal 10, result.news.size
assert_equal "Viscotears Tropfgel, Augengel", result.news.first[2].value
assert_equal 2, result.updates.size
assert_equal "Colon Sérocytol, suppositoire", result.updates.first[2].value
assert_equal 5, result.changes.size
assert_equal 6, result.changes.size
expected = {
"00278"=>[:company, :atc_class],
"48624"=>[:new],
"62069"=>[:new],
"16105"=>[:new],
"00488"=>[:new],
"00279"=>[:delete]
}
assert_equal(expected, result.changes)
Expand All @@ -1201,6 +1214,7 @@ def test_to_s
result = @plugin.diff(@current, @older)
@plugin.to_s
assert_equal <<-EOS.strip, @plugin.to_s
+ 00488: Hepatect CP, Infusionslösung
+ 16105: Hirudoid, Creme
+ 48624: Viscotears Tropfgel, Augengel
+ 62069: Levetiracetam Desitin 250 mg, Minipacks mit Mini-Filmtabletten
Expand All @@ -1210,13 +1224,15 @@ def test_to_s
assert_equal <<-EOS.strip, @plugin.to_s(:name)
> 00278: Colon Sérocytol, suppositoire; Zulassungsinhaber (Sérolab AG), ATC-Code (J06A)
- 00279: Conjonctif Sérocytol, suppositoire
+ 00488: Hepatect CP, Infusionslösung
+ 16105: Hirudoid, Creme
+ 62069: Levetiracetam Desitin 250 mg, Minipacks mit Mini-Filmtabletten
+ 48624: Viscotears Tropfgel, Augengel
EOS
assert_equal <<-EOS.strip, @plugin.to_s(:registration)
> 00278: Colon Sérocytol, suppositoire; Zulassungsinhaber (Sérolab AG), ATC-Code (J06A)
- 00279: Conjonctif Sérocytol, suppositoire
+ 00488: Hepatect CP, Infusionslösung
+ 16105: Hirudoid, Creme
+ 48624: Viscotears Tropfgel, Augengel
+ 62069: Levetiracetam Desitin 250 mg, Minipacks mit Mini-Filmtabletten
Expand Down Expand Up @@ -1626,8 +1642,8 @@ def test_plugin_update
assert_equal(nil, composition.label)
assert_equal("carbomerum 980 2 mg, conserv.: cetrimidum, excipiens ad gelatum pro 1 g.", composition.source)
assert_equal("Augengel: Carbomerum 980 2 mg, Cetrimidum 0 ", composition.to_s)
end if false
end
end
end if RUN_ALL

# Tests for using with xlsx files
class StubSequence < Sequence
Expand All @@ -1647,7 +1663,7 @@ class SwissmedicPluginTestXLSX < Minitest::Test
def setup
ODDB::GalenicGroup.reset_oids
ODBA.storage.reset_id
@app = ODDB::App.new
@app = flexmock(ODDB::App.new)
@archive = File.expand_path('../var', File.dirname(__FILE__))
FileUtils.rm_rf(@archive)
FileUtils.mkdir_p(@archive)
Expand Down Expand Up @@ -1722,24 +1738,27 @@ def test_july_2015
seq.create_package('001')
seq.create_package('002')

reg = @app.create_registration('00288')
seq = reg.create_sequence('02')
seq.create_package('001')
@app.should_receive(:delete).at_least.times(5)

result = @plugin.update({:update_compositions => true}, agent)
assert_equal(3, @app.registrations.size)
assert_equal(3, @app.sequences.size)
assert_equal(5, @app.packages.size)
assert_equal(true, result)

result_second_run = @plugin.update({}, agent)
assert File.exist?(@target), "#@target was not saved"
@app.registrations.each{ |reg| puts "reg #{reg[1].iksnr} with #{reg[1].sequences.size} sequences"} if $VERBOSE
if true # skipping an error
assert_equal(2, @app.registrations.size)
puts "Don't know howto avoid error Could not create: :!00278,sequence,01!composition. "
else
assert_equal(5, @app.registrations.size)
assert_equal(7, @app.sequences.size)
assert_equal(13, @app.packages.size)
assert_equal({"00278"=>[:company], "48624"=>[:new], "62069"=>[:new], "16105"=>[:new], "00279"=>[:delete]}, result)
assert_equal(7, @app.registrations.size)
assert_equal(9, @app.sequences.size)
assert_equal(15, @app.packages.size)
assert_equal(6, result_second_run.changes.size)
assert(result_second_run)
assert_equal({"00278"=>[:company], "48624"=>[:new], "62069"=>[:new], "16105"=>[:new], "00488"=>[:new], "00279"=>[:delete]}, result_second_run.changes)

result_second_run = @plugin.update({}, agent)
assert_equal({}, result_second_run)
assert_equal(5, @app.registrations.size)
assert_equal(7, @app.sequences.size)
assert_equal(13, @app.packages.size)
end
end
end if RUN_ALL
end
end

0 comments on commit 25a470a

Please sign in to comment.