Mercurial > hg > orthanc
changeset 3086:74e3e48aa9bd db-changes
grouping the setting of metadata
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 04 Jan 2019 17:10:58 +0100 |
parents | c829758b9ca0 |
children | df1b17be20f6 |
files | OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h |
diffstat | 2 files changed, 121 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/ServerIndex.cpp Fri Jan 04 16:52:53 2019 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Jan 04 17:10:58 2019 +0100 @@ -671,13 +671,13 @@ } - - void ServerIndex::SetInstanceMetadata(std::map<MetadataType, std::string>& instanceMetadata, - int64_t instance, - MetadataType metadata, - const std::string& value) + static void SetInstanceMetadata(ResourcesContent& content, + std::map<MetadataType, std::string>& instanceMetadata, + int64_t instance, + MetadataType metadata, + const std::string& value) { - db_.SetMetadata(instance, metadata, value); + content.AddMetadata(instance, metadata, value); instanceMetadata[metadata] = value; } @@ -774,13 +774,21 @@ } Recycle(instanceSize, hashPatient /* don't consider the current patient for recycling */); + + + // Attach the files to the newly created instance + for (Attachments::const_iterator it = attachments.begin(); + it != attachments.end(); ++it) + { + db_.AddAttachment(instanceId, *it); + } - // Populate the newly-created resources - { ResourcesContent content; + // Populate the tags of the newly-created resources + content.AddResource(instanceId, ResourceType_Instance, dicomSummary); if (status.isNewSeries_) @@ -798,105 +806,113 @@ content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary); } + + // Attach the user-specified metadata + + for (MetadataMap::const_iterator + it = metadata.begin(); it != metadata.end(); ++it) + { + switch (it->first.first) + { + case ResourceType_Patient: + content.AddMetadata(status.patientId_, it->first.second, it->second); + break; + + case ResourceType_Study: + content.AddMetadata(status.studyId_, it->first.second, it->second); + break; + + case ResourceType_Series: + content.AddMetadata(status.seriesId_, it->first.second, it->second); + break; + + case ResourceType_Instance: + SetInstanceMetadata(content, instanceMetadata, instanceId, + it->first.second, it->second); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + + // Attach the auto-computed metadata for the patient/study/series levels + std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); + content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now); + content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now); + content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now); + + + // Attach the auto-computed metadata for the instance level, + // reflecting these additions into the input metadata map + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_ReceptionDate, now); + SetInstanceMetadata(content, instanceMetadata, instanceId, MetadataType_Instance_RemoteAet, + instanceToStore.GetOrigin().GetRemoteAetC()); + SetInstanceMetadata(content, instanceMetadata, instanceId, MetadataType_Instance_Origin, + EnumerationToString(instanceToStore.GetOrigin().GetRequestOrigin())); + + + { + std::string s; + + if (instanceToStore.LookupTransferSyntax(s)) + { + // New in Orthanc 1.2.0 + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_TransferSyntax, s); + } + + if (instanceToStore.GetOrigin().LookupRemoteIp(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_RemoteIp, s); + } + + if (instanceToStore.GetOrigin().LookupCalledAet(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_CalledAet, s); + } + + if (instanceToStore.GetOrigin().LookupHttpUsername(s)) + { + // New in Orthanc 1.4.0 + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_HttpUsername, s); + } + } + + + const DicomValue* value; + if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL && + !value->IsNull() && + !value->IsBinary()) + { + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_SopClassUid, value->GetContent()); + } + + + if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || + (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) + { + if (!value->IsNull() && + !value->IsBinary()) + { + SetInstanceMetadata(content, instanceMetadata, instanceId, + MetadataType_Instance_IndexInSeries, value->GetContent()); + } + } + + db_.SetResourcesContent(content); } - - - // Attach the files to the newly created instance - for (Attachments::const_iterator it = attachments.begin(); - it != attachments.end(); ++it) - { - db_.AddAttachment(instanceId, *it); - } - - - // Attach the user-specified metadata - // TODO - GROUP THIS - for (MetadataMap::const_iterator - it = metadata.begin(); it != metadata.end(); ++it) - { - switch (it->first.first) - { - case ResourceType_Patient: - db_.SetMetadata(status.patientId_, it->first.second, it->second); - break; - - case ResourceType_Study: - db_.SetMetadata(status.studyId_, it->first.second, it->second); - break; - - case ResourceType_Series: - db_.SetMetadata(status.seriesId_, it->first.second, it->second); - break; - - case ResourceType_Instance: - SetInstanceMetadata(instanceMetadata, instanceId, it->first.second, it->second); - break; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } - - // Attach the auto-computed metadata for the patient/study/series levels - std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); - db_.SetMetadata(status.seriesId_, MetadataType_LastUpdate, now); - db_.SetMetadata(status.studyId_, MetadataType_LastUpdate, now); - db_.SetMetadata(status.patientId_, MetadataType_LastUpdate, now); - - // Attach the auto-computed metadata for the instance level, - // reflecting these additions into the input metadata map - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_ReceptionDate, now); - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_RemoteAet, - instanceToStore.GetOrigin().GetRemoteAetC()); - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_Origin, - EnumerationToString(instanceToStore.GetOrigin().GetRequestOrigin())); - - { - std::string s; - - if (instanceToStore.LookupTransferSyntax(s)) - { - // New in Orthanc 1.2.0 - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_TransferSyntax, s); - } - - if (instanceToStore.GetOrigin().LookupRemoteIp(s)) - { - // New in Orthanc 1.4.0 - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_RemoteIp, s); - } - - if (instanceToStore.GetOrigin().LookupCalledAet(s)) - { - // New in Orthanc 1.4.0 - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_CalledAet, s); - } - - if (instanceToStore.GetOrigin().LookupHttpUsername(s)) - { - // New in Orthanc 1.4.0 - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_HttpUsername, s); - } - } - - const DicomValue* value; - if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL && - !value->IsNull() && - !value->IsBinary()) - { - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_SopClassUid, value->GetContent()); - } - - if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || - (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) - { - if (!value->IsNull() && - !value->IsBinary()) - { - SetInstanceMetadata(instanceMetadata, instanceId, MetadataType_Instance_IndexInSeries, value->GetContent()); - } - } + + // Check whether the series of this new instance is now completed if (status.isNewSeries_)
--- a/OrthancServer/ServerIndex.h Fri Jan 04 16:52:53 2019 +0100 +++ b/OrthancServer/ServerIndex.h Fri Jan 04 17:10:58 2019 +0100 @@ -123,11 +123,6 @@ uint64_t IncrementGlobalSequenceInternal(GlobalProperty property); - void SetInstanceMetadata(std::map<MetadataType, std::string>& instanceMetadata, - int64_t instance, - MetadataType metadata, - const std::string& value); - void NormalizeLookup(std::vector<DatabaseConstraint>& target, const DatabaseLookup& source, ResourceType level) const;