Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5809:023a99146dd0 attach-custom-data
merged find-refactoring -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 12:53:43 +0200 |
parents | c5ca97d21023 |
children |
comparison
equal
deleted
inserted
replaced
5808:63c025cf6958 | 5809:023a99146dd0 |
---|---|
742 { | 742 { |
743 targetPatientId = modification_->GetReplacementAsString(DICOM_TAG_PATIENT_ID); | 743 targetPatientId = modification_->GetReplacementAsString(DICOM_TAG_PATIENT_ID); |
744 } | 744 } |
745 else | 745 else |
746 { | 746 { |
747 ExpandedResource originalStudy; | 747 FindRequest request(ResourceType_Study); |
748 if (GetContext().GetIndex().ExpandResource(originalStudy, *studyId, ResourceType_Study, emptyRequestedTags, ExpandResourceFlags_IncludeMainDicomTags)) | 748 request.SetOrthancStudyId(*studyId); |
749 request.SetRetrieveMainDicomTags(true); | |
750 | |
751 FindResponse response; | |
752 GetContext().GetIndex().ExecuteFind(response, request); | |
753 | |
754 if (response.GetSize() == 1) | |
749 { | 755 { |
750 targetPatientId = originalStudy.GetMainDicomTags().GetStringValue(DICOM_TAG_PATIENT_ID, "", false); | 756 DicomMap tags; |
757 response.GetResourceByIndex(0).GetMainDicomTags(tags, ResourceType_Study); | |
758 targetPatientId = tags.GetStringValue(DICOM_TAG_PATIENT_ID, "", false); | |
751 } | 759 } |
752 else | 760 else |
753 { | 761 { |
754 throw OrthancException(ErrorCode_UnknownResource, "Study not found"); | 762 throw OrthancException(ErrorCode_UnknownResource, "Study not found"); |
755 } | 763 } |
760 GetContext().GetIndex().LookupIdentifierExact(lookupPatientResult, ResourceType_Patient, DICOM_TAG_PATIENT_ID, targetPatientId); | 768 GetContext().GetIndex().LookupIdentifierExact(lookupPatientResult, ResourceType_Patient, DICOM_TAG_PATIENT_ID, targetPatientId); |
761 | 769 |
762 // if the patient exists, check how many child studies it has. | 770 // if the patient exists, check how many child studies it has. |
763 if (lookupPatientResult.size() >= 1) | 771 if (lookupPatientResult.size() >= 1) |
764 { | 772 { |
765 ExpandedResource targetPatient; | 773 FindRequest request(ResourceType_Patient); |
766 | 774 request.SetOrthancPatientId(lookupPatientResult[0]); |
767 if (GetContext().GetIndex().ExpandResource(targetPatient, lookupPatientResult[0], ResourceType_Patient, emptyRequestedTags, static_cast<ExpandResourceFlags>(ExpandResourceFlags_IncludeMainDicomTags | ExpandResourceFlags_IncludeChildren))) | 775 request.SetRetrieveMainDicomTags(true); |
776 request.GetChildrenSpecification(ResourceType_Study).SetRetrieveIdentifiers(true); | |
777 | |
778 FindResponse response; | |
779 GetContext().GetIndex().ExecuteFind(response, request); | |
780 | |
781 if (response.GetSize() == 1) | |
768 { | 782 { |
769 const std::list<std::string> childrenIds = targetPatient.childrenIds_; | 783 const FindResponse::Resource& targetPatient = response.GetResourceByIndex(0); |
784 | |
785 const std::set<std::string>& childrenIds = targetPatient.GetChildrenIdentifiers(ResourceType_Study); | |
786 | |
770 bool targetPatientHasOtherStudies = childrenIds.size() > 1; | 787 bool targetPatientHasOtherStudies = childrenIds.size() > 1; |
771 if (childrenIds.size() == 1) | 788 if (childrenIds.size() == 1) |
772 { | 789 { |
773 targetPatientHasOtherStudies = std::find(childrenIds.begin(), childrenIds.end(), *studyId) == childrenIds.end(); // if the patient has one study that is not the one being modified | 790 targetPatientHasOtherStudies = (childrenIds.find(*studyId) == childrenIds.end()); // if the patient has one study that is not the one being modified |
774 } | 791 } |
775 | 792 |
776 if (targetPatientHasOtherStudies) | 793 if (targetPatientHasOtherStudies) |
777 { | 794 { |
795 DicomMap mainDicomTags; | |
796 targetPatient.GetMainDicomTags(mainDicomTags, ResourceType_Patient); | |
797 | |
778 // this is allowed if all patient replacedTags do match the target patient tags | 798 // this is allowed if all patient replacedTags do match the target patient tags |
779 DicomMap targetPatientTags; | 799 DicomMap targetPatientTags; |
780 targetPatient.GetMainDicomTags().ExtractPatientInformation(targetPatientTags); | 800 mainDicomTags.ExtractPatientInformation(targetPatientTags); |
781 | 801 |
782 std::set<DicomTag> mainPatientTags; | 802 std::set<DicomTag> mainPatientTags; |
783 DicomMap::GetMainDicomTags(mainPatientTags, ResourceType_Patient); | 803 DicomMap::GetMainDicomTags(mainPatientTags, ResourceType_Patient); |
784 | 804 |
785 for (std::set<DicomTag>::const_iterator mainPatientTag = mainPatientTags.begin(); | 805 for (std::set<DicomTag>::const_iterator mainPatientTag = mainPatientTags.begin(); |