Mercurial > hg > orthanc
changeset 1566:3be6eb3757c8
error handling
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Aug 2015 17:37:13 +0200 |
parents | 4b23310eb7e8 |
children | 9c5d93510414 |
files | OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp |
diffstat | 2 files changed, 57 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Fri Aug 21 17:29:16 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Fri Aug 21 17:37:13 2015 +0200 @@ -549,54 +549,76 @@ std::string someInstance; - for (Json::ArrayIndex i = 0; i < content.size(); i++) + bool ok = true; + + try { - std::auto_ptr<ParsedDicomFile> dicom(base.Clone()); - const Json::Value* payload = NULL; - - if (content[i].type() == Json::stringValue) + for (Json::ArrayIndex i = 0; ok && i < content.size(); i++) { - payload = &content[i]; - } - else if (content[i].type() == Json::objectValue) - { - if (!content[i].isMember("Content")) + std::auto_ptr<ParsedDicomFile> dicom(base.Clone()); + const Json::Value* payload = NULL; + + if (content[i].type() == Json::stringValue) + { + payload = &content[i]; + } + else if (content[i].type() == Json::objectValue) { - LOG(ERROR) << "No payload is present for one instance in the series"; - return; + if (!content[i].isMember("Content")) + { + LOG(ERROR) << "No payload is present for one instance in the series"; + ok = false; + break; + } + + payload = &content[i]["Content"]; + + if (content[i].isMember("Tags") && + !InjectTags(*dicom, content[i]["Tags"])) + { + ok = false; + break; + } } - payload = &content[i]["Content"]; + if (payload == NULL || + payload->type() != Json::stringValue) + { + LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; + ok = false; + break; + } - if (content[i].isMember("Tags") && - !InjectTags(*dicom, content[i]["Tags"])) + dicom->EmbedContent(payload->asString()); + dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); + dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); + + if (!StoreCreatedInstance(someInstance, context, *dicom)) { - return; + LOG(ERROR) << "Error while creating the series"; + ok = false; + break; } } - - if (payload == NULL || - payload->type() != Json::stringValue) - { - LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; - return; - } - - dicom->EmbedContent(payload->asString()); - dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); - dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); - - if (!StoreCreatedInstance(someInstance, context, *dicom)) - { - LOG(ERROR) << "Error while creating the series"; - return; - } + } + catch (OrthancException&) + { + ok = false; } std::string series; if (context.GetIndex().LookupParent(series, someInstance)) { - OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); + if (ok) + { + OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); + } + else + { + // Error: Remove the newly-created series + Json::Value dummy; + context.GetIndex().DeleteResource(dummy, series, ResourceType_Series); + } } }
--- a/OrthancServer/ParsedDicomFile.cpp Fri Aug 21 17:29:16 2015 +0200 +++ b/OrthancServer/ParsedDicomFile.cpp Fri Aug 21 17:37:13 2015 +0200 @@ -1398,7 +1398,7 @@ Replace(FromDcmtkBridge::Convert(DCM_Modality), "OT"); Replace(FromDcmtkBridge::Convert(DCM_ConversionType), "WSD"); Replace(FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument), "application/pdf"); - Replace(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1"); + //Replace(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1"); std::auto_ptr<DcmPolymorphOBOW> element(new DcmPolymorphOBOW(DCM_EncapsulatedDocument));