# HG changeset patch # User Sebastien Jodogne # Date 1445269534 -7200 # Node ID 3926e6317a43ec5dea555445b8fb08f518b0ef98 # Parent 2ca7888f860039feea5b62258aea8afd76b72b7f SetIdentifierTagInternal diff -r 2ca7888f8600 -r 3926e6317a43 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Sat Oct 17 12:16:27 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Mon Oct 19 17:45:34 2015 +0200 @@ -268,6 +268,8 @@ void DatabaseWrapper::Open() { + db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); + // Performance tuning of SQLite with PRAGMAs // http://www.sqlite.org/pragma.html db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); diff -r 2ca7888f8600 -r 3926e6317a43 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Sat Oct 17 12:16:27 2015 +0200 +++ b/OrthancServer/ServerIndex.cpp Mon Oct 19 17:45:34 2015 +0200 @@ -873,29 +873,6 @@ } - static std::string GetPatientIdOfStudy(IDatabaseWrapper& db, - int64_t resourceId) - { - int64_t patient; - if (!db.LookupParent(patient, resourceId)) - { - throw OrthancException(ErrorCode_InternalError); - } - - DicomMap tags; - db.GetMainDicomTags(tags, patient); - - if (tags.HasTag(DICOM_TAG_PATIENT_ID)) - { - return tags.GetValue(DICOM_TAG_PATIENT_ID).AsString(); - } - else - { - return ""; - } - } - - void ServerIndex::MainDicomTagsToJson(Json::Value& target, int64_t resourceId, ResourceType resourceType) @@ -914,8 +891,6 @@ target["PatientMainDicomTags"] = Json::objectValue; FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true); - - target["PatientMainDicomTags"]["PatientID"] = GetPatientIdOfStudy(db_, resourceId); } else { @@ -2136,7 +2111,6 @@ { case ResourceType_Patient: tmp.ExtractPatientInformation(result); - result.SetValue(DICOM_TAG_PATIENT_ID, GetPatientIdOfStudy(db_, id)); return true; case ResourceType_Study: diff -r 2ca7888f8600 -r 3926e6317a43 OrthancServer/ServerToolbox.cpp --- a/OrthancServer/ServerToolbox.cpp Sat Oct 17 12:16:27 2015 +0200 +++ b/OrthancServer/ServerToolbox.cpp Mon Oct 19 17:45:34 2015 +0200 @@ -182,11 +182,31 @@ if (value != NULL && !value->IsNull()) { - database.SetIdentifierTag(resource, tag, value->AsString()); + std::string s = value->AsString(); + + if (!tag.IsIdentifier()) + { + s = NormalizeIdentifierTag(s); + } + + database.SetIdentifierTag(resource, tag, s); } } + static void AttachPatientInformation(IDatabaseWrapper& database, + int64_t resource, + const DicomMap& dicomSummary) + { + DicomMap tags; + dicomSummary.ExtractPatientInformation(tags); + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID); + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME); + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE); + SetMainDicomTagsInternal(database, resource, tags); + } + + void SetMainDicomTags(IDatabaseWrapper& database, int64_t resource, ResourceType level, @@ -199,15 +219,18 @@ switch (level) { case ResourceType_Patient: - dicomSummary.ExtractPatientInformation(tags); - SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID); + AttachPatientInformation(database, resource, dicomSummary); break; case ResourceType_Study: + // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) + AttachPatientInformation(database, resource, dicomSummary); + dicomSummary.ExtractStudyInformation(tags); SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_INSTANCE_UID); - SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION); // ??? - SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE); // ??? + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_ACCESSION_NUMBER); + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION); + SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE); break; case ResourceType_Series: @@ -225,15 +248,6 @@ } SetMainDicomTagsInternal(database, resource, tags); - - // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6) - if (level == ResourceType_Study) - { - dicomSummary.ExtractPatientInformation(tags); - SetMainDicomTagsInternal(database, resource, tags); - SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME); // ??? - SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE); // ??? - } } @@ -335,5 +349,13 @@ Toolbox::SetMainDicomTags(database, resource, level, dicomSummary); } } + + + std::string NormalizeIdentifierTag(const std::string& value) + { + std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value)); + Toolbox::ToUpperCase(s); + return s; + } } } diff -r 2ca7888f8600 -r 3926e6317a43 OrthancServer/ServerToolbox.h --- a/OrthancServer/ServerToolbox.h Sat Oct 17 12:16:27 2015 +0200 +++ b/OrthancServer/ServerToolbox.h Mon Oct 19 17:45:34 2015 +0200 @@ -59,5 +59,7 @@ void ReconstructMainDicomTags(IDatabaseWrapper& database, IStorageArea& storageArea, ResourceType level); + + std::string NormalizeIdentifierTag(const std::string& value); } } diff -r 2ca7888f8600 -r 3926e6317a43 Plugins/Samples/DatabasePlugin/Database.cpp --- a/Plugins/Samples/DatabasePlugin/Database.cpp Sat Oct 17 12:16:27 2015 +0200 +++ b/Plugins/Samples/DatabasePlugin/Database.cpp Mon Oct 19 17:45:34 2015 +0200 @@ -184,6 +184,8 @@ { db_.Open(path_); + db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); + // http://www.sqlite.org/pragma.html db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); db_.Execute("PRAGMA JOURNAL_MODE=WAL;");