Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5226:49e906a8fea2 db-protobuf
integration mainline->db-protobuf
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Apr 2023 07:09:22 +0200 |
parents | 3a61fd50f804 5874e5dd9a38 |
children | 7363b6e7edf5 |
comparison
equal
deleted
inserted
replaced
5222:3a61fd50f804 | 5226:49e906a8fea2 |
---|---|
2965 std::map<MetadataType, std::string>& instanceMetadata, | 2965 std::map<MetadataType, std::string>& instanceMetadata, |
2966 int64_t instance, | 2966 int64_t instance, |
2967 MetadataType metadata, | 2967 MetadataType metadata, |
2968 const std::string& value) | 2968 const std::string& value) |
2969 { | 2969 { |
2970 if (metadata == 15) | |
2971 { | |
2972 LOG(INFO) << "toto"; | |
2973 } | |
2970 content.AddMetadata(instance, metadata, value); | 2974 content.AddMetadata(instance, metadata, value); |
2971 instanceMetadata[metadata] = value; | 2975 instanceMetadata[metadata] = value; |
2972 } | 2976 } |
2973 | 2977 |
2974 static void SetMainDicomSequenceMetadata(ResourcesContent& content, | 2978 static void SetMainDicomSequenceMetadata(ResourcesContent& content, |
3090 { | 3094 { |
3091 try | 3095 try |
3092 { | 3096 { |
3093 IDatabaseWrapper::CreateInstanceResult status; | 3097 IDatabaseWrapper::CreateInstanceResult status; |
3094 int64_t instanceId; | 3098 int64_t instanceId; |
3099 | |
3100 bool isNewInstance = transaction.CreateInstance(status, instanceId, hashPatient_, | |
3101 hashStudy_, hashSeries_, hashInstance_); | |
3102 | |
3103 if (isReconstruct_ && isNewInstance) | |
3104 { | |
3105 // In case of reconstruct, we just want to modify the attachments and some metadata like the TransferSyntex | |
3106 // The DicomTags and many metadata have already been updated before we get here in ReconstructInstance | |
3107 throw OrthancException(ErrorCode_InternalError, "New instance while reconstructing; this should not happen."); | |
3108 } | |
3095 | 3109 |
3096 // Check whether this instance is already stored | 3110 // Check whether this instance is already stored |
3097 if (!transaction.CreateInstance(status, instanceId, hashPatient_, | 3111 if (!isNewInstance && !isReconstruct_) |
3098 hashStudy_, hashSeries_, hashInstance_)) | |
3099 { | 3112 { |
3100 // The instance already exists | 3113 // The instance already exists |
3101 | |
3102 if (overwrite_) | 3114 if (overwrite_) |
3103 { | 3115 { |
3104 // Overwrite the old instance | 3116 // Overwrite the old instance |
3105 LOG(INFO) << "Overwriting instance: " << hashInstance_; | 3117 LOG(INFO) << "Overwriting instance: " << hashInstance_; |
3106 transaction.DeleteResource(instanceId); | 3118 transaction.DeleteResource(instanceId); |
3107 | 3119 |
3108 // Re-create the instance, now that the old one is removed | 3120 // Re-create the instance, now that the old one is removed |
3109 if (!transaction.CreateInstance(status, instanceId, hashPatient_, | 3121 if (!transaction.CreateInstance(status, instanceId, hashPatient_, |
3110 hashStudy_, hashSeries_, hashInstance_)) | 3122 hashStudy_, hashSeries_, hashInstance_)) |
3111 { | 3123 { |
3112 throw OrthancException(ErrorCode_InternalError); | 3124 throw OrthancException(ErrorCode_InternalError, "No new instance while overwriting; this should not happen."); |
3113 } | 3125 } |
3114 } | 3126 } |
3115 else | 3127 else |
3116 { | 3128 { |
3117 // Do nothing if the instance already exists and overwriting is disabled | 3129 // Do nothing if the instance already exists and overwriting is disabled |
3182 | 3194 |
3183 // Attach the files to the newly created instance | 3195 // Attach the files to the newly created instance |
3184 for (Attachments::const_iterator it = attachments_.begin(); | 3196 for (Attachments::const_iterator it = attachments_.begin(); |
3185 it != attachments_.end(); ++it) | 3197 it != attachments_.end(); ++it) |
3186 { | 3198 { |
3199 if (isReconstruct_) | |
3200 { | |
3201 // we are replacing attachments during a reconstruction | |
3202 transaction.DeleteAttachment(instanceId, it->GetContentType()); | |
3203 } | |
3204 | |
3187 transaction.AddAttachment(instanceId, *it, 0 /* this is the first revision */); | 3205 transaction.AddAttachment(instanceId, *it, 0 /* this is the first revision */); |
3188 } | 3206 } |
3189 | 3207 |
3190 | 3208 if (!isReconstruct_) |
3191 { | 3209 { |
3192 ResourcesContent content(true /* new resource, metadata can be set */); | 3210 ResourcesContent content(true /* new resource, metadata can be set */); |
3193 | |
3194 | 3211 |
3195 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep) | 3212 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep) |
3196 for (MetadataMap::const_iterator | 3213 for (MetadataMap::const_iterator |
3197 it = metadata_.begin(); it != metadata_.end(); ++it) | 3214 it = metadata_.begin(); it != metadata_.end(); ++it) |
3198 { | 3215 { |
3218 default: | 3235 default: |
3219 throw OrthancException(ErrorCode_ParameterOutOfRange); | 3236 throw OrthancException(ErrorCode_ParameterOutOfRange); |
3220 } | 3237 } |
3221 } | 3238 } |
3222 | 3239 |
3223 // Populate the tags of the newly-created resources | 3240 if (!isReconstruct_) |
3224 | 3241 { |
3225 content.AddResource(instanceId, ResourceType_Instance, dicomSummary_); | 3242 // Populate the tags of the newly-created resources |
3226 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0 | 3243 content.AddResource(instanceId, ResourceType_Instance, dicomSummary_); |
3227 SetMainDicomSequenceMetadata(content, instanceId, dicomSummary_, ResourceType_Instance); // new in Orthanc 1.11.1 | 3244 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0 |
3228 | 3245 SetMainDicomSequenceMetadata(content, instanceId, dicomSummary_, ResourceType_Instance); // new in Orthanc 1.11.1 |
3229 if (status.isNewSeries_) | 3246 |
3230 { | 3247 if (status.isNewSeries_) |
3231 content.AddResource(status.seriesId_, ResourceType_Series, dicomSummary_); | |
3232 content.AddMetadata(status.seriesId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0 | |
3233 SetMainDicomSequenceMetadata(content, status.seriesId_, dicomSummary_, ResourceType_Series); // new in Orthanc 1.11.1 | |
3234 } | |
3235 | |
3236 if (status.isNewStudy_) | |
3237 { | |
3238 content.AddResource(status.studyId_, ResourceType_Study, dicomSummary_); | |
3239 content.AddMetadata(status.studyId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0 | |
3240 SetMainDicomSequenceMetadata(content, status.studyId_, dicomSummary_, ResourceType_Study); // new in Orthanc 1.11.1 | |
3241 } | |
3242 | |
3243 if (status.isNewPatient_) | |
3244 { | |
3245 content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary_); | |
3246 content.AddMetadata(status.patientId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0 | |
3247 SetMainDicomSequenceMetadata(content, status.patientId_, dicomSummary_, ResourceType_Patient); // new in Orthanc 1.11.1 | |
3248 } | |
3249 | |
3250 // Attach the auto-computed metadata for the patient/study/series levels | |
3251 std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); | |
3252 content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now); | |
3253 content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now); | |
3254 content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now); | |
3255 | |
3256 if (status.isNewSeries_) | |
3257 { | |
3258 if (hasExpectedInstances_) | |
3259 { | 3248 { |
3260 content.AddMetadata(status.seriesId_, MetadataType_Series_ExpectedNumberOfInstances, | 3249 content.AddResource(status.seriesId_, ResourceType_Series, dicomSummary_); |
3261 boost::lexical_cast<std::string>(expectedInstances_)); | 3250 content.AddMetadata(status.seriesId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0 |
3251 SetMainDicomSequenceMetadata(content, status.seriesId_, dicomSummary_, ResourceType_Series); // new in Orthanc 1.11.1 | |
3262 } | 3252 } |
3263 | 3253 |
3264 // New in Orthanc 1.9.0 | 3254 if (status.isNewStudy_) |
3265 content.AddMetadata(status.seriesId_, MetadataType_RemoteAet, | 3255 { |
3266 origin_.GetRemoteAetC()); | 3256 content.AddResource(status.studyId_, ResourceType_Study, dicomSummary_); |
3267 } | 3257 content.AddMetadata(status.studyId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0 |
3268 | 3258 SetMainDicomSequenceMetadata(content, status.studyId_, dicomSummary_, ResourceType_Study); // new in Orthanc 1.11.1 |
3269 if (hasTransferSyntax_) | 3259 } |
3270 { | 3260 |
3271 // New in Orthanc 1.2.0 | 3261 if (status.isNewPatient_) |
3272 SetInstanceMetadata(content, instanceMetadata_, instanceId, | 3262 { |
3273 MetadataType_Instance_TransferSyntax, | 3263 content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary_); |
3274 GetTransferSyntaxUid(transferSyntax_)); | 3264 content.AddMetadata(status.patientId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0 |
3275 } | 3265 SetMainDicomSequenceMetadata(content, status.patientId_, dicomSummary_, ResourceType_Patient); // new in Orthanc 1.11.1 |
3276 | 3266 } |
3277 if (!isReconstruct_) // don't change origin metadata | 3267 |
3278 { | 3268 // Attach the auto-computed metadata for the patient/study/series levels |
3269 std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); | |
3270 content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now); | |
3271 content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now); | |
3272 content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now); | |
3273 | |
3274 if (status.isNewSeries_) | |
3275 { | |
3276 if (hasExpectedInstances_) | |
3277 { | |
3278 content.AddMetadata(status.seriesId_, MetadataType_Series_ExpectedNumberOfInstances, | |
3279 boost::lexical_cast<std::string>(expectedInstances_)); | |
3280 } | |
3281 | |
3282 // New in Orthanc 1.9.0 | |
3283 content.AddMetadata(status.seriesId_, MetadataType_RemoteAet, | |
3284 origin_.GetRemoteAetC()); | |
3285 } | |
3279 // Attach the auto-computed metadata for the instance level, | 3286 // Attach the auto-computed metadata for the instance level, |
3280 // reflecting these additions into the input metadata map | 3287 // reflecting these additions into the input metadata map |
3281 SetInstanceMetadata(content, instanceMetadata_, instanceId, | 3288 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
3282 MetadataType_Instance_ReceptionDate, now); | 3289 MetadataType_Instance_ReceptionDate, now); |
3283 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_RemoteAet, | 3290 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_RemoteAet, |
3305 { | 3312 { |
3306 // New in Orthanc 1.4.0 | 3313 // New in Orthanc 1.4.0 |
3307 SetInstanceMetadata(content, instanceMetadata_, instanceId, | 3314 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
3308 MetadataType_Instance_HttpUsername, s); | 3315 MetadataType_Instance_HttpUsername, s); |
3309 } | 3316 } |
3317 } | |
3318 | |
3319 // Following metadatas are also updated if reconstructing the instance. | |
3320 // They might be missing since they have been introduced along Orthanc versions. | |
3321 | |
3322 if (hasTransferSyntax_) | |
3323 { | |
3324 // New in Orthanc 1.2.0 | |
3325 SetInstanceMetadata(content, instanceMetadata_, instanceId, | |
3326 MetadataType_Instance_TransferSyntax, | |
3327 GetTransferSyntaxUid(transferSyntax_)); | |
3310 } | 3328 } |
3311 | 3329 |
3312 if (hasPixelDataOffset_) | 3330 if (hasPixelDataOffset_) |
3313 { | 3331 { |
3314 // New in Orthanc 1.9.1 | 3332 // New in Orthanc 1.9.1 |