Python plugin, access dicom fields through GetInstanceMetadata

Hello all,

I’m following the tutorial here about python plugin and more specifically how to access info about newly stored instances:

https://book.orthanc-server.com/plugins/python.html?highlight=getinstancesimplifiedjson#accessing-the-content-of-a-new-instance

this works (this is the exemple’s code):
print(‘Received instance %s of size %d (transfer syntax %s, SOP class UID %s)’ % (
instanceId, dicom.GetInstanceSize(),
dicom.GetInstanceMetadata(‘TransferSyntax’),
dicom.GetInstanceMetadata(‘SopClassUid’)))

but this does not and it prints ‘null’ for each value:
print(‘–> %s - %s - %s’ % (
dicom.GetInstanceMetadata(‘StudyInstanceUID’),
dicom.GetInstanceMetadata(‘SopInstanceUID’),
dicom.GetInstanceMetadata(‘SeriesInstanceUID’))

Obviously the strings I asked for are not understood by Orthanc, but I’m lost regarding where I can know what values can be used… I tried different possibilities (Uid/UID) bu nothing worked.

Do you have any pointer or idea ?
Regards
François

Hello,

Metadata is not the same as DICOM tags:
https://book.orthanc-server.com/faq/features.html#metadata-attachments

Here is how to reach your objective:

import orthanc
import json

def OnStoredInstance(dicom, instanceId):
tags = json.loads(dicom.GetInstanceSimplifiedJson())
print(‘–> %s - %s - %s’ % (tags[‘StudyInstanceUID’],
tags[‘SOPInstanceUID’],
tags[‘SeriesInstanceUID’]))

orthanc.RegisterOnStoredInstanceCallback(OnStoredInstance)

Sébastien-

Thank you very much Sebastien :slight_smile: