annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2552:54b4cab77f12

new Orthanc framework available
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Apr 2018 09:32:20 +0200
parents 6db878376018
children 75a404e40323
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
4 * Department, University Hospital of Liege, Belgium
2447
878b59270859 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
37 #include "../../Core/Logging.h"
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
38 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
39 #include "../ServerContext.h"
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
40 #include "../OrthancInitialization.h"
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
41
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
42 #include <boost/lexical_cast.hpp>
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
43 #include <boost/algorithm/string/predicate.hpp>
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
44
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 // Modification of DICOM instances ------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
49
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 static std::string GeneratePatientName(ServerContext& context)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 return "Anonymized" + boost::lexical_cast<std::string>(seq);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
57 static void ParseModifyRequest(DicomModification& target,
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
58 const RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
59 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
60 // curl http://localhost:8042/series/95a6e2bf-9296e2cc-bf614e2f-22b391ee-16e010e0/modify -X POST -d '{"Replace":{"InstitutionName":"My own clinic"}}'
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
61
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
62 Json::Value request;
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
63 if (call.ParseJsonRequest(request))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
64 {
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
65 target.ParseModifyRequest(request);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
66 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
67 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
68 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
69 throw OrthancException(ErrorCode_BadFileFormat);
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
70 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
71 }
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
72
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
73
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
74 static void ParseAnonymizationRequest(DicomModification& target,
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
75 RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
76 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
77 // curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{"Replace":{"PatientName":"hello","0010-0020":"world"},"Keep":["StudyDescription", "SeriesDescription"],"KeepPrivateTags": true,"Remove":["Modality"]}' > Anonymized.dcm
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
78
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
79 Json::Value request;
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
80 if (call.ParseJsonRequest(request) &&
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
81 request.isObject())
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
82 {
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
83 bool patientNameReplaced;
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
84 target.ParseAnonymizationRequest(patientNameReplaced, request);
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
85
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
86 if (patientNameReplaced)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
87 {
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
88 // Overwrite the random Patient's Name by one that is more
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
89 // user-friendly (provided none was specified by the user)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
90 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true);
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
91 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
92 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
93 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
94 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
95 throw OrthancException(ErrorCode_BadFileFormat);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
96 }
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
97 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
98
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
99
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
100 static void AnonymizeOrModifyInstance(DicomModification& modification,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
101 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
103 std::string id = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
105 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
106
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
107 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone(true));
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
108 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 modified->Answer(call.GetOutput());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
113 static void AnonymizeOrModifyResource(DicomModification& modification,
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 MetadataType metadataType,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ChangeType changeType,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ResourceType resourceType,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
117 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 bool isFirst = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 Json::Value result(Json::objectValue);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
124 typedef std::list<std::string> Instances;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 Instances instances;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 std::string id = call.GetUriComponent("id", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 context.GetIndex().GetChildInstances(instances, id);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (instances.empty())
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
134
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 * Loop over all the instances of the resource.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 for (Instances::const_iterator it = instances.begin();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 it != instances.end(); ++it)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 LOG(INFO) << "Modifying instance " << *it;
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
143
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
144 std::auto_ptr<ServerContext::DicomCacheLocker> locker;
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
145
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
146 try
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
147 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
148 locker.reset(new ServerContext::DicomCacheLocker(OrthancRestApi::GetContext(call), *it));
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
149 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
150 catch (OrthancException&)
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
151 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
152 // This child instance has been removed in between
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
153 continue;
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
154 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
155
1129
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1120
diff changeset
156
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
157 ParsedDicomFile& original = locker->GetDicom();
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 DicomInstanceHasher originalHasher = original.GetHasher();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 /**
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
162 * Compute the resulting DICOM instance.
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
165 std::auto_ptr<ParsedDicomFile> modified(original.Clone(true));
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
166 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
168 DicomInstanceToStore toStore;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
169 toStore.SetRestOrigin(call);
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
170 toStore.SetParsedDicomFile(*modified);
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
171
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
172
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
173 /**
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
174 * Prepare the metadata information to associate with the
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
175 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom).
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
176 **/
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
177
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
178 DicomInstanceHasher modifiedHasher = modified->GetHasher();
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
179
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
180 if (originalHasher.HashSeries() != modifiedHasher.HashSeries())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
181 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
182 toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher.HashSeries());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
183 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
184
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
185 if (originalHasher.HashStudy() != modifiedHasher.HashStudy())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
186 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
187 toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher.HashStudy());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
188 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
189
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
190 if (originalHasher.HashPatient() != modifiedHasher.HashPatient())
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
191 {
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
192 toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher.HashPatient());
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
193 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
194
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
195 assert(*it == originalHasher.HashInstance());
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
196 toStore.AddMetadata(ResourceType_Instance, metadataType, *it);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
197
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
198
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
199 /**
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
200 * Store the resulting DICOM instance into the Orthanc store.
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
201 **/
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
202
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 std::string modifiedInstance;
1005
84b6d7bca6db refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
204 if (context.Store(modifiedInstance, toStore) != StoreStatus_Success)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
206 LOG(ERROR) << "Error while storing a modified instance " << *it;
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
207 throw OrthancException(ErrorCode_CannotStoreInstance);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
210 // Sanity checks in debug mode
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 assert(modifiedInstance == modifiedHasher.HashInstance());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 * Compute the JSON object that is returned by the REST call.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 if (isFirst)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 std::string newId;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 switch (resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 case ResourceType_Series:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 newId = modifiedHasher.HashSeries();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 case ResourceType_Study:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 newId = modifiedHasher.HashStudy();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 case ResourceType_Patient:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 newId = modifiedHasher.HashPatient();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 default:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 throw OrthancException(ErrorCode_InternalError);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 result["Type"] = EnumerationToString(resourceType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 result["ID"] = newId;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 result["Path"] = GetBasePath(resourceType, newId);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 result["PatientID"] = modifiedHasher.HashPatient();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 isFirst = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 call.GetOutput().AnswerJson(result);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
253 static void ModifyInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
255 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
256 modification.SetAllowManualIdentifiers(true);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
257
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
258 ParseModifyRequest(modification, call);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
259
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
260 if (modification.IsReplaced(DICOM_TAG_PATIENT_ID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
261 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
262 modification.SetLevel(ResourceType_Patient);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
263 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
264 else if (modification.IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
266 modification.SetLevel(ResourceType_Study);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
267 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
268 else if (modification.IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
269 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
270 modification.SetLevel(ResourceType_Series);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
271 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
272 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
273 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
274 modification.SetLevel(ResourceType_Instance);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
275 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
276
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
277 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
281 static void AnonymizeInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
283 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
284 modification.SetAllowManualIdentifiers(true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
286 ParseAnonymizationRequest(modification, call);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
287
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
288 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
292 template <enum ChangeType changeType,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
293 enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
294 static void ModifyResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
296 DicomModification modification;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
298 ParseModifyRequest(modification, call);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
299
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
300 modification.SetLevel(resourceType);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
301 AnonymizeOrModifyResource(modification, MetadataType_ModifiedFrom,
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
302 changeType, resourceType, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
306 template <enum ChangeType changeType,
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
307 enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
308 static void AnonymizeResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
310 DicomModification modification;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
312 ParseAnonymizationRequest(modification, call);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
313
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
314 AnonymizeOrModifyResource(modification, MetadataType_AnonymizedFrom,
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
315 changeType, resourceType, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
319 static void StoreCreatedInstance(std::string& id /* out */,
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
320 RestApiPostCall& call,
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
321 ParsedDicomFile& dicom)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
322 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
323 DicomInstanceToStore toStore;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
324 toStore.SetRestOrigin(call);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
325 toStore.SetParsedDicomFile(dicom);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
326
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
327 ServerContext& context = OrthancRestApi::GetContext(call);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
328 StoreStatus status = context.Store(id, toStore);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
329
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
330 if (status == StoreStatus_Failure)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
331 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
332 throw OrthancException(ErrorCode_CannotStoreInstance);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
333 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
334 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
335
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
336
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
337 static void CreateDicomV1(ParsedDicomFile& dicom,
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
338 RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
339 const Json::Value& request)
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
340 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
341 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World"}'
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 796
diff changeset
342 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World","PixelData":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="}'
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
343
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
344 assert(request.isObject());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
345 LOG(WARNING) << "Using a deprecated call to /tools/create-dicom";
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
346
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
347 Json::Value::Members members = request.getMemberNames();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
348 for (size_t i = 0; i < members.size(); i++)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
349 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
350 const std::string& name = members[i];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
351 if (request[name].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
352 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
353 throw OrthancException(ErrorCode_CreateDicomNotString);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
354 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
355
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
356 std::string value = request[name].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
357
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
358 DicomTag tag = FromDcmtkBridge::ParseTag(name);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
359 if (tag == DICOM_TAG_PIXEL_DATA)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
360 {
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
361 dicom.EmbedContent(value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
362 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
363 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
364 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
365 // This is V1, don't try and decode data URI scheme
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
366 dicom.ReplacePlainString(tag, value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
367 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
368 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
369 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
370
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
371
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
372 static void InjectTags(ParsedDicomFile& dicom,
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
373 const Json::Value& tags,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
374 bool decodeBinaryTags)
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
375 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
376 if (tags.type() != Json::objectValue)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
377 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
378 throw OrthancException(ErrorCode_BadRequest);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
379 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
380
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
381 // Inject the user-specified tags
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
382 Json::Value::Members members = tags.getMemberNames();
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
383 for (size_t i = 0; i < members.size(); i++)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
384 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
385 const std::string& name = members[i];
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
386 DicomTag tag = FromDcmtkBridge::ParseTag(name);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
387
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
388 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
389 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
390 if (tag != DICOM_TAG_PATIENT_ID &&
1640
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
391 tag != DICOM_TAG_ACQUISITION_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
392 tag != DICOM_TAG_ACQUISITION_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
393 tag != DICOM_TAG_CONTENT_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
394 tag != DICOM_TAG_CONTENT_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
395 tag != DICOM_TAG_INSTANCE_CREATION_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
396 tag != DICOM_TAG_INSTANCE_CREATION_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
397 tag != DICOM_TAG_SERIES_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
398 tag != DICOM_TAG_SERIES_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
399 tag != DICOM_TAG_STUDY_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
400 tag != DICOM_TAG_STUDY_TIME &&
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
401 dicom.HasTag(tag))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
402 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
403 throw OrthancException(ErrorCode_CreateDicomOverrideTag);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
404 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
405
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
406 if (tag == DICOM_TAG_PIXEL_DATA)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
407 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
408 throw OrthancException(ErrorCode_CreateDicomUseContent);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
409 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
410 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
411 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
412 dicom.Replace(tag, tags[name], decodeBinaryTags, DicomReplaceMode_InsertIfAbsent);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
413 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
414 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
415 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
416 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
417
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
418
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
419 static void CreateSeries(RestApiPostCall& call,
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
420 ParsedDicomFile& base /* in */,
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
421 const Json::Value& content,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
422 bool decodeBinaryTags)
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
423 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
424 assert(content.isArray());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
425 assert(content.size() > 0);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
426 ServerContext& context = OrthancRestApi::GetContext(call);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
427
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
428 base.ReplacePlainString(DICOM_TAG_IMAGES_IN_ACQUISITION, boost::lexical_cast<std::string>(content.size()));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
429 base.ReplacePlainString(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "1");
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
430
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
431 std::string someInstance;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
432
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
433 try
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
434 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
435 for (Json::ArrayIndex i = 0; i < content.size(); i++)
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
436 {
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
437 std::auto_ptr<ParsedDicomFile> dicom(base.Clone(false));
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
438 const Json::Value* payload = NULL;
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
439
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
440 if (content[i].type() == Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
441 {
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
442 payload = &content[i];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
443 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
444 else if (content[i].type() == Json::objectValue)
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
445 {
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
446 if (!content[i].isMember("Content"))
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
447 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
448 throw OrthancException(ErrorCode_CreateDicomNoPayload);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
449 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
450
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
451 payload = &content[i]["Content"];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
452
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
453 if (content[i].isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
454 {
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
455 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
456 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
457 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
458
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
459 if (payload == NULL ||
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
460 payload->type() != Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
461 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
462 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
463 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
464
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
465 dicom->EmbedContent(payload->asString());
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
466 dicom->ReplacePlainString(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1));
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
467 dicom->ReplacePlainString(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1));
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
468
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
469 StoreCreatedInstance(someInstance, call, *dicom);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
470 }
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
471 }
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
472 catch (OrthancException&)
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
473 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
474 // Error: Remove the newly-created series
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
475
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
476 std::string series;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
477 if (context.GetIndex().LookupParent(series, someInstance))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
478 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
479 Json::Value dummy;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
480 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
481 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
482
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
483 throw;
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
484 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
485
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
486 std::string series;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
487 if (context.GetIndex().LookupParent(series, someInstance))
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
488 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
489 OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
490 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
491 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
492
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
493
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
494 static void CreateDicomV2(RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
495 const Json::Value& request)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
496 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
497 assert(request.isObject());
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
498 ServerContext& context = OrthancRestApi::GetContext(call);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
499
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
500 if (!request.isMember("Tags") ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
501 request["Tags"].type() != Json::objectValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
502 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
503 throw OrthancException(ErrorCode_BadRequest);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
504 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
505
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
506 ParsedDicomFile dicom(true);
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
507
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
508 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
509 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
510
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
511 if (request["Tags"].isMember("SpecificCharacterSet"))
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
512 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
513 const char* tmp = request["Tags"]["SpecificCharacterSet"].asCString();
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
514 if (!GetDicomEncoding(encoding, tmp))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
515 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
516 LOG(ERROR) << "Unknown specific character set: " << std::string(tmp);
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
517 throw OrthancException(ErrorCode_ParameterOutOfRange);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
518 }
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
519 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
520 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
521 {
2381
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2361
diff changeset
522 encoding = GetDefaultDicomEncoding();
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
523 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
524
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
525 dicom.SetEncoding(encoding);
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
526 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
527
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
528 ResourceType parentType = ResourceType_Instance;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
529
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
530 if (request.isMember("Parent"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
531 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
532 // Locate the parent tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
533 std::string parent = request["Parent"].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
534 if (!context.GetIndex().LookupResourceType(parentType, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
535 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
536 throw OrthancException(ErrorCode_CreateDicomBadParent);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
537 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
538
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
539 if (parentType == ResourceType_Instance)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
540 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
541 throw OrthancException(ErrorCode_CreateDicomParentIsInstance);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
542 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
543
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
544 // Select one existing child instance of the parent resource, to
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
545 // retrieve all its tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
546 Json::Value siblingTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
547
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
548 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
549 // Retrieve all the instances of the parent resource
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
550 std::list<std::string> siblingInstances;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
551 context.GetIndex().GetChildInstances(siblingInstances, parent);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
552
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
553 if (siblingInstances.empty())
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
554 {
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
555 // Error: No instance (should never happen)
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
556 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
557 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
558
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
559 context.ReadDicomAsJson(siblingTags, siblingInstances.front());
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
560 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
561
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
562
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
563 // Choose the same encoding as the parent resource
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
564 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
565 static const char* SPECIFIC_CHARACTER_SET = "0008,0005";
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
566
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
567 if (siblingTags.isMember(SPECIFIC_CHARACTER_SET))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
568 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
569 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
570 if (!siblingTags[SPECIFIC_CHARACTER_SET].isMember("Value") ||
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
571 siblingTags[SPECIFIC_CHARACTER_SET]["Value"].type() != Json::stringValue ||
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
572 !GetDicomEncoding(encoding, siblingTags[SPECIFIC_CHARACTER_SET]["Value"].asCString()))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
573 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
574 throw OrthancException(ErrorCode_CreateDicomParentEncoding);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
575 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
576
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
577 dicom.SetEncoding(encoding);
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
578 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
579 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
580
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
581
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
582 // Retrieve the tags for all the parent modules
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
583 typedef std::set<DicomTag> ModuleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
584 ModuleTags moduleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
585
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
586 ResourceType type = parentType;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
587 for (;;)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
588 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
589 DicomTag::AddTagsForModule(moduleTags, GetModule(type));
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
590
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
591 if (type == ResourceType_Patient)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
592 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
593 break; // We're done
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
594 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
595
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
596 // Go up
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
597 std::string tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
598 if (!context.GetIndex().LookupParent(tmp, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
599 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
600 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
601 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
602
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
603 parent = tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
604 type = GetParentResourceType(type);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
605 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
606
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
607 for (ModuleTags::const_iterator it = moduleTags.begin();
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
608 it != moduleTags.end(); ++it)
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
609 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
610 std::string t = it->Format();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
611 if (siblingTags.isMember(t))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
612 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
613 const Json::Value& tag = siblingTags[t];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
614 if (tag["Type"] == "Null")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
615 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
616 dicom.ReplacePlainString(*it, "");
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
617 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
618 else if (tag["Type"] == "String")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
619 {
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
620 std::string value = tag["Value"].asString();
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
621 dicom.ReplacePlainString(*it, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding()));
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
622 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
623 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
624 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
625 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
626
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
627
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
628 bool decodeBinaryTags = true;
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
629 if (request.isMember("InterpretBinaryTags"))
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
630 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
631 const Json::Value& v = request["InterpretBinaryTags"];
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
632 if (v.type() != Json::booleanValue)
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
633 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
634 throw OrthancException(ErrorCode_BadRequest);
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
635 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
636
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
637 decodeBinaryTags = v.asBool();
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
638 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
639
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
640
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
641 // Inject time-related information
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
642 std::string date, time;
2475
8cc3ca64a534 Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
643 SystemToolbox::GetNowDicom(date, time, true /* use UTC time (not local time) */);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
644 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
645 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_TIME, time);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
646 dicom.ReplacePlainString(DICOM_TAG_CONTENT_DATE, date);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
647 dicom.ReplacePlainString(DICOM_TAG_CONTENT_TIME, time);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
648 dicom.ReplacePlainString(DICOM_TAG_INSTANCE_CREATION_DATE, date);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
649 dicom.ReplacePlainString(DICOM_TAG_INSTANCE_CREATION_TIME, time);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
650
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
651 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
652 parentType == ResourceType_Study ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
653 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
654 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
655 dicom.ReplacePlainString(DICOM_TAG_SERIES_DATE, date);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
656 dicom.ReplacePlainString(DICOM_TAG_SERIES_TIME, time);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
657 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
658
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
659 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
660 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
661 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
662 dicom.ReplacePlainString(DICOM_TAG_STUDY_DATE, date);
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
663 dicom.ReplacePlainString(DICOM_TAG_STUDY_TIME, time);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
664 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
665
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
666
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
667 InjectTags(dicom, request["Tags"], decodeBinaryTags);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
668
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
669
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
670 // Inject the content (either an image, or a PDF file)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
671 if (request.isMember("Content"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
672 {
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
673 const Json::Value& content = request["Content"];
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
674
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
675 if (content.type() == Json::stringValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
676 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
677 dicom.EmbedContent(request["Content"].asString());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
678
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
679 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
680 else if (content.type() == Json::arrayValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
681 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
682 if (content.size() > 0)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
683 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
684 // Let's create a series instead of a single instance
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
685 CreateSeries(call, dicom, content, decodeBinaryTags);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
686 return;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
687 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
688 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
689 else
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
690 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
691 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
692 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
693 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
694
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
695 std::string id;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
696 StoreCreatedInstance(id, call, dicom);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
697 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
698
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
699 return;
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
700 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
701
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
702
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
703 static void CreateDicom(RestApiPostCall& call)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
704 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
705 Json::Value request;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
706 if (!call.ParseJsonRequest(request) ||
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
707 !request.isObject())
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
708 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
709 throw OrthancException(ErrorCode_BadRequest);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
710 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
711
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
712 if (request.isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
713 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
714 CreateDicomV2(call, request);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
715 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
716 else
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
717 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
718 // Compatibility with Orthanc <= 0.9.3
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
719 ParsedDicomFile dicom(true);
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
720 CreateDicomV1(dicom, call, request);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
721
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
722 std::string id;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
723 StoreCreatedInstance(id, call, dicom);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
724 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
725 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
726 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
727
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
728
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 void OrthancRestApi::RegisterAnonymizeModify()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 Register("/instances/{id}/modify", ModifyInstance);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
732 Register("/series/{id}/modify", ModifyResource<ChangeType_ModifiedSeries, ResourceType_Series>);
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
733 Register("/studies/{id}/modify", ModifyResource<ChangeType_ModifiedStudy, ResourceType_Study>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
734 Register("/patients/{id}/modify", ModifyResource<ChangeType_ModifiedPatient, ResourceType_Patient>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 Register("/instances/{id}/anonymize", AnonymizeInstance);
2250
b5c8c0590f7f fix in /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
737 Register("/series/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedSeries, ResourceType_Series>);
b5c8c0590f7f fix in /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
738 Register("/studies/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedStudy, ResourceType_Study>);
b5c8c0590f7f fix in /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
739 Register("/patients/{id}/anonymize", AnonymizeResource<ChangeType_AnonymizedPatient, ResourceType_Patient>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
740
1120
009dce4ea2f6 /tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
741 Register("/tools/create-dicom", CreateDicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 }