annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2813:6d5b20af216f

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Sep 2018 18:24:44 +0200
parents a21b244efb37
children 8aa6aef11b70
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
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
37 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1437
diff changeset
38 #include "../../Core/Logging.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
39 #include "../ServerContext.h"
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
40 #include "../ServerJobs/ResourceModificationJob.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
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
57 static int GetPriority(const Json::Value& request)
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
58 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
59 static const char* PRIORITY = "Priority";
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
60
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
61 if (request.isMember(PRIORITY))
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
62 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
63 if (request[PRIORITY].type() == Json::intValue)
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
64 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
65 return request[PRIORITY].asInt();
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
66 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
67 else
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
68 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
69 LOG(ERROR) << "Field \"" << PRIORITY << "\" of a modification request should be an integer";
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
70 throw OrthancException(ErrorCode_BadFileFormat);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
71 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
72 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
73 else
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
74 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
75 return 0; // Default priority
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
76 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
77 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
78
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
79
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
80 static void ParseModifyRequest(DicomModification& target,
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
81 int& priority,
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
82 const RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
83 {
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
84 // curl http://localhost:8042/series/95a6e2bf-9296e2cc-bf614e2f-22b391ee-16e010e0/modify -X POST -d '{"Replace":{"InstitutionName":"My own clinic"},"Priority":9}'
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
85
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
86 Json::Value request;
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
87 if (call.ParseJsonRequest(request))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
88 {
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
89 priority = GetPriority(request);
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
90 target.ParseModifyRequest(request);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
91 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
92 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
93 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
94 throw OrthancException(ErrorCode_BadFileFormat);
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
95 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
96 }
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
97
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
98
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
99 static void ParseAnonymizationRequest(DicomModification& target,
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
100 int& priority,
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
101 RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
102 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
103 // 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
104
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
105 Json::Value request;
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
106 if (call.ParseJsonRequest(request) &&
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
107 request.isObject())
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
108 {
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
109 priority = GetPriority(request);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
110
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
111 bool patientNameReplaced;
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
112 target.ParseAnonymizationRequest(patientNameReplaced, request);
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
113
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
114 if (patientNameReplaced)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
115 {
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
116 // Overwrite the random Patient's Name by one that is more
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
117 // user-friendly (provided none was specified by the user)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
118 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true);
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
119 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
120 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
121 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
122 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
123 throw OrthancException(ErrorCode_BadFileFormat);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
124 }
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
125 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
126
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
127
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
128 static void AnonymizeOrModifyInstance(DicomModification& modification,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
129 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
131 std::string id = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
133 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
134
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
135 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
136 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 modified->Answer(call.GetOutput());
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
141
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
142 static void SubmitJob(std::auto_ptr<DicomModification>& modification,
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
143 bool isAnonymization,
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
144 ResourceType level,
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
145 int priority,
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
146 RestApiPostCall& call)
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
147 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
148 ServerContext& context = OrthancRestApi::GetContext(call);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
149
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
150 std::auto_ptr<ResourceModificationJob> job(new ResourceModificationJob(context));
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
151
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
152 boost::shared_ptr<ResourceModificationJob::Output> output(new ResourceModificationJob::Output(level));
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
153 job->SetModification(modification.release(), isAnonymization);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
154 job->SetOutput(output);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
155 job->SetOrigin(call);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
156 job->SetDescription("REST API");
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
157
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
158 context.AddChildInstances(*job, call.GetUriComponent("id", ""));
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
159
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
160 if (context.GetJobsEngine().GetRegistry().SubmitAndWait(job.release(), priority))
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
161 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
162 Json::Value json;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
163 if (output->Format(json))
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
164 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
165 call.GetOutput().AnswerJson(json);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
166 return;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
167 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
168 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
169
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
170 call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
175 static void ModifyInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
177 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
178 modification.SetAllowManualIdentifiers(true);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
179
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
180 int priority;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
181 ParseModifyRequest(modification, priority, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
182
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
183 if (modification.IsReplaced(DICOM_TAG_PATIENT_ID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
184 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
185 modification.SetLevel(ResourceType_Patient);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
186 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
187 else if (modification.IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
189 modification.SetLevel(ResourceType_Study);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
190 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
191 else if (modification.IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
192 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
193 modification.SetLevel(ResourceType_Series);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
194 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
195 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
196 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
197 modification.SetLevel(ResourceType_Instance);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
198 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
199
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
200 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
204 static void AnonymizeInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
206 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
207 modification.SetAllowManualIdentifiers(true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
209 int priority;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
210 ParseAnonymizationRequest(modification, priority, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
211
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
212 AnonymizeOrModifyInstance(modification, call);
751
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
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
216 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
217 static void ModifyResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
219 std::auto_ptr<DicomModification> modification(new DicomModification);
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
220
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
221 int priority;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
222 ParseModifyRequest(*modification, priority, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
223
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
224 modification->SetLevel(resourceType);
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
225 SubmitJob(modification, false, resourceType, priority, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
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
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
229 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
230 static void AnonymizeResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
232 std::auto_ptr<DicomModification> modification(new DicomModification);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
234 int priority;
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
235 ParseAnonymizationRequest(*modification, priority, call);
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
236
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
237 SubmitJob(modification, true, resourceType, priority, call);
751
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
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
241 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
242 RestApiPostCall& call,
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
243 ParsedDicomFile& dicom)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
244 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
245 DicomInstanceToStore toStore;
2664
a21b244efb37 serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2642
diff changeset
246 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
247 toStore.SetParsedDicomFile(dicom);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
248
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
249 ServerContext& context = OrthancRestApi::GetContext(call);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
250 StoreStatus status = context.Store(id, toStore);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
251
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
252 if (status == StoreStatus_Failure)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
253 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
254 throw OrthancException(ErrorCode_CannotStoreInstance);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
255 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
256 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
257
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
258
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
259 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
260 RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
261 const Json::Value& request)
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
262 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
263 // 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
264 // 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
265
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
266 assert(request.isObject());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267 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
268
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
269 Json::Value::Members members = request.getMemberNames();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
270 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
271 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
272 const std::string& name = members[i];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
273 if (request[name].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
274 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
275 throw OrthancException(ErrorCode_CreateDicomNotString);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
276 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
277
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
278 std::string value = request[name].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
279
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
280 DicomTag tag = FromDcmtkBridge::ParseTag(name);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
281 if (tag == DICOM_TAG_PIXEL_DATA)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
282 {
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
283 dicom.EmbedContent(value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
284 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
285 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
286 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
287 // 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
288 dicom.ReplacePlainString(tag, value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
289 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
290 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
291 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
292
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
293
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
294 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
295 const Json::Value& tags,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
296 bool decodeBinaryTags)
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
297 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
298 if (tags.type() != Json::objectValue)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
299 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
300 throw OrthancException(ErrorCode_BadRequest);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
301 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
302
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
303 // Inject the user-specified tags
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
304 Json::Value::Members members = tags.getMemberNames();
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
305 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
306 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
307 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
308 DicomTag tag = FromDcmtkBridge::ParseTag(name);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
309
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
310 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
311 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
312 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
313 tag != DICOM_TAG_ACQUISITION_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
314 tag != DICOM_TAG_ACQUISITION_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
315 tag != DICOM_TAG_CONTENT_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
316 tag != DICOM_TAG_CONTENT_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
317 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
318 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
319 tag != DICOM_TAG_SERIES_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
320 tag != DICOM_TAG_SERIES_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
321 tag != DICOM_TAG_STUDY_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
322 tag != DICOM_TAG_STUDY_TIME &&
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
323 dicom.HasTag(tag))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
324 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
325 throw OrthancException(ErrorCode_CreateDicomOverrideTag);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
326 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
327
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
328 if (tag == DICOM_TAG_PIXEL_DATA)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
329 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
330 throw OrthancException(ErrorCode_CreateDicomUseContent);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
331 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
332 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
333 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
334 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
335 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
336 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
337 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
338 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
339
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
340
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
341 static void CreateSeries(RestApiPostCall& call,
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
342 ParsedDicomFile& base /* in */,
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
343 const Json::Value& content,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
344 bool decodeBinaryTags)
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
345 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
346 assert(content.isArray());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
347 assert(content.size() > 0);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
348 ServerContext& context = OrthancRestApi::GetContext(call);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
349
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
350 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
351 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
352
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
353 std::string someInstance;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
354
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
355 try
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
356 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
357 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
358 {
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
359 std::auto_ptr<ParsedDicomFile> dicom(base.Clone(false));
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
360 const Json::Value* payload = NULL;
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
361
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
362 if (content[i].type() == Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
363 {
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
364 payload = &content[i];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
365 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
366 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
367 {
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
368 if (!content[i].isMember("Content"))
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
369 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
370 throw OrthancException(ErrorCode_CreateDicomNoPayload);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
371 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
372
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
373 payload = &content[i]["Content"];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
374
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
375 if (content[i].isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
376 {
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
377 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
378 }
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
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
381 if (payload == NULL ||
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
382 payload->type() != Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
383 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
384 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
385 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
386
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
387 dicom->EmbedContent(payload->asString());
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
388 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
389 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
390
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
391 StoreCreatedInstance(someInstance, call, *dicom);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
392 }
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
393 }
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
394 catch (OrthancException&)
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
395 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
396 // Error: Remove the newly-created series
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
397
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
398 std::string series;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
399 if (context.GetIndex().LookupParent(series, someInstance))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
400 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
401 Json::Value dummy;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
402 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
403 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
404
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
405 throw;
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
406 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
407
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
408 std::string series;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
409 if (context.GetIndex().LookupParent(series, someInstance))
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
410 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
411 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
412 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
413 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
414
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
415
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
416 static void CreateDicomV2(RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
417 const Json::Value& request)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
418 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
419 assert(request.isObject());
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
420 ServerContext& context = OrthancRestApi::GetContext(call);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
421
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
422 if (!request.isMember("Tags") ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
423 request["Tags"].type() != Json::objectValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
424 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
425 throw OrthancException(ErrorCode_BadRequest);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
426 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
427
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
428 ParsedDicomFile dicom(true);
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
429
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
430 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
431 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
432
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
433 if (request["Tags"].isMember("SpecificCharacterSet"))
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
434 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
435 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
436 if (!GetDicomEncoding(encoding, tmp))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
437 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
438 LOG(ERROR) << "Unknown specific character set: " << std::string(tmp);
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
439 throw OrthancException(ErrorCode_ParameterOutOfRange);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
440 }
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
441 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
442 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
443 {
2381
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2361
diff changeset
444 encoding = GetDefaultDicomEncoding();
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
445 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
446
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
447 dicom.SetEncoding(encoding);
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
448 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
449
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
450 ResourceType parentType = ResourceType_Instance;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
451
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
452 if (request.isMember("Parent"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
453 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
454 // Locate the parent tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
455 std::string parent = request["Parent"].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
456 if (!context.GetIndex().LookupResourceType(parentType, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
457 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
458 throw OrthancException(ErrorCode_CreateDicomBadParent);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
459 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
460
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
461 if (parentType == ResourceType_Instance)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
462 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
463 throw OrthancException(ErrorCode_CreateDicomParentIsInstance);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
464 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
465
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
466 // 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
467 // retrieve all its tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
468 Json::Value siblingTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
469
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
470 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
471 // 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
472 std::list<std::string> siblingInstances;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
473 context.GetIndex().GetChildInstances(siblingInstances, parent);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
474
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
475 if (siblingInstances.empty())
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
476 {
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
477 // Error: No instance (should never happen)
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
478 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
479 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
480
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
481 context.ReadDicomAsJson(siblingTags, siblingInstances.front());
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
482 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
483
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
484
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
485 // 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
486 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
487 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
488
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
489 if (siblingTags.isMember(SPECIFIC_CHARACTER_SET))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
490 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
491 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
492 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
493 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
494 !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
495 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
496 throw OrthancException(ErrorCode_CreateDicomParentEncoding);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
497 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
498
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
499 dicom.SetEncoding(encoding);
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
500 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
501 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
502
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
503
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
504 // 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
505 typedef std::set<DicomTag> ModuleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
506 ModuleTags moduleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
507
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
508 ResourceType type = parentType;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
509 for (;;)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
510 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
511 DicomTag::AddTagsForModule(moduleTags, GetModule(type));
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
512
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
513 if (type == ResourceType_Patient)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
514 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
515 break; // We're done
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
516 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
517
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
518 // Go up
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
519 std::string tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
520 if (!context.GetIndex().LookupParent(tmp, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
521 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
522 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
523 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
524
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
525 parent = tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
526 type = GetParentResourceType(type);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
527 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
528
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
529 for (ModuleTags::const_iterator it = moduleTags.begin();
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
530 it != moduleTags.end(); ++it)
1555
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 std::string t = it->Format();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
533 if (siblingTags.isMember(t))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
534 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
535 const Json::Value& tag = siblingTags[t];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
536 if (tag["Type"] == "Null")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
537 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
538 dicom.ReplacePlainString(*it, "");
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
539 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
540 else if (tag["Type"] == "String")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
541 {
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
542 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
543 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
544 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
545 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
546 }
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
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
549
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
550 bool decodeBinaryTags = true;
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
551 if (request.isMember("InterpretBinaryTags"))
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
552 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
553 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
554 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
555 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
556 throw OrthancException(ErrorCode_BadRequest);
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
557 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
558
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
559 decodeBinaryTags = v.asBool();
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
560 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
561
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
562
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
563 // Inject time-related information
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
564 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
565 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
566 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
567 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
568 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
569 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
570 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
571 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
572
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
573 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
574 parentType == ResourceType_Study ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
575 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
576 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
577 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
578 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
579 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
580
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
581 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
582 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
583 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
584 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
585 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
586 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
587
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
588
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
589 InjectTags(dicom, request["Tags"], decodeBinaryTags);
1555
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
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
592 // 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
593 if (request.isMember("Content"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
594 {
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
595 const Json::Value& content = request["Content"];
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
596
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
597 if (content.type() == Json::stringValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
598 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
599 dicom.EmbedContent(request["Content"].asString());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
600
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
601 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
602 else if (content.type() == Json::arrayValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
603 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
604 if (content.size() > 0)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
605 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
606 // Let's create a series instead of a single instance
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
607 CreateSeries(call, dicom, content, decodeBinaryTags);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
608 return;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
609 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
610 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
611 else
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
612 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
613 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
614 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
615 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
616
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
617 std::string id;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
618 StoreCreatedInstance(id, call, dicom);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
619 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
620
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
621 return;
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 static void CreateDicom(RestApiPostCall& call)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
626 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
627 Json::Value request;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
628 if (!call.ParseJsonRequest(request) ||
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
629 !request.isObject())
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
630 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
631 throw OrthancException(ErrorCode_BadRequest);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
632 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
633
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
634 if (request.isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
635 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
636 CreateDicomV2(call, request);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
637 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
638 else
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
639 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
640 // Compatibility with Orthanc <= 0.9.3
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
641 ParsedDicomFile dicom(true);
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
642 CreateDicomV1(dicom, call, request);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
643
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
644 std::string id;
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
645 StoreCreatedInstance(id, call, dicom);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
646 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
647 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
648 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
649
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
650
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 void OrthancRestApi::RegisterAnonymizeModify()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 Register("/instances/{id}/modify", ModifyInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
654 Register("/series/{id}/modify", ModifyResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
655 Register("/studies/{id}/modify", ModifyResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
656 Register("/patients/{id}/modify", ModifyResource<ResourceType_Patient>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 Register("/instances/{id}/anonymize", AnonymizeInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
659 Register("/series/{id}/anonymize", AnonymizeResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
660 Register("/studies/{id}/anonymize", AnonymizeResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
661 Register("/patients/{id}/anonymize", AnonymizeResource<ResourceType_Patient>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
662
1120
009dce4ea2f6 /tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
663 Register("/tools/create-dicom", CreateDicom);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 }