DIMSE: Unexpected Response MsgId

With Orthanc 1.8.2, interspersed in succeeding sends:

orthanc_1 | 2021-01-21T15:15:35.301398137Z W0121 15:15:35.301022 LuaContext.cpp:93] Lua says: send to research-osirix: Investigators^Drucker^Test (1.3.12.2.1107.5.2.43.66094.2021012110005717403706623)

orthanc_1 | 2021-01-21T15:15:35.305179698Z E0121 15:15:35.305020 OrthancException.cpp:57] Error in the network protocol: DicomAssociation - C-STORE to AET “RESEARCH2012”: DIMSE: Unexpected Response MsgId: 139 (expected: 140)
orthanc_1 | 2021-01-21T15:15:35.305278072Z E0121 15:15:35.305165 StoreScuOperation.cpp:73] Lua: Unable to send instance 1f9ce757-7f58f885-0d5ebb95-18f876a5-28c99b20 to modality “RESEARCH2012”: Error in the network protocol
orthanc_1 | 2021-01-21T15:15:35.323736091Z W0121 15:15:35.323352 LuaContext.cpp:93] Lua says: send to research-osirix: Investigators^Drucker^Test (1.3.12.2.1107.5.2.43.66094.2021012110005717418806624)

What does this mean? What can I do about it?

My script to forward is extremely simple:

function OnStoredInstance(instanceId, tags, metadata, origin)
if origin[‘RequestOrigin’] == ‘Lua’ then
return
end

local destination = router(tags[‘StudyDescription’])

print('send to ’ … destination … ‘: ’ … (tags[‘StudyDescription’] or ‘[SD is empty]’) … ’ (’ … tags[‘SOPInstanceUID’] … ‘)’)
SendToModality(instanceId, destination)
end

This presumably indicates that the sending of one of the images by your Lua script has failed (the image contained in the DIMSE message with index 138), and that OsiriX doesn’t accept a “hole” in the sequence.

You could try and set the “DicomAssociationCloseDelay” configuration option to “0”: This should re-negotiate a new separate DICOM association for each image to be sent (this would slow down the transmission though).

As explained in the Orthanc Book, you shouldn’t be using “SendToModality()” but instead call the REST API (URI “/modalities/{…}/store”) to transmit full studies:
https://book.orthanc-server.com/users/lua.html#important-remarks-about-auto-routing

In either case, if you need further support, please provide a full minimal working example for other people to be able to independently reproduce your issue:

https://book.orthanc-server.com/users/support.html#discussing-a-minimal-working-example

So, oddly enough, in spite of that error, OsiriX did in fact receive every image. I’ve now hand-checked the files on the modality vs the files that arrived at Orthanc vs the files that were forwarded to OsiriX, and there are the same number of files, and the images and non-metadata-headers are all identical.

So I don’t know what that error actually means.

Thanks for the note about the REST API. I have changed from

SendToModality(instanceId, destination)
to
RestApiPost(‘/modalities/’ … destination … ‘/store’, instanceId)