Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1668:de1413733c97 db-changes
reconstructing main dicom tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2015 17:18:39 +0200 |
parents | d6a93e12b1c1 |
children | f079f3efe33b |
comparison
equal
deleted
inserted
replaced
1667:9e875db36aef | 1668:de1413733c97 |
---|---|
38 #endif | 38 #endif |
39 | 39 |
40 #include "ServerIndexChange.h" | 40 #include "ServerIndexChange.h" |
41 #include "EmbeddedResources.h" | 41 #include "EmbeddedResources.h" |
42 #include "OrthancInitialization.h" | 42 #include "OrthancInitialization.h" |
43 #include "ServerToolbox.h" | |
43 #include "../Core/Toolbox.h" | 44 #include "../Core/Toolbox.h" |
44 #include "../Core/Logging.h" | 45 #include "../Core/Logging.h" |
45 #include "../Core/Uuid.h" | 46 #include "../Core/Uuid.h" |
46 #include "../Core/DicomFormat/DicomArray.h" | 47 #include "../Core/DicomFormat/DicomArray.h" |
47 | 48 |
488 } | 489 } |
489 } | 490 } |
490 | 491 |
491 | 492 |
492 | 493 |
493 void ServerIndex::SetMainDicomTags(int64_t resource, | |
494 const DicomMap& tags) | |
495 { | |
496 DicomArray flattened(tags); | |
497 for (size_t i = 0; i < flattened.GetSize(); i++) | |
498 { | |
499 const DicomElement& element = flattened.GetElement(i); | |
500 db_.SetMainDicomTag(resource, element.GetTag(), element.GetValue().AsString()); | |
501 } | |
502 } | |
503 | |
504 | |
505 int64_t ServerIndex::CreateResource(const std::string& publicId, | 494 int64_t ServerIndex::CreateResource(const std::string& publicId, |
506 ResourceType type) | 495 ResourceType type) |
507 { | 496 { |
508 int64_t id = db_.CreateResource(publicId, type); | 497 int64_t id = db_.CreateResource(publicId, type); |
509 | 498 |
636 | 625 |
637 Recycle(instanceSize, hasher.HashPatient()); | 626 Recycle(instanceSize, hasher.HashPatient()); |
638 | 627 |
639 // Create the instance | 628 // Create the instance |
640 int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance); | 629 int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance); |
641 | 630 Toolbox::SetMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary, true); |
642 DicomMap dicom; | |
643 dicomSummary.ExtractInstanceInformation(dicom); | |
644 SetMainDicomTags(instance, dicom); | |
645 | 631 |
646 // Detect up to which level the patient/study/series/instance | 632 // Detect up to which level the patient/study/series/instance |
647 // hierarchy must be created | 633 // hierarchy must be created |
648 int64_t patient = -1, study = -1, series = -1; | 634 int64_t patient = -1, study = -1, series = -1; |
649 bool isNewPatient = false; | 635 bool isNewPatient = false; |
691 | 677 |
692 // Create the series if needed | 678 // Create the series if needed |
693 if (isNewSeries) | 679 if (isNewSeries) |
694 { | 680 { |
695 series = CreateResource(hasher.HashSeries(), ResourceType_Series); | 681 series = CreateResource(hasher.HashSeries(), ResourceType_Series); |
696 dicomSummary.ExtractSeriesInformation(dicom); | 682 Toolbox::SetMainDicomTags(db_, series, ResourceType_Series, dicomSummary, true); |
697 SetMainDicomTags(series, dicom); | |
698 } | 683 } |
699 | 684 |
700 // Create the study if needed | 685 // Create the study if needed |
701 if (isNewStudy) | 686 if (isNewStudy) |
702 { | 687 { |
703 study = CreateResource(hasher.HashStudy(), ResourceType_Study); | 688 study = CreateResource(hasher.HashStudy(), ResourceType_Study); |
704 dicomSummary.ExtractStudyInformation(dicom); | 689 Toolbox::SetMainDicomTags(db_, study, ResourceType_Study, dicomSummary, true); |
705 SetMainDicomTags(study, dicom); | 690 Toolbox::SetMainDicomTags(db_, study, ResourceType_Patient, dicomSummary, false); // New in version 0.9.5 (db v6) |
706 } | 691 } |
707 | 692 |
708 // Create the patient if needed | 693 // Create the patient if needed |
709 if (isNewPatient) | 694 if (isNewPatient) |
710 { | 695 { |
711 patient = CreateResource(hasher.HashPatient(), ResourceType_Patient); | 696 patient = CreateResource(hasher.HashPatient(), ResourceType_Patient); |
712 dicomSummary.ExtractPatientInformation(dicom); | 697 Toolbox::SetMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary, true); |
713 SetMainDicomTags(patient, dicom); | |
714 } | 698 } |
715 | 699 |
716 // Create the parent-to-child links | 700 // Create the parent-to-child links |
717 db_.AttachChild(series, instance); | 701 db_.AttachChild(series, instance); |
718 | 702 |
890 } | 874 } |
891 | 875 |
892 | 876 |
893 | 877 |
894 void ServerIndex::MainDicomTagsToJson(Json::Value& target, | 878 void ServerIndex::MainDicomTagsToJson(Json::Value& target, |
895 int64_t resourceId) | 879 int64_t resourceId, |
880 ResourceType resourceType) | |
896 { | 881 { |
897 DicomMap tags; | 882 DicomMap tags; |
898 db_.GetMainDicomTags(tags, resourceId); | 883 db_.GetMainDicomTags(tags, resourceId); |
899 target["MainDicomTags"] = Json::objectValue; | 884 target["MainDicomTags"] = Json::objectValue; |
900 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); | 885 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); |
1031 throw OrthancException(ErrorCode_InternalError); | 1016 throw OrthancException(ErrorCode_InternalError); |
1032 } | 1017 } |
1033 | 1018 |
1034 // Record the remaining information | 1019 // Record the remaining information |
1035 result["ID"] = publicId; | 1020 result["ID"] = publicId; |
1036 MainDicomTagsToJson(result, id); | 1021 MainDicomTagsToJson(result, id, type); |
1037 | 1022 |
1038 std::string tmp; | 1023 std::string tmp; |
1039 | 1024 |
1040 if (db_.LookupMetadata(tmp, id, MetadataType_AnonymizedFrom)) | 1025 if (db_.LookupMetadata(tmp, id, MetadataType_AnonymizedFrom)) |
1041 { | 1026 { |
2106 | 2091 |
2107 int64_t id; | 2092 int64_t id; |
2108 return db_.LookupResource(id, type, publicId); | 2093 return db_.LookupResource(id, type, publicId); |
2109 } | 2094 } |
2110 | 2095 |
2096 | |
2097 unsigned int ServerIndex::GetDatabaseVersion() | |
2098 { | |
2099 boost::mutex::scoped_lock lock(mutex_); | |
2100 return db_.GetDatabaseVersion(); | |
2101 } | |
2111 } | 2102 } |