Mercurial > hg > orthanc
changeset 1299:4ce47e8ed0d2
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Feb 2015 15:13:05 +0100 |
parents | cf9779324cbf |
children | 919dfb2fb3fe |
files | OrthancServer/DatabaseWrapper.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h |
diffstat | 3 files changed, 41 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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); }
--- 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);