Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp @ 4658:66f6fd77deaf Orthanc-1.9.3
Orthanc-1.9.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 May 2021 09:22:38 +0200 |
parents | 8f9090b137f1 |
children | f0038043fb97 bad8935cd5f2 |
rev | line source |
---|---|
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
99863d6245b2
New URI: "/studies/.../split" to split a study
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "SplitStudyJob.h" |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
4045 | 36 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" |
37 #include "../../../OrthancFramework/Sources/Logging.h" | |
38 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
39 #include "../ServerContext.h" |
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
40 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 namespace Orthanc |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 void SplitStudyJob::CheckAllowedTag(const DicomTag& tag) const |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 if (allowedTags_.find(tag) == allowedTags_.end()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
2955 | 48 throw OrthancException(ErrorCode_ParameterOutOfRange, |
49 "Cannot modify the following tag while splitting a study " | |
50 "(not in the patient/study modules): " + | |
51 FromDcmtkBridge::GetTagName(tag, "") + | |
52 " (" + tag.Format() + ")"); | |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
57 void SplitStudyJob::Setup() |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 SetPermissive(false); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Patient); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Study); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 allowedTags_.erase(DICOM_TAG_STUDY_INSTANCE_UID); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 allowedTags_.erase(DICOM_TAG_SERIES_INSTANCE_UID); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 bool SplitStudyJob::HandleInstance(const std::string& instance) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 { |
3940
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
70 if (!HasTrailingStep()) |
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
71 { |
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
72 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
73 "AddTrailingStep() should have been called after AddSourceSeries()"); |
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
74 } |
3661e2a72482
safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3814
diff
changeset
|
75 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 * Retrieve the DICOM instance to be modified |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
80 std::unique_ptr<ParsedDicomFile> modified; |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 try |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 { |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
84 ServerContext::DicomCacheLocker locker(GetContext(), instance); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 modified.reset(locker.GetDicom().Clone(true)); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 catch (OrthancException&) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 LOG(WARNING) << "An instance was removed after the job was issued: " << instance; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 return false; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 * Chose the target UIDs |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 **/ |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
97 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
98 assert(modified->GetHasher().HashStudy() == sourceStudy_); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
99 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
100 std::string series = modified->GetHasher().HashSeries(); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
101 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
102 SeriesUidMap::const_iterator targetSeriesUid = seriesUidMap_.find(series); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
103 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
104 if (targetSeriesUid == seriesUidMap_.end()) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 throw OrthancException(ErrorCode_BadFileFormat); // Should never happen |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 * Apply user-specified modifications |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
114 for (std::set<DicomTag>::const_iterator it = removals_.begin(); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 it != removals_.end(); ++it) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 modified->Remove(*it); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 for (Replacements::const_iterator it = replacements_.begin(); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 it != replacements_.end(); ++it) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 modified->ReplacePlainString(it->first, it->second); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 * Store the new instance into Orthanc |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 modified->ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, targetStudyUid_); |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
132 modified->ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, targetSeriesUid->second); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
3507
69e49fc044f8
Fix generation of "SOP Instance UID" on split and merge
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
134 // Fix since Orthanc 1.5.8: Assign new "SOPInstanceUID", as the instance has been modified |
69e49fc044f8
Fix generation of "SOP Instance UID" on split and merge
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
135 modified->ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance)); |
69e49fc044f8
Fix generation of "SOP Instance UID" on split and merge
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
136 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 if (targetStudy_.empty()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 targetStudy_ = modified->GetHasher().HashStudy(); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
142 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*modified)); |
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
143 toStore->SetOrigin(origin_); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 std::string modifiedInstance; |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
146 if (GetContext().Store(modifiedInstance, *toStore, |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
147 StoreInstanceMode_Default) != StoreStatus_Success) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 LOG(ERROR) << "Error while storing a modified instance " << instance; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 return false; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 return true; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 SplitStudyJob::SplitStudyJob(ServerContext& context, |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 const std::string& sourceStudy) : |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
159 CleaningInstancesJob(context, false /* by default, remove source instances */), |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
160 sourceStudy_(sourceStudy), |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
161 targetStudyUid_(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study)) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 { |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
163 Setup(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
164 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
165 ResourceType type; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
166 |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
167 if (!GetContext().GetIndex().LookupResourceType(type, sourceStudy) || |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
168 type != ResourceType_Study) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
169 { |
2955 | 170 throw OrthancException(ErrorCode_UnknownResource, |
171 "Cannot split unknown study " + sourceStudy); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
172 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 void SplitStudyJob::SetOrigin(const DicomInstanceOrigin& origin) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 else |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 origin_ = origin; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 void SplitStudyJob::SetOrigin(const RestApiCall& call) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 void SplitStudyJob::AddSourceSeries(const std::string& series) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
197 std::string parent; |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
198 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 } |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
203 else if (!GetContext().GetIndex().LookupParent(parent, series, ResourceType_Study) || |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
204 parent != sourceStudy_) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 { |
2955 | 206 throw OrthancException(ErrorCode_UnknownResource, |
207 "This series does not belong to the study to be split: " + series); | |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 else |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 { |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
211 // Generate a target SeriesInstanceUID for this series |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
212 seriesUidMap_[series] = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
213 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 // Add all the instances of the series as to be processed |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 std::list<std::string> instances; |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
216 GetContext().GetIndex().GetChildren(instances, series); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 for (std::list<std::string>::const_iterator |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 it = instances.begin(); it != instances.end(); ++it) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 AddInstance(*it); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 |
2847
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
227 bool SplitStudyJob::LookupTargetSeriesUid(std::string& uid, |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
228 const std::string& series) const |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
229 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
230 SeriesUidMap::const_iterator found = seriesUidMap_.find(series); |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
231 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
232 if (found == seriesUidMap_.end()) |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
233 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
234 return false; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
235 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
236 else |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
237 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
238 uid = found->second; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
239 return true; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
240 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
241 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
242 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
243 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 void SplitStudyJob::Remove(const DicomTag& tag) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 CheckAllowedTag(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 removals_.insert(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 void SplitStudyJob::Replace(const DicomTag& tag, |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 const std::string& value) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 CheckAllowedTag(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 replacements_[tag] = value; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 } |
2847
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
267 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
268 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
269 bool SplitStudyJob::LookupReplacement(std::string& value, |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
270 const DicomTag& tag) const |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
271 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
272 Replacements::const_iterator found = replacements_.find(tag); |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
273 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
274 if (found == replacements_.end()) |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
275 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
276 return false; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
277 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
278 else |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
279 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
280 value = found->second; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
281 return true; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
282 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
283 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 void SplitStudyJob::GetPublicContent(Json::Value& value) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 { |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
288 CleaningInstancesJob::GetPublicContent(value); |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 if (!targetStudy_.empty()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 value["TargetStudy"] = targetStudy_; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 value["TargetStudyUID"] = targetStudyUid_; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
297 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
298 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
299 static const char* SOURCE_STUDY = "SourceStudy"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
300 static const char* TARGET_STUDY = "TargetStudy"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
301 static const char* TARGET_STUDY_UID = "TargetStudyUID"; |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
302 static const char* SERIES_UID_MAP = "SeriesUIDMap"; |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
303 static const char* ORIGIN = "Origin"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
304 static const char* REPLACEMENTS = "Replacements"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
305 static const char* REMOVALS = "Removals"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
306 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
307 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
308 SplitStudyJob::SplitStudyJob(ServerContext& context, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
309 const Json::Value& serialized) : |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
310 CleaningInstancesJob(context, serialized, |
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
311 false /* by default, remove source instances */) // (*) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
312 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
313 if (!HasTrailingStep()) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
314 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
315 // Should have been set by (*) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
316 throw OrthancException(ErrorCode_InternalError); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
317 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
318 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
319 Setup(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
320 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
321 sourceStudy_ = SerializationToolbox::ReadString(serialized, SOURCE_STUDY); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
322 targetStudy_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
323 targetStudyUid_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY_UID); |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
324 SerializationToolbox::ReadMapOfStrings(seriesUidMap_, serialized, SERIES_UID_MAP); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
325 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
326 SerializationToolbox::ReadMapOfTags(replacements_, serialized, REPLACEMENTS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
327 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
328 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
329 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 bool SplitStudyJob::Serialize(Json::Value& target) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 { |
3941
771dbd9eb3bd
class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3940
diff
changeset
|
333 if (!CleaningInstancesJob::Serialize(target)) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
334 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
335 return false; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
336 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
337 else |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
338 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
339 target[SOURCE_STUDY] = sourceStudy_; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
340 target[TARGET_STUDY] = targetStudy_; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
341 target[TARGET_STUDY_UID] = targetStudyUid_; |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
342 SerializationToolbox::WriteMapOfStrings(target, seriesUidMap_, SERIES_UID_MAP); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
343 origin_.Serialize(target[ORIGIN]); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
344 SerializationToolbox::WriteMapOfTags(target, replacements_, REPLACEMENTS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
345 SerializationToolbox::WriteSetOfTags(target, removals_, REMOVALS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
346 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
347 return true; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
348 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 } |