annotate OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 3495:cc3e408165eb

revert
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Aug 2019 16:02:00 +0200
parents 6cc72ebfd6ef
children 94f4a18a79cc
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
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3009
diff changeset
5 * Copyright (C) 2017-2019 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 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
274 throw OrthancException(ErrorCode_BadRequest, "Tags field is not an array");
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
275 }
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 // Inject the user-specified tags
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
278 Json::Value::Members members = tags.getMemberNames();
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
279 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
280 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
281 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
282 DicomTag tag = FromDcmtkBridge::ParseTag(name);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
283
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
284 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
285 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
286 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
287 tag != DICOM_TAG_ACQUISITION_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
288 tag != DICOM_TAG_ACQUISITION_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
289 tag != DICOM_TAG_CONTENT_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
290 tag != DICOM_TAG_CONTENT_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
291 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
292 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
293 tag != DICOM_TAG_SERIES_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
294 tag != DICOM_TAG_SERIES_TIME &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
295 tag != DICOM_TAG_STUDY_DATE &&
48224db51ee7 allow override date/time when creating DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1616
diff changeset
296 tag != DICOM_TAG_STUDY_TIME &&
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
297 dicom.HasTag(tag))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
298 {
2952
4ceb9bf7b00c added details string in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2936
diff changeset
299 throw OrthancException(ErrorCode_CreateDicomOverrideTag, name);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
300 }
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 if (tag == DICOM_TAG_PIXEL_DATA)
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
303 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
304 throw OrthancException(ErrorCode_CreateDicomUseContent);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
305 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
306 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
307 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
308 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
309 }
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
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
315 static void CreateSeries(RestApiPostCall& call,
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
316 ParsedDicomFile& base /* in */,
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
317 const Json::Value& content,
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
318 bool decodeBinaryTags)
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
319 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
320 assert(content.isArray());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
321 assert(content.size() > 0);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
322 ServerContext& context = OrthancRestApi::GetContext(call);
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
323
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
324 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
325 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
326
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
327 std::string someInstance;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
328
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
329 try
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
330 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
331 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
332 {
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2519
diff changeset
333 std::auto_ptr<ParsedDicomFile> dicom(base.Clone(false));
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
334 const Json::Value* payload = NULL;
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
335
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
336 if (content[i].type() == Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
337 {
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
338 payload = &content[i];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
339 }
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
340 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
341 {
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
342 if (!content[i].isMember("Content"))
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
343 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
344 throw OrthancException(ErrorCode_CreateDicomNoPayload);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
345 }
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 payload = &content[i]["Content"];
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
348
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
349 if (content[i].isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
350 {
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
351 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
352 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
353 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
354
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
355 if (payload == NULL ||
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
356 payload->type() != Json::stringValue)
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
357 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
358 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
359 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
360
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
361 dicom->EmbedContent(payload->asString());
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
362 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
363 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
364
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
365 StoreCreatedInstance(someInstance, call, *dicom, false);
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
366 }
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
367 }
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
368 catch (OrthancException&)
1566
3be6eb3757c8 error handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1565
diff changeset
369 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
370 // Error: Remove the newly-created series
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
371
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
372 std::string series;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
373 if (context.GetIndex().LookupParent(series, someInstance))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
374 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
375 Json::Value dummy;
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
376 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
377 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
378
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
379 throw;
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
380 }
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 std::string series;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
383 if (context.GetIndex().LookupParent(series, someInstance))
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
384 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
385 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
386 }
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 static void CreateDicomV2(RestApiPostCall& call,
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
391 const Json::Value& request)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
392 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
393 assert(request.isObject());
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
394 ServerContext& context = OrthancRestApi::GetContext(call);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
395
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
396 if (!request.isMember("Tags") ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
397 request["Tags"].type() != Json::objectValue)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
398 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
399 throw OrthancException(ErrorCode_BadRequest);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
400 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
401
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
402 ParsedDicomFile dicom(true);
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
403
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
404 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
405 Encoding encoding;
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
406
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
407 if (request["Tags"].isMember("SpecificCharacterSet"))
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
408 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
409 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
410 if (!GetDicomEncoding(encoding, tmp))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
411 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
412 throw OrthancException(ErrorCode_ParameterOutOfRange,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2952
diff changeset
413 "Unknown specific character set: " + std::string(tmp));
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
414 }
1558
124de28b32ed fix encodings of newly created dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
415 }
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
416 else
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
417 {
2381
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2361
diff changeset
418 encoding = GetDefaultDicomEncoding();
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
419 }
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 dicom.SetEncoding(encoding);
1557
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
422 }
ad1e127b4ed5 fix in encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1555
diff changeset
423
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
424 ResourceType parentType = ResourceType_Instance;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
425
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
426 if (request.isMember("Parent"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
427 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
428 // Locate the parent tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
429 std::string parent = request["Parent"].asString();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
430 if (!context.GetIndex().LookupResourceType(parentType, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
431 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
432 throw OrthancException(ErrorCode_CreateDicomBadParent);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
433 }
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 if (parentType == ResourceType_Instance)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
436 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
437 throw OrthancException(ErrorCode_CreateDicomParentIsInstance);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
438 }
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 // 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
441 // retrieve all its tags
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
442 Json::Value siblingTags;
3009
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
443 std::string siblingInstanceId;
1555
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
3009
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
456 siblingInstanceId = siblingInstances.front();
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
457 context.ReadDicomAsJson(siblingTags, siblingInstanceId);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
458 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
459
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
460
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
461 // 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
462 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
463 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
464
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
465 if (siblingTags.isMember(SPECIFIC_CHARACTER_SET))
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
466 {
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
467 Encoding encoding;
3009
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
468
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
469 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
470 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
471 !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
472 {
3009
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
473 LOG(WARNING) << "Instance with an incorrect Specific Character Set, "
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
474 << "using the default Orthanc encoding: " << siblingInstanceId;
750de70b3603 make "/tools/create-dicom" more tolerant to invalid specific character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
475 encoding = GetDefaultDicomEncoding();
1565
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 dicom.SetEncoding(encoding);
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
479 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
480 }
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
481
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
482
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
483 // 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
484 typedef std::set<DicomTag> ModuleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
485 ModuleTags moduleTags;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
486
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
487 ResourceType type = parentType;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
488 for (;;)
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 DicomTag::AddTagsForModule(moduleTags, GetModule(type));
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 if (type == ResourceType_Patient)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
493 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
494 break; // We're done
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
495 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
496
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
497 // Go up
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
498 std::string tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
499 if (!context.GetIndex().LookupParent(tmp, parent))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
500 {
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
501 throw OrthancException(ErrorCode_InternalError);
1555
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 parent = tmp;
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
505 type = GetParentResourceType(type);
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
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
508 for (ModuleTags::const_iterator it = moduleTags.begin();
1616
644c32c07306 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
509 it != moduleTags.end(); ++it)
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
510 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
511 std::string t = it->Format();
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
512 if (siblingTags.isMember(t))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
513 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
514 const Json::Value& tag = siblingTags[t];
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
515 if (tag["Type"] == "Null")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
516 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
517 dicom.ReplacePlainString(*it, "");
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
518 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
519 else if (tag["Type"] == "String")
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
520 {
3441
6cc72ebfd6ef Fix issue #141 (/tools/create-dicom removes non-ASCII characters from study description)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
521 std::string value = tag["Value"].asString(); // This is an UTF-8 value (as it comes from JSON)
6cc72ebfd6ef Fix issue #141 (/tools/create-dicom removes non-ASCII characters from study description)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
522 dicom.ReplacePlainString(*it, value);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
523 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
524 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
525 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
526 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
527
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
528
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
529 bool decodeBinaryTags = true;
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
530 if (request.isMember("InterpretBinaryTags"))
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
531 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
532 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
533 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
534 {
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
535 throw OrthancException(ErrorCode_BadRequest);
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
536 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
537
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
538 decodeBinaryTags = v.asBool();
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
539 }
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
540
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
541
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
542 // Inject time-related information
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
543 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
544 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
545 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
546 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
547 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
548 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
549 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
550 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
551
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
552 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
553 parentType == ResourceType_Study ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
554 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
555 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
556 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
557 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
558 }
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
559
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
560 if (parentType == ResourceType_Patient ||
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
561 parentType == ResourceType_Instance /* no parent */)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
562 {
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
563 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
564 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
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
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
568 InjectTags(dicom, request["Tags"], decodeBinaryTags);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
569
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
570
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
571 // 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
572 if (request.isMember("Content"))
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
573 {
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
574 const Json::Value& content = request["Content"];
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 if (content.type() == Json::stringValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
577 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
578 dicom.EmbedContent(request["Content"].asString());
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
579
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
580 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
581 else if (content.type() == Json::arrayValue)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
582 {
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
583 if (content.size() > 0)
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
584 {
1565
4b23310eb7e8 add tags per instances in a series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
585 // Let's create a series instead of a single instance
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1652
diff changeset
586 CreateSeries(call, dicom, content, decodeBinaryTags);
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
587 return;
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
588 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
589 }
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
590 else
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
591 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
592 throw OrthancException(ErrorCode_CreateDicomUseDataUriScheme);
1555
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
593 }
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
1564
1b7def486e62 creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
596 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
597 StoreCreatedInstance(id, call, dicom, true);
1555
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
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
600
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
601 static void CreateDicom(RestApiPostCall& call)
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
602 {
d6a93e12b1c1 Creation of DICOM files with encapsulated PDF
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
603 Json::Value request;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
604 if (!call.ParseJsonRequest(request) ||
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
605 !request.isObject())
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
606 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
607 throw OrthancException(ErrorCode_BadRequest);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
608 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
609
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
610 if (request.isMember("Tags"))
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
611 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
612 CreateDicomV2(call, request);
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
613 }
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
614 else
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
615 {
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
616 // Compatibility with Orthanc <= 0.9.3
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1699
diff changeset
617 ParsedDicomFile dicom(true);
1572
904096e7367e More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
618 CreateDicomV1(dicom, call, request);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1566
diff changeset
619
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
620 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
621 StoreCreatedInstance(id, call, dicom, true);
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
622 }
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
623 }
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
624
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
625
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
626 static void SplitStudy(RestApiPostCall& call)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
627 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
628 ServerContext& context = OrthancRestApi::GetContext(call);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
629
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
630 Json::Value request;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
631 if (!call.ParseJsonRequest(request))
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 // Bad JSON request
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
634 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
635 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
636
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
637 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
638
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
639 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
640 job->SetOrigin(call);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
641
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
642 std::vector<std::string> series;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
643 SerializationToolbox::ReadArrayOfStrings(series, request, "Series");
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 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
646 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
647 job->AddSourceSeries(series[i]);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
648 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
649
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
650 job->AddTrailingStep();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
651
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
652 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
653 if (request.isMember(KEEP_SOURCE))
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
654 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
655 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
656 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
657
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
658 static const char* REMOVE = "Remove";
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
659 if (request.isMember(REMOVE))
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 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
662 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
663 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
664 }
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 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
667 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
668 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
669 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
670 throw OrthancException(ErrorCode_BadFileFormat);
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 else
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 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
675 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
676 }
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
679 static const char* REPLACE = "Replace";
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
680 if (request.isMember(REPLACE))
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 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
683 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
684 throw OrthancException(ErrorCode_BadFileFormat);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
685 }
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 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
688
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
689 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
690 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
691 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
692
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
693 if (value.type() != Json::stringValue)
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 throw OrthancException(ErrorCode_BadFileFormat);
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 else
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 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
700 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
701 }
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
2869
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
704 OrthancRestApi::GetApi(call).SubmitCommandsJob
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
705 (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
706 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
707
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
708
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
709 static void MergeStudy(RestApiPostCall& call)
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
710 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
711 ServerContext& context = OrthancRestApi::GetContext(call);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
712
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
713 Json::Value request;
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
714 if (!call.ParseJsonRequest(request))
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 // Bad JSON request
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
717 throw OrthancException(ErrorCode_BadFileFormat);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
718 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
719
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
720 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
721
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
722 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
723 job->SetOrigin(call);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
724
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
725 std::vector<std::string> resources;
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
726 SerializationToolbox::ReadArrayOfStrings(resources, request, "Resources");
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 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
729 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
730 job->AddSource(resources[i]);
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
731 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
732
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
733 job->AddTrailingStep();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
734
2853
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
735 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
736 if (request.isMember(KEEP_SOURCE))
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
737 {
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
738 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
739 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
740
2869
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
741 OrthancRestApi::GetApi(call).SubmitCommandsJob
2bd87764709c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
742 (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
743 }
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
744
52b017d22a4f New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
745
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 void OrthancRestApi::RegisterAnonymizeModify()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 Register("/instances/{id}/modify", ModifyInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
749 Register("/series/{id}/modify", ModifyResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
750 Register("/studies/{id}/modify", ModifyResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
751 Register("/patients/{id}/modify", ModifyResource<ResourceType_Patient>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 Register("/instances/{id}/anonymize", AnonymizeInstance);
2639
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
754 Register("/series/{id}/anonymize", AnonymizeResource<ResourceType_Series>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
755 Register("/studies/{id}/anonymize", AnonymizeResource<ResourceType_Study>);
75a404e40323 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
756 Register("/patients/{id}/anonymize", AnonymizeResource<ResourceType_Patient>);
796
e7b1ca0f1e04 creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
757
1120
009dce4ea2f6 /tools/create-dicom now accepts PatientID
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
758 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
759
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2825
diff changeset
760 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
761 Register("/studies/{id}/merge", MergeStudy);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }