LUA scripting - I have a need to change the Institution Name(0008,0080) based on what the first two letters of the Accession Number starts with(0008, 0050)

Hi All,
I have little to no experience with Lua and am looking for some help on our DICOM Systems dicom router.
Our offhours, offsite teleradiology reading service needs consistent institution names to help them route their studies. They unfortunately cannot route based on Accession number prefixes as of yet and I’m unsure on how soon their R&D team can implement this.

Example: DICOM tag, Accession (0008,0050) number - EH1234567890 (if accession number begins with EH)
then replace current DICOM tag - Institution name (0008, 0080) with - EXAMPLE HOSPITAL

There are multiple institutions so after the first “if and then” statement, is there away to do an OR statement for the next Accession number variable and next hospital?

Thank you so much everyone.

Perhaps this will help. The OnStorededIstance function automatically runs when an instance arrives

function OnStoredInstance(instanceId, tags, metadata, origin)

if origin[‘RequestOrigin’] ~= ‘Lua’ then

local replace = {}

local accession = tags[‘AccessionNumber’]

local institution = string.sub(accession, 1, 2)

if institution == “EH” then
replace[‘InstitutionName’] = ‘Example Hospital’
end

– Modify the instance

local command = {}

command[‘Replace’] = replace

– sometimes you need to do a force like when changing patientid
– command[‘Force’] = true

local modifiedFile = RestApiPost(
‘/instances/’ … instanceId … ‘/modify’,
DumpJson(command, true))

– Upload the modified instance to the Orthanc database so that
– it can be sent by Orthanc to other modalities

local modifiedId =
ParseJson(RestApiPost(‘/instances/’, modifiedFile))[‘ID’]

– Delete the original

RestApiDelete(‘/instances/’ … instanceId)

end
end

Thanks so much Andrew,
I’ll try it and let you know.