comparison Core/DicomNetworking/DicomUserConnection.cpp @ 3607:d0ecb355db33 storage-commitment

DicomUserConnection::ReportStorageCommitment() complete
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 17 Jan 2020 15:56:02 +0100
parents 33ba63637d48
children 7ae553d9c366
comparison
equal deleted inserted replaced
3606:33ba63637d48 3607:d0ecb355db33
1418 * 1418 *
1419 * Status code: 1419 * Status code:
1420 * http://dicom.nema.org/medical/dicom/2019a/output/chtml/part07/chapter_10.html#sect_10.1.1.1.8 1420 * http://dicom.nema.org/medical/dicom/2019a/output/chtml/part07/chapter_10.html#sect_10.1.1.1.8
1421 **/ 1421 **/
1422 1422
1423 T_DIMSE_Message response; 1423 /**
1424 memset(&response, 0, sizeof(response)); 1424 * Send the "EVENT_REPORT_RQ" request
1425 response.CommandField = DIMSE_N_EVENT_REPORT_RQ; 1425 **/
1426 1426
1427 T_DIMSE_N_EventReportRQ& content = response.msg.NEventReportRQ; 1427 LOG(INFO) << "Reporting modality \"" << remoteAet_
1428 content.MessageID = pimpl_->assoc_->nextMsgID; 1428 << "\" about storage commitment transaction: " << transactionUid
1429 strncpy(content.AffectedSOPClassUID, UID_StorageCommitmentPushModelSOPClass, DIC_UI_LEN); 1429 << " (" << successSopClassUids.size() << " successes, "
1430 strncpy(content.AffectedSOPInstanceUID, UID_StorageCommitmentPushModelSOPInstance, DIC_UI_LEN); 1430 << failureSopClassUids.size() << " failures)";
1431 content.DataSetType = DIMSE_DATASET_PRESENT; 1431 DIC_US messageId = pimpl_->assoc_->nextMsgID;
1432
1433 DcmDataset dataset;
1434 if (!dataset.putAndInsertString(DCM_TransactionUID, transactionUid.c_str()).good())
1435 {
1436 throw OrthancException(ErrorCode_InternalError);
1437 }
1438
1439 FillSopSequence(dataset, DCM_ReferencedSOPSequence, successSopClassUids, successSopInstanceUids);
1440
1441 // http://dicom.nema.org/medical/dicom/2019a/output/chtml/part04/sect_J.3.3.html
1442 if (failureSopClassUids.empty())
1443 {
1444 content.EventTypeID = 1; // "Storage Commitment Request Successful"
1445 }
1446 else
1447 {
1448 content.EventTypeID = 2; // "Storage Commitment Request Complete - Failures Exist"
1449 FillSopSequence(dataset, DCM_FailedSOPSequence, failureSopClassUids, failureSopInstanceUids);
1450 }
1451
1452 dataset.writeXML(std::cout);
1453 1432
1454 int presID = ASC_findAcceptedPresentationContextID( 1433 {
1455 pimpl_->assoc_, UID_StorageCommitmentPushModelSOPClass); 1434 T_DIMSE_Message message;
1456 if (presID == 0) 1435 memset(&message, 0, sizeof(message));
1457 { 1436 message.CommandField = DIMSE_N_EVENT_REPORT_RQ;
1458 throw OrthancException(ErrorCode_NetworkProtocol, "Storage commitment - " 1437
1459 "Unable to send N-EVENT-REPORT to AET: " + remoteAet_); 1438 T_DIMSE_N_EventReportRQ& content = message.msg.NEventReportRQ;
1460 } 1439 content.MessageID = messageId;
1461 1440 strncpy(content.AffectedSOPClassUID, UID_StorageCommitmentPushModelSOPClass, DIC_UI_LEN);
1462 if (!DIMSE_sendMessageUsingMemoryData( 1441 strncpy(content.AffectedSOPInstanceUID, UID_StorageCommitmentPushModelSOPInstance, DIC_UI_LEN);
1463 pimpl_->assoc_, presID, &response, NULL /* status detail */, 1442 content.DataSetType = DIMSE_DATASET_PRESENT;
1464 &dataset, NULL /* callback */, NULL /* callback context */, 1443
1465 NULL /* commandSet */).good()) 1444 DcmDataset dataset;
1466 { 1445 if (!dataset.putAndInsertString(DCM_TransactionUID, transactionUid.c_str()).good())
1467 throw OrthancException(ErrorCode_NetworkProtocol); 1446 {
1468 } 1447 throw OrthancException(ErrorCode_InternalError);
1469 1448 }
1470 // TODO - Read answer 1449
1471 1450 FillSopSequence(dataset, DCM_ReferencedSOPSequence, successSopClassUids, successSopInstanceUids);
1451
1452 // http://dicom.nema.org/medical/dicom/2019a/output/chtml/part04/sect_J.3.3.html
1453 if (failureSopClassUids.empty())
1454 {
1455 content.EventTypeID = 1; // "Storage Commitment Request Successful"
1456 }
1457 else
1458 {
1459 content.EventTypeID = 2; // "Storage Commitment Request Complete - Failures Exist"
1460 FillSopSequence(dataset, DCM_FailedSOPSequence, failureSopClassUids, failureSopInstanceUids);
1461 }
1462
1463 int presID = ASC_findAcceptedPresentationContextID(
1464 pimpl_->assoc_, UID_StorageCommitmentPushModelSOPClass);
1465 if (presID == 0)
1466 {
1467 throw OrthancException(ErrorCode_NetworkProtocol, "Storage commitment - "
1468 "Unable to send N-EVENT-REPORT request to AET: " + remoteAet_);
1469 }
1470
1471 if (!DIMSE_sendMessageUsingMemoryData(
1472 pimpl_->assoc_, presID, &message, NULL /* status detail */,
1473 &dataset, NULL /* callback */, NULL /* callback context */,
1474 NULL /* commandSet */).good())
1475 {
1476 throw OrthancException(ErrorCode_NetworkProtocol);
1477 }
1478 }
1479
1480 /**
1481 * Read the "EVENT_REPORT_RSP" response
1482 **/
1483
1484 {
1485 T_ASC_PresentationContextID presID = 0;
1486 T_DIMSE_Message message;
1487
1488 if (!DIMSE_receiveCommand(pimpl_->assoc_, DIMSE_NONBLOCKING, 1, &presID,
1489 &message, NULL /* no statusDetail */).good() ||
1490 message.CommandField != DIMSE_N_EVENT_REPORT_RSP)
1491 {
1492 throw OrthancException(ErrorCode_NetworkProtocol, "Storage commitment - "
1493 "Unable to read N-EVENT-REPORT response from AET: " + remoteAet_);
1494 }
1495
1496 const T_DIMSE_N_EventReportRSP& content = message.msg.NEventReportRSP;
1497 if (content.MessageIDBeingRespondedTo != messageId ||
1498 !(content.opts & O_NEVENTREPORT_AFFECTEDSOPCLASSUID) ||
1499 !(content.opts & O_NEVENTREPORT_AFFECTEDSOPINSTANCEUID) ||
1500 //(content.opts & O_NEVENTREPORT_EVENTTYPEID) || // Pedantic test - The "content.EventTypeID" has no sense here
1501 std::string(content.AffectedSOPClassUID) != UID_StorageCommitmentPushModelSOPClass ||
1502 std::string(content.AffectedSOPInstanceUID) != UID_StorageCommitmentPushModelSOPInstance ||
1503 content.DataSetType != DIMSE_DATASET_NULL)
1504 {
1505 throw OrthancException(ErrorCode_NetworkProtocol, "Storage commitment - "
1506 "Badly formatted N-EVENT-REPORT response from AET: " + remoteAet_);
1507 }
1508
1509 if (content.DimseStatus != 0 /* success */)
1510 {
1511 throw OrthancException(ErrorCode_NetworkProtocol, "Storage commitment - "
1512 "The request cannot be handled by remote AET: " + remoteAet_);
1513 }
1514 }
1515
1472 Close(); 1516 Close();
1473 } 1517 }
1474 catch (OrthancException&) 1518 catch (OrthancException&)
1475 { 1519 {
1476 Close(); 1520 Close();