Skip to content

Commit

Permalink
Fix home_interactions for iksnr and atc
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Aug 13, 2014
1 parent 1f548a1 commit c477b44
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 68 deletions.
11 changes: 4 additions & 7 deletions spec/rezept_and_instantsearch_spec.rb
Expand Up @@ -84,8 +84,7 @@ def setGeneralInfo(nrMedis=0)
@browser.radio(:name => "prescription_sex", :value => "2").click # Set M for männlich
@browser.send_keys :tab
@browser.text_field(:name => 'prescription_first_name').set FirstName
@browser.send_keys :tab
require 'pry'; binding.pry
# require 'pry'; binding.pry
@browser.text_field(:name => 'prescription_family_name').set FamilyName
@browser.send_keys :tab
@browser.text_field(:name => 'prescription_birth_day').set Birthday
Expand All @@ -100,6 +99,8 @@ def setGeneralInfo(nrMedis=0)
def set_zsr_of_doctor(zsr_id)
@browser.text_field(:name => 'prescription_zsr_id').set zsr_id
@browser.send_keys :tab
@browser.text_field(:name => 'prescription_zsr_id').click
sleep(1)
end
def checkGeneralInfo(nrMedis=0)
if @browser.url.index('/print/rezept/')
Expand Down Expand Up @@ -162,10 +163,8 @@ def waitForPrintInfo(maxSeconds = 120)
add_one_drug_to_rezept(Four_Medis[0])
setGeneralInfo(1)
set_zsr_of_doctor('J 0390.19')
@browser.url.should match /zsr.J039019/
@browser.text.should match /Davatz/
@browser.text.should match /Dr. med. Ursula Davatz/
set_zsr_of_doctor('P006309')
@browser.url.should match /zsr.P006309/
@browser.text.should match /Dr. med. Werner Meier/
oldWindowsSize = @browser.windows.size
@browser.button(:name, "print").click
Expand All @@ -183,7 +182,6 @@ def waitForPrintInfo(maxSeconds = 120)
@browser.text.index("|#{FamilyName}|").should > 0
@browser.text.index("|19901231|").should > 0 # Must of format YYYYMMDD
end
if false
it "should print the fachinfo when opening the fachinfo from a prescription" do
@browser.select_list(:name, "search_type").select("Markenname")
@browser.text_field(:name, "search_query").set(Four_Medis.first)
Expand Down Expand Up @@ -426,5 +424,4 @@ def waitForPrintInfo(maxSeconds = 120)
inhalt.scan(/\nInteraktionen\n/).size.should == 2
checkGeneralInfo(nrRemarks)
end
end
end
5 changes: 2 additions & 3 deletions src/state/drugs/fachinfo_search.rb
Expand Up @@ -69,13 +69,12 @@ def package_for(ean13)
end
end
def match_term
puts "fachinfo_search.match_term #{@session.request_path} drugsFromUrl: #{@session.drugsFromUrl}"
hits = []
if @session.drugsFromUrl
if @session.choosen_drugs
chapter = @session.user_input(:fachinfo_search_type).to_s.gsub(/^fi_/, '').intern
term = @session.user_input(:fachinfo_search_term)
is_full = (@session.user_input(:fachinfo_search_full_text) == "1")
drugsFromUrl.each do |ean13, pac|
choosen_drugs.each do |ean13, pac|
$stdout.puts "match_term #{ean13} #{pac}"
doc = pac.fachinfo.description(@session.language)
if doc.respond_to?(chapter)
Expand Down
2 changes: 1 addition & 1 deletion src/state/drugs/prescription.rb
Expand Up @@ -24,7 +24,7 @@ class Prescription < State::Drugs::Global
VIEW = View::Drugs::Prescription
@@ean13_form = /^(7680)(\d{5})(\d{3})(\d)$/u
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
ean13 = @session.user_input(:search_query)
@drugs[ean13] = package_for(ean13) if ean13
super
Expand Down
24 changes: 7 additions & 17 deletions src/state/interactions/interaction_chooser.rb
Expand Up @@ -19,27 +19,18 @@ class InteractionChooser < State::Interactions::Global
VIEW = View::Interactions::InteractionChooser
@@ean13_form = /^(7680)(\d{5})(\d{3})(\d)$/u

