Mercurial > hg > orthanc
diff OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 3920:82e88ff003d7 c-get
merge default -> c-get
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Tue, 12 May 2020 14:58:24 +0200 |
parents | 6ddad3e0b569 |
children | 7dc5e7e0045d |
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 12 07:50:38 2020 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 12 14:58:24 2020 +0200 @@ -112,19 +112,45 @@ static void AnonymizeOrModifyInstance(DicomModification& modification, - RestApiPostCall& call) + RestApiPostCall& call, + bool transcode, + DicomTransferSyntax targetSyntax) { + ServerContext& context = OrthancRestApi::GetContext(call); std::string id = call.GetUriComponent("id", ""); std::unique_ptr<ParsedDicomFile> modified; { - ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); + ServerContext::DicomCacheLocker locker(context, id); modified.reset(locker.GetDicom().Clone(true)); } modification.Apply(*modified); - modified->Answer(call.GetOutput()); + + if (transcode) + { + std::string transcoded; + DicomTransferSyntax sourceSyntax; + bool hasSopInstanceUidChanged; + + if (context.GetTranscoder().TranscodeParsedToBuffer( + transcoded, sourceSyntax, hasSopInstanceUidChanged, + modified->GetDcmtkObject(), targetSyntax, true)) + { + call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom); + } + else + { + throw OrthancException(ErrorCode_InternalError, + "Cannot transcode to transfer syntax: " + + std::string(GetTransferSyntaxUid(targetSyntax))); + } + } + else + { + modified->Answer(call.GetOutput()); + } } @@ -153,7 +179,25 @@ modification.SetLevel(ResourceType_Instance); } - AnonymizeOrModifyInstance(modification, call); + if (request.isMember("Transcode")) + { + std::string s = SerializationToolbox::ReadString(request, "Transcode"); + + DicomTransferSyntax syntax; + if (LookupTransferSyntax(syntax, s)) + { + AnonymizeOrModifyInstance(modification, call, true, syntax); + } + else + { + throw OrthancException(ErrorCode_ParameterOutOfRange, "Unknown transfer syntax: " + s); + } + } + else + { + AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, + DicomTransferSyntax_LittleEndianImplicit /* unused */); + } } @@ -165,7 +209,8 @@ Json::Value request; ParseAnonymizationRequest(request, modification, call); - AnonymizeOrModifyInstance(modification, call); + AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, + DicomTransferSyntax_LittleEndianImplicit /* unused */); } @@ -227,7 +272,7 @@ toStore.SetParsedDicomFile(dicom); ServerContext& context = OrthancRestApi::GetContext(call); - StoreStatus status = context.Store(id, toStore); + StoreStatus status = context.Store(id, toStore, StoreInstanceMode_Default); if (status == StoreStatus_Failure) { @@ -236,7 +281,7 @@ if (sendAnswer) { - OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status); + OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status, id); } }