-
Notifications
You must be signed in to change notification settings - Fork 6
/
convertNDJSON.rb
40 lines (37 loc) · 1.24 KB
/
convertNDJSON.rb
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
require 'json'
require 'pry'
# FHIR_SERVER_BASE = "http://localhost:8080/plan-net"
FHIR_SERVER_BASE = "http://davinci-plan-net-ri.logicahealth.org/plan-net"
#FHIR_SERVER_BASE = "https://plan-net-ri.davinci.hl7.org"
ndouts = []
FileUtils.mkdir_p("export/")
Dir.glob("output/*") do |typedir|
puts "working on input directory: #{typedir}..."
resourceType = File.basename(typedir)
url = "#{FHIR_SERVER_BASE}/resources/#{resourceType}.ndjson"
ndouts << {
"type" => resourceType,
"url" => url
}
outfile = "export/#{resourceType}.ndjson"
puts "writing to #{outfile}"
o = File.open(outfile,"w")
Dir.glob("#{typedir}/*.json") do |jsonfile|
puts "working on: #{jsonfile}"
s = File.read(jsonfile)
h = JSON.parse(s)
o.puts(JSON.generate(h))
end
o.close
end
output = {
"transactionTime" => Time.now.strftime("%d/%m/%Y %H:%M"),
"request" => "#{FHIR_SERVER_BASE}/fhir/$export",
"requiresAccessToken" => false,
"output" => ndouts,
"error" => { "type" => "OperationOutcome",
"url" => "http://serverpath2/err_file_1.ndjson"}
}
export = File.open("export/export.json","w")
export.write(JSON.pretty_generate(output))
puts("Files written to /export")