# HG changeset patch # User Sebastien Jodogne # Date 1423231985 -3600 # Node ID 4ce47e8ed0d28bec7fe17cd0459885cdca4429c5 # Parent cf9779324cbf4886996c24a4e915d4c64881e3fe refactoring diff -r cf9779324cbf -r 4ce47e8ed0d2 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Fri Feb 06 14:42:30 2015 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Fri Feb 06 15:13:05 2015 +0100 @@ -221,34 +221,7 @@ s.BindInt(0, type); s.BindString(1, publicId); s.Run(); - int64_t id = db_.GetLastInsertRowId(); - - ChangeType changeType; - switch (type) - { - case ResourceType_Patient: - changeType = ChangeType_NewPatient; - break; - - case ResourceType_Study: - changeType = ChangeType_NewStudy; - break; - - case ResourceType_Series: - changeType = ChangeType_NewSeries; - break; - - case ResourceType_Instance: - changeType = ChangeType_NewInstance; - break; - - default: - throw OrthancException(ErrorCode_InternalError); - } - - ServerIndexChange change(changeType, type, publicId); - LogChange(id, change); - return id; + return db_.GetLastInsertRowId(); } bool DatabaseWrapper::LookupResource(int64_t& id, diff -r cf9779324cbf -r 4ce47e8ed0d2 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Feb 06 14:42:30 2015 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Feb 06 15:13:05 2015 +0100 @@ -492,6 +492,39 @@ } + int64_t ServerIndex::CreateResource(const std::string& publicId, + ResourceType type) + { + int64_t id = db_.CreateResource(publicId, type); + + ChangeType changeType; + switch (type) + { + case ResourceType_Patient: + changeType = ChangeType_NewPatient; + break; + + case ResourceType_Study: + changeType = ChangeType_NewStudy; + break; + + case ResourceType_Series: + changeType = ChangeType_NewSeries; + break; + + case ResourceType_Instance: + changeType = ChangeType_NewInstance; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + ServerIndexChange change(changeType, type, publicId); + db_.LogChange(id, change); + return id; + } + ServerIndex::ServerIndex(ServerContext& context, IDatabaseWrapper& db) : @@ -569,7 +602,7 @@ Recycle(instanceSize, hasher.HashPatient()); // Create the instance - int64_t instance = db_.CreateResource(hasher.HashInstance(), ResourceType_Instance); + int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance); DicomMap dicom; dicomSummary.ExtractInstanceInformation(dicom); @@ -624,7 +657,7 @@ // Create the series if needed if (isNewSeries) { - series = db_.CreateResource(hasher.HashSeries(), ResourceType_Series); + series = CreateResource(hasher.HashSeries(), ResourceType_Series); dicomSummary.ExtractSeriesInformation(dicom); SetMainDicomTags(series, dicom); } @@ -632,7 +665,7 @@ // Create the study if needed if (isNewStudy) { - study = db_.CreateResource(hasher.HashStudy(), ResourceType_Study); + study = CreateResource(hasher.HashStudy(), ResourceType_Study); dicomSummary.ExtractStudyInformation(dicom); SetMainDicomTags(study, dicom); } @@ -640,7 +673,7 @@ // Create the patient if needed if (isNewPatient) { - patient = db_.CreateResource(hasher.HashPatient(), ResourceType_Patient); + patient = CreateResource(hasher.HashPatient(), ResourceType_Patient); dicomSummary.ExtractPatientInformation(dicom); SetMainDicomTags(patient, dicom); } diff -r cf9779324cbf -r 4ce47e8ed0d2 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Fri Feb 06 14:42:30 2015 +0100 +++ b/OrthancServer/ServerIndex.h Fri Feb 06 15:13:05 2015 +0100 @@ -117,6 +117,9 @@ void SetMainDicomTags(int64_t resource, const DicomMap& tags); + int64_t CreateResource(const std::string& publicId, + ResourceType type); + public: ServerIndex(ServerContext& context, IDatabaseWrapper& database);