Mercurial > hg > orthanc-python
comparison Sources/DicomScpCallbacks.cpp @ 207:968dbd6982bb
renamed variables to highlight that they are Python dictionaries
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 12:38:31 +0200 |
parents | e9be3c9294d4 |
children | 6ca37fcf0979 |
comparison
equal
deleted
inserted
replaced
206:4e6079e27965 | 207:968dbd6982bb |
---|---|
230 | 230 |
231 virtual void Apply() ORTHANC_OVERRIDE | 231 virtual void Apply() ORTHANC_OVERRIDE |
232 { | 232 { |
233 PythonLock lock; | 233 PythonLock lock; |
234 | 234 |
235 PythonObject kw(lock, PyDict_New()); | 235 PythonObject dict(lock, PyDict_New()); |
236 | 236 |
237 std::string level; | 237 std::string level; |
238 switch (resourceType_) | 238 switch (resourceType_) |
239 { | 239 { |
240 case OrthancPluginResourceType_Patient: | 240 case OrthancPluginResourceType_Patient: |
257 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_ParameterOutOfRange); | 257 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_ParameterOutOfRange); |
258 } | 258 } |
259 | 259 |
260 { | 260 { |
261 PythonString tmp(lock, level); | 261 PythonString tmp(lock, level); |
262 PyDict_SetItemString(kw.GetPyObject(), "Level", tmp.GetPyObject()); | 262 PyDict_SetItemString(dict.GetPyObject(), "Level", tmp.GetPyObject()); |
263 } | 263 } |
264 | 264 |
265 { | 265 { |
266 PythonString tmp(lock, patientId_); | 266 PythonString tmp(lock, patientId_); |
267 PyDict_SetItemString(kw.GetPyObject(), "PatientID", tmp.GetPyObject()); | 267 PyDict_SetItemString(dict.GetPyObject(), "PatientID", tmp.GetPyObject()); |
268 } | 268 } |
269 | 269 |
270 { | 270 { |
271 PythonString tmp(lock, accessionNumber_); | 271 PythonString tmp(lock, accessionNumber_); |
272 PyDict_SetItemString(kw.GetPyObject(), "AccessionNumber", tmp.GetPyObject()); | 272 PyDict_SetItemString(dict.GetPyObject(), "AccessionNumber", tmp.GetPyObject()); |
273 } | 273 } |
274 | 274 |
275 { | 275 { |
276 PythonString tmp(lock, studyInstanceUid_); | 276 PythonString tmp(lock, studyInstanceUid_); |
277 PyDict_SetItemString(kw.GetPyObject(), "StudyInstanceUID", tmp.GetPyObject()); | 277 PyDict_SetItemString(dict.GetPyObject(), "StudyInstanceUID", tmp.GetPyObject()); |
278 } | 278 } |
279 | 279 |
280 { | 280 { |
281 PythonString tmp(lock, seriesInstanceUid_); | 281 PythonString tmp(lock, seriesInstanceUid_); |
282 PyDict_SetItemString(kw.GetPyObject(), "SeriesInstanceUID", tmp.GetPyObject()); | 282 PyDict_SetItemString(dict.GetPyObject(), "SeriesInstanceUID", tmp.GetPyObject()); |
283 } | 283 } |
284 | 284 |
285 { | 285 { |
286 PythonString tmp(lock, sopInstanceUid_); | 286 PythonString tmp(lock, sopInstanceUid_); |
287 PyDict_SetItemString(kw.GetPyObject(), "SOPInstanceUID", tmp.GetPyObject()); | 287 PyDict_SetItemString(dict.GetPyObject(), "SOPInstanceUID", tmp.GetPyObject()); |
288 } | 288 } |
289 | 289 |
290 { | 290 { |
291 PythonString tmp(lock, originatorAet_); | 291 PythonString tmp(lock, originatorAet_); |
292 PyDict_SetItemString(kw.GetPyObject(), "OriginatorAET", tmp.GetPyObject()); | 292 PyDict_SetItemString(dict.GetPyObject(), "OriginatorAET", tmp.GetPyObject()); |
293 } | 293 } |
294 | 294 |
295 { | 295 { |
296 PythonString tmp(lock, sourceAet_); | 296 PythonString tmp(lock, sourceAet_); |
297 PyDict_SetItemString(kw.GetPyObject(), "SourceAET", tmp.GetPyObject()); | 297 PyDict_SetItemString(dict.GetPyObject(), "SourceAET", tmp.GetPyObject()); |
298 } | 298 } |
299 | 299 |
300 { | 300 { |
301 PythonString tmp(lock, targetAet_); | 301 PythonString tmp(lock, targetAet_); |
302 PyDict_SetItemString(kw.GetPyObject(), "TargetAET", tmp.GetPyObject()); | 302 PyDict_SetItemString(dict.GetPyObject(), "TargetAET", tmp.GetPyObject()); |
303 } | 303 } |
304 | 304 |
305 { | 305 { |
306 PythonObject tmp(lock, PyLong_FromUnsignedLong(originatorId_)); | 306 PythonObject tmp(lock, PyLong_FromUnsignedLong(originatorId_)); |
307 PyDict_SetItemString(kw.GetPyObject(), "OriginatorID", tmp.GetPyObject()); | 307 PyDict_SetItemString(dict.GetPyObject(), "OriginatorID", tmp.GetPyObject()); |
308 } | 308 } |
309 | 309 |
310 PythonObject args(lock, PyTuple_New(0)); | 310 PythonObject args(lock, PyTuple_New(0)); |
311 | 311 |
312 assert(moveScpCallback_ != NULL); | 312 assert(moveScpCallback_ != NULL); |
313 PythonObject result(lock, PyObject_Call(moveScpCallback_, args.GetPyObject(), kw.GetPyObject())); | 313 PythonObject result(lock, PyObject_Call(moveScpCallback_, args.GetPyObject(), dict.GetPyObject())); |
314 | 314 |
315 OrthancPluginErrorCode code = lock.CheckCallbackSuccess("Python C-MOVE SCP callback"); | 315 OrthancPluginErrorCode code = lock.CheckCallbackSuccess("Python C-MOVE SCP callback"); |
316 if (code != OrthancPluginErrorCode_Success) | 316 if (code != OrthancPluginErrorCode_Success) |
317 { | 317 { |
318 throw OrthancPlugins::PluginException(code); | 318 throw OrthancPlugins::PluginException(code); |
419 _targetAet.assign(targetAet); | 419 _targetAet.assign(targetAet); |
420 } | 420 } |
421 | 421 |
422 PythonLock lock; | 422 PythonLock lock; |
423 | 423 |
424 PythonObject kw(lock, PyDict_New()); | 424 PythonObject dict(lock, PyDict_New()); |
425 | 425 |
426 std::string level; | 426 std::string level; |
427 switch (resourceType) | 427 switch (resourceType) |
428 { | 428 { |
429 case OrthancPluginResourceType_Patient: | 429 case OrthancPluginResourceType_Patient: |
446 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_ParameterOutOfRange); | 446 throw OrthancPlugins::PluginException(OrthancPluginErrorCode_ParameterOutOfRange); |
447 } | 447 } |
448 | 448 |
449 { | 449 { |
450 PythonString tmp(lock, level); | 450 PythonString tmp(lock, level); |
451 PyDict_SetItemString(kw.GetPyObject(), "Level", tmp.GetPyObject()); | 451 PyDict_SetItemString(dict.GetPyObject(), "Level", tmp.GetPyObject()); |
452 } | 452 } |
453 | 453 |
454 { | 454 { |
455 PythonString tmp(lock, _patientId); | 455 PythonString tmp(lock, _patientId); |
456 PyDict_SetItemString(kw.GetPyObject(), "PatientID", tmp.GetPyObject()); | 456 PyDict_SetItemString(dict.GetPyObject(), "PatientID", tmp.GetPyObject()); |
457 } | 457 } |
458 | 458 |
459 { | 459 { |
460 PythonString tmp(lock, _accessionNumber); | 460 PythonString tmp(lock, _accessionNumber); |
461 PyDict_SetItemString(kw.GetPyObject(), "AccessionNumber", tmp.GetPyObject()); | 461 PyDict_SetItemString(dict.GetPyObject(), "AccessionNumber", tmp.GetPyObject()); |
462 } | 462 } |
463 | 463 |
464 { | 464 { |
465 PythonString tmp(lock, _studyInstanceUid); | 465 PythonString tmp(lock, _studyInstanceUid); |
466 PyDict_SetItemString(kw.GetPyObject(), "StudyInstanceUID", tmp.GetPyObject()); | 466 PyDict_SetItemString(dict.GetPyObject(), "StudyInstanceUID", tmp.GetPyObject()); |
467 } | 467 } |
468 | 468 |
469 { | 469 { |
470 PythonString tmp(lock, _seriesInstanceUid); | 470 PythonString tmp(lock, _seriesInstanceUid); |
471 PyDict_SetItemString(kw.GetPyObject(), "SeriesInstanceUID", tmp.GetPyObject()); | 471 PyDict_SetItemString(dict.GetPyObject(), "SeriesInstanceUID", tmp.GetPyObject()); |
472 } | 472 } |
473 | 473 |
474 { | 474 { |
475 PythonString tmp(lock, _sopInstanceUid); | 475 PythonString tmp(lock, _sopInstanceUid); |
476 PyDict_SetItemString(kw.GetPyObject(), "SOPInstanceUID", tmp.GetPyObject()); | 476 PyDict_SetItemString(dict.GetPyObject(), "SOPInstanceUID", tmp.GetPyObject()); |
477 } | 477 } |
478 | 478 |
479 { | 479 { |
480 PythonString tmp(lock, _originatorAet); | 480 PythonString tmp(lock, _originatorAet); |
481 PyDict_SetItemString(kw.GetPyObject(), "OriginatorAET", tmp.GetPyObject()); | 481 PyDict_SetItemString(dict.GetPyObject(), "OriginatorAET", tmp.GetPyObject()); |
482 } | 482 } |
483 | 483 |
484 { | 484 { |
485 PythonString tmp(lock, _sourceAet); | 485 PythonString tmp(lock, _sourceAet); |
486 PyDict_SetItemString(kw.GetPyObject(), "SourceAET", tmp.GetPyObject()); | 486 PyDict_SetItemString(dict.GetPyObject(), "SourceAET", tmp.GetPyObject()); |
487 } | 487 } |
488 | 488 |
489 { | 489 { |
490 PythonString tmp(lock, _targetAet); | 490 PythonString tmp(lock, _targetAet); |
491 PyDict_SetItemString(kw.GetPyObject(), "TargetAET", tmp.GetPyObject()); | 491 PyDict_SetItemString(dict.GetPyObject(), "TargetAET", tmp.GetPyObject()); |
492 } | 492 } |
493 | 493 |
494 { | 494 { |
495 PythonObject tmp(lock, PyLong_FromUnsignedLong(originatorId)); | 495 PythonObject tmp(lock, PyLong_FromUnsignedLong(originatorId)); |
496 PyDict_SetItemString(kw.GetPyObject(), "OriginatorID", tmp.GetPyObject()); | 496 PyDict_SetItemString(dict.GetPyObject(), "OriginatorID", tmp.GetPyObject()); |
497 } | 497 } |
498 | 498 |
499 PythonObject args(lock, PyTuple_New(0)); | 499 PythonObject args(lock, PyTuple_New(0)); |
500 | 500 |
501 // Note: the result is not attached to the PythonLock because we want it to survive after this call since | 501 // Note: the result is not attached to the PythonLock because we want it to survive after this call since |
502 // the result is the python move driver that will be passed as first argument to GetMoveSize, Apply and Free. | 502 // the result is the python move driver that will be passed as first argument to GetMoveSize, Apply and Free. |
503 // After the PyObject_Call, result's ref count is 1 -> no need to add a reference but we need to decref explicitely | 503 // After the PyObject_Call, result's ref count is 1 -> no need to add a reference but we need to decref explicitely |
504 // to delete the object at the end of the move. | 504 // to delete the object at the end of the move. |
505 PyObject* result = PyObject_Call(createMoveScpDriverCallback_, args.GetPyObject(), kw.GetPyObject()); | 505 PyObject* result = PyObject_Call(createMoveScpDriverCallback_, args.GetPyObject(), dict.GetPyObject()); |
506 | 506 |
507 OrthancPluginErrorCode code = lock.CheckCallbackSuccess("Python C-MOVE SCP callback (Create)"); | 507 OrthancPluginErrorCode code = lock.CheckCallbackSuccess("Python C-MOVE SCP callback (Create)"); |
508 if (code != OrthancPluginErrorCode_Success) | 508 if (code != OrthancPluginErrorCode_Success) |
509 { | 509 { |
510 throw OrthancPlugins::PluginException(code); | 510 throw OrthancPlugins::PluginException(code); |