Skip to content

Commit

Permalink
Added epha-interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Dec 16, 2013
1 parent fdc0486 commit 876ad84
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 7 deletions.
16 changes: 16 additions & 0 deletions data/css/template.css
Expand Up @@ -579,6 +579,22 @@ td.interaction-substance {
font-size : 14px;
width : 20%;
}
td.interaction-drug {
margin-top : 0px;
list-style-type : circle;
width : 25%;
}
td.interaction-atc {
margin-top : 0px;
list-style-type : circle;
width : 7%;
}
td.interaction-info {
margin-top : 0px;
list-style-type : circle;
width : 60%;
}

td.sum {
border-color : black;
border-style : solid;
Expand Down
52 changes: 49 additions & 3 deletions spec/interactions_spec.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
# encoding: utf-8
require 'spec_helper'
require 'pp'
# require Dir.pwd + '/spec/spec_helper.rb'
@workThread = nil

Expand All @@ -9,6 +10,7 @@
before :all do
@idx = 0
@browser = Watir::Browser.new
waitForOddbToBeReady(@browser, OddbUrl)
end

before :each do
Expand All @@ -22,11 +24,53 @@
@browser.goto OddbUrl
end

it "should show interactions between Aspirin and Marcoumar" do
it "should show interactions between epha example in instant view" do
@browser.link(:text, "Einstellungen").click
puts @browser.radio(:id, 'plus').inspect
@browser.radio(:id, 'plus').set
@browser.button(:value,"Speichern").click
sleep 1
@browser.goto OddbUrl
medis = ['Losartan',
'Metoprolol',
'Nolvadex',
'Paroxetin',
]
@browser.link(:text=>'Interaktionen').click
@browser.url.should match ('/de/gcc/home_interactions/')
@browser.link(:text=>'Instant').click
id = 'interaction_searchbar'
medis.each{
|medi|
chooser = @browser.text_field(:id, id)
0.upto(10).each{ |idx|
chooser.set(medi)
sleep idx*1
chooser.send_keys(:down)
sleep idx*0.1
chooser.send_keys(:enter)
sleep idx*0.1
value = chooser.value
break unless /#{medi}/.match(value)
sleep 1
}
chooser.set(chooser.value + "\n")
createScreenshot(@browser, "_#{medi}_#{__LINE__}")
id = 'interaction_chooser_searchbar'
}
sleep 1
createScreenshot(@browser, "_interactions_#{__LINE__}")
medis.each{
|medi|
@browser.text.should match /#{medi}/
}
end
it "should show interactions between Aspirin and Marcoumar in old format" do
@browser.link(:text=>'Interaktionen').click
@browser.url.should match ('/de/gcc/home_interactions/')
# @browser.link(:text=>'Instant').click
@browser.link(:text=>'Instant').click
@browser.button(:value,"Suchen").click
@browser.url.should match ('/de/gcc/interaction_chooser/')
@browser.text_field(:id, "searchbar").set("Aspirin")
@browser.button(:value,"Suchen").click
@browser.text.should match /Ascorbinsäure/
Expand All @@ -48,7 +92,9 @@
# @browser.text "Quelle: Swissmedic\nVersion: 30.10.2013\nÜbersicht\nAlle löschen"
# @browser.text.should match 'Marcoumar'
# @browser.text.should match 'Aspirin'
end
end if false


after :all do
@browser.close
end
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -15,6 +15,16 @@
browsers2test ||= [ :firefox ] # could be any combination of :ie, :firefox, :chrome
Browser2test = browsers2test

def waitForOddbToBeReady(browser = Browser2test, url = OddbUrl, maxWait = 30)
0.upto(maxWait).each{
|idx|
browser.goto OddbUrl
break unless /Es tut uns leid/.match(browser.text)
puts "Waiting #{idx} of max #{maxWait} for #{url} to be ready"
sleep 1
}
end

def createScreenshot(browser, added=nil)
if browser.url.index('?')
name = File.join(ImageDest, File.basename(browser.url.split('?')[0]))
Expand Down
1 change: 1 addition & 0 deletions src/state/interactions/interaction_chooser.rb
Expand Up @@ -66,6 +66,7 @@ def delete_all
}
self
end

