Class: ODDB::SwissmedicPluginTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
test/test_plugin/swissmedic.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'test/test_plugin/swissmedic.rb', line 16

def setup
  @app = flexmock 'app'
  @archive = File.expand_path('../var', File.dirname(__FILE__))
  @latest = File.join @archive, 'xls', 'Packungen-latest.xls'
  @target = File.join @archive, 'xls',
                      @@today.strftime('Packungen-%Y.%m.%d.xls')
  @plugin = SwissmedicPlugin.new @app, @archive
  @data = File.expand_path '../data/xls/Packungen.xls',
                           File.dirname(__FILE__)
  @older = File.expand_path '../data/xls/Packungen.older.xls',
                            File.dirname(__FILE__)
  @initial = File.expand_path '../data/xls/Packungen.initial.xls',
                              File.dirname(__FILE__)
  @workbook = Spreadsheet.open(@data)
end

- (Object) setup_index_page



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'test/test_plugin/swissmedic.rb', line 36

def setup_index_page
  page = flexmock 'page'
  agent = flexmock 'agent'
  index = flexmock 'index'
  link1 = OpenStruct.new :attributes => {'title' => 'Packungen'},
                         :href => 'url'
  link2 = OpenStruct.new :attributes => {'title' => 'Something'},
                         :href => 'other'
  index.should_receive(:links).and_return [link1, link2]
  url = "http://www.swissmedic.ch/daten/00080/00251/index.html?lang=de"
  agent.should_receive(:get).with(url).and_return(index)
  agent.should_receive(:get).with('url').and_return(page)
  [agent, page]
end

- (Object) teardown



31
32
33
34
35
# File 'test/test_plugin/swissmedic.rb', line 31

def teardown
  File.delete(@latest) if File.exist?(@latest)
  File.delete(@target) if File.exist?(@target)
  super
end

- (Object) test_delete__packages



917
918
919
920
921
922
# File 'test/test_plugin/swissmedic.rb', line 917

def test_delete__packages
  ptr = Persistence::Pointer.new([:registration, '12345'], [:sequence, '01'],
                                 [:package, '234'])
  @app.should_receive(:delete).with(ptr).times(1).and_return { assert true }
  @plugin.delete([['12345', '01', '234']])
end

- (Object) test_delete__registration



928
929
930
931
932
# File 'test/test_plugin/swissmedic.rb', line 928

def test_delete__registration
  ptr = Persistence::Pointer.new([:registration, '12345'])
  @app.should_receive(:delete).with(ptr).times(1).and_return { assert true }
  @plugin.delete([['12345']])
end

- (Object) test_delete__sequences



923
924
925
926
927
# File 'test/test_plugin/swissmedic.rb', line 923

def test_delete__sequences
  ptr = Persistence::Pointer.new([:registration, '12345'], [:sequence, '01'])
  @app.should_receive(:delete).with(ptr).times(1).and_return { assert true }
  @plugin.delete([['12345', '01']])
end

- (Object) test_diff



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'test/test_plugin/swissmedic.rb', line 852

def test_diff
  pac = flexmock 'package'
  pac.should_receive(:data_origin).and_return :swissmedic
  reg = flexmock 'registration'
  reg.should_receive(:package).and_return pac
  @app.should_receive(:registration).and_return reg
  result = @plugin.diff(@data, @older)
  assert_equal 3, result.news.size
  assert_equal 'Osanit, homöopathische Kügelchen',
               result.news.first.at(2).to_s
  assert_equal 7, result.updates.size
  assert_equal 'Weleda Schnupfencrème, anthroposophisches Heilmittel',
               result.updates.first.at(2).to_s
  assert_equal 6, result.changes.size
  expected = {
    "09232" => [:name_base],
    "10368" => [:delete],
    "10999" => [:new],
    "25144" => [:sequence, :replaced_package],
    "57678" => [:company, :index_therapeuticus, :expiry_date, :ikscat, :atc_class ],
    "57699" => [:new],
  }
  assert_equal(expected, result.changes)
  assert_equal 2, result.package_deletions.size
  assert_equal 4, result.package_deletions.first.size
  iksnrs = result.package_deletions.collect { |row| row.at(0) }.sort
  ikscds = result.package_deletions.collect { |row| row.at(2) }.sort
  assert_equal ['10368', '25144'], iksnrs
  assert_equal ['013', '049'], ikscds
  assert_equal 1, result.sequence_deletions.size
  assert_equal ['10368', '01'], result.sequence_deletions.at(0)
  assert_equal 1, result.registration_deletions.size
  assert_equal ['10368'], result.registration_deletions.at(0)
  assert_equal 1, result.replacements.size
  assert_equal '013', result.replacements.values.first
end

- (Object) test_diff__initial



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'test/test_plugin/swissmedic.rb', line 888

