Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/SplitStudyJob.cpp @ 2998:0a52af0c66e7
sharing strings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Dec 2018 13:21:34 +0100 |
parents | bbfd95a0c429 |
children | 4e43e67f8ecf |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
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 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
36 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "../../Core/Logging.h" |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
38 #include "../../Core/SerializationToolbox.h" |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 namespace Orthanc |
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 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
|
43 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 if (allowedTags_.find(tag) == allowedTags_.end()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
2955 | 46 throw OrthancException(ErrorCode_ParameterOutOfRange, |
47 "Cannot modify the following tag while splitting a study " | |
48 "(not in the patient/study modules): " + | |
49 FromDcmtkBridge::GetTagName(tag, "") + | |
50 " (" + tag.Format() + ")"); | |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
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 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
55 void SplitStudyJob::Setup() |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 SetPermissive(false); |
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 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Patient); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Study); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 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
|
62 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
|
63 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
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 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
|
67 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 * 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
|
70 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 std::auto_ptr<ParsedDicomFile> modified; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 try |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 ServerContext::DicomCacheLocker locker(context_, instance); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 modified.reset(locker.GetDicom().Clone(true)); |
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 catch (OrthancException&) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 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
|
82 return false; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
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 * Chose the target UIDs |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 **/ |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
89 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
90 assert(modified->GetHasher().HashStudy() == sourceStudy_); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
91 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
92 std::string series = modified->GetHasher().HashSeries(); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
93 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
94 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
|
95 |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
96 if (targetSeriesUid == seriesUidMap_.end()) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 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
|
99 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 /** |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 * Apply user-specified modifications |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 **/ |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
106 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
|
107 it != removals_.end(); ++it) |
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 modified->Remove(*it); |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 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
|
113 it != replacements_.end(); ++it) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 modified->ReplacePlainString(it->first, it->second); |
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 |
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 * Store the new instance into Orthanc |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 **/ |
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(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
|
124 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
|
125 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 if (targetStudy_.empty()) |
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 targetStudy_ = modified->GetHasher().HashStudy(); |
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 DicomInstanceToStore toStore; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 toStore.SetOrigin(origin_); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 toStore.SetParsedDicomFile(*modified); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 std::string modifiedInstance; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 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
|
139 return false; |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 return true; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 } |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 bool SplitStudyJob::HandleTrailingStep() |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 if (!keepSource_) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 const size_t n = GetInstancesCount(); |
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 for (size_t i = 0; i < n; i++) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 Json::Value tmp; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 context_.DeleteResource(tmp, GetInstance(i), ResourceType_Instance); |
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 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 return true; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 SplitStudyJob::SplitStudyJob(ServerContext& context, |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 const std::string& sourceStudy) : |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
165 context_(context), |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
166 keepSource_(false), |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
167 sourceStudy_(sourceStudy), |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
168 targetStudyUid_(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study)) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
170 Setup(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
171 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
172 ResourceType type; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
173 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
174 if (!context_.GetIndex().LookupResourceType(type, sourceStudy) || |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
175 type != ResourceType_Study) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
176 { |
2955 | 177 throw OrthancException(ErrorCode_UnknownResource, |
178 "Cannot split unknown study " + sourceStudy); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
179 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 } |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 void SplitStudyJob::SetOrigin(const DicomInstanceOrigin& origin) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 if (IsStarted()) |
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 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
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 else |
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 origin_ = origin; |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 void SplitStudyJob::SetOrigin(const RestApiCall& call) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 } |
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 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 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
|
203 { |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
204 std::string parent; |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
205 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 } |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
210 else if (!context_.GetIndex().LookupParent(parent, series, ResourceType_Study) || |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
211 parent != sourceStudy_) |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 { |
2955 | 213 throw OrthancException(ErrorCode_UnknownResource, |
214 "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
|
215 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 else |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 { |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
218 // 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
|
219 seriesUidMap_[series] = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series); |
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
220 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 // 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
|
222 std::list<std::string> instances; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 context_.GetIndex().GetChildren(instances, series); |
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 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
|
226 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
|
227 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 AddInstance(*it); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 void SplitStudyJob::SetKeepSource(bool keep) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 keepSource_ = keep; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 |
2847
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
245 bool SplitStudyJob::LookupTargetSeriesUid(std::string& uid, |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
246 const std::string& series) const |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
247 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
248 SeriesUidMap::const_iterator found = seriesUidMap_.find(series); |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
249 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
250 if (found == seriesUidMap_.end()) |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
251 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
252 return false; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
253 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
254 else |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
255 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
256 uid = found->second; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
257 return true; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
258 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
259 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
260 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
261 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 void SplitStudyJob::Remove(const DicomTag& tag) |
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 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 CheckAllowedTag(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 removals_.insert(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 void SplitStudyJob::Replace(const DicomTag& tag, |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 const std::string& value) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 if (IsStarted()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 CheckAllowedTag(tag); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 replacements_[tag] = value; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 } |
2847
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
285 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
286 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
287 bool SplitStudyJob::LookupReplacement(std::string& value, |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
288 const DicomTag& tag) const |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
289 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
290 Replacements::const_iterator found = replacements_.find(tag); |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
291 |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
292 if (found == replacements_.end()) |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
293 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
294 return false; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
295 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
296 else |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
297 { |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
298 value = found->second; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
299 return true; |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
300 } |
2da68edacab6
unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2846
diff
changeset
|
301 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 void SplitStudyJob::GetPublicContent(Json::Value& value) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 SetOfInstancesJob::GetPublicContent(value); |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 if (!targetStudy_.empty()) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 { |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 value["TargetStudy"] = targetStudy_; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 value["TargetStudyUID"] = targetStudyUid_; |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
315 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
316 |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
317 static const char* KEEP_SOURCE = "KeepSource"; |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
318 static const char* SOURCE_STUDY = "SourceStudy"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
319 static const char* TARGET_STUDY = "TargetStudy"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
320 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
|
321 static const char* SERIES_UID_MAP = "SeriesUIDMap"; |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
322 static const char* ORIGIN = "Origin"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
323 static const char* REPLACEMENTS = "Replacements"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
324 static const char* REMOVALS = "Removals"; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
325 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
326 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
327 SplitStudyJob::SplitStudyJob(ServerContext& context, |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
328 const Json::Value& serialized) : |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
329 SetOfInstancesJob(serialized), // (*) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
330 context_(context) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
331 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
332 if (!HasTrailingStep()) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
333 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
334 // Should have been set by (*) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
335 throw OrthancException(ErrorCode_InternalError); |
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 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
338 Setup(); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
339 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
340 keepSource_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SOURCE); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
341 sourceStudy_ = SerializationToolbox::ReadString(serialized, SOURCE_STUDY); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
342 targetStudy_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
343 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
|
344 SerializationToolbox::ReadMapOfStrings(seriesUidMap_, serialized, SERIES_UID_MAP); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
345 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
346 SerializationToolbox::ReadMapOfTags(replacements_, serialized, REPLACEMENTS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
347 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
348 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
349 |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 bool SplitStudyJob::Serialize(Json::Value& target) |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 { |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
353 if (!SetOfInstancesJob::Serialize(target)) |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
354 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
355 return false; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
356 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
357 else |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
358 { |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
359 target[KEEP_SOURCE] = keepSource_; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
360 target[SOURCE_STUDY] = sourceStudy_; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
361 target[TARGET_STUDY] = targetStudy_; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
362 target[TARGET_STUDY_UID] = targetStudyUid_; |
2846
d386abc18133
simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2845
diff
changeset
|
363 SerializationToolbox::WriteMapOfStrings(target, seriesUidMap_, SERIES_UID_MAP); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
364 origin_.Serialize(target[ORIGIN]); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
365 SerializationToolbox::WriteMapOfTags(target, replacements_, REPLACEMENTS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
366 SerializationToolbox::WriteSetOfTags(target, removals_, REMOVALS); |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
367 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
368 return true; |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2844
diff
changeset
|
369 } |
2844
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 } |
99863d6245b2
New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 } |