679
bool GNC::GCS::HistoryController::LinkFilesToSeries(long seriesPk, GNC::GCS::HistoryController::DICOMFileModelList& files, GNC::IProxyNotificadorProgreso* pNotificador )
684
wxCriticalSectionLocker locker(*m_pCriticalSection);
685
DICOMFileModelList listOfInsertedFiles;
687
m_pConexion->Begin();
689
SeriesModel sm = GetSeriesModel(seriesPk);
692
for(GNC::GCS::HistoryController::DICOMFileModelList::iterator it=files.begin(); it!= files.end(); ++it, ++i)
694
if(pNotificador != NULL) {
695
std::ostringstream ostr;
696
ostr << _Std("Linking image ") << (i+1) << _Std(" of ") << files.size();
697
if(!pNotificador->NotificarProgreso((float)i/files.size(),ostr.str()))
699
m_pConexion->Commit();
704
DICOMFileModel& fileModel = (*it);
705
fileModel.file.series_fk = seriesPk;
706
FindOrLink(fileModel);
709
//update series and study summary info (modalities in study, number of instances...)
710
UpdateSeriesSummaryInfo(sm.pk);
712
UpdateStudySummaryInfo(sm.study_fk);
714
m_pConexion->Commit();
716
}catch (wxSQLite3Exception& ex) {
717
LOG_ERROR("BBDD", "Error linking file in database controller "<<ex.GetMessage().ToUTF8())
718
m_pConexion->Rollback();
673
723
void GNC::GCS::HistoryController::FindOrInsertStudy(DICOMFileModel& model)
675
725
std::ostringstream ostrSelect;
813
//true if file exists, false if it has been overwritten or if it's new
764
814
bool GNC::GCS::HistoryController::FindOrInsertFile(DICOMFileModel& model)
766
816
wxSQLite3StatementBuffer bufSQL;
767
817
std::stringstream ostr;
768
ostr << bufSQL.Format("Select pk from File where series_fk='%ld' "
769
"AND file_sopiuid='%q' AND file_tsuid='%q' AND sopcuid='%q' AND orientation='%c' "
770
"AND image_positionx='%f' AND image_positiony='%f' AND image_positionz='%f' "
771
"AND slice_location='%f' AND height = '%d' AND width = '%d' AND number_of_frames='%d' AND instance_number ='%d' AND file_desc = '%q' "
772
"AND direction_cosines = '%q' AND spacing = '%q'",
818
ostr << bufSQL.Format("Select pk, location from File where series_fk='%ld' "
819
"AND file_sopiuid='%q'",
773
820
model.file.series_fk,
774
model.file.sopiuid.c_str(), model.file.tsuid.c_str(), model.file.sopcuid.c_str(), model.file.orientation,
775
model.file.image_position[0], model.file.image_position[1], model.file.image_position[2],
776
model.file.slice_location, model.file.height, model.file.width,model.file.number_of_frames, model.file.instance_number, model.file.file_desc.c_str(),
777
model.file.direction_cosines.c_str(), model.file.spacing.c_str());
821
model.file.sopiuid.c_str());
778
822
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostr.str().c_str());
779
825
if (resultados.NextRow()) {
781
model.file.pk = resultados.GetInt(wxT("pk"));
827
pk = resultados.GetInt(wxT("pk"));
828
location = CharToLocation(*resultados.GetAsString(wxT("location")).ToUTF8());
832
//file doesn't exists so insert it
784
833
std::stringstream ostrInsert;
785
834
ostrInsert << bufSQL.Format("INSERT INTO File ("
786
835
"series_fk, file_path, file_sopiuid, file_tsuid,"
787
836
"sopcuid, orientation, image_positionx, image_positiony,"
788
837
"image_positionz, slice_location, slice_thickness, height, width, number_of_frames,"
789
"instance_number, file_desc, direction_cosines, spacing, created_time, updated_time, content_datetime) VALUES ("
838
"instance_number, file_desc, direction_cosines, spacing, location, created_time, updated_time, content_datetime) VALUES ("
790
839
"'%ld','%q','%q','%q',"
791
840
"'%q','%c','%f','%f',"
792
841
"'%f','%f', '%f', '%d','%d','%d',"
793
"'%d', '%q', '%q', '%q',datetime(),datetime(),",
842
"'%d', '%q', '%q', '%q', '%c',datetime(),datetime(),",
794
843
model.file.series_fk, model.file.file_path.c_str(), model.file.sopiuid.c_str(), model.file.tsuid.c_str(),
795
844
model.file.sopcuid.c_str(), model.file.orientation, model.file.image_position[0], model.file.image_position[1],
796
845
model.file.image_position[2], model.file.slice_location, model.file.slice_thickness, model.file.height, model.file.width, model.file.number_of_frames,
797
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str());
846
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str(), LocationToChar(model.file.location));
798
847
if (model.file.content_datetime.empty()){
799
848
ostrInsert << "NULL)";
804
853
model.file.pk = (long)m_pConexion->GetLastRowId().GetValue();
856
} else if (location != TL_LocalDatabase) {
862
//nothing to do file is in local database
868
bool GNC::GCS::HistoryController::FindOrLink(DICOMFileModel& model)
870
wxSQLite3StatementBuffer bufSQL;
871
model.file.location = TL_WadoLinked;
872
std::stringstream ostr;
873
ostr << bufSQL.Format("Select pk, location from File where series_fk='%ld' "
874
"AND file_sopiuid='%q'",
875
model.file.series_fk,
876
model.file.sopiuid.c_str());
877
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostr.str().c_str());
878
if (resultados.NextRow()) {
879
//file exists and is fully local then return true...
880
TLocation location = CharToLocation(*resultados.GetAsString(wxT("location")).ToUTF8());
881
if (location != TL_WadoLinked)
887
model.file.pk = resultados.GetInt(wxT("pk"));
888
//file is now linked so overwrite it!
889
std::stringstream ostrUpdate;
890
wxSQLite3StatementBuffer bufSQL;
891
ostrUpdate << bufSQL.Format("Update File SET "
892
"series_fk = '%ld',file_sopiuid='%q',file_tsuid = '%q',"
893
"sopcuid = '%q', orientation = '%c', image_positionx = '%f', image_positiony = '%f',"
894
"image_positionz = '%f',slice_location = '%f',height = '%d',width = '%d',number_of_frames='%d',"
895
"instance_number = '%d', file_desc='%q', direction_cosines = '%q', spacing='%q', location='%c', updated_time = datetime(), content_datetime = ",
896
model.file.series_fk, model.file.sopiuid.c_str(), model.file.tsuid.c_str(),
897
model.file.sopcuid.c_str(), model.file.orientation, model.file.image_position[0], model.file.image_position[1],
898
model.file.image_position[2], model.file.slice_location, model.file.height, model.file.width,model.file.number_of_frames,
899
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str(),
900
LocationToChar(model.file.location));
901
if (model.file.content_datetime.empty()){
902
ostrUpdate << "NULL";
904
ostrUpdate << "'" << model.file.content_datetime << "'";
906
ostrUpdate << bufSQL.Format(" WHERE File.pk = '%ld'", model.file.pk);
907
m_pConexion->ExecuteUpdate(ostrUpdate.str().c_str());
911
std::stringstream ostrInsert;
912
ostrInsert << bufSQL.Format("INSERT INTO File ("
913
"series_fk, file_path, file_sopiuid, file_tsuid,"
914
"sopcuid, orientation, image_positionx, image_positiony,"
915
"image_positionz, slice_location, slice_thickness, height, width, number_of_frames,"
916
"instance_number, file_desc, direction_cosines, spacing, location, created_time, updated_time, content_datetime) VALUES ("
917
"'%ld','%q','%q','%q',"
918
"'%q','%c','%f','%f',"
919
"'%f','%f', '%f', '%d','%d','%d',"
920
"'%d', '%q', '%q', '%q', '%c', datetime(),datetime(),",
921
model.file.series_fk, model.file.file_path.c_str(), model.file.sopiuid.c_str(), model.file.tsuid.c_str(),
922
model.file.sopcuid.c_str(), model.file.orientation, model.file.image_position[0], model.file.image_position[1],
923
model.file.image_position[2], model.file.slice_location, model.file.slice_thickness, model.file.height, model.file.width, model.file.number_of_frames,
924
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str(), LocationToChar(model.file.location));
925
if (model.file.content_datetime.empty()){
926
ostrInsert << "NULL)";
928
ostrInsert << "'" << model.file.content_datetime << "')";
930
if(m_pConexion->ExecuteUpdate(ostrInsert.str().c_str())>0){
931
model.file.pk = (long)m_pConexion->GetLastRowId().GetValue();
810
936
void GNC::GCS::HistoryController::UpdateStudy(DICOMFileModel& model)
814
940
ostrUpdate << bufSQL.Format("Update Study SET "
815
941
"pat_id='%q',pat_id_issuer='%q',pat_name='%q',"
816
942
"study_iuid='%q', study_id='%q', accession_no='%q', ref_physician='%q', study_desc='%q',"
817
"pat_sex='%c', updated_time=datetime(),pat_birthdate=",
943
"pat_sex='%c', location='%c', updated_time=datetime(),pat_birthdate=",
818
944
model.study.pat_id.c_str(), model.study.pat_id_issuer.c_str(), model.study.pat_name.c_str(),
819
945
model.study.study_iuid.c_str(), model.study.study_id.c_str(),model.study.study_acc_no.c_str(), model.study.ref_physician.c_str(), model.study.study_desc.c_str(),
820
model.study.pat_sex);
946
model.study.pat_sex, LocationToChar(model.study.location));
822
948
if (model.study.pat_bithdate.empty()){
823
949
ostrUpdate << "NULL";
841
967
"study_fk = '%ld', series_iuid='%q',series_no='%q',modality='%q',"
842
968
"uid_importer='%q', body_part='%q', laterality='%q', series_desc='%q',"
843
969
"institution='%q',station_name='%q',department='%q',perf_physician='%q',"
844
"frame_of_reference_uid='%q', updated_time = datetime(),series_datetime=",
970
"frame_of_reference_uid='%q', location='%c', updated_time = datetime(),series_datetime=",
845
971
model.series.study_fk, model.series.series_iuid.c_str(), model.series.series_no.c_str(), model.series.series_modality.c_str(),
846
972
model.series.uid_importer.c_str(), model.series.body_part.c_str(), model.series.laterality.c_str(), model.series.series_desc.c_str(),
847
973
model.series.institution.c_str(), model.series.station_name.c_str(), model.series.department.c_str(), model.series.perf_physician.c_str(),
848
model.series.frame_of_reference.c_str());
974
model.series.frame_of_reference.c_str(), LocationToChar(model.series.location));
849
975
if (model.series.series_datetime.empty()){
850
976
ostrUpdate << "NULL";
860
986
std::stringstream ostrUpdate;
861
987
wxSQLite3StatementBuffer bufSQL;
862
988
ostrUpdate << bufSQL.Format("Update File SET "
863
"series_fk = '%ld',file_sopiuid='%q',file_tsuid = '%q',"
989
"series_fk = '%ld', file_path = '%q',file_sopiuid='%q',file_tsuid = '%q',"
864
990
"sopcuid = '%q', orientation = '%c', image_positionx = '%f', image_positiony = '%f',"
865
991
"image_positionz = '%f',slice_location = '%f',height = '%d',width = '%d',number_of_frames='%d',"
866
"instance_number = '%d', file_desc='%q', direction_cosines = '%q', spacing='%q', updated_time = datetime(), content_datetime = ",
867
model.file.series_fk, model.file.sopiuid.c_str(), model.file.tsuid.c_str(),
992
"instance_number = '%d', file_desc='%q', direction_cosines = '%q', spacing='%q', slice_thickness='%f', location='%c', updated_time = datetime(), content_datetime = ",
993
model.file.series_fk, model.file.file_path.c_str(), model.file.sopiuid.c_str(), model.file.tsuid.c_str(),
868
994
model.file.sopcuid.c_str(), model.file.orientation, model.file.image_position[0], model.file.image_position[1],
869
995
model.file.image_position[2], model.file.slice_location, model.file.height, model.file.width,model.file.number_of_frames,
870
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str());
996
model.file.instance_number, model.file.file_desc.c_str(), model.file.direction_cosines.c_str(), model.file.spacing.c_str(),
997
model.file.slice_thickness, LocationToChar(model.file.location));
871
998
if (model.file.content_datetime.empty()){
872
999
ostrUpdate << "NULL";
877
1004
m_pConexion->ExecuteUpdate(ostrUpdate.str().c_str());
880
void GNC::GCS::HistoryController::GetPathOfFile(GNC::GCS::HistoryController::FileModel& fileModel)
1007
std::string GNC::GCS::HistoryController::GetPathOfFile(GNC::GCS::IHistoryController::TLocation location, long pk, const std::string& file_path)
882
if (fileModel.file_path.empty()) {
883
wxString pathDicom = FROMPATH(m_GinkgoDicomDir);
884
pathDicom += wxFileName::GetPathSeparator();
885
pathDicom += wxT("DicomDir");
886
wxString rootDir(pathDicom);
887
if (!wxDir::Exists(rootDir)) {
888
wxFileName::Mkdir(rootDir, 0700);
1010
case TL_LocalDatabase:
1012
wxString pathDicom = FROMPATH(m_GinkgoDicomDir);
1013
pathDicom += wxFileName::GetPathSeparator();
1014
pathDicom += wxT("DicomDir");
1015
wxString rootDir(pathDicom);
1016
if (!wxDir::Exists(rootDir)) {
1017
wxFileName::Mkdir(rootDir, 0700);
1019
pathDicom += wxFileName::GetPathSeparator();
1020
pathDicom += wxString::Format(wxT("%d"), pk);
1021
return std::string(TOPATH(pathDicom));
890
pathDicom += wxFileName::GetPathSeparator();
891
pathDicom += wxString::Format(wxT("%d"), fileModel.pk);
892
fileModel.real_path = TOPATH(pathDicom);
894
fileModel.real_path = GetAbsolutePath(fileModel.file_path);
1024
case TL_LocalLinked:
1025
return GetAbsolutePath(file_path);
910
1044
return std::string(TOPATH(pathDicom));
913
std::string GNC::GCS::HistoryController::GetRelativePath(const std::string& absolutePath)
915
wxFileName fileName(FROMPATH(absolutePath));
916
if (fileName.MakeRelativeTo(FROMPATH(GetGinkgoDicomDir()))) {
917
return std::string(TOPATH(fileName.GetFullPath()));
1047
std::string GNC::GCS::HistoryController::GetRelativePath(const std::string& absolutePath)
1049
wxFileName fileName(FROMPATH(absolutePath));
1050
if (fileName.MakeRelativeTo(FROMPATH(GetGinkgoDicomDir()))) {
1051
return std::string(TOPATH(fileName.GetFullPath()));
1053
return absolutePath;
923
std::string GNC::GCS::HistoryController::GetAbsolutePath(const std::string& relativePath)
925
wxFileName fileName(FROMPATH(relativePath));
926
if (fileName.IsRelative() && fileName.MakeAbsolute(FROMPATH(GetGinkgoDicomDir(true)))) {
927
return std::string(TOPATH(fileName.GetFullPath()));
1057
std::string GNC::GCS::HistoryController::GetAbsolutePath(const std::string& relativePath)
1059
wxFileName fileName(FROMPATH(relativePath));
1060
if (fileName.IsRelative() && fileName.MakeAbsolute(FROMPATH(GetGinkgoDicomDir(true)))) {
1061
return std::string(TOPATH(fileName.GetFullPath()));
1063
return relativePath;
933
1067
void GNC::GCS::HistoryController::UpdateSeriesSummaryInfo(long series_pk)
935
1069
wxSQLite3StatementBuffer bufSQL;
936
1070
bufSQL.Format("SELECT File.file_tsuid, count(*) as numberOfFiles "
938
"WHERE series_fk = '%d'"
1072
"WHERE series_fk = '%d' "
939
1073
"GROUP BY FILE.file_tsuid", series_pk);
940
1074
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
941
1075
std::list<std::string> tSyntaxUIDs;
942
1076
long number_instances = 0;
943
1077
while (resultados.NextRow()) {
944
1078
std::string path(resultados.GetAsString(wxT("file_tsuid")).ToUTF8());
945
tSyntaxUIDs.push_back(path);
1079
if (!path.empty()) {
1080
tSyntaxUIDs.push_back(path);
946
1082
number_instances += resultados.GetInt64(wxT("numberOfFiles")).GetValue();
1084
//order is W,L,B => if there is a wado is wado and if there is a linked is linked
1085
bufSQL.Format("SELECT distinct(location) "
1087
"WHERE series_fk = '%d' "
1088
"Order by location DESC", series_pk);
1089
resultados = m_pConexion->ExecuteQuery(bufSQL);
1090
TLocation seriesLocation = TL_LocalDatabase;
1091
if (resultados.NextRow()) {
1092
seriesLocation = CharToLocation(*resultados.GetAsString(0).ToUTF8());
949
bufSQL.Format("Update Series SET num_instances = '%d', tuids_in_series='%q' WHERE pk = '%d'",
950
number_instances, ListToString(tSyntaxUIDs).c_str(), series_pk);
1095
bufSQL.Format("Update Series SET num_instances = '%d', tuids_in_series='%q', location='%c' WHERE pk = '%d'",
1096
number_instances, ListToString(tSyntaxUIDs).c_str(), LocationToChar(seriesLocation), series_pk);
951
1097
m_pConexion->ExecuteUpdate(bufSQL);
978
1126
modalities.push_back(mod);
979
1127
number_series += resultados.GetInt64(wxT("numberOfSeries")).GetValue();
1129
//order is W,L,B => if there is a wado is wado and if there is a linked is linked
1130
bufSQL.Format("SELECT distinct(location) "
1132
"WHERE study_fk = '%d' "
1133
"Order by location DESC", study_pk);
1134
resultados = m_pConexion->ExecuteQuery(bufSQL);
1135
TLocation studyLocation = TL_LocalDatabase;
1136
if (resultados.NextRow()) {
1137
studyLocation = CharToLocation(*resultados.GetAsString(0).ToUTF8());
982
bufSQL.Format("Update Study SET num_instances = '%d', num_series='%d', cuids_in_study='%q', mods_in_study = '%q' WHERE pk = '%d'",
983
number_instances, number_series, ListToString(sopclasses).c_str(), ListToString(modalities).c_str(), study_pk);
1140
bufSQL.Format("Update Study SET num_instances = '%d', num_series='%d', cuids_in_study='%q', mods_in_study = '%q', location='%c' WHERE pk = '%d'",
1141
number_instances, number_series, ListToString(sopclasses).c_str(), ListToString(modalities).c_str(), LocationToChar(studyLocation), study_pk);
984
1142
m_pConexion->ExecuteUpdate(bufSQL);
1021
1180
bufSQL.Format("SELECT Series.pk, Series.study_fk, Series.series_iuid, Series.series_datetime, Series.series_no,Series.modality,"
1022
1181
"Series.uid_importer, Series.body_part, Series.laterality, Series.series_desc,"
1023
1182
"Series.institution,Series.station_name,Series.department,Series.perf_physician,"
1024
"Series.num_instances, Series.frame_of_reference_uid, Series.tuids_in_series, Series.created_time, Series.updated_time, "
1183
"Series.num_instances, Series.frame_of_reference_uid, Series.tuids_in_series, Series.created_time, Series.updated_time, Series.location, "
1027
1186
"LEFT OUTER JOIN ("
1028
1187
"select distinct TasksSeries.task_fk as task_pk, series_fk from TasksSeries, Tasks "
1029
1188
"where series_fk = '%ld' AND TasksSeries.task_fk = Tasks.pk AND Tasks.status IN('%d','%d') "
1030
1189
") on series_fk=pk "
1031
"WHERE pk = '%ld' AND modality != 'SR'", series_pk,GNC::GCS::IPersistentCommand::Pending,GNC::GCS::IPersistentCommand::Error, series_pk);
1190
"WHERE pk = '%ld'", series_pk,GNC::GCS::IPersistentCommand::Pending,GNC::GCS::IPersistentCommand::Error, series_pk);
1032
1191
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1033
1192
while (resultados.NextRow()) {
1034
1193
FillInSeriesModel(resultados, seriesModel);
1070
1229
ostr << bufSQL.Format("SELECT Series.pk, Series.study_fk, Series.series_iuid, Series.series_datetime, Series.series_no,Series.modality,"
1071
1230
"Series.uid_importer, Series.body_part, Series.laterality, Series.series_desc,"
1072
1231
"Series.institution,Series.station_name,Series.department,Series.perf_physician,"
1073
"Series.num_instances, Series.frame_of_reference_uid, Series.tuids_in_series, Series.created_time, Series.updated_time, "
1232
"Series.num_instances, Series.frame_of_reference_uid, Series.tuids_in_series, Series.location, Series.created_time, Series.updated_time, "
1076
1235
"LEFT OUTER JOIN ("
1114
1273
bufSQL.Format("SELECT Series.pk, Series.study_fk, Series.series_iuid, Series.series_datetime, Series.series_no,Series.modality,"
1115
1274
"Series.uid_importer, Series.body_part, Series.laterality, Series.series_desc,"
1116
1275
"Series.institution,Series.station_name,Series.department,Series.perf_physician,"
1117
"Series.num_instances, Series.frame_of_reference_uid, Series.tuids_in_series, Series.created_time, Series.updated_time, "
1276
"Series.num_instances, Series.frame_of_reference_uid, Series.location, Series.tuids_in_series, Series.created_time, Series.updated_time, "
1120
1279
"LEFT OUTER JOIN ("
1121
1280
"select distinct TasksSeries.task_fk as task_pk, series_fk from TasksSeries, Tasks "
1122
1281
"where TasksSeries.task_fk = Tasks.pk AND Tasks.status IN('%d','%d') "
1123
1282
") on series_fk=pk "
1124
"WHERE study_fk = '%d' AND modality != 'SR'",GNC::GCS::IPersistentCommand::Pending,GNC::GCS::IPersistentCommand::Error, study_pk);
1283
"WHERE study_fk = '%d'",GNC::GCS::IPersistentCommand::Pending,GNC::GCS::IPersistentCommand::Error, study_pk);
1125
1284
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1126
1285
std::map<long, SeriesModel> mapOfSeries;
1127
1286
while (resultados.NextRow()) {
1168
1328
bufSQL.Format("SELECT Study.pk, Study.pat_id, Study.pat_id_issuer, Study.pat_name, Study.pat_birthdate,Study.pat_sex,"
1169
1329
"Study.study_iuid, Study.study_id, Study.study_datetime, Study.accession_no,"
1170
1330
"Study.ref_physician,Study.study_desc,Study.mods_in_study,Study.cuids_in_study,"
1171
"Study.num_series, Study.num_instances, Study.created_time, Study.updated_time, "
1331
"Study.num_series, Study.num_instances, Study.location, Study.created_time, Study.updated_time, "
1172
1332
"pending_tasks "
1174
1334
"LEFT OUTER JOIN ("
1188
1348
return studyModel;
1352
void GNC::GCS::HistoryController::GetStudyModelFromUID(const std::string& uid, GNC::GCS::HistoryController::StudyModelList& studies)
1355
wxSQLite3StatementBuffer bufSQL;
1356
bufSQL.Format("SELECT Study.pk, Study.pat_id, Study.pat_id_issuer, Study.pat_name, Study.pat_birthdate,Study.pat_sex,"
1357
"Study.study_iuid, Study.study_id, Study.study_datetime, Study.accession_no,"
1358
"Study.ref_physician,Study.study_desc,Study.mods_in_study,Study.cuids_in_study,"
1359
"Study.num_series, Study.num_instances, Study.location, Study.created_time, Study.updated_time, "
1363
"select count(distinct TasksSeries.task_fk) as pending_tasks, study_fk from TasksSeries, Tasks, Series "
1364
"where Series.pk = TasksSeries.series_fk AND TasksSeries.task_fk = Tasks.pk AND Tasks.status IN('%d','%d') "
1365
"GROUP by study_fk "
1367
"WHERE study_iuid = '%q'", GNC::GCS::IPersistentCommand::Pending,GNC::GCS::IPersistentCommand::Error,uid.c_str());
1368
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1369
std::map<long, StudyModel> mapOfStudies;
1370
while (resultados.NextRow()) {
1371
long pk = resultados.GetInt64(wxT("pk")).GetValue();
1372
FillInStudyModel(resultados, mapOfStudies[pk]);
1374
for (std::map<long, StudyModel>::const_iterator it = mapOfStudies.begin(); it != mapOfStudies.end(); ++it) {
1375
studies.push_back((*it).second);
1377
}catch (wxSQLite3Exception& ex) {
1378
LOG_ERROR("BBDD", "SeriesModel "<<ex.GetMessage().ToUTF8());
1191
1382
void GNC::GCS::HistoryController::GetDatabaseDatasetFromStudy(long study_pk, GIL::DICOM::DicomDataset& dataset)
1193
1384
GNC::GCS::HistoryController::StudyModel studyModel = GetStudyModel(study_pk);
1229
1420
ostr << bufSQL.Format("SELECT Study.pk, Study.pat_id, Study.pat_id_issuer, Study.pat_name, Study.pat_birthdate,Study.pat_sex,"
1230
1421
"Study.study_iuid, Study.study_id, Study.study_datetime, Study.accession_no,"
1231
1422
"Study.ref_physician,Study.study_desc,Study.mods_in_study,Study.cuids_in_study,"
1232
"Study.num_series, Study.num_instances, Study.created_time, Study.updated_time, "
1423
"Study.num_series, Study.num_instances, Study.location, Study.created_time, Study.updated_time, "
1233
1424
"pending_tasks "
1235
1426
"LEFT OUTER JOIN ("
1309
1501
bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.content_datetime,"
1310
1502
"File.sopcuid, File.orientation, File.image_positionx, File.image_positiony,"
1311
1503
"File.image_positionz,File.slice_location, File.slice_thickness, File.height,File.width, File.number_of_frames,"
1312
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.created_time, File.updated_time "
1504
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.location, File.created_time, File.updated_time "
1313
1505
"FROM File, Series "
1314
1506
"WHERE File.series_fk = Series.pk AND File.file_sopiuid=Series.frame_of_reference_uid AND Series.pk='%ld'", series_pk);
1316
1508
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1317
1509
if (resultados.NextRow()) {
1318
1510
FillInFileModel(resultados, fileModel);
1319
GetPathOfFile(fileModel);
1511
fileModel.real_path = GetPathOfFile(fileModel.location, fileModel.pk, fileModel.file_path);
1321
1513
FileModelList listOfFiles;
1322
1514
GetSeriesSortedFileModels(series_pk, listOfFiles, true);
1336
1528
bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.content_datetime,"
1337
1529
"File.sopcuid, File.orientation, File.image_positionx, File.image_positiony,"
1338
1530
"File.image_positionz,File.slice_location, File.slice_thickness, File.height,File.width, File.number_of_frames,"
1339
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.created_time, File.updated_time "
1531
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.location, File.created_time, File.updated_time "
1341
1533
"WHERE pk = '%ld'", file_pk);
1342
1534
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1343
1535
if (resultados.NextRow()) {
1344
1536
FillInFileModel(resultados, fileModel);
1345
GetPathOfFile(fileModel);
1537
fileModel.real_path = GetPathOfFile(fileModel.location, fileModel.pk, fileModel.file_path);
1347
1539
}catch (wxSQLite3Exception& ex) {
1348
1540
LOG_ERROR("BBDD", "FileModel "<<ex.GetMessage().ToUTF8());
1359
1551
bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.content_datetime,"
1360
1552
"File.sopcuid, File.orientation, File.image_positionx, File.image_positiony,"
1361
1553
"File.image_positionz,File.slice_location, File.slice_thickness, File.height,File.width, File.number_of_frames,"
1362
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.created_time, File.updated_time "
1554
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.location, File.created_time, File.updated_time "
1364
1556
"WHERE File.file_sopiuid = '%q'", sopInstanceUID.c_str());
1366
1558
bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.content_datetime,"
1367
1559
"File.sopcuid, File.orientation, File.image_positionx, File.image_positiony,"
1368
1560
"File.image_positionz,File.slice_location, File.slice_thickness, File.height,File.width, File.number_of_frames,"
1369
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.created_time, File.updated_time "
1561
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.location, File.created_time, File.updated_time "
1370
1562
"FROM File, Series "
1371
1563
"WHERE File.file_sopiuid = '%q' AND File.series_fk= Series.pk AND series.study_fk='%ld'", sopInstanceUID.c_str(), study_pk);
1373
1565
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(bufSQL);
1374
1566
if (resultados.NextRow()) {
1375
1567
FillInFileModel(resultados, fileModel);
1376
GetPathOfFile(fileModel);
1568
fileModel.real_path = GetPathOfFile(fileModel.location, fileModel.pk, fileModel.file_path);
1378
1570
}catch (wxSQLite3Exception& ex) {
1379
1571
LOG_ERROR("BBDD", "FileModel "<<ex.GetMessage().ToUTF8());
1473
1681
sentencia << bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.content_datetime,"
1474
1682
"File.sopcuid, File.orientation, File.image_positionx, File.image_positiony,"
1475
1683
"File.image_positionz,File.slice_location, File.slice_thickness, File.height,File.width, File.number_of_frames,"
1476
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.created_time, File.updated_time "
1684
"File.instance_number, File.file_desc, File.direction_cosines, File.spacing, File.location, File.created_time, File.updated_time "
1477
1685
"FROM File WHERE "
1478
1686
"File.series_fk='%ld' "
1483
1691
while (resultados.NextRow()) {
1484
1692
FileModel fileModel;
1485
1693
FillInFileModel(resultados, fileModel);
1486
GetPathOfFile(fileModel);
1694
fileModel.real_path = GetPathOfFile(fileModel.location, fileModel.pk, fileModel.file_path);
1695
fileList.push_back(fileModel);
1700
}catch (wxSQLite3Exception& ex) {
1701
LOG_ERROR("BBDD", "GetPathsSerieOrdenados "<<ex.GetMessage().ToUTF8())
1702
wxMessageBox(_("Error reading history: \n")+ex.GetMessage(), _("Info"),
1703
wxOK | wxICON_WARNING);
1708
inline void FillInLightFileModel(wxSQLite3ResultSet& resultados, GNC::GCS::HistoryController::LightFileModel& fileModel)
1710
fileModel.pk = resultados.GetInt64(wxT("pk")).GetValue();
1711
fileModel.series_fk = resultados.GetInt64(wxT("series_fk")).GetValue();
1713
int columnIndex = resultados.FindColumnIndex(wxT("file_path"));
1714
const char* filePath = (const char*) sqlite3_column_text((sqlite3_stmt*) resultados.GetStmt(), columnIndex);
1715
fileModel.file_path = std::string(filePath);
1717
fileModel.sopiuid = resultados.GetAsString(wxT("file_sopiuid")).ToUTF8();
1718
fileModel.tsuid = resultados.GetAsString(wxT("file_tsuid")).ToUTF8();
1719
fileModel.sopcuid = resultados.GetAsString(wxT("sopcuid")).ToUTF8();
1720
fileModel.location = GNC::GCS::IHistoryController::CharToLocation(*resultados.GetString(wxT("location")).ToUTF8());
1724
void GNC::GCS::HistoryController::GetSeriesSortedFileModels(long series_pk, GNC::GCS::HistoryController::LightFileModelList& fileList, bool onlyFirst)
1727
std::ostringstream sentencia;
1728
wxSQLite3StatementBuffer bufSQL;
1729
sentencia << bufSQL.Format("SELECT File.pk, File.series_fk, File.file_path, File.file_sopiuid, File.file_tsuid, File.sopcuid, File.location "
1731
"File.series_fk='%ld' "
1733
sentencia << GetFileOrderBySentence(GetSeriesOrientation(series_pk));
1735
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(sentencia.str().c_str());
1736
while (resultados.NextRow()) {
1737
LightFileModel fileModel;
1738
FillInLightFileModel(resultados, fileModel);
1739
fileModel.real_path = GetPathOfFile(fileModel.location, fileModel.pk, fileModel.file_path);
1487
1740
fileList.push_back(fileModel);
1488
1741
if (onlyFirst) {
1889
bool GNC::GCS::HistoryController::DeleteSopInstanceUIDs(const StringList& sopInstanceUIds)
1892
if (sopInstanceUIds.size() == 0) {
1896
std::list<std::string> listOfPaths;
1897
std::list<long> listOfThumbnails;
1898
wxSQLite3StatementBuffer bufSQL;
1900
std::ostringstream ostrSelect;
1901
ostrSelect << "SELECT DISTINCT File.pk, File.file_path FROM File "
1904
for (StringList::const_iterator it = sopInstanceUIds.begin(); it != sopInstanceUIds.end(); ++it) {
1905
if (it != sopInstanceUIds.begin()) {
1906
ostrSelect << " OR";
1908
ostrSelect << bufSQL.Format(" File.file_sopiuid = '%q'", (*it).c_str());
1911
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostrSelect.str().c_str());
1912
while (resultados.NextRow()) {
1913
wxString filePath = resultados.GetAsString(wxT("file_path"));
1914
long pk = resultados.GetInt64(wxT("pk")).GetValue();
1915
listOfThumbnails.push_back(pk);
1916
if (filePath.empty()) {
1917
std::string filePath = GetPathOfFile(pk);
1918
listOfPaths.push_back(filePath);
1922
RemoveFilesFromDisk(listOfPaths);
1923
DeleteThumbnails(listOfThumbnails);
1926
std::ostringstream ostrDelete;
1927
ostrDelete << "Delete from File where ";
1928
for (StringList::const_iterator it = sopInstanceUIds.begin(); it != sopInstanceUIds.end(); ++it) {
1929
if (it != sopInstanceUIds.begin()) {
1930
ostrDelete << " OR";
1932
ostrDelete << bufSQL.Format(" File.file_sopiuid = '%q'", (*it).c_str());
1934
wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostrDelete.str().c_str());
1937
} catch (wxSQLite3Exception& ex) {
1938
LOG_ERROR("BBDD", "DeleteSopInstanceUIDs "<<ex.GetMessage().ToUTF8())
1939
wxMessageBox(_("Failed to delete the number of database:\n")+ex.GetMessage(), _("Info"),
1940
wxOK | wxICON_WARNING);
1636
1946
bool GNC::GCS::HistoryController::EmptyHistory(bool eliminarDelDisco)
1638
1948
wxCriticalSectionLocker locker(*m_pCriticalSection);