def test_diff__initial
  File.delete @initial if File.exist? @initial
  part = flexmock 'part'
  pac = flexmock 'package'
  pac.should_receive(:parts).and_return [ part ]
  seq = flexmock 'sequence'
  seq.should_receive(:packages).and_return({ '001' => pac })
  seq.should_receive(:name_base).and_return 'delete me'
  reg = flexmock 'registration'
  reg.should_receive(:sequences).and_return({ '01' => seq })
  reg.should_receive(:company_name).and_return('ywesee.com')
  reg.should_receive(:inactive?).and_return false
  reg.should_receive(:vaccine).and_return nil
  reg.should_ignore_missing
  @app.should_receive(:registrations).and_return({ '11111' => reg })
  result = @plugin.diff(@data, @initial)
  assert_equal 16, result.news.size
  assert_equal 'Aspirin, Tabletten',
               result.news.first.at(2).to_s
  assert_equal 0, result.updates.size
  assert_equal 12, result.changes.size
  deletion = result.changes.delete('11111')
  assert_equal [:delete], deletion
  assert result.changes.all? { |key, flags| flags == [:new] }
  assert_equal 1, result.package_deletions.size
  assert_equal [['11111', '01', '001', 0]], result.package_deletions
  assert_equal 1, result.sequence_deletions.size
  assert_equal 1, result.registration_deletions.size
end

- (Object) test_get_latest_file__identical



58
59
60
61
62
63
64
65
66
67
# File 'test/test_plugin/swissmedic.rb', line 58

def test_get_latest_file__identical
  assert !File.exist?(@latest), "A previous test did not clean up #@latest"
  assert !File.exist?(@target), "A previous test did not clean up #@target"
  File.open(@latest, 'w') { |fh| fh.puts 'Content of the xml' }
  agent, page = setup_index_page
  page.should_receive(:body).and_return('Content of the xml')
  agent.should_receive(:get).and_return(page)
  @plugin.get_latest_file(agent)
  assert !File.exist?(@target), "#@target should not have been saved"
end

- (Object) test_get_latest_file__new



50
51
52
53
54
55
56
57
# File 'test/test_plugin/swissmedic.rb', line 50

def test_get_latest_file__new
  assert !File.exist?(@latest), "A previous test did not clean up #@latest"
  assert !File.exist?(@target), "A previous test did not clean up #@target"
  agent, page = setup_index_page
  page.should_receive(:body).and_return('Content of the xls')
  @plugin.get_latest_file(agent)
  assert File.exist?(@target), "#@target was not saved"
end

- (Object) test_get_latest_file__replace



68
69
70
71
72
73
74
75
76
77
# File 'test/test_plugin/swissmedic.rb', line 68

def test_get_latest_file__replace
  assert !File.exist?(@latest), "A previous test did not clean up #@latest"
  assert !File.exist?(@target), "A previous test did not clean up #@target"
  File.open(@latest, 'w') { |fh| fh.puts 'Content of a previous xml' }
  agent, page = setup_index_page
  page.should_receive(:body).and_return('Content of the xml')
  agent.should_receive(:get).and_return(page)
  @plugin.get_latest_file(agent)
  assert File.exist?(@target), "#@target was not saved"
end

- (Object) test_to_s



933
934
935
936
937
938
939
940
941
942
943
944
945
946
# File 'test/test_plugin/swissmedic.rb', line 933

def test_to_s
  pac = flexmock 'package'
  pac.should_receive(:data_origin).and_return :swissmedic
  reg = flexmock 'registration'
  reg.should_receive(:package).and_return pac
  @app.should_receive(:registration).and_return reg
  assert_nothing_raised {
    @plugin.to_s
  }
  result = @plugin.diff(@data, @older)
  assert_equal "+ 10999: Osanit, hom\303\266opathische K\303\274gelchen\n+ 57699: Pyrazinamide Labatec, comprim\303\251s\n- 10368: Alcacyl, Tabletten\n> 09232: Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel; Namens\303\244nderung (Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel)\n> 25144: Panadol, Filmtabletten; Packungs-Nummer (013 -> 031)\n> 57678: Amlodipin-B Adico 5, Tabletten; Zulassungsinhaber (Adico Pharma AG), Index Therapeuticus (02.06.1.), Ablaufdatum der Zulassung (10.05.2012), Abgabekategorie (B), ATC-Code (C08CA01)\n".strip, @plugin.to_s
  assert_equal "- 10368: Alcacyl, Tabletten\n> 57678: Amlodipin-B Adico 5, Tabletten; Zulassungsinhaber (Adico Pharma AG), Index Therapeuticus (02.06.1.), Ablaufdatum der Zulassung (10.05.2012), Abgabekategorie (B), ATC-Code (C08CA01)\n+ 10999: Osanit, hom\303\266opathische K\303\274gelchen\n> 25144: Panadol, Filmtabletten; Packungs-Nummer (013 -> 031)\n+ 57699: Pyrazinamide Labatec, comprim\303\251s\n> 09232: Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel; Namens\303\244nderung (Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel)\n".strip, @plugin.to_s(:name)
  assert_equal "> 09232: Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel; Namens\303\244nderung (Weleda Schnupfencr\303\250me, anthroposophisches Heilmittel)\n- 10368: Alcacyl, Tabletten\n+ 10999: Osanit, hom\303\266opathische K\303\274gelchen\n> 25144: Panadol, Filmtabletten; Packungs-Nummer (013 -> 031)\n> 57678: Amlodipin-B Adico 5, Tabletten; Zulassungsinhaber (Adico Pharma AG), Index Therapeuticus (02.06.1.), Ablaufdatum der Zulassung (10.05.2012), Abgabekategorie (B), ATC-Code (C08CA01)\n+ 57699: Pyrazinamide Labatec, comprim\303\251s\n".strip, @plugin.to_s(:registration)
end

- (Object) test_update_company__create



78
79
80
81
82
83
84
85
86
87
# File 'test/test_plugin/swissmedic.rb', line 78

