-
Notifications
You must be signed in to change notification settings - Fork 15
/
prefetching.lua
48 lines (38 loc) · 1.9 KB
/
prefetching.lua
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
function OnStableStudy(studyId, tags, metadata)
--PrintRecursive(tags)
-- forward this "current" study to the Workstation
local moveBody = {}
moveBody["Synchronous"] = false
moveBody["Resources"] = {}
table.insert(moveBody["Resources"], studyId)
local moveJobId = ParseJson(RestApiPost('/modalities/workstation/store', DumpJson(moveBody)))["ID"]
print('moving current study to workstation in job ' .. moveJobId)
-- retrieve PatientID to sea
local StudyInstanceUID = tags["StudyInstanceUID"]
local PatientID = ParseJson(RestApiGet('/studies/' .. studyId .. '/patient'))["MainDicomTags"]["PatientID"]
-- build the C-Find query to the PACS to explore all studies from this patient
local queryBody = {}
queryBody["Level"] = "Study"
queryBody["Query"] = {}
queryBody["Query"]["PatientID"] = PatientID
local queryId = ParseJson(RestApiPost('/modalities/pacs/query', DumpJson(queryBody)))["ID"]
local queryResponse = ParseJson(RestApiGet('/queries/' .. queryId .. '/answers'))
for k, v in pairs(queryResponse) do
local study = ParseJson(RestApiGet('/queries/' .. queryId .. '/answers/' .. v .. '/content?simplify'))
-- if the study is not the current one, send it directly from the PACS to the Workstation
if study["StudyInstanceUID"] ~= StudyInstanceUID then
local retrieveBody = {}
retrieveBody["TargetAet"] = "WORKSTATION"
retrieveBody["Synchronous"] = false
local retrieveResponse = ParseJson(RestApiPost('/queries/' .. queryId .. '/answers/' .. v .. '/retrieve', DumpJson(retrieveBody)))
PrintRecursive(retrieveResponse)
end
end
end
function OnJobSuccess(jobId)
local job = ParseJson(RestApiGet('/jobs/' .. jobId))
if job["Type"] == "DicomModalityStore" then
-- delete the study once it has been forwarded
RestApiDelete('/studies/' .. job["Content"]["ParentResources"][1])
end
end