1 /*
2  *
3  *  Copyright (C) 1993-2017, OFFIS e.V.
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation were developed by
7  *
8  *    OFFIS e.V.
9  *    R&D Division Health
10  *    Escherweg 2
11  *    D-26121 Oldenburg, Germany
12  *
13  *
14  *  Module:  dcmqrdb
15  *
16  *  Author:  Marco Eichelberg
17  *
18  *  Purpose: class DcmQueryRetrieveFindContext
19  *
20  */
21 
22 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
23 #include "dcmtk/dcmqrdb/dcmqrcbf.h"
24 
25 #include "dcmtk/dcmqrdb/dcmqrcnf.h"
26 #include "dcmtk/dcmdata/dcdeftag.h"
27 #include "dcmtk/dcmqrdb/dcmqropt.h"
28 #include "dcmtk/dcmnet/diutil.h"
29 #include "dcmtk/dcmdata/dcfilefo.h"
30 #include "dcmtk/dcmqrdb/dcmqrdbs.h"
31 #include "dcmtk/dcmqrdb/dcmqrdbi.h"
32 
33 
callbackHandler(OFBool cancelled,T_DIMSE_C_FindRQ * request,DcmDataset * requestIdentifiers,int responseCount,T_DIMSE_C_FindRSP * response,DcmDataset ** responseIdentifiers,DcmDataset ** stDetail)34 void DcmQueryRetrieveFindContext::callbackHandler(
35     /* in */
36     OFBool cancelled, T_DIMSE_C_FindRQ *request,
37     DcmDataset *requestIdentifiers, int responseCount,
38     /* out */
39     T_DIMSE_C_FindRSP *response,
40     DcmDataset **responseIdentifiers,
41     DcmDataset **stDetail)
42 {
43     OFCondition dbcond = EC_Normal;
44     DcmQueryRetrieveDatabaseStatus dbStatus(priorStatus);
45 
46     if (responseCount == 1) {
47         /* start the database search */
48         DCMQRDB_INFO("Find SCP Request Identifiers:" << OFendl << DcmObject::PrintHelper(*requestIdentifiers));
49         dbcond = dbHandle.startFindRequest(
50             request->AffectedSOPClassUID, requestIdentifiers, &dbStatus);
51         if (dbcond.bad()) {
52             DCMQRDB_ERROR("findSCP: Database: startFindRequest Failed ("
53                     << DU_cfindStatusString(dbStatus.status()) << "):");
54         }
55     }
56 
57     /* only cancel if we have pending responses */
58     if (cancelled && DICOM_PENDING_STATUS(dbStatus.status())) {
59         dbHandle.cancelFindRequest(&dbStatus);
60     }
61 
62     if (DICOM_PENDING_STATUS(dbStatus.status())) {
63         dbcond = dbHandle.nextFindResponse(responseIdentifiers, &dbStatus, characterSetOptions);
64         if (dbcond.bad()) {
65              DCMQRDB_ERROR("findSCP: Database: nextFindResponse Failed ("
66                      << DU_cfindStatusString(dbStatus.status()) << "):");
67         }
68     }
69 
70     if (*responseIdentifiers != NULL)
71     {
72 
73         if (! DU_putStringDOElement(*responseIdentifiers, DCM_RetrieveAETitle, ourAETitle.c_str())) {
74             DCMQRDB_ERROR("DO: adding Retrieve AE Title");
75         }
76     }
77 
78     /* set response status */
79     response->DimseStatus = dbStatus.status();
80     *stDetail = dbStatus.extractStatusDetail();
81 
82     OFString str;
83     DCMQRDB_INFO("Find SCP Response " << responseCount << " [status: "
84             << DU_cfindStatusString(dbStatus.status()) << "]");
85     DCMQRDB_DEBUG(DIMSE_dumpMessage(str, *response, DIMSE_OUTGOING));
86     if (DICOM_PENDING_STATUS(dbStatus.status()) && (*responseIdentifiers != NULL))
87         DCMQRDB_DEBUG("Find SCP Response Identifiers:" << OFendl << DcmObject::PrintHelper(**responseIdentifiers));
88     if (*stDetail)
89         DCMQRDB_DEBUG("  Status detail:" << OFendl << DcmObject::PrintHelper(**stDetail));
90 }
91