modify within a sequence

Hi all,

I can get the beam type from :

beamtype = ToolBox.DoGet(LOCAL, '/instances/%s/content/BeamSequence/%s/BeamType' % (instance['ID'],bs))

how do I go about modifying the BeamType tag for all items in BeamSequence ?

Thanks

Does anyone have an idea how to change and item in a sequence ?

Thanks

Here is what I tried: Physicists, Don't ask why I am doing this/ :slight_smile:

for serie_index, serie in enumerate(series):

    instances = ToolBox.DoGet(LOCAL, '/series/%s/instances' % (serie['ID']))

    for instance in instances:
        # 300a,00b0 (BeamSequence)
        beamSequence = ToolBox.DoGet(LOCAL, '/instances/%s/tags' % instance['ID'])['300a,00b0']['Value']
        for bs in beamSequence:
            # 300a,00c4 (BeamType): u'DYNAMIC'
            # 300a,00c4 (BeamType): u'STATIC'
            bs['300a,00c4']['Value'] = 'STATIC'
        #300a,00b0 (BeamSequence): []
        j = ToolBox.DoPost(LOCAL, '/instances/%s/modify' % instance['ID'],
                   json.dumps({
                    "Replace" : {
                        'BeamSequence': beamSequence,
                        },
                    }),
                   'application/json')
        #j = DoPost(_REMOTE, '/instances', j, 'application/dicom')['ID']
        #DoDelete(_REMOTE, '/instances/%s' % i)

Error:

  File "C:/Users/xxx/Development/PycharmProjects/scripts/renameARC.py", line 72, in <module>
    'application/json')
  File "C:/Users/xxx/Development/PycharmProjects/scripts\ToolBox.py", line 156, in DoPost
    return _DoPutOrPost(orthanc, uri, 'POST', data, contentType, headers)
  File "C:/Users/xxx/Development/PycharmProjects/scripts\ToolBox.py", line 137, in _DoPutOrPost
    raise Exception(resp.status)
Exception: 400
Thanks

Hello,

You will find attached to this message, a working example to fulfill your request.

The main trick consists in adding “?simplify” to your “DoGet()” query, in order to retrieve a JSON value that is compatible with what is expected by the “Replace” call.

HTH,
Sébastien-

ModifyBeamSequence.py (1.25 KB)