annotate OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp @ 4880:81dfdcf16e16

merge
author Alain Mazy <am@osimis.io>
date Wed, 19 Jan 2022 17:06:22 +0100
parents 43e613a7756b
children 6eff25f70121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * 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
12 *
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * 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
22 * 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
23 * 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
24 *
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * 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
26 * 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
27 * 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
28 * General Public License for more details.
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 *
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * 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
31 * 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
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "SplitStudyJob.h"
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
3095
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
40 #include "../ServerContext.h"
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
41
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 namespace Orthanc
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 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
46 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 if (allowedTags_.find(tag) == allowedTags_.end())
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
49 throw OrthancException(ErrorCode_ParameterOutOfRange,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
50 "Cannot modify the following tag while splitting a study "
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
51 "(not in the patient/study modules): " +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
52 FromDcmtkBridge::GetTagName(tag, "") +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
53 " (" + tag.Format() + ")");
2844
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
58 void SplitStudyJob::Setup()
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 SetPermissive(false);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Patient);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 DicomTag::AddTagsForModule(allowedTags_, DicomModule_Study);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 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
65 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
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 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
70 {
3940
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
71 if (!HasTrailingStep())
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
72 {
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
73 throw OrthancException(ErrorCode_BadSequenceOfCalls,
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
74 "AddTrailingStep() should have been called after AddSourceSeries()");
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
75 }
3661e2a72482 safeguard in merge/split job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3814
diff changeset
76
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 /**
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 * 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
79 **/
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
81 std::unique_ptr<ParsedDicomFile> modified;
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 try
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
3941
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
85 ServerContext::DicomCacheLocker locker(GetContext(), instance);
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 modified.reset(locker.GetDicom().Clone(true));
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 catch (OrthancException&)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 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
91 return false;
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 /**
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 * Chose the target UIDs
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 **/
2846
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
98
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
99 assert(modified->GetHasher().HashStudy() == sourceStudy_);
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
100
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
101 std::string series = modified->GetHasher().HashSeries();
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
102
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
103 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
104
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
105 if (targetSeriesUid == seriesUidMap_.end())
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 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
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 /**
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 * Apply user-specified modifications
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 **/
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
115 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
116 it != removals_.end(); ++it)
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 modified->Remove(*it);
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 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
122 it != replacements_.end(); ++it)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 modified->ReplacePlainString(it->first, it->second);
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 /**
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 * Store the new instance into Orthanc
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 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
133 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
134
3507
69e49fc044f8 Fix generation of "SOP Instance UID" on split and merge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3095
diff changeset
135 // 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
136 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
137
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 if (targetStudy_.empty())
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 targetStudy_ = modified->GetHasher().HashStudy();
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
4508
8f9090b137f1 Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
143 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
144 toStore->SetOrigin(origin_);
2844
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 std::string modifiedInstance;
4796
94616af363ec added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents: 4712
diff changeset
147 ServerContext::StoreResult result = GetContext().Store(modifiedInstance, *toStore, StoreInstanceMode_Default);
94616af363ec added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents: 4712
diff changeset
148 if (result.GetStatus() != StoreStatus_Success)
2844
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 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
151 return false;
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 return true;
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 SplitStudyJob::SplitStudyJob(ServerContext& context,
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 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
160 CleaningInstancesJob(context, false /* by default, remove source instances */),
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
161 sourceStudy_(sourceStudy),
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
162 targetStudyUid_(FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study))
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
164 Setup();
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
165
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
166 ResourceType type;
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
167
3941
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
168 if (!GetContext().GetIndex().LookupResourceType(type, sourceStudy) ||
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
169 type != ResourceType_Study)
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
170 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
171 throw OrthancException(ErrorCode_UnknownResource,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
172 "Cannot split unknown study " + sourceStudy);
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
173 }
2844
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 void SplitStudyJob::SetOrigin(const DicomInstanceOrigin& origin)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 if (IsStarted())
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 throw OrthancException(ErrorCode_BadSequenceOfCalls);
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 else
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 origin_ = origin;
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 void SplitStudyJob::SetOrigin(const RestApiCall& call)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 SetOrigin(DicomInstanceOrigin::FromRest(call));
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
4712
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
196 static void RegisterSeries(std::map<std::string, std::string>& target,
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
197 const std::string& series)
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
198 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
199 // Generate a target SeriesInstanceUID for this series
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
200 if (target.find(series) == target.end())
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
201 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
202 target[series] = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series);
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
203 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
204 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
205
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
206
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 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
208 {
2846
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
209 std::string parent;
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
210
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 if (IsStarted())
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 throw OrthancException(ErrorCode_BadSequenceOfCalls);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
3941
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
215 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
216 parent != sourceStudy_)
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
218 throw OrthancException(ErrorCode_UnknownResource,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
219 "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
220 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 else
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
4712
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
223 RegisterSeries(seriesUidMap_, series);
2846
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
224
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 // 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
226 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
227 GetContext().GetIndex().GetChildren(instances, series);
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 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
230 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
231 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 AddInstance(*it);
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 }
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
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
4712
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
238 void SplitStudyJob::AddSourceInstance(const std::string& instance)
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
239 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
240 std::string study, series;
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
241
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
242 if (IsStarted())
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
243 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
244 throw OrthancException(ErrorCode_BadSequenceOfCalls);
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
245 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
246 else if (!GetContext().GetIndex().LookupParent(series, instance, ResourceType_Series) ||
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
247 !GetContext().GetIndex().LookupParent(study, series, ResourceType_Study) ||
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
248 study != sourceStudy_)
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
249 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
250 throw OrthancException(ErrorCode_UnknownResource,
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
251 "This instance does not belong to the study to be split: " + instance);
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
252 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
253 else
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
254 {
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
255 RegisterSeries(seriesUidMap_, series);
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
256 AddInstance(instance);
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
257 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
258 }
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
259
bad8935cd5f2 "/studies/{id}/split" accepts "Instances" parameter to split instances instead of series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4508
diff changeset
260
2847
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
261 bool SplitStudyJob::LookupTargetSeriesUid(std::string& uid,
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
262 const std::string& series) const
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
263 {
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
264 SeriesUidMap::const_iterator found = seriesUidMap_.find(series);
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
265
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
266 if (found == seriesUidMap_.end())
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 return false;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
269 }
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
270 else
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 uid = found->second;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
273 return true;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
274 }
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
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
277
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 void SplitStudyJob::Remove(const DicomTag& tag)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 if (IsStarted())
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 throw OrthancException(ErrorCode_BadSequenceOfCalls);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
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 CheckAllowedTag(tag);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 removals_.insert(tag);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
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 void SplitStudyJob::Replace(const DicomTag& tag,
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 const std::string& value)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (IsStarted())
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 throw OrthancException(ErrorCode_BadSequenceOfCalls);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 CheckAllowedTag(tag);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 replacements_[tag] = value;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
2847
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
301
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
302
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
303 bool SplitStudyJob::LookupReplacement(std::string& value,
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
304 const DicomTag& tag) const
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
305 {
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
306 Replacements::const_iterator found = replacements_.find(tag);
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
307
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
308 if (found == replacements_.end())
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
309 {
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
310 return false;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
311 }
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
312 else
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
313 {
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
314 value = found->second;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
315 return true;
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
316 }
2da68edacab6 unit testing of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2846
diff changeset
317 }
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 void SplitStudyJob::GetPublicContent(Json::Value& value)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 {
3941
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
322 CleaningInstancesJob::GetPublicContent(value);
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 if (!targetStudy_.empty())
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 value["TargetStudy"] = targetStudy_;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 value["TargetStudyUID"] = targetStudyUid_;
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
2845
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
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
333 static const char* SOURCE_STUDY = "SourceStudy";
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
334 static const char* TARGET_STUDY = "TargetStudy";
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
335 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
336 static const char* SERIES_UID_MAP = "SeriesUIDMap";
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
337 static const char* ORIGIN = "Origin";
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
338 static const char* REPLACEMENTS = "Replacements";
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
339 static const char* REMOVALS = "Removals";
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
340
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
341
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
342 SplitStudyJob::SplitStudyJob(ServerContext& context,
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
343 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
344 CleaningInstancesJob(context, serialized,
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
345 false /* by default, remove source instances */) // (*)
2845
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 if (!HasTrailingStep())
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 // Should have been set by (*)
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
350 throw OrthancException(ErrorCode_InternalError);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
351 }
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
352
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
353 Setup();
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 sourceStudy_ = SerializationToolbox::ReadString(serialized, SOURCE_STUDY);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
356 targetStudy_ = SerializationToolbox::ReadString(serialized, TARGET_STUDY);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
357 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
358 SerializationToolbox::ReadMapOfStrings(seriesUidMap_, serialized, SERIES_UID_MAP);
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
359 origin_ = DicomInstanceOrigin(serialized[ORIGIN]);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
360 SerializationToolbox::ReadMapOfTags(replacements_, serialized, REPLACEMENTS);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
361 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
362 }
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
363
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 bool SplitStudyJob::Serialize(Json::Value& target)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
3941
771dbd9eb3bd class CleaningInstancesJob to share cleaning code by merge/split jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3940
diff changeset
367 if (!CleaningInstancesJob::Serialize(target))
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
368 {
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
369 return false;
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
370 }
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
371 else
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
372 {
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
373 target[SOURCE_STUDY] = sourceStudy_;
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
374 target[TARGET_STUDY] = targetStudy_;
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
375 target[TARGET_STUDY_UID] = targetStudyUid_;
2846
d386abc18133 simplification in SplitStudyJob, fix possible memory leak
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
376 SerializationToolbox::WriteMapOfStrings(target, seriesUidMap_, SERIES_UID_MAP);
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
377 origin_.Serialize(target[ORIGIN]);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
378 SerializationToolbox::WriteMapOfTags(target, replacements_, REPLACEMENTS);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
379 SerializationToolbox::WriteSetOfTags(target, removals_, REMOVALS);
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
380
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
381 return true;
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
382 }
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }