Preserving instance metadata in Lua script

Hello,
In my setup any instance that is received is compressed to JPEG2000 using the Lua script below. The problem is this changes the metadata on the instance to something like as follows:

{
“IndexInSeries”: “585”,
“Origin”: “Lua”,
“ReceptionDate”: “20190918T204126”,
“RemoteAET”: “”,
“SopClassUid”: “1.2.840.10008.5.1.4.1.1.2”,
“TransferSyntax”: “1.2.840.10008.1.2.4.90”
}

Is it possible to retain the original metadata as I really need to get the RemoteAET info. The script I’m using is below:

function OnStoredInstance(instanceId, tags, metadata, origin)
– Do not compress twice the same file
if origin[‘RequestOrigin’] ~= ‘Lua’ then

– Retrieve the incoming DICOM instance from Orthanc
local dicom = RestApiGet(‘/instances/’ … instanceId … ‘/file’)

– Write the DICOM content to some temporary file
local uncompressed = instanceId … ‘-uncompressed.dcm’
local target = assert(io.open(uncompressed, ‘wb’))
target:write(dicom)
target:close()

– Compress to JPEG2000 using gdcm
local compressed = instanceId … ‘-compressed.dcm’
os.execute('C:\Orthanc\Tools\GDCM\bin\gdcmconv.exe -U --j2k ’ … uncompressed … ’ ’ … compressed)

–os.execute('C:\Orthanc\Tools\dcmtk\bin\dcmodify.exe --no-backup -gin ’ … compressed)
os.execute(‘C:\Orthanc\Tools\dcmtk\bin\dcmodify.exe --no-backup -m "SOPInstanceUID=’ … tags[‘SOPInstanceUID’] … '" ’ … compressed)

– Read the JPEG2000 file
local source = assert(io.open(compressed, ‘rb’))
local jpeg2k = source:read(“*all”)
source:close()

– Upload the JPEG2000 file and remove the uncompressed file
RestApiDelete(‘/instances/’ … instanceId)
RestApiPost(‘/instances’, jpeg2k)

– Remove the temporary DICOM files
os.remove(uncompressed)
os.remove(compressed)

end
end

Hi Rana,

This is currently not possible.
What you could do in your lua script is:

  • read the Origin & RemoteAET from the uncompressed instance and store them in local variables
  • compress and upload the new instance
  • set new metadata in the compressed instance (however, you won’t be able to overwrite the Origin and RemoteAET since they are ‘internal’ metadatas https://book.orthanc-server.com/faq/features.html#core-metadata). So, this means that you’ll have to define “MyOrigin” and “MyRemoteAET” to store this info.

Best regards,

Alain.

Thank you.