def test_update_company__create
  row = @workbook.worksheet(0).row(3)
  name = 'Bayer (Schweiz) AG'
  @app.should_receive(:company_by_name).with(name, 0.8)
  ptr = Persistence::Pointer.new(:company)
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with(ptr.creator, args)\
    .times(1).and_return { assert true }
  @plugin.update_company(row)
end

- (Object) test_update_composition__chemical_form



703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'test/test_plugin/swissmedic.rb', line 703

def test_update_composition__chemical_form
  row = @workbook.worksheet(0).row(9)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-pointer'
  comp.should_receive(:active_agents).and_return []
  args = {
    :label  => nil,
    :source => "procainum 10 mg ut procaini hydrochloridum, phenazonum 50 mg, Antiox.: E 320, glycerolum q.s. ad solutionem pro 1 g."
  }
  @app.should_receive(:update).with('composition-pointer', args, :swissmedic)\
    .times(2).and_return { assert true; comp }
  seq.should_receive(:compositions).and_return [comp]
  substance1 = flexmock 'substance1'
  substance1.should_receive(:pointer).and_return 'substance-ptr'
  @app.should_receive(:substance).with('Procainum')\
    .and_return substance1
  equivalence = flexmock 'equivalence'
  equivalence.should_receive(:pointer).and_return 'equi-ptr'
  @app.should_receive(:substance).with('Procaini Hydrochloridum')\
    .and_return equivalence
  substance2 = flexmock 'substance2'
  @app.should_receive(:substance).with('Phenazonum')\
    .and_return substance2
  aptr1 = ptr + [:active_agent, 'Procainum']
  agent1 = flexmock 'active-agent1'
  agent1.should_receive(:pointer).and_return aptr1
  comp.should_receive(:active_agent).with('Procainum')\
    .and_return agent1
  aptr2 = ptr + [:active_agent, 'Phenazonum']
  agent2 = flexmock 'active-agent1'
  agent2.should_receive(:pointer).and_return aptr2
  comp.should_receive(:active_agent).with('Phenazonum')\
    .and_return agent2
  args =  {
    :substance          => 'Procainum',
    :dose               => %w{10 mg/g},
    :chemical_substance => 'Procaini Hydrochloridum',
    :chemical_dose      => nil,
  }
  @app.should_receive(:update).with(aptr1, args, :swissmedic)\
    .times(1).and_return { assert true }
  args =  {
    :substance          => 'Phenazonum',
    :dose               => %w'50 mg/g',
  }
  @app.should_receive(:update).with(aptr2, args, :swissmedic)\
    .times(1).and_return { assert true }
  args =  {
    :effective_form => 'substance-ptr',
  }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__create



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'test/test_plugin/swissmedic.rb', line 518

