From aafcbcd2487fee31469caab60ac707a3f77df9ac Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Wed, 15 Jul 2015 12:03:47 +0200 Subject: [PATCH] Updating view of active_agents. Take 23 Signed-off-by: Niklaus Giger --- src/custom/lookandfeelbase.rb | 8 +++-- src/view/admin/activeagent.rb | 31 +++++++++++++----- src/view/admin/sequence.rb | 64 ++++++++++++++++++++++++++++++++----- src/view/drugs/package.rb | 38 +++++++++++++++++++--- test/test_view/admin/activeagent.rb | 2 +- test/test_view/admin/sequence.rb | 30 +++++++++++++++-- test/test_view/drugs/package.rb | 57 +++++++++++++++++++++++++++++---- 7 files changed, 198 insertions(+), 32 deletions(-) diff --git a/src/custom/lookandfeelbase.rb b/src/custom/lookandfeelbase.rb index b268b2e..25374ea 100644 --- a/src/custom/lookandfeelbase.rb +++ b/src/custom/lookandfeelbase.rb @@ -1552,6 +1552,7 @@ Zeno Davatz :th_analysis_revision => 'Revision', :th_affiliations => 'Gruppen', :th_article_name => 'Artikelname', + :th_auxilliary => 'Hilfsstoffe', :thanks_for_cooperation => 'Besten Dank für Ihre Mitarbeit', :thanks_for_donation_title => 'Danke für Ihre Spende.', :thanks_for_donation_txt => 'Vielen herzlichen Dank für Ihre Spende.

