Lua Script - Marking tag "PatientID" as to be replaced requires the "Force" option to be set to true

I am trying to set up Orthanc as a pretty basic DICOM auto-router. The one thing I need to do is modify the Patient ID (0010,0020) before forwarding the images. I need to add a prefix to the Patient ID, so if the Patient ID I receive is 12345 then I want to send out XYZ-12345.

I was making progress, using the ‘Server-side scripting with Lua’ documentation until I tried to set the PatientID with a static value. The DICOM image did not auto-route and in my Log I got this:

E0715 14:00:29.281100 OrthancException.h:85] Bad request: Marking tag “PatientID” as to be replaced requires the “Force” option to be set to true

Looking around, I see where to set the Force option with the Rest API, but I was trying to do this all with just a Lua script.

How can I set the Force option for a Lua script?

Here is some if my script which uses Force

replace[‘2100-0070’] = varOriginator
replace[‘StudyInstanceUID’] = tags[‘StudyInstanceUID’]
replace[‘SeriesInstanceUID’] = tags[‘SeriesInstanceUID’]
replace[‘SOPInstanceUID’] = tags[‘SOPInstanceUID’]
–Check to see if prefixing is needed. If so, prefix.
if varPatientPrefixEnabled == “True” then
replace[‘PatientID’] = varPatientPrefix … tags[‘PatientID’]
end
– Commands to modify the study
local command = {}
command[‘Replace’] = replace
command[‘Force’] = true
local modifiedFile = RestApiPost(‘/instances/’ … instanceId … ‘/modify’, DumpJson(command, true))

Thanks, that’s helpful. I was able to make some changes and the PatientID is now being prefixed. The only issue I am having now is that for some reason every image is getting a new Study Instance UID, so if I do this on a 100 image CT I am getting 100 individual studies when it gets forwarded to the new device. Any ideas why? I don’t see anything in my code that is changing the Study Instance UID.

function OnStoredInstance(instanceId, tags, metadata, origin)

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

– The tags to be replaced
local replace = {}
replace[‘PatientID’] = “XYZ-” … tags[‘PatientID’]

– The tags to be removed
local remove = { ‘MilitaryRank’ }

– Modify the instance
local command = {}
command[‘Replace’] = replace
command[‘Remove’] = remove
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’]

– Send the modified instance to another modality
RestApiPost(‘/modalities/NEWPACS/store’, modifiedId)

– Delete the original and the modified instances
RestApiDelete(‘/instances/’ … instanceId)
RestApiDelete(‘/instances/’ … modifiedId)
end
end

How can I keep the Study Instance UID the same?

Yeppers. Orthanc Changes the study UID when changing patient ID. What I did was grab the original UID and changing it to that when modifying the study. Check my history I have had to do that before.