def test_update_composition__create
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  seq.should_receive(:active_agents).and_return []
  seq.should_receive(:compositions).and_return []
  @app.should_receive(:substance).with('Acidum Acetylsalicylicum')
  sptr = Persistence::Pointer.new([:substance]).creator
  args = { :lt => 'Acidum Acetylsalicylicum' }
  @app.should_receive(:update).with(sptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  comp = flexmock 'composition'
  comp.should_receive(:active_agent).with('Acidum Acetylsalicylicum')
  comp.should_receive(:active_agents).and_return []
  cptr = ptr + [:composition, 'id']
  comp.should_receive(:pointer).and_return(cptr)
  @app.should_receive(:create).with(ptr + :composition).and_return comp
  args = {
    :label  => nil,
    :source => "acidum acetylsalicylicum 500 mg, excipiens pro compresso."
  }
  @app.should_receive(:update).with(cptr, args, :swissmedic)\
    .times(1).and_return { assert true; comp }
  aptr = cptr + [:active_agent, 'Acidum Acetylsalicylicum']
  args =  {
    :substance => 'Acidum Acetylsalicylicum',
    :dose      => ["500", 'mg'],
  }
  @app.should_receive(:update).with(aptr.creator, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__delete



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'test/test_plugin/swissmedic.rb', line 758

def test_update_composition__delete
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-pointer'
  args = {
    :label  => nil,
    :source => "acidum acetylsalicylicum 500 mg, excipiens pro compresso."
  }
  @app.should_receive(:update).with('composition-pointer', args, :swissmedic)\
    .times(1).and_return { assert true; comp }
  seq.should_receive(:compositions).and_return [comp]
  substance = flexmock 'substance'
  substance.should_receive(:same_as?).with('Acidum Acetylsalicylicum').and_return false
  @app.should_receive(:substance).with('Acidum Acetylsalicylicum')\
    .and_return substance
  aptr = ptr + [:active_agent, 'Acidum Acetylsalicylicum']
  agent = flexmock 'active-agent'
  agent.should_receive(:pointer).and_return aptr
  agent.should_receive(:substance).and_return substance
  comp.should_receive(:active_agents).and_return [agent]
  comp.should_receive(:active_agent).with('Acidum Acetylsalicylicum')\
    .and_return agent
  args =  {
    :substance => 'Acidum Acetylsalicylicum',
    :dose      => ['500', 'mg'],
  }
  @app.should_receive(:update).with(aptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @app.should_receive(:delete).with(aptr)\
    .times(1).and_return { assert true }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__focus_on_doses



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'test/test_plugin/swissmedic.rb', line 551

def test_update_composition__focus_on_doses
  row = @workbook.worksheet(0).row(6)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  seq.should_receive(:active_agents).and_return []
  seq.should_receive(:compositions).and_return []
  sub = flexmock 'substance'
  sub.should_receive(:pointer).and_return 'substance-pointer'
  @app.should_receive(:substance).and_return sub
  act = flexmock 'active-agent'
  act.should_receive(:pointer).and_return 'active-agent-pointer'
  comp = flexmock 'composition'
  comp.should_receive(:active_agent).and_return act
  comp.should_receive(:active_agents).and_return []
  cptr = ptr + [:composition, 'id']
  comp.should_receive(:pointer).and_return(cptr)
  @app.should_receive(:create).with(ptr + :composition).and_return comp
  args = {
    :label  => nil,
    :source => "extractum ethanolicum liquidum ex berberidis fructus recens 10 mg et pruni spinosae fructus recens 10 mg et echinaceae purpureae planta tota recens 12 mg et bryoniae radix recens 0.1 mg, esculosidum 1.1 mg, dextrocamphora 0.12 mg, eucalypti aetheroleum 3.88 mg, menthae piperitae aetheroleum 3.88 mg, thymi aetheroleum 0.12 mg, adeps lanae (Schaf: Fell/Haare/Wolle), excipiens ad unguentum pro 1 g."
  }
  @app.should_receive(:update).with(cptr, args, :swissmedic)\
    .times(9).and_return { assert true; comp }
  args =  [
    { :dose => ["10", 'mg/g'], :substance => 'Berberidis Fructus Recens' },
    { :dose => ["10", "mg/g"],
      :substance => "Pruni Spinosae Fructus Recens" },
    { :dose => ["12", "mg/g"],
      :substance => "Echinaceae Purpureae Planta Tota Recens" },
    { :dose => ["0.1", "mg/g"], :substance => "Bryoniae Radix Recens" },
    { :dose => ["1.1", "mg/g"], :substance=>"Esculosidum" },
    { :dose => ["0.12", "mg/g"], :substance => "Dextrocamphora" },
    { :dose => ["3.88", "mg/g"], :substance => "Eucalypti Aetheroleum" },
    { :dose => ["3.88", "mg/g"],
      :substance => "Menthae Piperitae Aetheroleum" },
    { :dose=>["0.12", "mg/g"], :substance => "Thymi Aetheroleum" },
  ]
  @app.should_receive(:update)\
    .with('active-agent-pointer', Hash, :swissmedic)\
    .times(9).and_return { |ptr, data, key|
      assert_equal args.shift, data
  }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__focus_on_doses_percent



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'test/test_plugin/swissmedic.rb', line 596

def test_update_composition__focus_on_doses_percent
  row = @workbook.worksheet(0).row(8)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  seq.should_receive(:active_agents).and_return []
  seq.should_receive(:compositions).and_return []
  sub = flexmock 'substance'
  sub.should_receive(:pointer).and_return 'substance-pointer'
  @app.should_receive(:substance).and_return sub
  act = flexmock 'active-agent'
  act.should_receive(:pointer).and_return 'active-agent-pointer'
  comp = flexmock 'composition'
  comp.should_receive(:active_agent).and_return act
  comp.should_receive(:active_agents).and_return []
  cptr = ptr + [:composition, 'id']
  comp.should_receive(:pointer).and_return(cptr)
  @app.should_receive(:create).with(ptr + :composition).and_return comp
  args = {
    :label  => nil,
    :source => "calcii carbonas hahnemanni C7 5 %, chamomilla recutita D5 22.5 %, magnesii phosphas C5 50 %, passiflora incarnata D5 22.5 %, xylitolum, excipiens ad globulos."
  }
  @app.should_receive(:update).with(cptr, args, :swissmedic)\
    .times(4).and_return { assert true; comp }
  aptr = cptr + [:active_agent, 'Acidum Acetylsalicylicum']
  args =  [
    { :dose => ["5", '%'], :substance => 'Calcii Carbonas Hahnemanni C7' },
    { :dose => ["22.5", '%'], :substance => 'Chamomilla Recutita D5' },
    { :dose => ["50", '%'], :substance => 'Magnesii Phosphas C5' },
    { :dose => ["22.5", '%'], :substance => 'Passiflora Incarnata D5' },
  ]
  @app.should_receive(:update)\
    .with('active-agent-pointer', Hash, :swissmedic)\
    .times(4).and_return { |ptr, data, key|
      assert_equal args.shift, data
  }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__focus_on_doses_qty_in_scale



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'test/test_plugin/swissmedic.rb', line 634

def test_update_composition__focus_on_doses_qty_in_scale
  row = @workbook.worksheet(0).row(19)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  seq.should_receive(:active_agents).and_return []
  seq.should_receive(:compositions).and_return []
  sub = flexmock 'substance'
  sub.should_receive(:pointer).and_return 'substance-pointer'
  @app.should_receive(:substance).and_return sub
  act = flexmock 'active-agent'
  act.should_receive(:pointer).and_return 'active-agent-pointer'
  comp = flexmock 'composition'
  comp.should_receive(:active_agent).and_return act
  comp.should_receive(:active_agents).and_return []
  cptr = ptr + [:composition, 'id']
  comp.should_receive(:pointer).and_return(cptr)
  @app.should_receive(:create).with(ptr + :composition).and_return comp
  args = {
    :label  => nil,
    :source => "fluticasoni-17 propionas 100 \302\265g, lactosum monohydricum q.s. ad pulverem pro 25 mg.",
  }
  @app.should_receive(:update).with(cptr, args, :swissmedic)\
    .times(1).and_return { assert true; comp }
  aptr = cptr + [:active_agent, 'Acidum Acetylsalicylicum']
  args =  [
    { :dose => ["100", 'µg/25 mg'],
      :substance => 'Fluticasoni-17 Propionas' },
  ]
  @app.should_receive(:update)\
    .with('active-agent-pointer', Hash, :swissmedic)\
    .times(1).and_return { |ptr, data, key|
      assert_equal args.shift, data
  }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_composition__update



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'test/test_plugin/swissmedic.rb', line 670

def test_update_composition__update
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  comp = flexmock 'composition'
  seq.should_receive(:compositions).and_return [comp]
  substance = flexmock 'substance'
  substance.should_receive(:same_as?).with('Acidum Acetylsalicylicum').and_return true
  @app.should_receive(:substance).with('Acidum Acetylsalicylicum')\
    .and_return substance
  aptr = ptr + [:active_agent, 'Acidum Acetylsalicylicum']
  agent = flexmock 'active-agent'
  agent.should_receive(:pointer).and_return aptr
  agent.should_receive(:substance).and_return substance
  comp.should_receive(:pointer).and_return 'composition-pointer'
  comp.should_receive(:active_agents).and_return [agent]
  comp.should_receive(:active_agent).with('Acidum Acetylsalicylicum')\
    .and_return agent
  args = {
    :label  => nil,
    :source => "acidum acetylsalicylicum 500 mg, excipiens pro compresso."
  }
  @app.should_receive(:update).with('composition-pointer', args, :swissmedic)\
    .times(1).and_return { assert true; comp }
  args =  {
    :substance => 'Acidum Acetylsalicylicum',
    :dose      => ['500', 'mg'],
  }
  @app.should_receive(:update).with(aptr, args, :swissmedic)\
    .times(1).and_return { assert true; agent }
  @plugin.update_compositions(seq, row)
end

- (Object) test_update_galenic_form__create__composition



834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'test/test_plugin/swissmedic.rb', line 834

def test_update_galenic_form__create__composition
  row = @workbook.worksheet(0).row(6)
  seq = flexmock 'sequence'
  seq.should_receive(:name_descr)
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-ptr'
  comp.should_receive(:galenic_form).and_return nil
  comp.should_receive(:source).and_return 'extractum ethanolicum liquidum ex berberidis fructus recens 10 mg et pruni spinosae fructus recens 10 mg et echinaceae purpureae planta tota recens 12 mg et bryoniae radix recens 0.1 mg, esculosidum 1.1 mg, dextrocamphora 0.12 mg, eucalypti aetheroleum 3.88 mg, menthae piperitae aetheroleum 3.88 mg, thymi aetheroleum 0.12 mg, adeps lanae (Schaf: Fell/Haare/Wolle), excipiens ad unguentum pro 1 g.'
  @app.should_receive(:galenic_form).with('unguentum')
  args = { :lt => 'unguentum' }
  ptr = Persistence::Pointer.new([:galenic_group, 1], [:galenic_form]).creator
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  args = { :galenic_form => 'unguentum' }
  @app.should_receive(:update).with('composition-ptr', args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_galenic_form(seq, comp, row)
end

- (Object) test_update_galenic_form__create__descr



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'test/test_plugin/swissmedic.rb', line 816

def test_update_galenic_form__create__descr
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  seq.should_receive(:name_descr).and_return 'Tabletten'
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-ptr'
  comp.should_receive(:galenic_form).and_return nil
  @app.should_receive(:galenic_form).with('Tabletten')
  @app.should_receive(:galenic_form).with('compresso')
  args = { :de => 'Tabletten' }
  ptr = Persistence::Pointer.new([:galenic_group, 1], [:galenic_form]).creator
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  args = { :galenic_form => 'Tabletten' }
  @app.should_receive(:update).with('composition-ptr', args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_galenic_form(seq, comp, row)
end

- (Object) test_update_galenic_form__dont_update__composition



804
805
806
807
808
809
810
811
812
813
814
815
# File 'test/test_plugin/swissmedic.rb', line 804

def test_update_galenic_form__dont_update__composition
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  seq.should_receive(:name_descr)
  seq.should_receive(:pointer).and_return 'sequence-ptr'
  @app.should_receive(:galenic_form).with('Tabletten')
  comp = flexmock 'composition'
  galform = flexmock 'galenic-form'
  comp.should_receive(:galenic_form).and_return galform
  @plugin.update_galenic_form(seq, comp, row)
  assert true
end

- (Object) test_update_galenic_form__dont_update__descr



793
794
795
796
797
798
799
800
801
802
803
# File 'test/test_plugin/swissmedic.rb', line 793

def test_update_galenic_form__dont_update__descr
  row = @workbook.worksheet(0).row(3)
  seq = flexmock 'sequence'
  seq.should_receive(:name_descr).and_return 'Tabletten'
  seq.should_receive(:pointer).and_return 'sequence-ptr'
  comp = flexmock 'composition'
  galform = flexmock 'galform'
  comp.should_receive(:galenic_form).and_return galform
  @plugin.update_galenic_form(seq, comp, row)
  assert true
end

- (Object) test_update_package__create



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'test/test_plugin/swissmedic.rb', line 316

def test_update_package__create
  row = @workbook.worksheet(0).row(3)
  reg = flexmock 'registration'
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  reg.should_receive(:package).with('011')
  seq.should_receive(:name_base).and_return 'existing sequence'
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-pointer'
  seq.should_receive(:compositions).and_return [ comp ]
  pptr = Persistence::Pointer.new([:registration, '08537'],
                                  [:sequence, '01'], [:package, '011'])
  comform = flexmock 'commercial form'
  comform.should_receive(:pointer).and_return 'comform-pointer'
  @app.should_receive(:commercial_form_by_name).with('Tablette(n)')\
    .and_return comform
  args = {
    :ikscat            => "D",
    :refdata_override  => true,
    :swissmedic_source => {
      :atc_class       => "N02BA01",
      :composition     => "acidum acetylsalicylicum 500 mg, excipiens pro compresso.",
      :company         => "Bayer (Schweiz) AG",
      :name_base       => "Aspirin, Tabletten",
      :iksnr           => "08537",
      :import_date     => @@today,
      :ikscat          => "D",
      :expiry_date     => Date.new(2012,5,9),
      :index_therapeuticus => "01.01.1.",
      :seqnr           => "01",
      :ikscd           => "011",
      :production_science => "Synthetika human",
      :unit            => "Tablette(n)",
      :registration_date => Date.new(1936,6,30),
      :sequence_date   => Date.new(1936,6,30),
      :size            => "20",
      :substances      => "acidum acetylsalicylicum",
      :indication_sequence => nil,
      :indication_registration => 'Analgetikum, Antipyretikum',
    }
  }
  pac = flexmock 'package'
  pac.should_receive(:pointer).and_return pptr
  @app.should_receive(:update).with(pptr.creator, args, :swissmedic)\
    .times(1).and_return {
    assert true
    pac
  }
  pac.should_receive(:parts).and_return []
  ptptr = pptr + :part
  part = flexmock 'part'
  part.should_receive(:pointer).and_return('part-pointer')
  part.should_receive(:composition)
  part.should_ignore_missing
  @app.should_receive(:create).times(1).with(ptptr).and_return part
  args = {
    :commercial_form   => 'comform-pointer',
    :composition       => 'composition-pointer',
    :size              => "20 Tablette(n)",
  }
  @app.should_receive(:update).with('part-pointer', args, :swissmedic)\
    .times(1).and_return {
    assert true
    part
  }
  @plugin.update_package reg, seq, row
end

- (Object) test_update_package__create__replacement



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'test/test_plugin/swissmedic.rb', line 384

def test_update_package__create__replacement
  row = @workbook.worksheet(0).row(3)
  reg = flexmock 'registration'
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  seq.should_receive(:name_base).and_return 'existing sequence'
  comp = flexmock 'composition'
  comp.should_receive(:pointer).and_return 'composition-pointer'
  seq.should_receive(:compositions).and_return [ comp ]
  pac = flexmock 'package'
  pac.should_receive(:pharmacode).and_return '1234567'
  pac.should_receive(:ancestors).and_return nil
  pac.should_ignore_missing
  reg.should_receive(:package).with('007').and_return pac
  reg.should_receive(:package).with('011')
  pptr = Persistence::Pointer.new([:registration, '08537'],
                                  [:sequence, '01'], [:package, '011'])
  comform = flexmock 'commercial form'
  comform.should_receive(:pointer).and_return 'comform-pointer'
  @app.should_receive(:commercial_form_by_name).with('Tablette(n)')\
    .and_return comform
  args = {
    :ikscat          => "D",
    :refdata_override=> true,
    :pharmacode      => '1234567',
    :ancestors       => ['007'],
    :swissmedic_source => {
      :atc_class       => "N02BA01",
      :composition     => "acidum acetylsalicylicum 500 mg, excipiens pro compresso.",
      :company         => "Bayer (Schweiz) AG",
      :name_base       => "Aspirin, Tabletten",
      :iksnr           => "08537",
      :import_date     => @@today,
      :ikscat          => "D",
      :expiry_date     => Date.new(2012,5,9),
      :index_therapeuticus => "01.01.1.",
      :seqnr           => "01",
      :ikscd           => "011",
      :production_science => "Synthetika human",
      :unit            => "Tablette(n)",
      :registration_date => Date.new(1936,6,30),
      :sequence_date   => Date.new(1936,6,30),
      :size            => "20",
      :substances      => "acidum acetylsalicylicum",
      :indication_sequence => nil,
      :indication_registration => 'Analgetikum, Antipyretikum',
    }
  }
  @app.should_receive(:update).with(pptr.creator, args, :swissmedic)\
    .times(1).and_return {
    assert true
    pac
  }
  pac.should_receive(:parts).and_return []
  pac.should_receive(:pointer).and_return pptr
  ptptr = pptr + :part
  part = flexmock 'part'
  part.should_receive(:pointer).and_return('part-pointer')
  part.should_receive(:composition)
  part.should_ignore_missing
  @app.should_receive(:create).times(1).with(ptptr).and_return part
  args = {
    :commercial_form   => 'comform-pointer',
    :composition       => 'composition-pointer',
    :size              => "20 Tablette(n)",
  }
  @app.should_receive(:update).with('part-pointer', args, :swissmedic)\
    .times(1).and_return {
    assert true
    part
  }
  @plugin.update_package reg, seq, row, {row => '007'}
end

- (Object) test_update_package__update



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'test/test_plugin/swissmedic.rb', line 458

def test_update_package__update
  row = @workbook.worksheet(0).row(3)
  reg = flexmock 'registration'
  seq = flexmock 'sequence'
  ptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  seq.should_receive(:pointer).and_return ptr
  pac = flexmock 'package'
  reg.should_receive(:package).with('011').and_return pac
  seq.should_receive(:name_base).and_return 'existing sequence'
  pptr = Persistence::Pointer.new([:registration, '08537'],
                                  [:sequence, '01'], [:package, '011'])
  pac.should_receive(:pointer).and_return pptr
  comform = flexmock 'commercial form'
  comform.should_receive(:pointer).and_return 'comform-pointer'
  @app.should_receive(:commercial_form_by_name).with('Tablette(n)')\
    .and_return comform
  args = {
    :ikscat          => "D",
    :swissmedic_source => {
      :atc_class       => "N02BA01",
      :composition     => "acidum acetylsalicylicum 500 mg, excipiens pro compresso.",
      :company         => "Bayer (Schweiz) AG",
      :name_base       => "Aspirin, Tabletten",
      :iksnr           => "08537",
      :import_date     => @@today,
      :ikscat          => "D",
      :expiry_date     => Date.new(2012,5,9),
      :index_therapeuticus => "01.01.1.",
      :seqnr           => "01",
      :ikscd           => "011",
      :production_science => "Synthetika human",
      :unit            => "Tablette(n)",
      :registration_date => Date.new(1936,6,30),
      :sequence_date   => Date.new(1936,6,30),
      :size            => "20",
      :substances      => "acidum acetylsalicylicum",
      :indication_sequence => nil,
      :indication_registration => 'Analgetikum, Antipyretikum',
    }
  }
  @app.should_receive(:update).with(pptr, args, :swissmedic)\
    .times(1).and_return {
    assert true
    pac
  }
  part = flexmock 'part'
  part.should_receive(:composition).and_return 'some composition'
  part.should_receive(:pointer).and_return 'part-pointer'
  pac.should_receive(:parts).and_return [part]
  args = {
    :commercial_form   => 'comform-pointer',
    :size              => "20 Tablette(n)",
  }
  @app.should_receive(:update).with('part-pointer', args, :swissmedic)\
    .times(1).and_return {
    assert true
    pac
  }
  @plugin.update_package reg, seq, row
end

- (Object) test_update_registration__anthropo



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'test/test_plugin/swissmedic.rb', line 192

def test_update_registration__anthropo
  row = @workbook.worksheet(0).row(6)
  indication = flexmock 'indication'
  indication.should_receive(:pointer).and_return 'indication-pointer'
  @app.should_receive(:indication_by_text).with("Zur Linderung von Schnupfen")\
    .and_return indication
  company = flexmock 'company'
  name = 'Weleda AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  registration = flexmock 'registration'
  @app.should_receive(:registration).with('09232').and_return registration
  ptr = Persistence::Pointer.new([:registration, '09232'])
  registration.should_receive(:pointer).and_return ptr
  args = {
    :ith_swissmedic      => '20.02.0.',
    :production_science  => 'Anthroposophika',
    :registration_date   => Date.new(1937,9,21),
    :expiration_date     => Date.new(2011,11,1),
    :inactive_date       => nil,
    :company             => 'company-pointer',
    :complementary_type  => 'anthroposophy',
    :indication          => 'indication-pointer',
    :renewal_flag        => false,
    :export_flag         => nil,
  }
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2008,3,19))
end

- (Object) test_update_registration__create



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'test/test_plugin/swissmedic.rb', line 88

def test_update_registration__create
  row = @workbook.worksheet(0).row(3)
  company = flexmock 'company'
  @app.should_receive(:indication_by_text).and_return nil
  ptr = Persistence::Pointer.new(:indication)
  args = {:de=>"Analgetikum, Antipyretikum"}
  @app.should_receive(:update).with(ptr.creator, args, :swissmedic)\
    .times(1).and_return { assert true }
  name = 'Bayer (Schweiz) AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  @app.should_receive(:registration).with('08537')
  ptr = Persistence::Pointer.new([:registration, '08537'])
  args = {
    :ith_swissmedic      => '01.01.1.',
    :production_science  => 'Synthetika human',
    :registration_date   => Date.new(1936,6,30),
    :expiration_date     => Date.new(2012,5,9),
    :inactive_date       => nil,
    :export_flag         => nil,
    :company             => 'company-pointer',
    :renewal_flag        => false,
  }
  @app.should_receive(:update).with(ptr.creator, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2008,3,19))
end

- (Object) test_update_registration__homoeo



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'test/test_plugin/swissmedic.rb', line 226

def test_update_registration__homoeo
  row = @workbook.worksheet(0).row(8)
  indication = flexmock 'indication'
  indication.should_receive(:pointer).and_return 'indication-pointer'
  @app.should_receive(:indication_by_text).with("Bei Zahnungsbeschwerden")\
    .and_return indication
  company = flexmock 'company'
  name = 'Iromedica AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  registration = flexmock 'registration'
  @app.should_receive(:registration).with('10999').and_return registration
  ptr = Persistence::Pointer.new([:registration, '10999'])
  registration.should_receive(:pointer).and_return ptr
  args = {
    :ith_swissmedic      => '20.01.0.',
    :production_science  => 'Homöopathika',
    :registration_date   => Date.new(1935,9,5),
    :expiration_date     => Date.new(2011,11,6),
    :inactive_date       => nil,
    :company             => 'company-pointer',
    :complementary_type  => 'homeopathy',
    :indication          => 'indication-pointer',
    :renewal_flag        => false,
    :export_flag         => nil,
  }
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2008,3,19))
end

