Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/Operations/ModifyInstanceOperation.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * modify it under the terms of the GNU General Public License as |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * published by the Free Software Foundation, either version 3 of the |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * License, or (at your option) any later version. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * General Public License for more details. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
2641 | 24 #include "../../PrecompiledHeadersServer.h" |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "ModifyInstanceOperation.h" |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "DicomInstanceOperationValue.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
28 #include "../../ServerContext.h" |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
4045 | 30 #include "../../../../OrthancFramework/Sources/Logging.h" |
31 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h" | |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 namespace Orthanc |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 ModifyInstanceOperation::ModifyInstanceOperation(ServerContext& context, |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 RequestOrigin origin, |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 DicomModification* modification) : |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 context_(context), |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 origin_(origin), |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 modification_(modification) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 if (modification == NULL) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 throw OrthancException(ErrorCode_NullPointer); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
5122
8638522eeda1
revert changeset df4a90a65af9 that removes features used elsewhere, and protect by Force the change of UIDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5087
diff
changeset
|
47 modification_->SetAllowManualIdentifiers(true); |
8638522eeda1
revert changeset df4a90a65af9 that removes features used elsewhere, and protect by Force the change of UIDs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5087
diff
changeset
|
48 |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 if (modification_->IsReplaced(DICOM_TAG_PATIENT_ID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 modification_->SetLevel(ResourceType_Patient); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 else if (modification_->IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 modification_->SetLevel(ResourceType_Study); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 else if (modification_->IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID)) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 modification_->SetLevel(ResourceType_Series); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 else |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 modification_->SetLevel(ResourceType_Instance); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 if (origin_ != RequestOrigin_Lua) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 // TODO If issued from HTTP, "remoteIp" and "username" must be provided |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 throw OrthancException(ErrorCode_NotImplemented); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 void ModifyInstanceOperation::Apply(JobOperationValues& outputs, |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
74 const IJobOperationValue& input) |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
76 if (input.GetType() != IJobOperationValue::Type_DicomInstance) |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 throw OrthancException(ErrorCode_BadParameterType); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 const DicomInstanceOperationValue& instance = |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 dynamic_cast<const DicomInstanceOperationValue&>(input); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 LOG(INFO) << "Lua: Modifying instance " << instance.GetId(); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
86 std::unique_ptr<ParsedDicomFile> modified; |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 ServerContext::DicomCacheLocker lock(context_, instance.GetId()); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 modified.reset(lock.GetDicom().Clone(true)); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 try |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 modification_->Apply(*modified); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
97 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*modified)); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 assert(origin_ == RequestOrigin_Lua); |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
99 toStore->SetOrigin(DicomInstanceOrigin::FromLua()); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 // TODO other metadata |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
102 toStore->AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, instance.GetId()); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 std::string modifiedId; |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
105 context_.Store(modifiedId, *toStore, StoreInstanceMode_Default); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 // Only chain with other commands if this command succeeds |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
108 outputs.Append(new DicomInstanceOperationValue(instance.GetServerContext(), modifiedId)); |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 catch (OrthancException& e) |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 { |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 LOG(ERROR) << "Lua: Unable to modify instance " << instance.GetId() |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 << ": " << e.What(); |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 } |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
116 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
117 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
118 void ModifyInstanceOperation::Serialize(Json::Value& target) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
119 { |
2655 | 120 target = Json::objectValue; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
121 target["Type"] = "ModifyInstance"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
122 target["Origin"] = EnumerationToString(origin_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
123 modification_->Serialize(target["Modification"]); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
124 } |
2655 | 125 |
126 | |
127 ModifyInstanceOperation::ModifyInstanceOperation(ServerContext& context, | |
128 const Json::Value& serialized) : | |
129 context_(context) | |
130 { | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
131 if (SerializationToolbox::ReadString(serialized, "Type") != "ModifyInstance" || |
2655 | 132 !serialized.isMember("Modification")) |
133 { | |
134 throw OrthancException(ErrorCode_BadFileFormat); | |
135 } | |
136 | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
137 origin_ = StringToRequestOrigin(SerializationToolbox::ReadString(serialized, "Origin")); |
2655 | 138 |
139 modification_.reset(new DicomModification(serialized["Modification"])); | |
140 } | |
2607
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 } |
44e268605478
ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |