Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5222:3a61fd50f804 db-protobuf
starting refactoring ExpandedResource
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Apr 2023 21:14:45 +0200 |
parents | 0ea402b4d901 |
children | 0854cc13b4d5 |
comparison
equal
deleted
inserted
replaced
5221:d0f7c742d397 | 5222:3a61fd50f804 |
---|---|
673 for (std::set<DicomTag>::const_iterator it = replacedTags.begin(); it != replacedTags.end(); ++it) | 673 for (std::set<DicomTag>::const_iterator it = replacedTags.begin(); it != replacedTags.end(); ++it) |
674 { | 674 { |
675 replacePatientMainDicomTags |= DicomMap::IsMainDicomTag(*it, ResourceType_Patient); | 675 replacePatientMainDicomTags |= DicomMap::IsMainDicomTag(*it, ResourceType_Patient); |
676 } | 676 } |
677 | 677 |
678 if ((modificationLevel == ResourceType_Study || modificationLevel == ResourceType_Patient) | 678 if ((modificationLevel == ResourceType_Study || |
679 && !modification_->IsReplaced(DICOM_TAG_PATIENT_ID) | 679 modificationLevel == ResourceType_Patient) && |
680 && modification_->IsKept(DICOM_TAG_STUDY_INSTANCE_UID) && modification_->IsKept(DICOM_TAG_SERIES_INSTANCE_UID) && modification_->IsKept(DICOM_TAG_SOP_INSTANCE_UID)) | 680 !modification_->IsReplaced(DICOM_TAG_PATIENT_ID) && |
681 modification_->IsKept(DICOM_TAG_STUDY_INSTANCE_UID) && | |
682 modification_->IsKept(DICOM_TAG_SERIES_INSTANCE_UID) && | |
683 modification_->IsKept(DICOM_TAG_SOP_INSTANCE_UID)) | |
681 { | 684 { |
682 // if we keep the SOPInstanceUID, it very likely means that we are modifying existing resources 'in place' | 685 // if we keep the SOPInstanceUID, it very likely means that we are modifying existing resources 'in place' |
683 | 686 |
684 // we must make sure we do not delete them at the end of the job | 687 // we must make sure we do not delete them at the end of the job |
685 if (!IsKeepSource()) // note: we can refine this criteria -> this is valid only if all DicomUIDs are kept identical (but this can happen through Keep or Replace options) | 688 if (!IsKeepSource()) // note: we can refine this criteria -> this is valid only if all DicomUIDs are kept identical (but this can happen through Keep or Replace options) |
713 targetPatientId = modification_->GetReplacementAsString(DICOM_TAG_PATIENT_ID); | 716 targetPatientId = modification_->GetReplacementAsString(DICOM_TAG_PATIENT_ID); |
714 } | 717 } |
715 else | 718 else |
716 { | 719 { |
717 ExpandedResource originalStudy; | 720 ExpandedResource originalStudy; |
718 if (GetContext().GetIndex().ExpandResource(originalStudy, *studyId, ResourceType_Study, emptyRequestedTags, ExpandResourceDbFlags_IncludeMainDicomTags)) | 721 if (GetContext().GetIndex().ExpandResource(originalStudy, *studyId, ResourceType_Study, emptyRequestedTags, ExpandResourceFlags_IncludeMainDicomTags)) |
719 { | 722 { |
720 targetPatientId = originalStudy.tags_.GetStringValue(DICOM_TAG_PATIENT_ID, "", false); | 723 targetPatientId = originalStudy.GetMainDicomTags().GetStringValue(DICOM_TAG_PATIENT_ID, "", false); |
721 } | 724 } |
722 else | 725 else |
723 { | 726 { |
724 throw OrthancException(ErrorCode_UnknownResource, "Study not found"); | 727 throw OrthancException(ErrorCode_UnknownResource, "Study not found"); |
725 } | 728 } |
732 // if the patient exists, check how many child studies it has. | 735 // if the patient exists, check how many child studies it has. |
733 if (lookupPatientResult.size() >= 1) | 736 if (lookupPatientResult.size() >= 1) |
734 { | 737 { |
735 ExpandedResource targetPatient; | 738 ExpandedResource targetPatient; |
736 | 739 |
737 if (GetContext().GetIndex().ExpandResource(targetPatient, lookupPatientResult[0], ResourceType_Patient, emptyRequestedTags, static_cast<ExpandResourceDbFlags>(ExpandResourceDbFlags_IncludeMainDicomTags | ExpandResourceDbFlags_IncludeChildren))) | 740 if (GetContext().GetIndex().ExpandResource(targetPatient, lookupPatientResult[0], ResourceType_Patient, emptyRequestedTags, static_cast<ExpandResourceFlags>(ExpandResourceFlags_IncludeMainDicomTags | ExpandResourceFlags_IncludeChildren))) |
738 { | 741 { |
739 const std::list<std::string> childrenIds = targetPatient.childrenIds_; | 742 const std::list<std::string> childrenIds = targetPatient.childrenIds_; |
740 bool targetPatientHasOtherStudies = childrenIds.size() > 1; | 743 bool targetPatientHasOtherStudies = childrenIds.size() > 1; |
741 if (childrenIds.size() == 1) | 744 if (childrenIds.size() == 1) |
742 { | 745 { |
745 | 748 |
746 if (targetPatientHasOtherStudies) | 749 if (targetPatientHasOtherStudies) |
747 { | 750 { |
748 // this is allowed if all patient replacedTags do match the target patient tags | 751 // this is allowed if all patient replacedTags do match the target patient tags |
749 DicomMap targetPatientTags; | 752 DicomMap targetPatientTags; |
750 targetPatient.tags_.ExtractPatientInformation(targetPatientTags); | 753 targetPatient.GetMainDicomTags().ExtractPatientInformation(targetPatientTags); |
751 | 754 |
752 std::set<DicomTag> mainPatientTags; | 755 std::set<DicomTag> mainPatientTags; |
753 DicomMap::GetMainDicomTags(mainPatientTags, ResourceType_Patient); | 756 DicomMap::GetMainDicomTags(mainPatientTags, ResourceType_Patient); |
754 | 757 |
755 for (std::set<DicomTag>::const_iterator mainPatientTag = mainPatientTags.begin(); | 758 for (std::set<DicomTag>::const_iterator mainPatientTag = mainPatientTags.begin(); |
756 mainPatientTag != mainPatientTags.end(); ++mainPatientTag) | 759 mainPatientTag != mainPatientTags.end(); ++mainPatientTag) |
757 { | 760 { |
758 if (targetPatientTags.HasTag(*mainPatientTag) | 761 if (targetPatientTags.HasTag(*mainPatientTag) && |
759 && (!modification_->IsReplaced(*mainPatientTag) | 762 (!modification_->IsReplaced(*mainPatientTag) || |
760 || modification_->GetReplacementAsString(*mainPatientTag) != targetPatientTags.GetStringValue(*mainPatientTag, "", false))) | 763 modification_->GetReplacementAsString(*mainPatientTag) != targetPatientTags.GetStringValue(*mainPatientTag, "", false))) |
761 { | 764 { |
762 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. The Patient already exists and has other studies. All the 'Replace' tags should match the existing patient main dicom tags. Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format()); | 765 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. The Patient already exists and has other studies. All the 'Replace' tags should match the existing patient main dicom tags. Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format()); |
763 } | 766 } |
764 else if (!targetPatientTags.HasTag(*mainPatientTag) && modification_->IsReplaced(*mainPatientTag) ) | 767 else if (!targetPatientTags.HasTag(*mainPatientTag) && modification_->IsReplaced(*mainPatientTag) ) |
765 { | 768 { |
767 } | 770 } |
768 } | 771 } |
769 } | 772 } |
770 } | 773 } |
771 } | 774 } |
772 } | 775 } |
773 | |
774 } | 776 } |
775 } | 777 } |
776 } | 778 } |