Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomUserConnection.cpp @ 689:2d0a347e8cfc
switch to 2014
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Feb 2014 16:06:58 +0100 |
parents | b8383ac0b227 |
children | 1a3f9d90a2dd |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "DicomUserConnection.h" | |
34 | |
62 | 35 #include "../../Core/OrthancException.h" |
0 | 36 #include "../ToDcmtkBridge.h" |
37 #include "../FromDcmtkBridge.h" | |
38 | |
39 #include <dcmtk/dcmdata/dcistrmb.h> | |
40 #include <dcmtk/dcmdata/dcistrmf.h> | |
41 #include <dcmtk/dcmdata/dcfilefo.h> | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
42 #include <dcmtk/dcmdata/dcmetinf.h> |
0 | 43 #include <dcmtk/dcmnet/diutil.h> |
44 | |
45 #include <set> | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
46 #include <glog/logging.h> |
0 | 47 |
48 | |
49 | |
50 #ifdef _WIN32 | |
51 /** | |
52 * "The maximum length, in bytes, of the string returned in the buffer | |
53 * pointed to by the name parameter is dependent on the namespace provider, | |
54 * but this string must be 256 bytes or less. | |
55 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms738527(v=vs.85).aspx | |
56 **/ | |
57 #define HOST_NAME_MAX 256 | |
58 #endif | |
59 | |
60 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
61 static const char* DEFAULT_PREFERRED_TRANSFER_SYNTAX = UID_LittleEndianImplicitTransferSyntax; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
62 |
62 | 63 namespace Orthanc |
0 | 64 { |
65 struct DicomUserConnection::PImpl | |
66 { | |
67 // Connection state | |
68 T_ASC_Network* net_; | |
69 T_ASC_Parameters* params_; | |
70 T_ASC_Association* assoc_; | |
71 | |
72 bool IsOpen() const | |
73 { | |
74 return assoc_ != NULL; | |
75 } | |
76 | |
77 void CheckIsOpen() const; | |
78 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
79 void Store(DcmInputStream& is, DicomUserConnection& connection); |
0 | 80 }; |
81 | |
82 | |
83 static void Check(const OFCondition& cond) | |
84 { | |
85 if (cond.bad()) | |
86 { | |
62 | 87 throw OrthancException("DicomUserConnection: " + std::string(cond.text())); |
0 | 88 } |
89 } | |
90 | |
91 void DicomUserConnection::PImpl::CheckIsOpen() const | |
92 { | |
93 if (!IsOpen()) | |
94 { | |
62 | 95 throw OrthancException("DicomUserConnection: First open the connection"); |
0 | 96 } |
97 } | |
98 | |
99 | |
100 void DicomUserConnection::CheckIsOpen() const | |
101 { | |
102 pimpl_->CheckIsOpen(); | |
103 } | |
104 | |
105 | |
106 void DicomUserConnection::CopyParameters(const DicomUserConnection& other) | |
107 { | |
108 Close(); | |
109 localAet_ = other.localAet_; | |
110 distantAet_ = other.distantAet_; | |
111 distantHost_ = other.distantHost_; | |
112 distantPort_ = other.distantPort_; | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
113 manufacturer_ = other.manufacturer_; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
114 preferredTransferSyntax_ = other.preferredTransferSyntax_; |
0 | 115 } |
116 | |
117 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
118 void DicomUserConnection::SetupPresentationContexts(const std::string& preferredTransferSyntax) |
0 | 119 { |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
120 // Fallback transfer syntaxes |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
121 std::set<std::string> fallbackSyntaxes; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
122 fallbackSyntaxes.insert(UID_LittleEndianExplicitTransferSyntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
123 fallbackSyntaxes.insert(UID_BigEndianExplicitTransferSyntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
124 fallbackSyntaxes.insert(UID_LittleEndianImplicitTransferSyntax); |
0 | 125 |
126 // Transfer syntaxes for C-ECHO, C-FIND and C-MOVE | |
127 std::vector<std::string> transferSyntaxes; | |
128 transferSyntaxes.push_back(UID_VerificationSOPClass); | |
129 transferSyntaxes.push_back(UID_FINDPatientRootQueryRetrieveInformationModel); | |
130 transferSyntaxes.push_back(UID_FINDStudyRootQueryRetrieveInformationModel); | |
131 transferSyntaxes.push_back(UID_MOVEStudyRootQueryRetrieveInformationModel); | |
132 | |
133 // TODO: Allow the set below to be configured | |
134 std::set<std::string> uselessSyntaxes; | |
135 uselessSyntaxes.insert(UID_BlendingSoftcopyPresentationStateStorage); | |
136 uselessSyntaxes.insert(UID_GrayscaleSoftcopyPresentationStateStorage); | |
137 uselessSyntaxes.insert(UID_ColorSoftcopyPresentationStateStorage); | |
138 uselessSyntaxes.insert(UID_PseudoColorSoftcopyPresentationStateStorage); | |
139 | |
140 // Add the transfer syntaxes for C-STORE | |
141 for (int i = 0; i < numberOfDcmShortSCUStorageSOPClassUIDs - 1; i++) | |
142 { | |
143 // Test to make some room to allow the ECHO and FIND requests | |
144 if (uselessSyntaxes.find(dcmShortSCUStorageSOPClassUIDs[i]) == uselessSyntaxes.end()) | |
145 { | |
146 transferSyntaxes.push_back(dcmShortSCUStorageSOPClassUIDs[i]); | |
147 } | |
148 } | |
149 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
150 // Flatten the fallback transfer syntaxes array |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
151 const char* asPreferred[1] = { preferredTransferSyntax.c_str() }; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
152 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
153 fallbackSyntaxes.erase(preferredTransferSyntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
154 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
155 std::vector<const char*> asFallback; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
156 asFallback.reserve(fallbackSyntaxes.size()); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
157 for (std::set<std::string>::const_iterator |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
158 it = fallbackSyntaxes.begin(); it != fallbackSyntaxes.end(); ++it) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
159 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
160 asFallback.push_back(it->c_str()); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
161 } |
0 | 162 |
163 unsigned int presentationContextId = 1; | |
164 for (size_t i = 0; i < transferSyntaxes.size(); i++) | |
165 { | |
166 Check(ASC_addPresentationContext(pimpl_->params_, presentationContextId, | |
167 transferSyntaxes[i].c_str(), asPreferred, 1)); | |
168 presentationContextId += 2; | |
169 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
170 if (asFallback.size() > 0) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
171 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
172 Check(ASC_addPresentationContext(pimpl_->params_, presentationContextId, |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
173 transferSyntaxes[i].c_str(), &asFallback[0], asFallback.size())); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
174 presentationContextId += 2; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
175 } |
0 | 176 } |
177 } | |
178 | |
179 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
180 static bool IsGenericTransferSyntax(const std::string& syntax) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
181 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
182 return (syntax == UID_LittleEndianExplicitTransferSyntax || |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
183 syntax == UID_BigEndianExplicitTransferSyntax || |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
184 syntax == UID_LittleEndianImplicitTransferSyntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
185 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
186 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
187 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
188 void DicomUserConnection::PImpl::Store(DcmInputStream& is, DicomUserConnection& connection) |
0 | 189 { |
190 CheckIsOpen(); | |
191 | |
192 DcmFileFormat dcmff; | |
193 Check(dcmff.read(is, EXS_Unknown, EGL_noChange, DCM_MaxReadLength)); | |
194 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
195 // Determine whether a new presentation context must be |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
196 // negociated, depending on the transfer syntax of this instance |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
197 DcmXfer xfer(dcmff.getDataset()->getOriginalXfer()); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
198 const std::string syntax(xfer.getXferID()); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
199 bool isGeneric = IsGenericTransferSyntax(syntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
200 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
201 if (isGeneric ^ IsGenericTransferSyntax(connection.GetPreferredTransferSyntax())) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
202 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
203 // Making a generic-to-specific or specific-to-generic change of |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
204 // the transfer syntax. Renegociate the connection. |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
205 LOG(INFO) << "Renegociating a C-Store association due to a change in the transfer syntax"; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
206 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
207 if (isGeneric) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
208 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
209 connection.ResetPreferredTransferSyntax(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
210 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
211 else |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
212 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
213 connection.SetPreferredTransferSyntax(syntax); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
214 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
215 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
216 connection.Open(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
217 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
218 |
0 | 219 // Figure out which SOP class and SOP instance is encapsulated in the file |
220 DIC_UI sopClass; | |
221 DIC_UI sopInstance; | |
222 if (!DU_findSOPClassAndInstanceInDataSet(dcmff.getDataset(), sopClass, sopInstance)) | |
223 { | |
62 | 224 throw OrthancException("DicomUserConnection: Unable to find the SOP class and instance"); |
0 | 225 } |
226 | |
227 // Figure out which of the accepted presentation contexts should be used | |
228 int presID = ASC_findAcceptedPresentationContextID(assoc_, sopClass); | |
229 if (presID == 0) | |
230 { | |
231 const char *modalityName = dcmSOPClassUIDToModality(sopClass); | |
232 if (!modalityName) modalityName = dcmFindNameOfUID(sopClass); | |
233 if (!modalityName) modalityName = "unknown SOP class"; | |
62 | 234 throw OrthancException("DicomUserConnection: No presentation context for modality " + |
0 | 235 std::string(modalityName)); |
236 } | |
237 | |
238 // Prepare the transmission of data | |
239 T_DIMSE_C_StoreRQ req; | |
240 memset(&req, 0, sizeof(req)); | |
241 req.MessageID = assoc_->nextMsgID++; | |
242 strcpy(req.AffectedSOPClassUID, sopClass); | |
243 strcpy(req.AffectedSOPInstanceUID, sopInstance); | |
244 req.DataSetType = DIMSE_DATASET_PRESENT; | |
245 req.Priority = DIMSE_PRIORITY_MEDIUM; | |
246 | |
247 // Finally conduct transmission of data | |
248 T_DIMSE_C_StoreRSP rsp; | |
249 DcmDataset* statusDetail = NULL; | |
250 Check(DIMSE_storeUser(assoc_, presID, &req, | |
251 NULL, dcmff.getDataset(), /*progressCallback*/ NULL, NULL, | |
252 /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0, | |
253 &rsp, &statusDetail, NULL)); | |
254 | |
255 if (statusDetail != NULL) | |
256 { | |
257 delete statusDetail; | |
258 } | |
259 } | |
260 | |
261 | |
262 static void FindCallback( | |
263 /* in */ | |
264 void *callbackData, | |
265 T_DIMSE_C_FindRQ *request, /* original find request */ | |
266 int responseCount, | |
267 T_DIMSE_C_FindRSP *response, /* pending response received */ | |
268 DcmDataset *responseIdentifiers /* pending response identifiers */ | |
269 ) | |
270 { | |
657
5425bb6f1ea5
further cppcheck fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
271 DicomFindAnswers& answers = *reinterpret_cast<DicomFindAnswers*>(callbackData); |
0 | 272 |
273 if (responseIdentifiers != NULL) | |
274 { | |
275 DicomMap m; | |
276 FromDcmtkBridge::Convert(m, *responseIdentifiers); | |
277 answers.Add(m); | |
278 } | |
279 } | |
280 | |
281 void DicomUserConnection::Find(DicomFindAnswers& result, | |
282 FindRootModel model, | |
283 const DicomMap& fields) | |
284 { | |
285 CheckIsOpen(); | |
286 | |
287 const char* sopClass; | |
288 std::auto_ptr<DcmDataset> dataset(ToDcmtkBridge::Convert(fields)); | |
289 switch (model) | |
290 { | |
291 case FindRootModel_Patient: | |
292 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0052), "PATIENT"); | |
293 sopClass = UID_FINDPatientRootQueryRetrieveInformationModel; | |
294 | |
295 // Accession number | |
296 if (!fields.HasTag(0x0008, 0x0050)) | |
297 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0050), ""); | |
298 | |
299 // Patient ID | |
300 if (!fields.HasTag(0x0010, 0x0020)) | |
301 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0010, 0x0020), ""); | |
302 | |
303 break; | |
304 | |
305 case FindRootModel_Study: | |
306 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0052), "STUDY"); | |
307 sopClass = UID_FINDStudyRootQueryRetrieveInformationModel; | |
308 | |
309 // Accession number | |
310 if (!fields.HasTag(0x0008, 0x0050)) | |
311 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0050), ""); | |
312 | |
313 // Study instance UID | |
314 if (!fields.HasTag(0x0020, 0x000d)) | |
315 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0020, 0x000d), ""); | |
316 | |
317 break; | |
318 | |
319 case FindRootModel_Series: | |
320 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0052), "SERIES"); | |
321 sopClass = UID_FINDStudyRootQueryRetrieveInformationModel; | |
322 | |
323 // Accession number | |
324 if (!fields.HasTag(0x0008, 0x0050)) | |
325 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0050), ""); | |
326 | |
327 // Study instance UID | |
328 if (!fields.HasTag(0x0020, 0x000d)) | |
329 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0020, 0x000d), ""); | |
330 | |
331 // Series instance UID | |
332 if (!fields.HasTag(0x0020, 0x000e)) | |
333 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0020, 0x000e), ""); | |
334 | |
335 break; | |
336 | |
337 case FindRootModel_Instance: | |
519
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
338 if (manufacturer_ == ModalityManufacturer_ClearCanvas) |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
339 { |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
340 // This is a particular case for ClearCanvas, thanks to Peter Somlo <peter.somlo@gmail.com>. |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
341 // https://groups.google.com/d/msg/orthanc-users/j-6C3MAVwiw/iolB9hclom8J |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
342 // http://www.clearcanvas.ca/Home/Community/OldForums/tabid/526/aff/11/aft/14670/afv/topic/Default.aspx |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
343 printf("CLEAR CANVAS\n"); |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
344 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0052), "IMAGE"); |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
345 } |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
346 else |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
347 { |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
348 printf("GENERIC\n"); |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
349 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0052), "INSTANCE"); |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
350 } |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
351 |
0 | 352 sopClass = UID_FINDStudyRootQueryRetrieveInformationModel; |
353 | |
354 // Accession number | |
355 if (!fields.HasTag(0x0008, 0x0050)) | |
356 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0050), ""); | |
357 | |
358 // Study instance UID | |
359 if (!fields.HasTag(0x0020, 0x000d)) | |
360 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0020, 0x000d), ""); | |
361 | |
362 // Series instance UID | |
363 if (!fields.HasTag(0x0020, 0x000e)) | |
364 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0020, 0x000e), ""); | |
365 | |
366 // SOP Instance UID | |
367 if (!fields.HasTag(0x0008, 0x0018)) | |
368 DU_putStringDOElement(dataset.get(), DcmTagKey(0x0008, 0x0018), ""); | |
369 | |
370 break; | |
371 | |
372 default: | |
62 | 373 throw OrthancException(ErrorCode_ParameterOutOfRange); |
0 | 374 } |
375 | |
376 // Figure out which of the accepted presentation contexts should be used | |
377 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass); | |
378 if (presID == 0) | |
379 { | |
62 | 380 throw OrthancException("DicomUserConnection: The C-FIND command is not supported by the distant AET"); |
0 | 381 } |
382 | |
383 T_DIMSE_C_FindRQ request; | |
384 memset(&request, 0, sizeof(request)); | |
385 request.MessageID = pimpl_->assoc_->nextMsgID++; | |
386 strcpy(request.AffectedSOPClassUID, sopClass); | |
387 request.DataSetType = DIMSE_DATASET_PRESENT; | |
388 request.Priority = DIMSE_PRIORITY_MEDIUM; | |
389 | |
390 T_DIMSE_C_FindRSP response; | |
391 DcmDataset* statusDetail = NULL; | |
392 OFCondition cond = DIMSE_findUser(pimpl_->assoc_, presID, &request, dataset.get(), | |
393 FindCallback, &result, | |
394 /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0, | |
395 &response, &statusDetail); | |
396 | |
397 if (statusDetail) | |
398 { | |
399 delete statusDetail; | |
400 } | |
401 | |
402 Check(cond); | |
403 } | |
404 | |
405 | |
406 void DicomUserConnection::FindPatient(DicomFindAnswers& result, | |
407 const DicomMap& fields) | |
408 { | |
409 // Only keep the filters from "fields" that are related to the patient | |
410 DicomMap s; | |
411 fields.ExtractPatientInformation(s); | |
412 Find(result, FindRootModel_Patient, s); | |
413 } | |
414 | |
415 void DicomUserConnection::FindStudy(DicomFindAnswers& result, | |
416 const DicomMap& fields) | |
417 { | |
418 // Only keep the filters from "fields" that are related to the study | |
419 DicomMap s; | |
420 fields.ExtractStudyInformation(s); | |
421 | |
80 | 422 s.CopyTagIfExists(fields, DICOM_TAG_PATIENT_ID); |
423 s.CopyTagIfExists(fields, DICOM_TAG_ACCESSION_NUMBER); | |
0 | 424 |
425 Find(result, FindRootModel_Study, s); | |
426 } | |
427 | |
428 void DicomUserConnection::FindSeries(DicomFindAnswers& result, | |
429 const DicomMap& fields) | |
430 { | |
431 // Only keep the filters from "fields" that are related to the series | |
432 DicomMap s; | |
433 fields.ExtractSeriesInformation(s); | |
434 | |
80 | 435 s.CopyTagIfExists(fields, DICOM_TAG_PATIENT_ID); |
436 s.CopyTagIfExists(fields, DICOM_TAG_ACCESSION_NUMBER); | |
437 s.CopyTagIfExists(fields, DICOM_TAG_STUDY_INSTANCE_UID); | |
0 | 438 |
439 Find(result, FindRootModel_Series, s); | |
440 } | |
441 | |
442 void DicomUserConnection::FindInstance(DicomFindAnswers& result, | |
443 const DicomMap& fields) | |
444 { | |
445 // Only keep the filters from "fields" that are related to the instance | |
446 DicomMap s; | |
447 fields.ExtractInstanceInformation(s); | |
448 | |
80 | 449 s.CopyTagIfExists(fields, DICOM_TAG_PATIENT_ID); |
450 s.CopyTagIfExists(fields, DICOM_TAG_ACCESSION_NUMBER); | |
451 s.CopyTagIfExists(fields, DICOM_TAG_STUDY_INSTANCE_UID); | |
452 s.CopyTagIfExists(fields, DICOM_TAG_SERIES_INSTANCE_UID); | |
0 | 453 |
454 Find(result, FindRootModel_Instance, s); | |
455 } | |
456 | |
457 | |
458 void DicomUserConnection::Move(const std::string& targetAet, | |
459 const DicomMap& fields) | |
460 { | |
461 CheckIsOpen(); | |
462 | |
463 const char* sopClass = UID_MOVEStudyRootQueryRetrieveInformationModel; | |
464 std::auto_ptr<DcmDataset> dataset(ToDcmtkBridge::Convert(fields)); | |
465 | |
466 // Figure out which of the accepted presentation contexts should be used | |
467 int presID = ASC_findAcceptedPresentationContextID(pimpl_->assoc_, sopClass); | |
468 if (presID == 0) | |
469 { | |
62 | 470 throw OrthancException("DicomUserConnection: The C-MOVE command is not supported by the distant AET"); |
0 | 471 } |
472 | |
473 T_DIMSE_C_MoveRQ request; | |
474 memset(&request, 0, sizeof(request)); | |
475 request.MessageID = pimpl_->assoc_->nextMsgID++; | |
476 strcpy(request.AffectedSOPClassUID, sopClass); | |
477 request.DataSetType = DIMSE_DATASET_PRESENT; | |
478 request.Priority = DIMSE_PRIORITY_MEDIUM; | |
479 strncpy(request.MoveDestination, targetAet.c_str(), sizeof(DIC_AE) / sizeof(char)); | |
480 | |
481 T_DIMSE_C_MoveRSP response; | |
482 DcmDataset* statusDetail = NULL; | |
483 DcmDataset* responseIdentifiers = NULL; | |
484 OFCondition cond = DIMSE_moveUser(pimpl_->assoc_, presID, &request, dataset.get(), | |
485 NULL, NULL, | |
486 /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0, | |
487 pimpl_->net_, NULL, NULL, | |
488 &response, &statusDetail, &responseIdentifiers); | |
489 | |
490 if (statusDetail) | |
491 { | |
492 delete statusDetail; | |
493 } | |
494 | |
495 if (responseIdentifiers) | |
496 { | |
497 delete responseIdentifiers; | |
498 } | |
499 | |
500 Check(cond); | |
501 } | |
502 | |
503 | |
656 | 504 DicomUserConnection::DicomUserConnection() : |
505 pimpl_(new PImpl), | |
666
b8383ac0b227
fix cppcheck warning
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
662
diff
changeset
|
506 preferredTransferSyntax_(DEFAULT_PREFERRED_TRANSFER_SYNTAX), |
656 | 507 localAet_("STORESCU"), |
508 distantAet_("ANY-SCP"), | |
509 distantHost_("127.0.0.1") | |
0 | 510 { |
511 distantPort_ = 104; | |
519
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
512 manufacturer_ = ModalityManufacturer_Generic; |
0 | 513 |
514 pimpl_->net_ = NULL; | |
515 pimpl_->params_ = NULL; | |
516 pimpl_->assoc_ = NULL; | |
517 } | |
518 | |
519 DicomUserConnection::~DicomUserConnection() | |
520 { | |
521 Close(); | |
522 } | |
523 | |
524 void DicomUserConnection::SetLocalApplicationEntityTitle(const std::string& aet) | |
525 { | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
526 if (localAet_ != aet) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
527 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
528 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
529 localAet_ = aet; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
530 } |
0 | 531 } |
532 | |
533 void DicomUserConnection::SetDistantApplicationEntityTitle(const std::string& aet) | |
534 { | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
535 if (distantAet_ != aet) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
536 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
537 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
538 distantAet_ = aet; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
539 } |
0 | 540 } |
541 | |
519
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
542 void DicomUserConnection::SetDistantManufacturer(ModalityManufacturer manufacturer) |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
543 { |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
544 if (manufacturer_ != manufacturer) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
545 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
546 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
547 manufacturer_ = manufacturer; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
548 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
549 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
550 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
551 void DicomUserConnection::ResetPreferredTransferSyntax() |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
552 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
553 SetPreferredTransferSyntax(DEFAULT_PREFERRED_TRANSFER_SYNTAX); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
554 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
555 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
556 void DicomUserConnection::SetPreferredTransferSyntax(const std::string& preferredTransferSyntax) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
557 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
558 if (preferredTransferSyntax_ != preferredTransferSyntax) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
559 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
560 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
561 preferredTransferSyntax_ = preferredTransferSyntax; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
562 } |
519
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
563 } |
1b2cdc855bd3
Parameter for PACS manufacturer, support for ClearCanvas
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
564 |
0 | 565 |
566 void DicomUserConnection::SetDistantHost(const std::string& host) | |
567 { | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
568 if (distantHost_ != host) |
0 | 569 { |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
570 if (host.size() > HOST_NAME_MAX - 10) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
571 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
572 throw OrthancException("Distant host name is too long"); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
573 } |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
574 |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
575 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
576 distantHost_ = host; |
0 | 577 } |
578 } | |
579 | |
580 void DicomUserConnection::SetDistantPort(uint16_t port) | |
581 { | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
582 if (distantPort_ != port) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
583 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
584 Close(); |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
585 distantPort_ = port; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
586 } |
0 | 587 } |
588 | |
589 void DicomUserConnection::Open() | |
590 { | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
591 if (IsOpen()) |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
592 { |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
593 // Don't reopen the connection |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
594 return; |
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
595 } |
0 | 596 |
597 Check(ASC_initializeNetwork(NET_REQUESTOR, 0, /*opt_acse_timeout*/ 30, &pimpl_->net_)); | |
598 Check(ASC_createAssociationParameters(&pimpl_->params_, /*opt_maxReceivePDULength*/ ASC_DEFAULTMAXPDU)); | |
599 | |
600 // Set this application's title and the called application's title in the params | |
601 Check(ASC_setAPTitles(pimpl_->params_, localAet_.c_str(), distantAet_.c_str(), NULL)); | |
602 | |
603 // Set the network addresses of the local and distant entities | |
604 char localHost[HOST_NAME_MAX]; | |
605 gethostname(localHost, HOST_NAME_MAX - 1); | |
606 | |
607 char distantHostAndPort[HOST_NAME_MAX]; | |
2 | 608 |
609 #ifdef _MSC_VER | |
610 _snprintf | |
611 #else | |
612 snprintf | |
613 #endif | |
614 (distantHostAndPort, HOST_NAME_MAX - 1, "%s:%d", distantHost_.c_str(), distantPort_); | |
0 | 615 |
616 Check(ASC_setPresentationAddresses(pimpl_->params_, localHost, distantHostAndPort)); | |
617 | |
618 // Set various options | |
619 Check(ASC_setTransportLayerType(pimpl_->params_, /*opt_secureConnection*/ false)); | |
620 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
621 SetupPresentationContexts(preferredTransferSyntax_); |
0 | 622 |
623 // Do the association | |
624 Check(ASC_requestAssociation(pimpl_->net_, pimpl_->params_, &pimpl_->assoc_)); | |
625 | |
626 if (ASC_countAcceptedPresentationContexts(pimpl_->params_) == 0) | |
627 { | |
62 | 628 throw OrthancException("DicomUserConnection: No Acceptable Presentation Contexts"); |
0 | 629 } |
630 } | |
631 | |
632 void DicomUserConnection::Close() | |
633 { | |
634 if (pimpl_->assoc_ != NULL) | |
635 { | |
636 ASC_releaseAssociation(pimpl_->assoc_); | |
637 ASC_destroyAssociation(&pimpl_->assoc_); | |
638 pimpl_->assoc_ = NULL; | |
639 pimpl_->params_ = NULL; | |
640 } | |
641 else | |
642 { | |
643 if (pimpl_->params_ != NULL) | |
644 { | |
645 ASC_destroyAssociationParameters(&pimpl_->params_); | |
646 pimpl_->params_ = NULL; | |
647 } | |
648 } | |
649 | |
650 if (pimpl_->net_ != NULL) | |
651 { | |
652 ASC_dropNetwork(&pimpl_->net_); | |
653 pimpl_->net_ = NULL; | |
654 } | |
655 } | |
656 | |
657 bool DicomUserConnection::IsOpen() const | |
658 { | |
659 return pimpl_->IsOpen(); | |
660 } | |
661 | |
662 void DicomUserConnection::Store(const char* buffer, size_t size) | |
663 { | |
664 // Prepare an input stream for the memory buffer | |
665 DcmInputBufferStream is; | |
666 if (size > 0) | |
667 is.setBuffer(buffer, size); | |
668 is.setEos(); | |
669 | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
670 pimpl_->Store(is, *this); |
0 | 671 } |
672 | |
673 void DicomUserConnection::Store(const std::string& buffer) | |
674 { | |
675 if (buffer.size() > 0) | |
676 Store(reinterpret_cast<const char*>(&buffer[0]), buffer.size()); | |
677 else | |
678 Store(NULL, 0); | |
679 } | |
680 | |
681 void DicomUserConnection::StoreFile(const std::string& path) | |
682 { | |
683 // Prepare an input stream for the file | |
684 DcmInputFileStream is(path.c_str()); | |
662
70161eb45b5c
orthanc can act as a C-Store SCU for JPEG transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
657
diff
changeset
|
685 pimpl_->Store(is, *this); |
0 | 686 } |
687 | |
688 bool DicomUserConnection::Echo() | |
689 { | |
690 CheckIsOpen(); | |
691 DIC_US status; | |
692 Check(DIMSE_echoUser(pimpl_->assoc_, pimpl_->assoc_->nextMsgID++, | |
693 /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0, | |
694 &status, NULL)); | |
695 return status == STATUS_Success; | |
696 } | |
697 | |
698 | |
699 void DicomUserConnection::MoveSeries(const std::string& targetAet, | |
700 const DicomMap& findResult) | |
701 { | |
702 DicomMap simplified; | |
80 | 703 simplified.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, findResult.GetValue(DICOM_TAG_STUDY_INSTANCE_UID)); |
704 simplified.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, findResult.GetValue(DICOM_TAG_SERIES_INSTANCE_UID)); | |
0 | 705 Move(targetAet, simplified); |
706 } | |
707 | |
708 void DicomUserConnection::MoveSeries(const std::string& targetAet, | |
709 const std::string& studyUid, | |
710 const std::string& seriesUid) | |
711 { | |
712 DicomMap map; | |
80 | 713 map.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, studyUid); |
714 map.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, seriesUid); | |
0 | 715 Move(targetAet, map); |
716 } | |
717 | |
718 void DicomUserConnection::MoveInstance(const std::string& targetAet, | |
719 const DicomMap& findResult) | |
720 { | |
721 DicomMap simplified; | |
80 | 722 simplified.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, findResult.GetValue(DICOM_TAG_STUDY_INSTANCE_UID)); |
723 simplified.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, findResult.GetValue(DICOM_TAG_SERIES_INSTANCE_UID)); | |
724 simplified.SetValue(DICOM_TAG_SOP_INSTANCE_UID, findResult.GetValue(DICOM_TAG_SOP_INSTANCE_UID)); | |
0 | 725 Move(targetAet, simplified); |
726 } | |
727 | |
728 void DicomUserConnection::MoveInstance(const std::string& targetAet, | |
729 const std::string& studyUid, | |
730 const std::string& seriesUid, | |
731 const std::string& instanceUid) | |
732 { | |
733 DicomMap map; | |
80 | 734 map.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, studyUid); |
735 map.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, seriesUid); | |
736 map.SetValue(DICOM_TAG_SOP_INSTANCE_UID, instanceUid); | |
0 | 737 Move(targetAet, map); |
738 } | |
739 | |
740 void DicomUserConnection::SetConnectionTimeout(uint32_t seconds) | |
741 { | |
742 dcmConnectionTimeout.set(seconds); | |
743 } | |
744 | |
745 } |