Python Auto-route and called AET

Hi Mex,

You may retrieve the metadata from the first instance of the study with this code:

import orthanc
import json
import pprint

def OnChange(changeType, level, resourceId):
    if changeType == orthanc.ChangeType.STABLE_STUDY:
        print('Stable study: %s' % resourceId)

        instances_ids = json.loads(orthanc.RestApiGet(f"/studies/{resourceId}/instances"))
        instance_metadata = json.loads(orthanc.RestApiGet(f"/instances/{instances_ids[0]['ID']}/metadata?expand"))
        
        pprint.pprint(instance_metadata)
        if "CalledAET" in instance_metadata and "RemoteAET" in instance_metadata:
            print(f"This study orginates from {instance_metadata['RemoteAET']} and was addressed to {instance_metadata['CalledAET']}")

        # orthanc.RestApiPost('/modalities/sample/store', resourceId)

orthanc.RegisterOnChangeCallback(OnChange)

HTH,

Alain.

1 Like