-------------------------------------------------------------------------------
-- pure lua weasis (V3.0 up) connector for conquest dicom server
-- to use, copy into webserver/cgi-bin/newweb and modify dicom.ini there as follows:
-- lines 18, 19
-- viewer = weasis_starter
-- studyviewer = weasis_starter
-- line 26 (for newweb only, not for the classical interface)
-- exceptions=start,listpatients,liststudies,listseries,listimageswiththumbs,listimages,wadostudyviewer,wadoseriesviewer,wadoviewerhelp,slice,listtrials,listtrialpatient,weasis_starter
--
-- To update weasis version just replace the jnlp and xml text block indicated in the code
--
-- This file runs as one of the following four modes, 2 create the jnlp starter, 2 create xml manifests
-- dgate.exe?mode=weasis_starter&study=patid:studyuid
-- dgate.exe?mode=weasis_starter&series=patid:seriesuid
-- dgate.exe?mode=weasis_starter&accession=accessionnumber
-- dgate.exe?mode=weasis_starter¶meter=xml&study=patid:studyuid
-- dgate.exe?mode=weasis_starter¶meter=xml&series=patid:seriesuid
-- dgate.exe?mode=weasis_starter¶meter=xml&accession=accessionnumber
--
-- optional parameters:
-- compress, WebScriptAddress and WebCodebase are taken from dicom.ini
-------------------------------------------------------------------------------
-- mvh 20181123 Created for 1.4.19c
-- mvh 20181124 Fixed server links; Removed PatientID for study xml
-- mvh 20181213 server_name does not copy port use relative link and WebScriptAddress;
-- moved WadoTransferSyntaxUID to series level
-- mvh 20181214 Made to work with help from lyakh92; uses compress and WebScriptAddress from dicom.ini
-- mvh 20181227 Use remotequery to limit contralize access to server; use gpps WebScriptAddress
-- mvh 20181229 Fixed section of WebScriptAddress
-- mvh 20180112 Fix to allow : in patientID
-- mvh 20180302 Added accession= access for external use
-- mvh 20180303 Some fixes in that code
local source_server = Global.WebCodeBase
local parameter = CGI('parameter', 'jnlp')
local study = CGI('study', '')
local series = CGI('series', '')
local accession = CGI('accession', '')
local level = 'study'
local ident = study
if study=='' then
level = 'series'
ident = series
end
if series=='' then
level = 'accession'
ident = accession
end
-- for testing
-- parameter='xml'
-- script_name=script_name or 'aap'
-------------------------------------------------------------------------------------------------------------
-- this text between [[ ]] is the JNLP sample file from the weasis website without change, it is adapted by the lua code below
-- I had to remove line , for weasis_portable3.0
local jnlp = [[
Weasis
Weasis Team
DICOM images viewer
An application to visualize and analyze DICOM images.
DICOM images viewer
Weasis
$dicom:get -w "http://localhost:8080/dcm4chee-web/wadoQueries/wado_query3888637380.xml.gz"
$dicom:get -l "/home/Images/MRIX LUMBAR/"
$dicom:get -i "H4sIAAAAAAAAALVV7Y+aMBz+vr+i6XdLXwDBHHdxpy4mvgX0dvtkOqnaBOGO1qn//RUQnW5uy3JHCC2/1+d5Wsrdw36TgB8iVzJLA0gQhkCkiyyW6SqAW71seBA83H+62/E4m79uR..."
$dicom:get -r "http://server/images/img1.dcm http://server/images/img2.dcm"
]]
-------------------------------------------------------------------------------------------------------------
-- split string into pieces, return as table
function split(str, pat)
local t = {}
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
function remotequery(ae, level, q)
local remotecode =
[[
local ae=']]..ae..[[';
local level=']]..level..[[';
local q=]]..q:Serialize()..[[;
local q2=DicomObject:new(); for k,v in pairs(q) do q2[k]=v end;
local r = dicomquery(ae, level, q2):Serialize();
local s=tempfile('txt') local f=io.open(s, "wb") f:write(r) returnfile=s f:close();
]]
local f = loadstring('return '..servercommand('lua:'..remotecode));
if f then return f() end
end
-----------------------------------
-- render jnlp file if requested --
-----------------------------------
if parameter=='jnlp' then
HTML("Content-Type: application/x-java-jnlp-file\n")
local xmlline = string.format([[$dicom:get -w "%s?mode=weasis_starter¶meter=xml&compress=%s&%s&dum=.xml"]],
gpps('sscscp', 'WebScriptAddress', ''), gpps('webdefaults', 'compress', 'un'), level..'='..ident)
jnlp = split(jnlp, '\n')
for k,v in ipairs(jnlp) do
v = string.gsub(v, 'http://localhost:8080/', source_server)
if string.find(v, 'dicom:get -r', 1, true) then v='' end
if string.find(v, 'dicom:get -i', 1, true) then v='' end
if string.find(v, 'dicom:get -l', 1, true) then v='' end
if string.find(v, 'dicom:get -w', 1, true) then v=xmlline end
print(v)
end
return
end
-------------------------------------------------------------------------------------------------------------
-- this between [[ and ]] is the XML sample file from the weasis website without change,
-- optionally all items may be reduced to one, for the rest it is adapted by the lua code below
local xml=
[[
]]
-------------------------------------------------------------------------------------------------------------
-----------------------------------
-- render xml file if requested ---
-----------------------------------
if parameter=='xml' then
-- utility functions first
-- make DICOM query from sample xml line
function xmltoquery(line)
local q = DicomObject:new()
local level = string.match(line, '<(.-) ')
if level=='Instance' then level='Image' end
q.QueryRetrieveLevel = level
string.gsub(line, "([%w:]+)=([\"'])(.-)%2", function (w, _, a)
q[w]=''
end)
return q
end
-- print level xml open statement
function xmlopen(level, t)
local s
if level=='PATIENT' then
s=' ')
else
print(s .. '>')
end
end
-- print level xml close statement
function xmlclose(level, t)
if level=='PATIENT' then
print(' ')
elseif level=='STUDY' then
print(' ')
elseif level=='SERIES' then
print(' ')
end
end
-- start of xml generator
-- split query information
local patid = string.gsub(ident, ':[^:]-$', '')
local uid = string.gsub(ident, '^.*:', '')
local compress = CGI('compression', 'un')
local source = servercommand('get_param:MyACRNema')
local paq, stq, seq, inq
-- create compression transfer syntax
local wt = ''
if compress=='J5' or compress=='j5' then wt = '1.2.840.10008.1.2.4.53' end
if compress=='J4' or compress=='j4' then wt = '1.2.840.10008.1.2.4.51' end
if compress=='J3' or compress=='j3' then wt = '1.2.840.10008.1.2.4.50' end
if compress=='J1' or compress=='j1' then wt = '1.2.840.10008.1.2.4.55' end
if compress=='J2' or compress=='j2' then wt = '1.2.840.10008.1.2.4.57' end
if compress=='J1' or compress=='j1' then wt = '1.2.840.10008.1.2.4.70' end
if compress=='JK' or compress=='jk' then wt = '1.2.840.10008.1.2.4.90' end
if compress=='JL' or compress=='jl' then wt = '1.2.840.10008.1.2.4.91' end
-- first pass: set baseUrl and build default queries
xml = split(xml, '\n')
for k,v in ipairs(xml) do
if string.find(v, 'baseUrl=') then
xml[k] = string.gsub(v, 'baseUrl=".-"', 'baseUrl="'..gpps('sscscp', 'WebScriptAddress', '')..'"')
end
if string.find(v, '