Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1566:3be6eb3757c8
error handling
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Aug 2015 17:37:13 +0200 |
parents | 4b23310eb7e8 |
children | 27774f6f84e4 |
comparison
equal
deleted
inserted
replaced
1565:4b23310eb7e8 | 1566:3be6eb3757c8 |
---|---|
547 base.Replace(DICOM_TAG_IMAGES_IN_ACQUISITION, boost::lexical_cast<std::string>(content.size())); | 547 base.Replace(DICOM_TAG_IMAGES_IN_ACQUISITION, boost::lexical_cast<std::string>(content.size())); |
548 base.Replace(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "1"); | 548 base.Replace(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS, "1"); |
549 | 549 |
550 std::string someInstance; | 550 std::string someInstance; |
551 | 551 |
552 for (Json::ArrayIndex i = 0; i < content.size(); i++) | 552 bool ok = true; |
553 { | 553 |
554 std::auto_ptr<ParsedDicomFile> dicom(base.Clone()); | 554 try |
555 const Json::Value* payload = NULL; | 555 { |
556 | 556 for (Json::ArrayIndex i = 0; ok && i < content.size(); i++) |
557 if (content[i].type() == Json::stringValue) | 557 { |
558 { | 558 std::auto_ptr<ParsedDicomFile> dicom(base.Clone()); |
559 payload = &content[i]; | 559 const Json::Value* payload = NULL; |
560 } | 560 |
561 else if (content[i].type() == Json::objectValue) | 561 if (content[i].type() == Json::stringValue) |
562 { | 562 { |
563 if (!content[i].isMember("Content")) | 563 payload = &content[i]; |
564 { | 564 } |
565 LOG(ERROR) << "No payload is present for one instance in the series"; | 565 else if (content[i].type() == Json::objectValue) |
566 return; | 566 { |
567 } | 567 if (!content[i].isMember("Content")) |
568 | 568 { |
569 payload = &content[i]["Content"]; | 569 LOG(ERROR) << "No payload is present for one instance in the series"; |
570 | 570 ok = false; |
571 if (content[i].isMember("Tags") && | 571 break; |
572 !InjectTags(*dicom, content[i]["Tags"])) | 572 } |
573 { | 573 |
574 return; | 574 payload = &content[i]["Content"]; |
575 } | 575 |
576 } | 576 if (content[i].isMember("Tags") && |
577 | 577 !InjectTags(*dicom, content[i]["Tags"])) |
578 if (payload == NULL || | 578 { |
579 payload->type() != Json::stringValue) | 579 ok = false; |
580 { | 580 break; |
581 LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; | 581 } |
582 return; | 582 } |
583 } | 583 |
584 | 584 if (payload == NULL || |
585 dicom->EmbedContent(payload->asString()); | 585 payload->type() != Json::stringValue) |
586 dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); | 586 { |
587 dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); | 587 LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; |
588 | 588 ok = false; |
589 if (!StoreCreatedInstance(someInstance, context, *dicom)) | 589 break; |
590 { | 590 } |
591 LOG(ERROR) << "Error while creating the series"; | 591 |
592 return; | 592 dicom->EmbedContent(payload->asString()); |
593 } | 593 dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); |
594 dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); | |
595 | |
596 if (!StoreCreatedInstance(someInstance, context, *dicom)) | |
597 { | |
598 LOG(ERROR) << "Error while creating the series"; | |
599 ok = false; | |
600 break; | |
601 } | |
602 } | |
603 } | |
604 catch (OrthancException&) | |
605 { | |
606 ok = false; | |
594 } | 607 } |
595 | 608 |
596 std::string series; | 609 std::string series; |
597 if (context.GetIndex().LookupParent(series, someInstance)) | 610 if (context.GetIndex().LookupParent(series, someInstance)) |
598 { | 611 { |
599 OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); | 612 if (ok) |
613 { | |
614 OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); | |
615 } | |
616 else | |
617 { | |
618 // Error: Remove the newly-created series | |
619 Json::Value dummy; | |
620 context.GetIndex().DeleteResource(dummy, series, ResourceType_Series); | |
621 } | |
600 } | 622 } |
601 } | 623 } |
602 | 624 |
603 | 625 |
604 static void CreateDicomV2(RestApiPostCall& call, | 626 static void CreateDicomV2(RestApiPostCall& call, |