Skip to content

Commit

Permalink
Adapt to new CSV format of epha-interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed May 12, 2014
1 parent 30db110 commit bf60769
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
15 changes: 7 additions & 8 deletions src/plugin/epha_interactions.rb
Expand Up @@ -35,16 +35,16 @@ def update(csv_file_path = nil)
@lineno = 0
first_line = nil
File.readlines(csv_file_path).each do |line|
unless first_line
first_line = line
# $stdout.puts "first: "+ first_line
next
end
@lineno += 1
# $stdout.puts "#{Time.now} #{@lineno}: #{line}"; $stdout.flush
elements = line.chomp.split(';')
next if /ATC1.*Name1.*ATC2.*Name2/.match(line)
begin
elements = CSV.parse_line(line)
rescue CSV::MalformedCSVError
$stdout.puts "CSV::MalformedCSVError in line #{@lineno}: #{line}"
next
end
values = Hash.new
elements.each{ |elem| elem.gsub!(/^"|"$/,'') }
epha_interaction = @app.create_epha_interaction(elements[0], elements[2])
epha_interaction.atc_code_self = elements[0]
epha_interaction.atc_name = elements[1]
Expand All @@ -56,7 +56,6 @@ def update(csv_file_path = nil)
epha_interaction.measures = elements[7]
epha_interaction.severity = elements[8]
end
# $stdout.puts "#{Time.now} read #{@lineno} lines. Storing the results"; $stdout.flush
$stdout.puts "#{Time.now}: Calling @app.odba_store"; $stdout.flush
@app.odba_store
$stdout.puts "#{Time.now}: Calling @app.epha_interactions.odba_store"; $stdout.flush
Expand Down
5 changes: 3 additions & 2 deletions test/data/csv/epha_interactions_de_utf8-latest-latest.csv
@@ -1,2 +1,3 @@
ATC1;Name1;ATC2;Name2;Info;Mechanismus;Effekt;Massnahmen;Grad
N06AB06;Sertralin;M03BX02;Tizanidin;Keine Interaktion;Tizanidin wird über CYP1A2 metabolisiert. Sertralin beeinflusst CYP1A2 jedoch nicht.;Keine Interaktion.;Die Kombination aus Sertralin und Tizanidin hat kein bekanntes Interaktionspotential.;A
"ATC1","Name1","ATC2","Name2","Info","Mechanismus","Effekt","Massnahmen","Grad"
"N06AB06","Sertralin","M03BX02","Tizanidin","Keine Interaktion","Tizanidin wird über CYP1A2 metabolisiert. Sertralin beeinflusst CYP1A2 jedoch nicht.","Keine Interaktion.","Die Kombination aus Sertralin und Tizanidin hat kein bekanntes Interaktionspotential.","A"
J05AE08","Atazanavir","C10AA05","Atorvastatin","Erhöhtes Risiko für Myopathie und Rhabdomyolyse","Atazanavir hemmt CYP3A4 und darüber auch den Abbau von Atorvastatin, was zu erhöhten Plasmakonzentrationen von Atorvastatin führt. .","Aufgrund der Inhibition von CYP3A4 durch Atazanavir kann die Atorvastatinkonzentration im Plasma ansteigen, was mit einem erhöhten Risiko für Myopathie und Rhabdomyolyse einhergeht .","Kombination nach Möglichkeit meiden und alternativ Statin wählen, welches nicht mit Atazanavir interagiert, wie z.B. Pravastatin. Ist nach Nutzen-Risiko-Abwägung die Kombination aus Atorvastatin und Atazanavir erforderlich, niedrige Atorvastatindosis (z.B. 10 mg/d) wählen und auf Zeichen der Myopathie und Rhabdomyolyse, wie Muskelschwäche, Muskelschmerzen, verfärbter Urin und CK-Anstieg, achten . Die Kombination aus Atazanavir und Ritonavir mit Atorvastatin ist kontraindiziert.","D"
29 changes: 18 additions & 11 deletions test/test_util/updater.rb
Expand Up @@ -11,6 +11,7 @@
require 'util/updater'
require 'stub/odba'
require 'date'

module ODDB
module Doctors
class DoctorPlugin; end
Expand Down Expand Up @@ -41,32 +42,36 @@ def incomplete_pointers
end
alias :recipients :incomplete_pointers
end
class TestUpdater <Minitest::Test
class TestUpdater < Minitest::Test
include FlexMock::TestCase
class StubLog
include ODDB::Persistence
attr_accessor :report, :pointers, :recipients, :hash
def notify(arg=nil)
end
end
class StubApp
class StubEphaInteractions
attr_accessor :atc_code_self, :atc_code_other # these two items are our unique index. They may not be changed
attr_accessor :atc_name, :name_other, :info, :action, :effect, :measures, :severity
def odba_store
end
end
class StubApp
attr_writer :log_group
attr_reader :pointer, :values, :model
attr_accessor :last_date, :epha_interactions
def initialize
attr_accessor :last_date, :epha_interactions
def initialize
@model = StubLog.new
@epha_interactions = []
epha_mock = FlexMock.new(@epha_interactions)
epha_mock = FlexMock.new(epha_interactions)
epha_mock.should_receive(:odba_store)
end
def odba_store
end
def create_epha_interaction(atc_code_self, atc_code_other)
epha_interaction = ODDB::EphaInteraction.new
mock = FlexMock.new(epha_interaction)
epha_interaction = StubEphaInteractions.new
@epha_interactions ||= []
@epha_interactions << mock
mock.should_receive(:odba_store)
@epha_interactions << epha_interaction
epha_interaction
end
def delete_all_epha_interactions
Expand Down Expand Up @@ -374,8 +379,10 @@ def test_update_epha_interactions_from_csv_file
@plugin = ODDB::EphaInteractionPlugin.new(@app)
res = @plugin.update(csv_file)
assert_equal(1, @app.epha_interactions.size, 'We have 1 line in epha-CSV')
assert_equal('<FlexMock:N06AB06;Sertralin;M03BX02;Tizanidin;Keine Interaktion;Tizanidin wird über CYP1A2 metabolisiert. Sertralin beeinflusst CYP1A2 jedoch nicht.;Keine Interaktion.;Die Kombination aus Sertralin und Tizanidi>',
@app.epha_interactions.first.inspect)
assert_equal('N06AB06', @app.epha_interactions.first.atc_code_self )
assert_equal('M03BX02', @app.epha_interactions.first.atc_code_other )
assert_equal('Keine Interaktion.', @app.epha_interactions.first.effect )
assert_equal('A', @app.epha_interactions.first.severity )
end

def test_update_simple # update_simple is a private method
Expand Down

0 comments on commit bf60769

Please sign in to comment.