forked from inferno-framework/client-fhir-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-Mapper.rb
More file actions
89 lines (75 loc) · 2.5 KB
/
data-Mapper.rb
File metadata and controls
89 lines (75 loc) · 2.5 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
require 'json'
require 'dm-migrations'
require 'nokogiri'
require_relative './CapabilityStatement-db'
class FCDataMapper
def initialize(file_name = 'data.db')
@db = SQLite3::Database.new(file_name)
end
DataMapper.auto_migrate!
DataMapper.auto_upgrade!
def mapJsonData()
json = File.read('./resources/CapabilityStatement-us-core-client.json')
jobj = JSON.parse(json)
# Interaction summary table
jobj['rest'][0]['resource'].each do |res|
type = res['type']
next unless res.include? 'interaction'
res['interaction'].each do |hash|
url = hash['extension'][0]['url']
valueCode = hash['extension'][0]['valueCode']
code = hash['code']
Interaction.create type: type, url: url, valueCode: valueCode, code: code
end
end
# SearchParam
jobj['rest'][0]['resource'].each do |res|
type = res['type']
next unless res.include? 'searchParam'
res['searchParam'].each do |s|
url = s['extension'][0]['url']
valueCode = s['extension'][0]['valueCode']
name = s['name']
definition = s['definition']
stype = s['type']
SearchParam.create type: type, url: url, valueCode: valueCode,
name: name, definition: definition, stype: stype
end
end
# Interaction.get(1)
# int1 = Interaction.all type: 'Patient', valueCode: 'SHOULD'
# puts(int1[0].code)
# SearchParam.get(1)
# parameter combination
docs = Nokogiri::HTML(jobj['text']['div'])
table = docs.at('.grid')
table.search('tr').each do |tr|
cells = tr.search('th, td')
# puts(cells)
# output cell data
cell_array = []
cells.each do |cell|
cell_array.append(cell.text.strip)
end
next unless cell_array[0] != "Resource Type"
#next unless cell_array[0] == "Medication"
unless cell_array[2] == ""
sup_params = cell_array[2].split("\n")
s_params = sup_params[0]
# puts(sup_params[1])
if sup_params[1].nil?
c_params = nil
else
c_params = sup_params[1].gsub("\t", "")
end
end
SearchCriteria.create res_type: cell_array[0],
profiles: cell_array[1],
s_searches: s_params,
c_searches: c_params,
includes: cell_array[3],
revincludes: cell_array[4],
opterations: cell_array[5]
end
end
end