def handle_drug_changes(drugs, msg)
def handle_drug_changes(drugs, msg)
path = @session.request_path
$stdout.puts "state.handle_drug_changes #{msg}: #{drugs} from #{path}"
$stdout.puts caller.join("\n")
@session.set_persistent_user_input(:drugs, drugs)
uri = @session.lookandfeel._event_url(:home_interactions, [])
first = true
drugs.each{|ean, pack|
if first
first = false
uri += pack.barcode
else
uri += ",#{pack.barcode}"
end
}
eans = []
drugs.each{|ean, pack| eans << pack.barcode }
@session.lookandfeel._event_url(:home_interactions, [eans])
end

def init
ean13 = @session.user_input(:search_query)
path = @session.request_path.sub(/(\?|)$/, '')
$stdout.puts "InteractionChooser init ean13 #{ean13}: path: #{path}"
return unless path.index('/home_interactions')
search_code = path.split('/home_interactions')[1]
drugs = {}
Expand Down Expand Up @@ -70,8 +61,7 @@ def init
}
handle_drug_changes(drugs, 'init')
else
$stdout.puts "InteractionChooser init set_persistent_user_input(:drugs, {})"
@session.set_persistent_user_input(:drugs, {})
@session.lookandfeel._event_url(:home_interactions, [])
end
super
end
Expand All @@ -81,7 +71,7 @@ def ajax_add_drug
unless error?
if ean13 = @session.user_input(:ean).to_s and
pack = package_for(ean13)
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
drugs[ean13] = pack unless drugs.has_key?(ean13)
return handle_drug_changes(drugs, 'ajax_add_drug')
end
Expand All @@ -93,7 +83,7 @@ def ajax_delete_drug
check_model
unless error?
if ean13 = @session.user_input(:ean).to_s
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
drugs.delete(ean13)
return handle_drug_changes(drugs, 'ajax_delete_drug')
end
Expand Down
10 changes: 5 additions & 5 deletions src/util/session.rb
Expand Up @@ -231,24 +231,24 @@ def sponsor
@app.sponsor(flavor)
end
ZsrAndEAN_Regexp = /(\/zsr_.+|)\/(ean|home_interactions)\/+([^\\?].+)/
def drugsFromUrl
def choosen_drugs
persistent = persistent_user_input(:drugs)
m = ZsrAndEAN_Regexp.match(request_path)
return {} unless m
ean13s = m[3].split(/[,?\/]/)
return {} unless m or persistent
ean13s = m ? m[3].split(/[,?\/]/) : []
drugs = {}
ean13s.each {
|ean13|
pack = @app.package_by_ean13(ean13)
drugs[ean13] = pack if pack
}
drugs.merge!(persistent) if persistent
drugs
end
def zsr_id
id = cookie_set_or_get(:zsr_id) || @persistent_user_input[:zsr_id]
$stdout.puts "cookie_set_or_get #{id} from cookie #{cookie_set_or_get(:zsr_id)} or user_input #{@persistent_user_input[:zsr_id]}"
@persistent_user_input[:zsr_id] = id ? id.gsub(/[ \.]/, '') : id
m = ZsrAndEAN_Regexp.match(request_path)
$stdout.puts "zsr from request_path is #{m.inspect}"
return id unless m and m[1].index('/zsr_')
return m[1].split('_').last
end
Expand Down
8 changes: 4 additions & 4 deletions src/view/drugs/fachinfo_search.rb
Expand Up @@ -29,7 +29,7 @@ class FachinfoSearchDrugHeader < HtmlGrid::Composite
[2,0] => 'small',
}
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
@index = (@drugs ? @drugs.length : 0).to_s
super
end
Expand Down Expand Up @@ -99,7 +99,7 @@ class FachinfoSearchDrugDiv < HtmlGrid::Div
def init
super
@value = []
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @drugs and !@drugs.empty?
@drugs.values.each do |pac|
@value << FachinfoSearchDrug.new(pac, @session, self)
Expand Down Expand Up @@ -242,7 +242,7 @@ class FachinfoSearchTermHitList < HtmlGrid::List
BACKGROUND_SUFFIX = ''
LEGACY_INTERFACE = false
def drug(model, session=@session)
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
if pac = drugs[model[:ean13]]
FachinfoSearchDrugHeader.new(pac, session, self)
end
Expand Down Expand Up @@ -344,7 +344,7 @@ def to_csv
'Search Match',
],
]
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
@model.each do |model|
if pac = drugs[model[:ean13]]
if model[:text].is_a? FachinfoDocument
Expand Down
22 changes: 11 additions & 11 deletions src/view/drugs/prescription.rb
Expand Up @@ -36,7 +36,7 @@ class PrescriptionInteractionDrugDiv < HtmlGrid::Div
def init
super
@value = []
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @drugs and !@drugs.empty?
@value << View::Interactions::InteractionChooserDrug.new(@model, @session, self)
end
Expand All @@ -56,7 +56,7 @@ class PrescriptionDrugHeader < HtmlGrid::Composite
[2,0] => 'small',
}
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @model and @model.barcode and @model.barcode.length == 13
@index = @drugs.keys.index(@model.barcode)
else
Expand Down Expand Up @@ -127,7 +127,7 @@ class PrescriptionDrug < HtmlGrid::Composite
}
CSS_CLASS = 'composite'
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
@index = -1
if @model and @drugs and !@drugs.empty?
@index = @drugs.keys.index(@model.barcode)
Expand Down Expand Up @@ -163,7 +163,7 @@ def prescription_comment(model, session)
end
class PrescriptionDrugDiv < HtmlGrid::Div
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
super # must come first or it will overwrite @value
@value = []
ODDB::View::Interactions.calculate_atc_codes(@drugs)
Expand Down Expand Up @@ -311,7 +311,7 @@ def prescription_zsr_id(model, session)
def buttons(model, session)
buttons = []
print = post_event_button(:print)
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
zsr_id = @session.zsr_id
elements = zsr_id ? [ :rezept, ('zsr_'+zsr_id).to_sym ] : [ :rezept]
elements += [:ean, drugs.keys].flatten
Expand All @@ -325,7 +325,7 @@ def buttons(model, session)
buttons
end
def delete_all(model, session=@session)
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
delete_all_link = HtmlGrid::Link.new(:delete, @model, @session, self)
delete_all_link.href = @lookandfeel._event_url(:rezept, [:ean] )
delete_all_link.value = @lookandfeel.lookup(:interaction_chooser_delete_all)
Expand Down Expand Up @@ -377,7 +377,7 @@ class PrescriptionPrintInnerComposite < HtmlGrid::Composite
CSS_CLASS = 'compose'
DEFAULT_CLASS = HtmlGrid::Value
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
@index = nil
if @model and @drugs and !@drugs.empty?
@index = @drugs.keys.index(@model.barcode)
Expand Down Expand Up @@ -465,7 +465,7 @@ class PrescriptionPrintComposite < HtmlGrid::DivComposite
[0,12] => 'print',
}
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
super
self.onload = %(require(["dojo/domReady!"], function(){
print_composite_init('#{@lookandfeel.lookup(:prescription_comment)}');
Expand Down Expand Up @@ -534,7 +534,7 @@ class PrescriptionPrint < View:: PrintTemplate
CONTENT = View::Drugs::PrescriptionPrintComposite
JAVASCRIPTS = ['qrcode', 'prescription']
def init
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
@index = (@drugs ? @drugs.length : 0).to_s
if @model and @drugs and !@drugs.empty?
@index = @drugs.keys.index(@model.barcode).to_s
Expand All @@ -543,7 +543,7 @@ def init
end
def head(model, session=@session)
span = HtmlGrid::Span.new(model, session, self)
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
span.value = @lookandfeel.lookup(:print_of) +
@lookandfeel._event_url(:print, [:rezept, :ean, drugs ? drugs.keys : [] ].flatten)
span
Expand Down Expand Up @@ -614,7 +614,7 @@ def to_csv
insert_blank
@lines << date
insert_blank
if drugs = @session.drugsFromUrl
if drugs = @session.choosen_drugs
@packages = drugs.values.unshift(model)
else
@packages = [model]
Expand Down
10 changes: 5 additions & 5 deletions src/view/interactions/interaction_chooser.rb
Expand Up @@ -142,7 +142,7 @@ def delete(model, session=@session)
if model
args = [:ean, model.barcode] if model
url = @session.request_path.sub(model.barcode.to_s, '').sub('/,', '/').sub(/,$/, '')
if @session.drugsFromUrl.size == 0
if @session.choosen_drugs.size == 0
ODDB::View::Interactions.calculate_atc_codes({})
end
link.onclick = %(
Expand Down Expand Up @@ -177,7 +177,7 @@ def init
@interactions = ODDB::View::Interactions.get_interactions(model.atc_class.code, @session)
ean13 = @session.user_input(:search_query)
path = @session.request_path
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @model.is_a? ODDB::Package
nextRow = 0
unless @hide_interaction_headers
Expand Down Expand Up @@ -259,7 +259,7 @@ class InteractionChooserDrugList < HtmlGrid::List
CSS_CLASS = 'composite'
SORT_HEADER = false
def initialize(model, session=@session, arg_self=nil)
@drugs = session.drugsFromUrl
@drugs = session.choosen_drugs
super # must come first or it will overwrite @value
@value = []
ODDB::View::Interactions.calculate_atc_codes(@drugs)
Expand All @@ -275,7 +275,7 @@ class InteractionChooserDrugDiv < HtmlGrid::Div
def init
super
@value = []
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @drugs and !@drugs.empty?
@value << InteractionChooserDrugList.new(@drugs, @session, self)
end
Expand Down Expand Up @@ -425,7 +425,7 @@ def epha_public_domain(model, session=@session)
end
def delete_all(model, session=@session)
$stdout.puts "InteractionChooserForm.delete_all #{@session.request_path}"
@drugs = @session.drugsFromUrl
@drugs = @session.choosen_drugs
if @drugs and !@drugs.empty?
delete_all_link = HtmlGrid::Link.new(:delete, @model, @session, self)
delete_all_link.href = @lookandfeel._event_url(:delete_all, [])
Expand Down
5 changes: 1 addition & 4 deletions src/view/searchbar.rb
Expand Up @@ -55,16 +55,13 @@ module InstantSearchBarMethods
def xhr_request_init(keyword)
target = keyword.intern
id = "#{target}_searchbar"
drugs = @session.drugsFromUrl
drugs = @session.choosen_drugs
drugs = drugs.keys.join(',') if drugs
ean13 = @session.persistent_user_input(:ean)
$stdout.puts "InstantSearchBarMethods prescription request_path #{@session.request_path} are #{drugs}"
if /prescription/i.match(target.to_s)
url = @lookandfeel._event_url(:rezept , [:ean, drugs ? drugs: [] ].flatten)
$stdout.puts "InstantSearchBarMethods prescription url #{url}"
else
url = @lookandfeel._event_url(:home_interactions, [drugs ? drugs : [] ].flatten)
$stdout.puts "InstantSearchBarMethods xx url #{url}"
end
val = @session.lookandfeel.lookup(:add_drug)
progressbar = ""
Expand Down

0 comments on commit c477b44

Please sign in to comment.