I have a weird use case for Orthanc and I was hoping to find out if it will work for me.
I have a working Orthanc install where xrays are now being automatically sent to it over my network from my xray capture PC after accepting each scan.
I don't want to use any web viewer or management features from Orthanc, I just wanted to use it to get the dicom files onto the filesystem where they can be manipulated freely. Mainly chose Orthanc because it was so easy to install and configure.
I have a script created using a program called AdvancedRenamer that will move and rename DICOM files based on their metadata (ie patient ID, etc) which I need to allow some automatic imports into other network software. My plan is to point it at the Orthanc storage directory and let it manipulate the files from there. I'm aware moving the dicom files straight from the Orthanc storage directory will probably make the software unhappy, but again I don't need an Orthanc features other than get the files to the filesystem from an automatic dicom send.
The problem I've run into is that while the script can filter which files it targets based on filename mask and regex, Orthanc stores other small files mixed in with the larger DICOM files (even after sqlite index directory moved), and uses filenames that are not only random strings (as far as I can tell), but don't even include a DCM extension.
Any of the following would solve my problem if at all possible:
1. Isolate storage directories so the small (11KB) files are stored in a separate folder structure from the large dicom files.
2. Give DICOM files a DCM extension so that I can filter them out.
3. Some other way to differentiate by file name, ie all DICOM files starting with a certain string, etc.
I knkw this is an unusual use case but any help would be appreciated in case I've missed a possible solution in the config file or anything else.
TARGET = 'C:\\OrthancExport'
function ToAscii(s)
-- http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub
return s
end
function OnStableSeries(seriesId, tags, metadata)
print('This series is now stable, writing its instances on the disk: ' .. seriesId)
local instances = ParseJson(RestApiGet('/series/' .. seriesId)) ['Instances']
local patient = ParseJson(RestApiGet('/series/' .. seriesId .. '/patient')) ['MainDicomTags']
local study = ParseJson(RestApiGet('/series/' .. seriesId .. '/study')) ['MainDicomTags']
local series = ParseJson(RestApiGet('/series/' .. seriesId)) ['MainDicomTags']
for i, instance in pairs(instances) do
local path = ToAscii(TARGET .. '\\' ..
patient['PatientID'] .. ' - ' .. patient['PatientName'] .. '\\' ..
study['StudyDate'] .. ' - ' .. study['StudyDescription'] .. '\\' ..
series['SeriesDescription'])
-- Retrieve the DICOM file from Orthanc
local dicom = RestApiGet('/instances/' .. instance .. '/file')
-- Create the subdirectory (CAUTION: For Linux demo only, this is insecure!)
-- http://stackoverflow.com/a/16029744/881731
os.execute('mkdir "' .. path .. '"')
-- Write to the file
local target = assert(io.open(path .. '\\' .. instance .. '.dcm', 'wb'))
target:write(dicom)
target:close()
end
end
TARGET = 'C:\\OrthancExport'
function ToAscii(s)
-- http://www.lua.org/manual/5.1/manual.html#pdf-string.gsub
return s
end
function OnStableSeries(seriesId, tags, metadata)
print('This series is now stable, writing its instances on the disk: ' .. seriesId)
local instances = ParseJson(RestApiGet('/series/' .. seriesId)) ['Instances']
local patient = ParseJson(RestApiGet('/series/' .. seriesId .. '/patient')) ['MainDicomTags']
local study = ParseJson(RestApiGet('/series/' .. seriesId .. '/study')) ['MainDicomTags']
local series = ParseJson(RestApiGet('/series/' .. seriesId)) ['MainDicomTags']
for i, instance in pairs(instances) do
local path = ToAscii(TARGET)
-- Retrieve the DICOM file from Orthanc
local dicom = RestApiGet('/instances/' .. instance .. '/file')
-- Write to the file
local target = assert(io.open(path .. '\\' .. 'H' .. patient['PatientID'] .. '-' .. series['SeriesNumber'] .. '-' .. i .. '.dcm', 'wb'))