Ihr ywesee-Team.', @@ -1658,6 +1659,7 @@ Zeno Davatz :th_market_date => 'Markteintritt', :th_measure => '25ml', :th_migel_code => 'Code', + :th_more_info => 'Zusätzliche Information', :th_most_precise_dose => 'Stärke', :th_multi => '2', :th_mutation_codes => 'Mutationscodes', @@ -1722,8 +1724,8 @@ Zeno Davatz :th_specialities => 'Facharzttitel', :th_specialization => 'Erlaubnis', :th_status => 'Status', - :th_substances => 'Wirkstoff', - :th_substance => 'Substanz', + :th_substances => 'Wirkstoffe', + :th_substance => 'Wirkstoff', :th_taxpoints => 'Taxpunkte', :th_time => 'Datum', :th_title => 'Titel', @@ -2981,6 +2983,7 @@ Zeno Davatz :th_list => 'Liste', #:th_location => 'Place', :th_mail_order_price => 'Pharmacie par corresp.', + :th_more_info => 'informations additionels', :th_most_precise_dose => 'Concentration', :th_mutation_codes => 'Codes mutation', :th_name_base => 'Préparation', @@ -4275,6 +4278,7 @@ Zeno Davatz :th_lt_description => 'Latin description', :th_mail_order_price => 'Mail Order Pharm.', :th_market_date => 'Market entry', + :th_more_info => 'additional_information', :th_most_precise_dose => 'Dose', :th_mutation_codes => 'Mutation codes', :th_name_base => 'Product', diff --git a/src/view/admin/activeagent.rb b/src/view/admin/activeagent.rb index 5d1decd..5607f28 100644 --- a/src/view/admin/activeagent.rb +++ b/src/view/admin/activeagent.rb @@ -79,19 +79,30 @@ class RootActiveAgentComposite < View::Admin::ActiveAgentComposite COMPONENTS = { [0,0] => :agent_name, [0,1] => View::Admin::ActiveAgentForm, - [0,2] => :active_agents, - [0,3] => 'th_source', - [0,4] => :source, + [0,2] => :active_agents, + [0,3] => 'th_auxilliary', + [0,4] => :auxilliary_substances, + [0,5] => 'th_source', + [0,6] => :source, } CSS_MAP = { - [0,0] => 'th', - [0,3] => 'subheading', + [0,0] => 'th agent_name', + [0,3] => 'subheading th_auxilliary', + [0,5] => 'subheading th_source', } - def active_agents(model, session=@session) - RootSequenceAgents.new(model.sequence.active_agents, @session, self) - end + def initialize(model, session, is_active_agent = true) + @is_active_agent = is_active_agent + $stdout.puts "RootActiveAgentComposite.init @is_active_agent #{@is_active_agent}" + super(model, session) + end + def active_agents(model, session=@session) + agents = model.sequence.active_agents.find_all{|x| x.is_active_agent == @is_active_agent} + $stdout.puts "RootActiveAgentComposite active_agents @is_active_agent #{@is_active_agent} #{model.sequence.active_agents.size} agents #{agents.size}" + RootSequenceAgents.new(agents, @session, self) + end def source(model, session=@session) val = HtmlGrid::Value.new(:source, model, @session, self) + val.css_class = 'RootActiveAgentComposite-source' val.value = sequence_source(model.sequence) if model val end @@ -99,6 +110,10 @@ end class ActiveAgent < View::Drugs::PrivateTemplate CONTENT = View::Admin::ActiveAgentComposite SNAPBACK_EVENT = :result + def initialize(agents, session, is_active_agent = true) + $stdout.puts "RootActiveAgentComposite.init is_active_agent #{is_active_agent}" + super(agents, session, is_active_agent) + end end class RootActiveAgent < View::Admin::ActiveAgent CONTENT = View::Admin::RootActiveAgentComposite diff --git a/src/view/admin/sequence.rb b/src/view/admin/sequence.rb index ceacd0f..456819a 100644 --- a/src/view/admin/sequence.rb +++ b/src/view/admin/sequence.rb @@ -31,6 +31,7 @@ class ActiveAgents < HtmlGrid::List COMPONENTS = { [0,0] => :substance, [1,0] => :dose, + [2,0] => :more_info, } DEFAULT_CLASS = HtmlGrid::Value EMPTY_LIST = true @@ -41,24 +42,38 @@ class ActiveAgents < HtmlGrid::List LEGACY_INTERFACE = false LABELS = false CSS_HEAD_MAP = { - [1,0] => 'right', + [1,0] => 'right ActiveAgents-Head', } CSS_MAP = { - [0,0] => 'list', - [1,0] => 'list right', + [0,0] => 'list ActiveAgents', + [1,0] => 'list right ActiveAgents', } + def initialize(model, session, container = nil, is_active_agent = true) + @is_active_agent = is_active_agent + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: initialize is_active_agent #{is_active_agent} model #{model.class} session #{session.class} container is #{container.class}" + is_active_agent ? components.store([0,0], :substance) : components.store([0,0], :auxilliary) + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: components #{components}" + super(model, session, container) + end + def th_substance + value = @is_active_agent ? @session.lookandfeel.lookup(:th_substances) : @session.lookandfeel.lookup(:th_auxilliary) + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: th_substance #{@is_active_agent} value #{value}" + value + end def compose_footer(offset) + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: compose_footer @is_active_agent #{@is_active_agent} offset #{offset}" + return nil if @is_active_agent _compose_footer offset end def _compose_footer(offset) comp = if act = @model.first act.parent(@session.app) - end + end input = galenic_form(comp) label = HtmlGrid::SimpleLabel.new(:galenic_form, input, @session, self) @grid.add [label, nil, input], *offset - @grid.add_style 'list', *offset - @grid.add_style 'list right', offset[0] + 1, offset[1] + @grid.add_style 'list ActiveAgents', *offset + @grid.add_style 'list right ActiveAgents', offset[0] + 1, offset[1] offset[1] += 1 offset end @@ -66,6 +81,8 @@ class ActiveAgents < HtmlGrid::List model.dose.to_s if model end def galenic_form(model) + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: galenic_form #{@is_active_agent}" + return nil if @is_active_agent element = HtmlGrid::Value.new(:galenic_form, model, @session, self) element.label = true if model && gf = model.galenic_form @@ -73,11 +90,23 @@ class ActiveAgents < HtmlGrid::List end element end + def auxilliary(model) + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: auxilliary #{model.substance}" + if model && sub = model.substance + sub.send(@session.language) + end + end def substance(model) if model && sub = model.substance sub.send(@session.language) end end + def more_info(model) + if model && info = model.more_info + $stdout.puts "View::Admin::ActiveAgents #{__LINE__}: more_info #{model.inspect} is #{info}" + info + end + end end class RootActiveAgents < ActiveAgents COMPONENTS = { @@ -173,12 +202,31 @@ class RootActiveAgents < ActiveAgents end end class CompositionList < HtmlGrid::DivList - COMPONENTS = { [0,0] => :composition } + COMPONENTS = { + [0,0] => :excipiens, + [1,0] => :composition, + } LABELS = false OFFSET_STEP = [1,0] OMIT_HEADER = true + def initialize(model, session, container = nil) + $stdout.puts "View::Admin::CompositionList #{__LINE__}: excipiens initialize model #{model.class} session #{session.class} container is #{container.class}" + super(model, session, container) + end + def excipiens(model) + excipiens = model.excipiens + $stdout.puts "View::Admin::CompositionList #{__LINE__}: sequence excipiens #{excipiens}" + if excipiens + span = HtmlGrid::Span.new(excipiens, @session, self) + span.css_class = 'italic excipiens' + span.value = 'dummy' + [span, excipiens] + else + 'no excipiens' + end + end def composition(model) - agents = ActiveAgents.new(model.active_agents, @session, self) + agents = ActiveAgents.new(model.active_agents.find_all{ |x| x.is_active_agent}, @session, self) if @model.size > 1 span = HtmlGrid::Span.new(model, @session, self) span.css_class = 'italic' diff --git a/src/view/drugs/package.rb b/src/view/drugs/package.rb index a50ab18..2b9e9bb 100644 --- a/src/view/drugs/package.rb +++ b/src/view/drugs/package.rb @@ -16,19 +16,49 @@ module ODDB module Drugs class CompositionList < HtmlGrid::DivList include PartSize - COMPONENTS = { [0,0] => :composition } + COMPONENTS = { + [0,0] => :composition, + [1,0] => :auxilliary, + [2,0] => :excipiens, + } LABELS = false - OFFSET_STEP = [1,0] + OFFSET_STEP = [1,0] # default is OFFSET_STEP = [0,1] OMIT_HEADER = true + def initialize(model, session, container = nil) + $stdout.puts "Drugs::CompositionList #{__LINE__}: with #{model.class} caller #{caller[0..10].join("\n")}" + $stdout.puts "Drugs::CompositionList #{__LINE__}: components #{components}" + super(model, session) + end + def excipiens(model) + $stdout.puts "Drugs::CompositionList #{__LINE__}: composition #{model.class}: oid #{model.oid}" + if (comp = model.composition) + div = HtmlGrid::Div.new(model, @session, self) + div.css_class = 'list CompositionList excipiens' + div.value = comp.excipiens.to_s + $stdout.puts "Drugs::CompositionList #{__LINE__}: comp.excipiens #{comp.excipiens} value #{div.value}" + [ div ] + end + end def composition(model) div = HtmlGrid::Div.new(model, @session, self) - div.css_class = 'galenic-form' + div.css_class = 'galenic-form CompositionList composition' + all_agents = model.active_agents + agents = all_agents.find_all{|x| x.is_active_agent} + $stdout.puts "Drugs::CompositionList #{__LINE__}: composition #{model.class}: Have #{all_agents.size} => #{all_agents.collect{ |x| [x.oid, x.is_active_agent]}}} agents. Displaying #{agents.size} => #{agents.collect{ |x| x.oid}}" size = part_size(model) if (comp = model.composition) && (label = comp.label) size = "#{label}) #{size}" end div.value = size - [ div, View::Admin::ActiveAgents.new(model.active_agents, @session, self)] + [ div, View::Admin::ActiveAgents.new(agents, @session, self, true)] + end + def auxilliary(model) + div = HtmlGrid::Div.new(model, @session, self) + div.css_class = 'galenic-form CompositionList auxilliary' + all_agents = model.active_agents + agents = all_agents.find_all{|x| x.is_active_agent == false} + $stdout.puts "Drugs::CompositionList #{__LINE__}: auxilliary: Have #{all_agents.size} => #{all_agents.collect{ |x| [x.oid, x.is_active_agent]}}} agents. Displaying #{agents.size} => #{agents.collect{ |x| x.oid}}" + [ div, View::Admin::ActiveAgents.new(agents, @session, self, false)] end end class Parts < View::Admin::Compositions diff --git a/test/test_view/admin/activeagent.rb b/test/test_view/admin/activeagent.rb index 4826bd4..faca814 100644 --- a/test/test_view/admin/activeagent.rb +++ b/test/test_view/admin/activeagent.rb @@ -106,7 +106,7 @@ class TestRootActiveAgentComposite nil ) parent = flexmock('parent', :name => 'name') - active_agent = flexmock('active_agent') + active_agent = flexmock('active_agent', :is_active_agent => false) package = flexmock('package', :swissmedic_source => {'swissmedic_source' => 'x'}) sequence = flexmock('sequence', :active_agents => [active_agent], diff --git a/test/test_view/admin/sequence.rb b/test/test_view/admin/sequence.rb index 79259f2..523f2e9 100644 --- a/test/test_view/admin/sequence.rb +++ b/test/test_view/admin/sequence.rb @@ -95,6 +95,7 @@ class TestRootActiveAgents nil) - flexmock(@model, :atc_class => atc_class) + flexmock(@model, :atc_class => atc_class) assert_kind_of(NilClass, @composite.atc_descr(@model, @session)) - skip("HtmlGrid::Text does not work, is the mocking wrong?") - assert_kind_of(HtmlGrid::Text, @composite.atc_descr(@model, @session)) + skip("HtmlGrid::Text does not work, is the mocking wrong?") {assert_kind_of(HtmlGrid::Text, @composite.atc_descr(@model, @session)) } end def test_atc_request flexmock(@model, :atc_request_time => Time.now - 60*60*24*3 - 100) @@ -504,10 +514,16 @@ class TestSequenceComposite 'divisable', @@ -651,8 +671,12 @@ class TestResellerSequenceComposite 'pointer') diff --git a/test/test_view/drugs/package.rb b/test/test_view/drugs/package.rb index 24743e8..e5f83f9 100644 --- a/test/test_view/drugs/package.rb +++ b/test/test_view/drugs/package.rb @@ -27,11 +27,26 @@ class TestCompositionList 'language') - composition = flexmock('composition', :label => 'label') substance = flexmock('substance', :language => 'language') galenic_form = flexmock('galenic_form', :language => 'language') parent = flexmock('parent', :galenic_form => galenic_form) - active_agent = flexmock('active_agent', + excipiens = flexmock('excipiens', + :more_info => 'more_info', + :oid => 'oid', + :is_active_agent => false, + :dose => 'dose', + :substance => substance, + :parent => parent + ) + composition = flexmock('composition', + :label => 'label', + :oid => 'oid', + :excipiens => excipiens, + ) + active_agent = flexmock('active_agent', + :more_info => 'more_info', + :oid => 'oid', + :is_active_agent => true, :substance => substance, :dose => 'dose', :parent => parent @@ -49,6 +64,7 @@ class TestCompositionList state ) @model = flexmock('model', + :oid => 'oid', :multi => 'multi', :count => 'count', :measure => 'measure', @@ -198,13 +214,29 @@ class TestODDBViewDrugsPackageComposite 'language') parent = flexmock('parent', :galenic_form => galenic_form) @active_agent = flexmock('active_agent', + :is_active_agent => true, + :oid => 'oid', + :more_info => 'more_info', :substance => substance, :dose => 'dose', :parent => parent ) @commercial_form = flexmock('commercial_form', :language => 'language') - composition = flexmock('composition', :label => 'label') - part = flexmock('part', + excipiens = flexmock('excipiens', + :more_info => 'more_info', + :oid => 'oid', + :is_active_agent => false, + :dose => 'dose', + :substance => substance, + :parent => parent + ) + composition = flexmock('composition', + :label => 'label', + :oid => 'oid', + :excipiens => excipiens, + ) + part = flexmock('part', + :oid => 'oid', :multi => 'multi', :count => 'count', :measure => 'measure', @@ -214,6 +246,7 @@ class TestODDBViewDrugsPackageComposite 'division') @model = flexmock('model', + :oid => 'oid', :name => 'name', :size => 'size', :narcotic? => nil, @@ -275,7 +308,7 @@ class TestODDBViewDrugsPackageComposite [@active_agent]) + composition = flexmock('composition', :active_agents => [@active_agent], :excipiens => 'excipiens') flexmock(@model, :compositions => [composition]) assert_kind_of(ODDB::View::Admin::Compositions, @composite.compositions(@model, @session)) end @@ -335,16 +368,28 @@ class TestPackage 'get_cookie_input', ) commercial_form = flexmock('commercial_form', :language => 'language') - composition = flexmock('composition', :label => 'label') substance = flexmock('substance', :language => 'language') galenic_form = flexmock('galenic_form', :language => 'language') parent = flexmock('parent', :galenic_form => galenic_form) + excipiens = flexmock('excipiens', + :more_info => 'more_info', + :oid => 'oid', + :is_active_agent => false, + :dose => 'dose', + :substance => substance, + :parent => parent + ) + composition = flexmock('composition', :label => 'label', :oid => 'oid', :excipiens => excipiens) active_agent = flexmock('active_agent', + :more_info => 'more_info', + :oid => 'oid', + :is_active_agent => true, :substance => substance, :dose => 'dose', :parent => parent ) part = flexmock('part', + :oid => 'oid', :multi => 'multi', :count => 'count', :measure => 'measure', -- 2.1.4