def show_interaction
atc_codes = []
iksnrs = []
Expand Down
100 changes: 96 additions & 4 deletions src/view/interactions/interaction_chooser.rb
Expand Up @@ -17,21 +17,45 @@
module ODDB
module View
module Interactions
# see http://matrix.epha.ch/#/56751,61537,39053,59256
Ratings = { 'A' => 'Keine Massnahmen erforderlich',
'B' => 'Vorsichtsmassnahmen empfohlen',
'C' => 'Regelmässige Überwachung',
'D' => 'Kombination vermeiden',
'X' => 'Kontraindiziert',
}
Colors = { 'A' => 'green',
'B' => 'yellow',
'C' => 'orange',
'D' => 'red',
'X' => 'firebrick',
}
class InteractionChooserDrugHeader < HtmlGrid::Composite
include View::AdditionalInformation
COMPONENTS = {
[0,0] => :fachinfo,
[1,0] => :drug,
[2,0] => :delete,
[3,0] => :atc_code,
[4,0] => :epha_interaction,
}
CSS_MAP = {
[0,0] => 'small',
[1,0] => 'list',
[1,0] => 'interaction-drug',
[2,0] => 'small',
[3,0] => 'interaction-atc',
[4,0] => 'interaction-info',
}
def init
@drugs = @session.persistent_user_input(:drugs)
@index = (@drugs ? @drugs.length : 0).to_s
@atc_codes = []
if @drugs and !@drugs.empty?
@drugs.values.each do |pac|
$stdout.puts "init adding pac #{pac.atc_class.code}"
@atc_codes << pac.atc_class.code
end
end
super
end
def fachinfo(model, session=@session)
Expand All @@ -42,7 +66,7 @@ def fachinfo(model, session=@session)
end
def drug(model, session=@session)
div = HtmlGrid::Div.new(model, @session, self)
div.set_attribute('class', 'drug')
div.set_attribute('class', 'interaction-drug')
div.value = []
if model
div.value << model.name_with_size
Expand All @@ -61,6 +85,74 @@ def drug(model, session=@session)
end
div
end
def atc_code(model, session=@session)
div = HtmlGrid::Div.new(model, @session, self)
div.set_attribute('class', 'interaction-atc')
div.value = []
div.value << model.atc_class.code + ': ' + model.atc_class.name
div
end
def my_get_epha_interaction(atc_code_self, atc_code_other)
@session.app.epha_interactions.each { |aInteraction|
return aInteraction if aInteraction.atc_code_self.to_s == atc_code_self.to_s and aInteraction.atc_code_other.to_s == atc_code_other.to_s
}
nil
end
def get_interactions(atc_codes, my_atc_code)
results = []
idx=atc_codes.index(my_atc_code)
atc_codes[0..idx].combination(2).to_a.each {
|combination|
next unless combination.index(my_atc_code)
[ @session.app.get_epha_interaction(combination[0], combination[1]),
@session.app.get_epha_interaction(combination[1], combination[0]),
].each{
|interaction|
next unless interaction
header = ''
header += interaction.atc_code_self + ': ' + interaction.atc_name + ' => '
header += interaction.atc_code_other + ': ' + interaction.name_other
header += ' ' + interaction.info
text = ''
text += interaction.severity + ': ' + Ratings[interaction.severity]
text += '<br>' + interaction.action
text += '<br>' + interaction.measures + '<br>'

results << { :header => header,
:severity => interaction.severity,
:color => Colors[interaction.severity],
:text => text
}
}
}
$stdout.puts results.inspect
results
end
def epha_interaction(model, session=@session)
div = HtmlGrid::Div.new(model, @session, self)
# the first element cannot have an interaction
return div if @atc_codes.index(model.atc_class.code) == 0
div.set_attribute('class', 'interaction-info')
div.value = []
list = HtmlGrid::Div.new(model, @session, self)
list.value = []
get_interactions(@atc_codes, model.atc_class.code).each {
|interaction|
headerDiv = HtmlGrid::Div.new(model, @session, self)
headerDiv.value = []
headerDiv.value << interaction[:header]
list.value << headerDiv

infoDiv = HtmlGrid::Div.new(model, @session, self)
infoDiv.value = []
infoDiv.value << interaction[:text]
infoDiv.set_attribute('style', "background-color: #{interaction[:color]}") unless interaction[:severity].eql?('A')
list.value << infoDiv

}
div.value << list
div
end
def delete(model, session=@session)
if @container.is_a? InteractionChooserDrug and # hide at search result
(@drugs and @drugs.length >= 1)
Expand Down Expand Up @@ -201,9 +293,9 @@ class InteractionChooser < View::PrivateTemplate
def backtracking(model, session=@session)
fields = []
fields << @lookandfeel.lookup(:th_pointer_descr)
link = HtmlGrid::Link.new(:home_interactions, model, @session, self)
link = HtmlGrid::Link.new(:home_interaction, model, @session, self)
link.css_class = "list"
link.href = @lookandfeel._event_url(:home_interactions, [])
link.href = @lookandfeel._event_url(:home_interaction, [])
link.value = @lookandfeel.lookup(:home)
fields << link
fields << '&nbsp;-&nbsp;'
Expand Down

0 comments on commit 876ad84

Please sign in to comment.