# HG changeset patch # User Sebastien Jodogne # Date 1393336279 -3600 # Node ID 309e686b41e7ca3b1996bf3b7da0496733480c90 # Parent 948720c72586e43bf3075b479cf82116b197840a better logging about nonexistent tags diff -r 948720c72586 -r 309e686b41e7 Core/DicomFormat/DicomMap.cpp --- a/Core/DicomFormat/DicomMap.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/Core/DicomFormat/DicomMap.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -199,7 +199,7 @@ } else { - throw OrthancException("Inexistent tag"); + throw OrthancException(ErrorCode_InexistentTag); } } diff -r 948720c72586 -r 309e686b41e7 Core/Enumerations.h --- a/Core/Enumerations.h Mon Feb 24 13:50:40 2014 +0100 +++ b/Core/Enumerations.h Tue Feb 25 14:51:19 2014 +0100 @@ -67,7 +67,8 @@ ErrorCode_UnknownResource, ErrorCode_IncompatibleDatabaseVersion, ErrorCode_FullStorage, - ErrorCode_CorruptedFile + ErrorCode_CorruptedFile, + ErrorCode_InexistentTag }; /** diff -r 948720c72586 -r 309e686b41e7 Core/OrthancException.cpp --- a/Core/OrthancException.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/Core/OrthancException.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -108,6 +108,9 @@ case ErrorCode_CorruptedFile: return "Corrupted file (inconsistent MD5 hash)"; + case ErrorCode_InexistentTag: + return "Inexistent tag"; + case ErrorCode_Custom: default: return "???"; diff -r 948720c72586 -r 309e686b41e7 NEWS --- a/NEWS Mon Feb 24 13:50:40 2014 +0100 +++ b/NEWS Tue Feb 25 14:51:19 2014 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Better logging about inexistent tags Version 0.7.3 (2014/02/14) diff -r 948720c72586 -r 309e686b41e7 OrthancServer/Internals/StoreScp.cpp --- a/OrthancServer/Internals/StoreScp.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/OrthancServer/Internals/StoreScp.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -33,6 +33,7 @@ #include "StoreScp.h" #include "../FromDcmtkBridge.h" +#include "../ServerToolbox.h" #include "../ToDcmtkBridge.h" #include "../../Core/OrthancException.h" @@ -57,7 +58,7 @@ uint32_t messageID; }; - + static void storeScpCallback( void *callbackData, @@ -155,7 +156,15 @@ catch (OrthancException& e) { rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources; - LOG(ERROR) << "Exception while storing DICOM: " << e.What(); + + if (e.GetErrorCode() == ErrorCode_InexistentTag) + { + LogMissingRequiredTag(summary); + } + else + { + LOG(ERROR) << "Exception while storing DICOM: " << e.What(); + } } } } diff -r 948720c72586 -r 309e686b41e7 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/OrthancServer/ServerContext.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -238,19 +238,31 @@ DicomMap dicomSummary; FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.getDataset()); - DicomInstanceHasher hasher(dicomSummary); - resultPublicId = hasher.HashInstance(); + try + { + DicomInstanceHasher hasher(dicomSummary); + resultPublicId = hasher.HashInstance(); - Json::Value dicomJson; - FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset()); + Json::Value dicomJson; + FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset()); - StoreStatus status = StoreStatus_Failure; - if (dicomSize > 0) + StoreStatus status = StoreStatus_Failure; + if (dicomSize > 0) + { + status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, ""); + } + + return status; + } + catch (OrthancException& e) { - status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, ""); - } + if (e.GetErrorCode() == ErrorCode_InexistentTag) + { + LogMissingRequiredTag(dicomSummary); + } - return status; + throw e; + } } diff -r 948720c72586 -r 309e686b41e7 OrthancServer/ServerToolbox.cpp --- a/OrthancServer/ServerToolbox.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/OrthancServer/ServerToolbox.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -35,6 +35,7 @@ #include "../Core/OrthancException.h" #include +#include namespace Orthanc { @@ -82,4 +83,71 @@ } } } + + + void LogMissingRequiredTag(const DicomMap& summary) + { + std::string s, t; + + if (summary.HasTag(DICOM_TAG_PATIENT_ID)) + { + if (t.size() > 0) + t += ", "; + t += "PatientID=" + summary.GetValue(DICOM_TAG_PATIENT_ID).AsString(); + } + else + { + if (s.size() > 0) + s += ", "; + s += "PatientID"; + } + + if (summary.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)) + { + if (t.size() > 0) + t += ", "; + t += "StudyInstanceUID=" + summary.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString(); + } + else + { + if (s.size() > 0) + s += ", "; + s += "StudyInstanceUID"; + } + + if (summary.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)) + { + if (t.size() > 0) + t += ", "; + t += "SeriesInstanceUID=" + summary.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString(); + } + else + { + if (s.size() > 0) + s += ", "; + s += "SeriesInstanceUID"; + } + + if (summary.HasTag(DICOM_TAG_SOP_INSTANCE_UID)) + { + if (t.size() > 0) + t += ", "; + t += "SOPInstanceUID=" + summary.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString(); + } + else + { + if (s.size() > 0) + s += ", "; + s += "SOPInstanceUID"; + } + + if (t.size() == 0) + { + LOG(ERROR) << "Store has failed because all the required tags (" << s << ") are missing (is it a DICOMDIR file?)"; + } + else + { + LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t; + } + } } diff -r 948720c72586 -r 309e686b41e7 OrthancServer/ServerToolbox.h --- a/OrthancServer/ServerToolbox.h Mon Feb 24 13:50:40 2014 +0100 +++ b/OrthancServer/ServerToolbox.h Tue Feb 25 14:51:19 2014 +0100 @@ -32,10 +32,14 @@ #pragma once +#include "../Core/DicomFormat/DicomMap.h" + #include namespace Orthanc { void SimplifyTags(Json::Value& target, const Json::Value& source); + + void LogMissingRequiredTag(const DicomMap& summary); } diff -r 948720c72586 -r 309e686b41e7 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Mon Feb 24 13:50:40 2014 +0100 +++ b/OrthancServer/main.cpp Tue Feb 25 14:51:19 2014 +0100 @@ -46,6 +46,7 @@ #include "ServerContext.h" #include "OrthancFindRequestHandler.h" #include "OrthancMoveRequestHandler.h" +#include "ServerToolbox.h" using namespace Orthanc;