Class: ODDB::AnalysisParse::IndexHandler

Inherits:
PageHandler show all
Defined in:
ext/analysisparse/src/pagehandler.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from PageHandler

#next_pagehandler

Constructor Details

- (IndexHandler) initialize(index)

A new instance of IndexHandler



29
30
31
32
33
# File 'ext/analysisparse/src/pagehandler.rb', line 29

def initialize(index)
  @index = index
  @incomplete = {}
  @positions = {}
end

Instance Attribute Details

- (Object) index (readonly)

Returns the value of attribute index



28
29
30
# File 'ext/analysisparse/src/pagehandler.rb', line 28

def index
  @index
end

Instance Method Details

- (Object) analyze(page, pagenum)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'ext/analysisparse/src/pagehandler.rb', line 34

def analyze(page, pagenum)
  case @index[pagenum]
  when /Chemie\/H\344matologie\/Immunologie/iu \
    , /Chimie\/Hématologie\/Immunologie/iu
    @parser = ListParser.new
    @list_title = $~.to_s
  when /genetik/iu, /génétique/iu
    @parser = ListParser.new
    @list_title = $~.to_s
  when /mikrobiologie/iu, /microbiologie/iu
    @parser = ListParser.new
    @list_title = $~.to_s
  when /allgemeine positionen/iu, /positions générales/iu
    @parser = SimpleListParser.new
    @list_title = $~.to_s
  when /Anonyme Positionen/iu, /positions anonymes/iu
    @list_title = nil
    @parser = AnonymousListParser.new
  when /Fixe Analysenblöcke/iu, /Blocs\s*d[\'\302\222]analyses\s*fixes/iu
    @parser = BlockListParser.new
    @list_title = $~.to_s
  when /Liste seltener Autoantikörper/u
    @parser = nil #AntibodyListParser.new
  when /Im Rahmen der Grundversorgung durchgef\374hrte Analysen/iu, /analyses effectuées dans le cadre des soins de base/iu
    @parser = FragmentedPageHandler.new
    @list_title = nil
    @permission = nil
  when /Von Chiropraktoren oder Chiropraktorinnen veranlasste Analysen/iu, /analyses prescrites par des chiropraticiens/iu
    @parser = AppendixListParser.new
    @permission = $~.to_s
  when /Von Hebammen veranlasste Analysen/iu,
       /analyses prescrites par des sages-femmes/iu
    @parser = AppendixListParser.new
    @permission = $~.to_s
  end
  if(@parser)
    handler = Rpdf2txt::SimpleHandler.new
    page.text(handler)
    txt = handler.out
    parse_page(txt, pagenum, @parser)
  end
  self
end

- (Object) parse_page(txt, pagenum, parser)



77
78
79
80
81
82
83
84
85
86
87
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
# File 'ext/analysisparse/src/pagehandler.rb', line 77

def parse_page(txt, pagenum, parser)
  parser.list_title = @list_title
  parser.permission = @permission
  pos = parser.parse_page(txt, pagenum)
  parser.footnotes.each { |key, rs|
    if(pairs = @incomplete.delete(key))
      pairs.each { |pair|
        pair[1] = rs
      }
    end
  }
  pos.each { |ps|
    same = nil
    rs = ps.delete(:restriction)
    perm = ps.delete(:permission)
    if(same = @positions[ps[:code]])
      ps.delete_if { |key, value|
        value.nil?
      }
      same.update(ps)
    else
      same = ps
      ps.store(:permissions, [])
      @positions.store(ps[:code], ps)
    end
    pair = [perm, rs]
    if(perm)
      same[:permissions].push(pair)
    end
    if(/^\d+$/u.match(rs))
      (@incomplete[rs] ||= []).push(pair)
    end
  }
  @list_title = parser.list_title
  @permission = parser.permission 
  pos
end

- (Object) positions



114
115
116
# File 'ext/analysisparse/src/pagehandler.rb', line 114

def positions
  @positions.values
end