Updating InstitutionName using Lua script

Hey everyone, having alot of issues updating the Institution Name tag in a Lua script. The goal is to update the institution name on all studies at first and then add logic to check for the origin called Aet.

please look at the script below and let me know if you see anything that stands out. Thank you!

Ps I tried to keep it as close to the example as possible.

function OnStoredInstance(instanceId, tags, metadata)
if (metadata[‘ModifiedFrom’] == nil and
metadata[‘AnonymizedFrom’] == nil) then

 local replace = {}

 replace['InstitutionName'] = 'MyMedicalDevice'

 local remove = { 'MilitaryRank' }

 SendToModality(ModifyInstance(instanceId, replace, remove, true), 'orthanc')

 Delete(instanceId)

end
end

Hi,

No, I do not see any issues by just “looking at it”.

Do not hesitate to check this article and share more info.

Best regards,

Alain.

Hello,

I have tested your Lua script:

function OnStoredInstance(instanceId, tags, metadata)
  if (metadata['ModifiedFrom'] == nil and
      metadata['AnonymizedFrom'] == nil) then
    local replace = {}
    replace['InstitutionName'] = 'MyMedicalDevice'
    local remove = { 'MilitaryRank' }
    SendToModality(ModifyInstance(instanceId, replace, remove, true), 'orthanc')
    Delete(instanceId)
  end
end

With the following Orthanc configuration file (where orthanc actually corresponds to a test C-Store SCP started a storescp -v 2000):

{
  "LuaScripts" : [ "sample.lua" ],
  "DicomModalities" : {
    "orthanc" : [ "STORESCP", "localhost", 2000 ]
  }
}

And I can confirm that the Lua script properly sets the InstitutionName tag as expected:

$ dcm2xml US.1.2.276.0.7230010.3.1.4.1757367822.20594.1711968988.143032 | grep InstitutionName
<element tag="0008,0080" vr="LO" vm="1" len="16" name="InstitutionName">MyMedicalDevice</element>

Regards,
Sébastien-

Thank you! I was able to get it to work eventually. It was my first Lua script so there was a slight learning curve.

1 Like