forked from inferno-framework/client-fhir-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateReport.rb
More file actions
164 lines (127 loc) · 3.81 KB
/
generateReport.rb
File metadata and controls
164 lines (127 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
114
115
116
117
118
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
152
153
154
155
156
157
158
159
require 'json'
require 'csv'
require 'sqlite3'
require 'dm-core'
require 'yaml'
class ReportGen
def initialize(file_name = 'data.db')
@db = SQLite3::Database.new(file_name)
@db.results_as_hash = true
end
def getSearchCategories()
stmtc = @db.prepare ("SELECT * FROM search_criteria")
rst = stmtc.execute
return rst
rescue SQLite3::Exception => e
puts "Exception occurred"
puts e
end
def getCountSessionID()
stm = @db.prepare ("SELECT count(request_id) as count FROM requests")
rs = stm.execute
resultSet = rs.next
puts resultSet
rescue SQLite3::Exception => e
puts "Exception occurred"
puts e
ensure
stm.close if stm
ret = resultSet['count']
puts ret
return ret
end
def insertSession(start_id,last_id,dt)
sql = %{
INSERT INTO sessions
(first_request_id, last_request_id, dt)
VALUES
(?, ?, ?);
}
ins = @db.prepare(sql)
ins.execute(start_id, last_id, dt)
end
def generateReport()
#todo: need to be able to populate data into check_lists table here.
#eval File.read("test-generator.rb")
# pid=Process.fork do
# require './test-generator.rb'
# Process.exit
# end
# ignored, status = Process.waitpid2(pid, Process::WNOHANG)
# puts "script.rb PID #{pid} exited, exit status: #{status.exitstatus}"
stm = @db.prepare ("SELECT first_request_id, last_request_id ,dt FROM sessions ORDER BY session_id ASC")
rs = stm.execute
rec_hash = Hash.new
rec_hash[:res] = []
while (resultSet = rs.next) do
res_hash = Hash.new
res_hash[:start] =resultSet['first_request_id']
res_hash[:last] =resultSet['last_request_id']
res_hash[:dt] =resultSet['dt']
puts resultSet
rec_hash[:res] << res_hash
end
retArray = Array.new
rec_hash[:res].each { |item|
puts item
retArray << buildSearchJson(item[:start],item[:last], item[:dt])
}
retData = retArray.join(',')
retData = "[" + retData + "]"
puts retData
rescue SQLite3::Exception => e
puts "Exception occurred"
puts e
ensure
stm.close if stm
#@db.close if @db
return retData
end
def buildSearchJson(start, last, dt)
s_hash = Hash.new
s_hash[:Session]=dt
s_hash[:Records] =[]
rstCategories = getSearchCategories()
while (i = rstCategories.next) do
i_hash = Hash.new
i_hash[:Interaction]="search-type"
i_hash[:Resource]=i['res_type']
i_hash[:TestResult]=[]
stmRepo = @db.prepare ("SELECT * FROM check_lists WHERE request_id >= ? and request_id <= ? and resource = ? and request_type = ? ")
stmRepo.bind_params start, last, i['res_type'], 'search-type'
rst = stmRepo.execute
cnt =0
while (resultSet2 = rst.next) do
cnt = cnt + 1
r_hash = Hash.new
r_hash[:search_param]=resultSet2['search_param']
r_hash[:present_code]=resultSet2['present_code']
r_hash[:request_id]=resultSet2['request_id']
r_hash[:response_status]=resultSet2['response_status']
if (resultSet2['search_valid'] == 't')
resultSet2['search_valid'] = 'TRUE'
else
resultSet2['search_valid'] = 'FALSE'
end
r_hash[:search_valid]=resultSet2['search_valid']
r_hash[:search_valid]=resultSet2['request_uri']
i_hash[:TestResult]<< r_hash
puts resultSet2
end
if cnt < 1
r_hash = Hash.new
r_hash[:no_match_found]="No search transaction found during recording session."
i_hash[:TestResult]<< r_hash
end
s_hash[:Records]<<i_hash
end
puts JSON.generate(s_hash)
returnJson = JSON.generate(s_hash)
rescue SQLite3::Exception => e
puts "Exception occurred"
puts e
ensure
stmRepo.close if stmRepo
returnJson
end
end