Module: ODDB::DocData

Defined in:
ext/docdata/src/docdata.rb,
ext/docdata/src/docparser.rb

Defined Under Namespace

Classes: DoctorFormatter, DoctorWriter

Constant Summary collapse

MEDDATA_SERVER =
DRbObject.new(nil, MEDDATA_URI)
HTTP_SERVER =
'www.emh.ch'
HTML_PATH =
'/medical_adresses/physicians_fmh/detail.cfm'
RETRIES =
3
RETRY_WAIT =
5

Class Method Summary collapse

Class Method Details

._define_structObject



98
99
100
# File 'ext/docdata/src/docdata.rb', line 98

def _define_struct
	Struct.new("Result", :session, :values, :ctl)
end

.data_path(doc_id) ⇒ Object



27
28
29
30
31
32
# File 'ext/docdata/src/docdata.rb', line 27

def data_path(doc_id)
	attributes = {
		'ds1nr'	=>	doc_id,	
	}
	doc_path(attributes)
end

.doc_data(doc_id) ⇒ Object



39
40
41
42
43
44
45
46
# File 'ext/docdata/src/docdata.rb', line 39

def doc_data(doc_id)
	html = doc_data_body(doc_id)
	if(html.index('Name:'))
		parse_doc_data(html)
	else
		nil
	end
end

.doc_data_add_ean(doc_id) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'ext/docdata/src/docdata.rb', line 64

def doc_data_add_ean(doc_id)
	data = doc_data(doc_id)
	# define Struct
	_define_struct
	unless(data.nil?)
		MEDDATA_SERVER.session { |meddata|
			results = meddata.search(data)
			keys = []
			results.select { |result|
				if(result.values[1] == data[:firstname])
					keys.push(result)
				end
			}
			ean13 = nil
			if(keys.size == 1)
				data = meddata.detail(keys.first, {:ean13 => [1,0]})
				ean13 = data[:ean13]
				puts "######### >>> #{ean13}"
			end
			unless(ean13.nil?)
				data.store(:ean13, ean13)
			end
		}
	end
	data
end

.doc_data_body(doc_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/docdata/src/docdata.rb', line 47

def doc_data_body(doc_id)
	retr = RETRIES
	begin
		session = Net::HTTP.new(HTTP_SERVER)
		resp = session.get(data_path(doc_id))
		if(resp.is_a? Net::HTTPOK)
			enc_resp = ODDB::HttpSession::ResponseWrapper.new(resp)
			enc_resp.body
		end
	rescue Timeout::Error
		if(retr > 0)
			sleep RETRY_WAIT
			retr -= 1
			retry
		end
	end
end

.doc_path(hsh) ⇒ Object



33
34
35
36
37
38
# File 'ext/docdata/src/docdata.rb', line 33

def doc_path(hsh)
	attributes = hsh.sort.collect { |pair| 
		pair.join('=')
	}.join('&')
	[ HTML_PATH, attributes ].join('?')
end

.parse_doc_data(html) ⇒ Object



90
91
92
93
94
95
96
97
# File 'ext/docdata/src/docdata.rb', line 90

def parse_doc_data(html)
	writer = DoctorWriter.new
	formatter = DoctorFormatter.new(writer)
	parser = HtmlParser.new(formatter)
	parser.feed(html)
	writer.extract_data
	writer.collected_values
end