- (Object) test_update_registration__ignore_vet



152
153
154
155
156
157
# File 'test/test_plugin/swissmedic.rb', line 152

def test_update_registration__ignore_vet
  row = @workbook.worksheet(0).row(7)
  assert_nothing_raised {
    @plugin.update_registration(row)
  }
end

- (Object) test_update_registration__phyto



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'test/test_plugin/swissmedic.rb', line 158

def test_update_registration__phyto
  row = @workbook.worksheet(0).row(4)
  indication = flexmock 'indication'
  indication.should_receive(:pointer).and_return 'indication-pointer'
  @app.should_receive(:indication_by_text).with("Bei Schnupfen")\
    .and_return indication
  company = flexmock 'company'
  name = 'Hänseler AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  registration = flexmock 'registration'
  @app.should_receive(:registration).with('08599').and_return registration
  ptr = Persistence::Pointer.new([:registration, '08599'])
  registration.should_receive(:pointer).and_return ptr
  args = {
    :ith_swissmedic      => '12.02.4.',
    :production_science  => 'Phytotherapeutika',
    :registration_date   => Date.new(1930,9,6),
    :expiration_date     => Date.new(2010,9,6),
    :inactive_date       => nil,
    :company             => 'company-pointer',
    :complementary_type  => 'phytotherapy',
    :indication          => 'indication-pointer',
    :renewal_flag        => false,
    :export_flag         => nil,
  }
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2008,3,19))
end

