annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 2953:210d5afd8f2b

GenerateErrorCodes.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 11:49:39 +0100
parents 4ceb9bf7b00c
children bbfd95a0c429
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"
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
39 #include "../../Core/SerializationToolbox.h"
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
40 #include "../ServerContext.h"
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
41 #include "../ServerJobs/MergeStudyJob.h"
2642
ccc470091ea6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
42 #include "../ServerJobs/ResourceModificationJob.h"
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
43 #include "../ServerJobs/SplitStudyJob.h"
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
44
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
45 #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
46 #include <boost/algorithm/string/predicate.hpp>
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
47
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 // Modification of DICOM instances ------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
52
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 static std::string GeneratePatientName(ServerContext& context)
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 uint64_t seq = context.GetIndex().IncrementGlobalSequence(GlobalProperty_AnonymizationSequence);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return "Anonymized" + boost::lexical_cast<std::string>(seq);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
60 static void ParseModifyRequest(Json::Value& request,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
61 DicomModification& target,
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
62 const RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
63 {
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
64 // 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
65
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
66 if (call.ParseJsonRequest(request))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
67 {
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
68 target.ParseModifyRequest(request);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
69 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
70 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
71 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
72 throw OrthancException(ErrorCode_BadFileFormat);
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
73 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
74 }
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2250
diff changeset
75
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
76
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
77 static void ParseAnonymizationRequest(Json::Value& request,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
78 DicomModification& target,
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
79 RestApiPostCall& call)
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
80 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
81 // 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
82
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
83 if (call.ParseJsonRequest(request) &&
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
84 request.isObject())
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
85 {
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
86 bool patientNameReplaced;
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2518
diff changeset
87 target.ParseAnonymizationRequest(patientNameReplaced, request);
2518
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
88
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
89 if (patientNameReplaced)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
90 {
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
91 // Overwrite the random Patient's Name by one that is more
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
92 // user-friendly (provided none was specified by the user)
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
93 target.Replace(DICOM_TAG_PATIENT_NAME, GeneratePatientName(OrthancRestApi::GetContext(call)), true);
63d2cc0fb40a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2517
diff changeset
94 }
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
95 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
96 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
97 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
98 throw OrthancException(ErrorCode_BadFileFormat);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
99 }
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
100 }
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
101
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
102
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
103 static void AnonymizeOrModifyInstance(DicomModification& modification,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
104 RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
106 std::string id = call.GetUriComponent("id", "");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
2825
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
108 std::auto_ptr<ParsedDicomFile> modified;
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 751
diff changeset
109
2825
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
110 {
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
111 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
112 modified.reset(locker.GetDicom().Clone(true));
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
113 }
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
114
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
115 modification.Apply(*modified);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 modified->Answer(call.GetOutput());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
120 static void ModifyInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
122 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
123 modification.SetAllowManualIdentifiers(true);
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
124
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
125 Json::Value request;
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
126 ParseModifyRequest(request, modification, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
127
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
128 if (modification.IsReplaced(DICOM_TAG_PATIENT_ID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
129 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
130 modification.SetLevel(ResourceType_Patient);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
131 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
132 else if (modification.IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
134 modification.SetLevel(ResourceType_Study);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
135 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
136 else if (modification.IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
137 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
138 modification.SetLevel(ResourceType_Series);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
139 }
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
140 else
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
141 {
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
142 modification.SetLevel(ResourceType_Instance);
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
143 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
144
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
145 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
149 static void AnonymizeInstance(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
151 DicomModification modification;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
152 modification.SetAllowManualIdentifiers(true);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
154 Json::Value request;
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
155 ParseAnonymizationRequest(request, modification, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
156
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
157 AnonymizeOrModifyInstance(modification, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
161 static void SubmitModificationJob(std::auto_ptr<DicomModification>& modification,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
162 bool isAnonymization,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
163 RestApiPostCall& call,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
164 const Json::Value& body,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
165 ResourceType level)
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
166 {
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
167 ServerContext& context = OrthancRestApi::GetContext(call);
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
168
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
169 std::auto_ptr<ResourceModificationJob> job(new ResourceModificationJob(context));
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
170
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
171 job->SetModification(modification.release(), level, isAnonymization);
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
172 job->SetOrigin(call);
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
173
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
174 context.AddChildInstances(*job, call.GetUriComponent("id", ""));
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
175
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
176 OrthancRestApi::GetApi(call).SubmitCommandsJob
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
177 (call, job.release(), true /* synchronous by default */, body);
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
178 }
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
179
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
180
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
181 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
182 static void ModifyResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
184 std::auto_ptr<DicomModification> modification(new DicomModification);
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
185
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
186 Json::Value body;
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
187 ParseModifyRequest(body, *modification, call);
2517
d3d306bc4b99 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2475
diff changeset
188
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
189 modification->SetLevel(resourceType);
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
190
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
191 SubmitModificationJob(modification, false /* not an anonymization */,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
192 call, body, resourceType);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
196 template <enum ResourceType resourceType>
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
197 static void AnonymizeResource(RestApiPostCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
199 std::auto_ptr<DicomModification> modification(new DicomModification);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
201 Json::Value body;
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
202 ParseAnonymizationRequest(body, *modification, call);
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2639
diff changeset
203
2868
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
204 SubmitModificationJob(modification, true /* anonymization */,
abce036683cd sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2867
diff changeset
205 call, body, resourceType);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
209 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
210 RestApiPostCall& call,
2899
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
211 ParsedDicomFile& dicom,
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
212 bool sendAnswer)
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
213 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
214 DicomInstanceToStore toStore;
2664
a21b244efb37 serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2642
diff changeset
215 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
216 toStore.SetParsedDicomFile(dicom);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
217
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
218 ServerContext& context = OrthancRestApi::GetContext(call);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
219 StoreStatus status = context.Store(id, toStore);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
220
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
221 if (status == StoreStatus_Failure)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
222 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
223 throw OrthancException(ErrorCode_CannotStoreInstance);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
224 }
2899
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
225
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
226 if (sendAnswer)
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
227 {
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
228 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
229 }
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
230 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
231
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
232
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
233 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
234 RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
235 const Json::Value& request)
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
236 {
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
237 // 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
238 // 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
239
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
240 assert(request.isObject());
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
241 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
242
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
243 Json::Value::Members members = request.getMemberNames();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
244 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
245 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
246 const std::string& name = members[i];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
247 if (request[name].type() != Json::stringValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
248 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
249 throw OrthancException(ErrorCode_CreateDicomNotString);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
250 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
251
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
252 std::string value = request[name].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
253
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
254 DicomTag tag = FromDcmtkBridge::ParseTag(name);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
255 if (tag == DICOM_TAG_PIXEL_DATA)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
256 {
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
257 dicom.EmbedContent(value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
258 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
259 else
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
260 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
261 // 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
262 dicom.ReplacePlainString(tag, value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
263 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
264 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
265 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
266
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
267
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
268 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
269 const Json::Value& tags,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
270 bool decodeBinaryTags)
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
271 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
272 if (tags.type() != Json::objectValue)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
273 {
2936
4b3929668358 create-dicom: more logs in case of error
am@osimis.io
parents: 2899
diff changeset
274 LOG(ERROR) << "Tags field is not an array";
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
275 throw OrthancException(ErrorCode_BadRequest);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
276 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
277
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
278 // Inject the user-specified tags
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
279 Json::Value::Members members = tags.getMemberNames();
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
280 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
281 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
282 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
283 DicomTag tag = FromDcmtkBridge::ParseTag(name);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
284
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
285 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
286 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
287 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
288 tag != DICOM_TAG_ACQUISITION_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
289 tag != DICOM_TAG_ACQUISITION_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
290 tag != DICOM_TAG_CONTENT_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
291 tag != DICOM_TAG_CONTENT_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
292 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
293 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
294 tag != DICOM_TAG_SERIES_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
295 tag != DICOM_TAG_SERIES_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
296 tag != DICOM_TAG_STUDY_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
297 tag != DICOM_TAG_STUDY_TIME &&
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
298 dicom.HasTag(tag))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
299 {
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2936
diff changeset
300 throw OrthancException(ErrorCode_CreateDicomOverrideTag, name);
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 if (tag == DICOM_TAG_PIXEL_DATA)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
304 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
305 throw OrthancException(ErrorCode_CreateDicomUseContent);
1565
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 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
308 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
309 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
310 }
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 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
313 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
314
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
315
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
316 static void CreateSeries(RestApiPostCall& call,
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
317 ParsedDicomFile& base /* in */,
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
318 const Json::Value& content,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
319 bool decodeBinaryTags)
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
320 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
321 assert(content.isArray());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
322 assert(content.size() > 0);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
323 ServerContext& context = OrthancRestApi::GetContext(call);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
324
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
325 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
326 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
327
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
328 std::string someInstance;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
329
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
330 try
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
331 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
332 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
333 {
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
334 std::auto_ptr<ParsedDicomFile> dicom(base.Clone(false));
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
335 const Json::Value* payload = NULL;
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
336
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
337 if (content[i].type() == Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
338 {
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
339 payload = &content[i];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
340 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
341 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
342 {
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
343 if (!content[i].isMember("Content"))
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
344 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
345 throw OrthancException(ErrorCode_CreateDicomNoPayload);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
346 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
347
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
348 payload = &content[i]["Content"];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
349
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
350 if (content[i].isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
351 {
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
352 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
353 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
354 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
355
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
356 if (payload == NULL ||
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
357 payload->type() != Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
358 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
359 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
360 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
361
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
362 dicom->EmbedContent(payload->asString());
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
363 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
364 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
365
2899
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
366 StoreCreatedInstance(someInstance, call, *dicom, false);
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 }
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
369 catch (OrthancException&)
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
370 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
371 // Error: Remove the newly-created series
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
372
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
373 std::string series;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
374 if (context.GetIndex().LookupParent(series, someInstance))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
375 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
376 Json::Value dummy;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
377 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
378 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
379
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
380 throw;
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
381 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
382
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
383 std::string series;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
384 if (context.GetIndex().LookupParent(series, someInstance))
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
385 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
386 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
387 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
388 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
389
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
390
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
391 static void CreateDicomV2(RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
392 const Json::Value& request)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
393 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
394 assert(request.isObject());
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
395 ServerContext& context = OrthancRestApi::GetContext(call);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
396
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
397 if (!request.isMember("Tags") ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
398 request["Tags"].type() != Json::objectValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
399 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
400 throw OrthancException(ErrorCode_BadRequest);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
401 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
402
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
403 ParsedDicomFile dicom(true);
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
404
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
405 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
406 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
407
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
408 if (request["Tags"].isMember("SpecificCharacterSet"))
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
409 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
410 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
411 if (!GetDicomEncoding(encoding, tmp))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
412 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
413 LOG(ERROR) << "Unknown specific character set: " << std::string(tmp);
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
414 throw OrthancException(ErrorCode_ParameterOutOfRange);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
415 }
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
416 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
417 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
418 {
2381
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2361
diff changeset
419 encoding = GetDefaultDicomEncoding();
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
420 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
421
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
422 dicom.SetEncoding(encoding);
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
423 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
424
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
425 ResourceType parentType = ResourceType_Instance;
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 if (request.isMember("Parent"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
428 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
429 // Locate the parent tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
430 std::string parent = request["Parent"].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
431 if (!context.GetIndex().LookupResourceType(parentType, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
432 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
433 throw OrthancException(ErrorCode_CreateDicomBadParent);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
434 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
435
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
436 if (parentType == ResourceType_Instance)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
437 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
438 throw OrthancException(ErrorCode_CreateDicomParentIsInstance);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
439 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
440
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
441 // 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
442 // retrieve all its tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
443 Json::Value siblingTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
444
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
445 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
446 // 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
447 std::list<std::string> siblingInstances;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
448 context.GetIndex().GetChildInstances(siblingInstances, parent);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
449
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
450 if (siblingInstances.empty())
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
451 {
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
452 // Error: No instance (should never happen)
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
453 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
454 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
455
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
456 context.ReadDicomAsJson(siblingTags, siblingInstances.front());
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
457 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
458
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
459
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
460 // 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
461 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
462 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
463
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
464 if (siblingTags.isMember(SPECIFIC_CHARACTER_SET))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
465 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
466 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
467 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
468 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
469 !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
470 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
471 throw OrthancException(ErrorCode_CreateDicomParentEncoding);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
472 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
473
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
474 dicom.SetEncoding(encoding);
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
475 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
476 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
477
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
478
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
479 // 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
480 typedef std::set<DicomTag> ModuleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
481 ModuleTags moduleTags;
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 ResourceType type = parentType;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
484 for (;;)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
485 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
486 DicomTag::AddTagsForModule(moduleTags, GetModule(type));
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
487
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
488 if (type == ResourceType_Patient)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
489 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
490 break; // We're done
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
491 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
492
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
493 // Go up
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
494 std::string tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
495 if (!context.GetIndex().LookupParent(tmp, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
496 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
497 throw OrthancException(ErrorCode_InternalError);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
498 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
499
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
500 parent = tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
501 type = GetParentResourceType(type);
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
502 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
503
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
504 for (ModuleTags::const_iterator it = moduleTags.begin();
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
505 it != moduleTags.end(); ++it)
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
506 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
507 std::string t = it->Format();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
508 if (siblingTags.isMember(t))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
509 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
510 const Json::Value& tag = siblingTags[t];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
511 if (tag["Type"] == "Null")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
512 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
513 dicom.ReplacePlainString(*it, "");
1555
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 else if (tag["Type"] == "String")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
516 {
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
517 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
518 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
519 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
520 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
521 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
522 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
523
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
524
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
525 bool decodeBinaryTags = true;
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
526 if (request.isMember("InterpretBinaryTags"))
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
527 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
528 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
529 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
530 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
531 throw OrthancException(ErrorCode_BadRequest);
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
532 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
533
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
534 decodeBinaryTags = v.asBool();
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
535 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
536
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
537
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
538 // Inject time-related information
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
548 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
549 parentType == ResourceType_Study ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
550 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
551 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
552 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
553 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
554 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
556 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
557 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
558 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
559 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
560 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
561 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
562
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
563
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
564 InjectTags(dicom, request["Tags"], decodeBinaryTags);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
565
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
566
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
567 // 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
568 if (request.isMember("Content"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
569 {
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
570 const Json::Value& content = request["Content"];
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
571
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
572 if (content.type() == Json::stringValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
573 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
574 dicom.EmbedContent(request["Content"].asString());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
575
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
576 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
577 else if (content.type() == Json::arrayValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
578 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
579 if (content.size() > 0)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
580 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
581 // Let's create a series instead of a single instance
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
582 CreateSeries(call, dicom, content, decodeBinaryTags);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
583 return;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
584 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
585 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
586 else
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
587 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
588 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
589 }
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
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
592 std::string id;
2899
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
593 StoreCreatedInstance(id, call, dicom, true);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
594 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
595
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
596
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
597 static void CreateDicom(RestApiPostCall& call)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
598 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
599 Json::Value request;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
600 if (!call.ParseJsonRequest(request) ||
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
601 !request.isObject())
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
602 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
603 throw OrthancException(ErrorCode_BadRequest);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
604 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
605
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
606 if (request.isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
607 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
608 CreateDicomV2(call, request);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
609 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
610 else
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
611 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
612 // Compatibility with Orthanc <= 0.9.3
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
613 ParsedDicomFile dicom(true);
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
614 CreateDicomV1(dicom, call, request);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
615
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
616 std::string id;
2899
5dd649de253d POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2869
diff changeset
617 StoreCreatedInstance(id, call, dicom, true);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
618 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
619 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
620
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
621
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
622 static void SplitStudy(RestApiPostCall& call)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
623 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
624 ServerContext& context = OrthancRestApi::GetContext(call);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
625
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
626 Json::Value request;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
627 if (!call.ParseJsonRequest(request))
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
628 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
629 // Bad JSON request
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
630 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
631 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
632
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
633 const std::string study = call.GetUriComponent("id", "");
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
634
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
635 std::auto_ptr<SplitStudyJob> job(new SplitStudyJob(context, study));
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
636 job->SetOrigin(call);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
637
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
638 std::vector<std::string> series;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
639 SerializationToolbox::ReadArrayOfStrings(series, request, "Series");
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
640
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
641 for (size_t i = 0; i < series.size(); i++)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
642 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
643 job->AddSourceSeries(series[i]);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
644 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
645
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
646 job->AddTrailingStep();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
647
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
648 static const char* KEEP_SOURCE = "KeepSource";
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
649 if (request.isMember(KEEP_SOURCE))
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
650 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
651 job->SetKeepSource(SerializationToolbox::ReadBoolean(request, KEEP_SOURCE));
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
652 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
653
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
654 static const char* REMOVE = "Remove";
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
655 if (request.isMember(REMOVE))
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
656 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
657 if (request[REMOVE].type() != Json::arrayValue)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
658 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
659 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
660 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
661
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
662 for (Json::Value::ArrayIndex i = 0; i < request[REMOVE].size(); i++)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
663 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
664 if (request[REMOVE][i].type() != Json::stringValue)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
665 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
666 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
667 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
668 else
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
669 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
670 job->Remove(FromDcmtkBridge::ParseTag(request[REMOVE][i].asCString()));
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
671 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
672 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
673 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
674
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
675 static const char* REPLACE = "Replace";
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
676 if (request.isMember(REPLACE))
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
677 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
678 if (request[REPLACE].type() != Json::objectValue)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
679 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
680 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
681 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
682
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
683 Json::Value::Members tags = request[REPLACE].getMemberNames();
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
684
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
685 for (size_t i = 0; i < tags.size(); i++)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
686 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
687 const Json::Value& value = request[REPLACE][tags[i]];
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
688
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
689 if (value.type() != Json::stringValue)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
690 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
691 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
692 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
693 else
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
694 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
695 job->Replace(FromDcmtkBridge::ParseTag(tags[i]), value.asString());
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
696 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
697 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
698 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
699
2869
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
700 OrthancRestApi::GetApi(call).SubmitCommandsJob
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
701 (call, job.release(), true /* synchronous by default */, request);
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
702 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
703
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
704
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
705 static void MergeStudy(RestApiPostCall& call)
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
706 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
707 ServerContext& context = OrthancRestApi::GetContext(call);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
708
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
709 Json::Value request;
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
710 if (!call.ParseJsonRequest(request))
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
711 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
712 // Bad JSON request
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
713 throw OrthancException(ErrorCode_BadFileFormat);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
714 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
715
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
716 const std::string study = call.GetUriComponent("id", "");
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
717
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
718 std::auto_ptr<MergeStudyJob> job(new MergeStudyJob(context, study));
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
719 job->SetOrigin(call);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
720
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
721 std::vector<std::string> resources;
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
722 SerializationToolbox::ReadArrayOfStrings(resources, request, "Resources");
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
723
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
724 for (size_t i = 0; i < resources.size(); i++)
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
725 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
726 job->AddSource(resources[i]);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
727 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
728
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
729 job->AddTrailingStep();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
730
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
731 static const char* KEEP_SOURCE = "KeepSource";
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
732 if (request.isMember(KEEP_SOURCE))
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
733 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
734 job->SetKeepSource(SerializationToolbox::ReadBoolean(request, KEEP_SOURCE));
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
735 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
736
2869
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
737 OrthancRestApi::GetApi(call).SubmitCommandsJob
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
738 (call, job.release(), true /* synchronous by default */, request);
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
739 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
740
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
741
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 void OrthancRestApi::RegisterAnonymizeModify()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 Register("/instances/{id}/modify", ModifyInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
745 Register("/series/{id}/modify", ModifyResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
746 Register("/studies/{id}/modify", ModifyResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
747 Register("/patients/{id}/modify", ModifyResource<ResourceType_Patient>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 Register("/instances/{id}/anonymize", AnonymizeInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
750 Register("/series/{id}/anonymize", AnonymizeResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
751 Register("/studies/{id}/anonymize", AnonymizeResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
752 Register("/patients/{id}/anonymize", AnonymizeResource<ResourceType_Patient>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
753
1120
009dce4ea2f6 /tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
754 Register("/tools/create-dicom", CreateDicom);
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
755
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
756 Register("/studies/{id}/split", SplitStudy);
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
757 Register("/studies/{id}/merge", MergeStudy);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 }