- (Object) test_update_registration__renewal



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'test/test_plugin/swissmedic.rb', line 260

def test_update_registration__renewal
  row = @workbook.worksheet(0).row(3)
  indication = flexmock 'indication'
  indication.should_receive(:pointer).and_return 'indication-pointer'
  @app.should_receive(:indication_by_text).with("Analgetikum, Antipyretikum")\
    .and_return indication
  company = flexmock 'company'
  name = 'Bayer (Schweiz) AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  registration = flexmock 'registration'
  @app.should_receive(:registration).with('08537').and_return registration
  ptr = Persistence::Pointer.new([:registration, '08537'])
  registration.should_receive(:pointer).and_return ptr
  args = {
    :ith_swissmedic      => '01.01.1.',
    :production_science  => 'Synthetika human',
    :registration_date   => Date.new(1936,6,30),
    :expiration_date     => Date.new(2012,5,9),
    :inactive_date       => nil,
    :company             => 'company-pointer',
    :renewal_flag        => true,
    :export_flag         => nil,
    :indication          => 'indication-pointer',
  }
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2012,5,10))
end

- (Object) test_update_registration__update



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'test/test_plugin/swissmedic.rb', line 119

def test_update_registration__update
  row = @workbook.worksheet(0).row(3)
  indication = flexmock 'indication'
  indication.should_receive(:pointer).and_return 'indication-pointer'
  @app.should_receive(:indication_by_text).with("Analgetikum, Antipyretikum")\
    .and_return indication
  company = flexmock 'company'
  name = 'Bayer (Schweiz) AG'
  @app.should_receive(:company_by_name)\
    .with(name, 0.8).and_return company
  company.should_receive(:pointer).and_return 'company-pointer'
  registration = flexmock 'registration'
  args = { :name => name, :business_area => 'ba_pharma' }
  @app.should_receive(:update).with('company-pointer', args)\
    .times(1).and_return { assert true; company }
  @app.should_receive(:registration).with('08537').and_return registration
  ptr = Persistence::Pointer.new([:registration, '08537'])
  registration.should_receive(:pointer).and_return ptr
  args = {
    :ith_swissmedic      => '01.01.1.',
    :production_science  => 'Synthetika human',
    :registration_date   => Date.new(1936,6,30),
    :expiration_date     => Date.new(2012,5,9),
    :inactive_date       => nil,
    :export_flag         => nil,
    :company             => 'company-pointer',
    :renewal_flag        => false,
    :indication          => 'indication-pointer',
  }
  @app.should_receive(:update).with(ptr, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_registration(row, :date => Date.new(2008,3,19))
end

- (Object) test_update_sequence__create



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'test/test_plugin/swissmedic.rb', line 293

def test_update_sequence__create
  row = @workbook.worksheet(0).row(3)
  reg = flexmock 'registration'
  ptr = Persistence::Pointer.new([:registration, '08537'])
  reg.should_receive(:pointer).and_return ptr
  reg.should_receive(:sequence).with('01')
  atc = flexmock 'atc'
  atc.should_receive(:code).and_return 'A01BC23'
  reg.should_receive(:atc_classes).and_return [atc]
  sptr = Persistence::Pointer.new([:registration, '08537'], [:sequence, '01'])
  args = {
    :name_base        => "Aspirin",
    :name_descr       => "Tabletten",
    :composition_text => "acidum acetylsalicylicum 500 mg, excipiens pro compresso.",
    :atc_class        => "A01BC23",
    :sequence_date    => Date.new(1936,6,30),
    :dose             => nil,
    :export_flag      => nil,
  }
  @app.should_receive(:update).with(sptr.creator, args, :swissmedic)\
    .times(1).and_return { assert true }
  @plugin.update_sequence reg, row
end