~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/historycontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <sqlite/ginkgosqlite.h>
38
38
#include <sqlite/sqlite3.h>
39
39
#include <commands/comandoincluirhistorial.h>
40
 
 
41
 
#include <api/controllers/icommandscontroller.h>
 
40
 
 
41
#include <main/controllers/commandcontroller.h>
42
42
#include <commands/dbmigrationcommand.h>
43
43
 
44
44
#include <main/entorno.h>
337
337
 
338
338
                                //check version
339
339
                                int version = 0;
340
 
                                try {
341
 
                                        wxSQLite3StatementBuffer bufSQL;
342
 
                                        bufSQL.Format("SELECT Value FROM MetadataBBDD WHERE Property ='Version'");
343
 
                                        wxSQLite3ResultSet result = m_pConexion->ExecuteQuery(bufSQL);
344
 
                                        if (result.NextRow()) {
345
 
                                                version = result.GetInt(0, -1);
346
 
                                        }
 
340
                                try {
 
341
                                        wxSQLite3StatementBuffer bufSQL;
 
342
                                        bufSQL.Format("SELECT Value FROM MetadataBBDD WHERE Property ='Version'");
 
343
                                        wxSQLite3ResultSet result = m_pConexion->ExecuteQuery(bufSQL);
 
344
                                        if (result.NextRow()) {
 
345
                                                version = result.GetInt(0, -1);
 
346
                                        }
347
347
                                }catch (wxSQLite3Exception& ) {
348
348
                                }
349
349
                                if (version != GINKGO_BBDD_VERSION) 
352
352
                                                error = true;
353
353
                                                LOG_ERROR("HistoryController", "Ginkgo BBDD version isn't valid and isn't GUI thread");
354
354
                                        } else {
 
355
                                                //close connection... 
 
356
                                                if(m_pConexion!=NULL) {
 
357
                                                        m_pConexion->Close();
 
358
                                                        delete m_pConexion;
 
359
                                                        m_pConexion = NULL;
 
360
                                                }
355
361
                                                GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Events::EventHideSplashWindow());
356
362
                                                std::string oldDicomDirPath = GetGinkgoDicomDir();
357
363
                                                GNC::GUI::DicomDirMigrationDialog dlg(GNC::Entorno::Instance()->GetVentanaRaiz(), oldDicomDirPath, version, version < GINKGO_BBDD_VERSION);
363
369
                                                        ReloadHistory(dlg.GetDicomDirPath(), tryTemp);
364
370
                                                        if (dlg.GetStatus() == GNC::GUI::DicomDirMigrationDialog::TS_Migrate) 
365
371
                                                        {
366
 
                                                                ::GADAPI::DBMigrationCommandParams* pParams = new ::GADAPI::DBMigrationCommandParams(oldDicomDirPath, dlg.GetDicomDirPath(), dlg.GetRemoveAfterMigration());
 
372
                                                                ::GADAPI::DBMigrationCommandParams* pParams = new ::GADAPI::DBMigrationCommandParams(dlg.GetOriginalDicomDirPath(), dlg.GetDicomDirPath(), dlg.GetRemoveAfterMigration());
367
373
                                                                ::GADAPI::DBMigrationCommand* pCmd = new ::GADAPI::DBMigrationCommand(pParams);
368
 
                                                                GNC::GCS::IControladorComandos::Instance()->ProcessAsync("Migrating...", pCmd, NULL);
 
374
                                                                GNC::GCS::ICommandController::Instance()->ProcessAsync("Migrating...", pCmd, NULL);
369
375
                                                        }
370
376
                                                        return;
371
377
                                                }
388
394
                                                std::string historyPath = GetGinkgoDicomDir();
389
395
                                                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams* pParams = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams(historyPath, true);
390
396
                                                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial* pCmd = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial(pParams);
391
 
                                                GNC::GCS::IControladorComandos::Instance()->ProcessAsync("Migrating History", pCmd, NULL);
 
397
                                                GNC::GCS::ICommandController::Instance()->ProcessAsync("Migrating History", pCmd, NULL);
392
398
                                        } else {
393
399
                                                LOG_ERROR("BBDD", "Error creating ginkgo BBDD")
394
400
                                        }
555
561
                        {
556
562
                                try {
557
563
                                        DICOMFileModel fileModel;
558
 
                                        if (!ReadFile(fileModel,(*it),errorList))
 
564
                                        if (!ReadFile(fileModel,(*it), errorList, action))
559
565
                                        {
560
566
                                                continue;
561
567
                                        }
575
581
                                        if (!FindOrInsertFile(fileModel)) {
576
582
                                                if (action == TAA_COPY || action == TAA_MOVE) 
577
583
                                                {
578
 
                                                        GetPathOfFile(fileModel.file);
 
584
                                                        fileModel.file.real_path = GetPathOfFile(fileModel.file.location, fileModel.file.pk, fileModel.file.file_path);
579
585
                                                        wxString pathDicom = FROMPATH(fileModel.file.real_path);
580
586
 
581
587
                                                        if(wxCopyFile(FROMPATH((*it)),pathDicom)) {
670
676
        }
671
677
}
672
678
 
 
679
bool GNC::GCS::HistoryController::LinkFilesToSeries(long seriesPk, GNC::GCS::HistoryController::DICOMFileModelList& files, GNC::IProxyNotificadorProgreso* pNotificador )
 
680
{
 
681
        if (m_readOnly) {
 
682
                return false;
 
683
        }
 
684
        wxCriticalSectionLocker locker(*m_pCriticalSection);
 
685
        DICOMFileModelList listOfInsertedFiles;
 
686
        try {
 
687
                m_pConexion->Begin();
 
688
 
 
689
                SeriesModel sm = GetSeriesModel(seriesPk);
 
690
 
 
691
                int i = 0;
 
692
                for(GNC::GCS::HistoryController::DICOMFileModelList::iterator it=files.begin(); it!= files.end(); ++it, ++i)
 
693
                {
 
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()))
 
698
                                {
 
699
                                        m_pConexion->Commit();
 
700
                                        return false;
 
701
                                }
 
702
                        }                       
 
703
 
 
704
                        DICOMFileModel& fileModel = (*it);
 
705
                        fileModel.file.series_fk = seriesPk;
 
706
                        FindOrLink(fileModel);
 
707
                }//for paths...
 
708
 
 
709
                //update series and study summary info (modalities in study, number of instances...)
 
710
                UpdateSeriesSummaryInfo(sm.pk);
 
711
                
 
712
                UpdateStudySummaryInfo(sm.study_fk);
 
713
 
 
714
                m_pConexion->Commit();
 
715
                return true;
 
716
        }catch (wxSQLite3Exception& ex) {
 
717
                LOG_ERROR("BBDD", "Error linking file in database controller "<<ex.GetMessage().ToUTF8())
 
718
                m_pConexion->Rollback();
 
719
                return false;
 
720
        }
 
721
}
 
722
 
673
723
void GNC::GCS::HistoryController::FindOrInsertStudy(DICOMFileModel& model)
674
724
{
675
725
        std::ostringstream ostrSelect;
726
776
        wxSQLite3StatementBuffer bufSQL;
727
777
        std::stringstream ostrSelect;
728
778
        ostrSelect << bufSQL.Format("Select pk from Series where study_fk='%ld' AND series_iuid='%q' "
729
 
                "AND series_no='%q' AND modality='%q' AND uid_importer='%q' AND body_part='%q' AND laterality='%q' ", 
 
779
                "AND series_no='%q' AND modality='%q' ", 
730
780
                model.series.study_fk, model.series.series_iuid.c_str(), model.series.series_no.c_str(), model.series.series_modality.c_str(),
731
781
                model.series.uid_importer.c_str(), model.series.body_part.c_str(), model.series.laterality.c_str());
732
782
        wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostrSelect.str().c_str());
760
810
        }       
761
811
}
762
812
 
763
 
 
 
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)
765
815
{
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());
 
823
        TLocation location;
 
824
        long pk = -1;
779
825
        if (resultados.NextRow()) {
780
826
                //file exists...
781
 
                model.file.pk = resultados.GetInt(wxT("pk"));
782
 
                return true;
783
 
        } else {
 
827
                pk = resultados.GetInt(wxT("pk"));
 
828
                location = CharToLocation(*resultados.GetAsString(wxT("location")).ToUTF8());   
 
829
        }
 
830
 
 
831
        if (pk == -1) {
 
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)";
800
849
                } else {
804
853
                        model.file.pk = (long)m_pConexion->GetLastRowId().GetValue();
805
854
                }                       
806
855
                return false;
807
 
        }       
 
856
        } else if (location != TL_LocalDatabase) {
 
857
                //update file...
 
858
                model.file.pk = pk;
 
859
                UpdateFile(model);
 
860
                return false;
 
861
        } else {
 
862
                //nothing to do file is in local database
 
863
                model.file.pk = pk;
 
864
                return true;
 
865
        }
 
866
}
 
867
 
 
868
bool GNC::GCS::HistoryController::FindOrLink(DICOMFileModel& model)
 
869
{
 
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)
 
882
                {
 
883
                        return true;
 
884
                }
 
885
                else 
 
886
                {
 
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";
 
903
                        } else {
 
904
                                ostrUpdate << "'" << model.file.content_datetime << "'";
 
905
                        }
 
906
                        ostrUpdate << bufSQL.Format(" WHERE File.pk = '%ld'", model.file.pk);
 
907
                        m_pConexion->ExecuteUpdate(ostrUpdate.str().c_str());
 
908
                        return true;
 
909
                }               
 
910
        }
 
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)";
 
927
        } else {
 
928
                ostrInsert << "'" << model.file.content_datetime << "')";
 
929
        }
 
930
        if(m_pConexion->ExecuteUpdate(ostrInsert.str().c_str())>0){
 
931
                model.file.pk = (long)m_pConexion->GetLastRowId().GetValue();
 
932
        }                       
 
933
        return false;
808
934
}
809
935
 
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));
821
947
 
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";
851
977
        } else {
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";
873
1000
        } else {
877
1004
        m_pConexion->ExecuteUpdate(ostrUpdate.str().c_str());
878
1005
}
879
1006
 
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)
881
1008
{
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);
 
1009
        switch (location) {
 
1010
        case TL_LocalDatabase:
 
1011
                {
 
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);
 
1018
                        }
 
1019
                        pathDicom += wxFileName::GetPathSeparator();
 
1020
                        pathDicom += wxString::Format(wxT("%d"), pk);
 
1021
                        return std::string(TOPATH(pathDicom));
889
1022
                }
890
 
                pathDicom += wxFileName::GetPathSeparator();
891
 
                pathDicom += wxString::Format(wxT("%d"), fileModel.pk);
892
 
                fileModel.real_path = TOPATH(pathDicom);
893
 
        } else {
894
 
                fileModel.real_path = GetAbsolutePath(fileModel.file_path);
 
1023
                break;
 
1024
        case TL_LocalLinked:
 
1025
                return GetAbsolutePath(file_path);
 
1026
        case TL_WadoLinked:
 
1027
        default:
 
1028
                return file_path;
895
1029
        }
896
1030
}
897
1031
 
910
1044
        return std::string(TOPATH(pathDicom));
911
1045
}
912
1046
 
913
 
std::string GNC::GCS::HistoryController::GetRelativePath(const std::string& absolutePath)
914
 
{
915
 
        wxFileName fileName(FROMPATH(absolutePath));
916
 
        if (fileName.MakeRelativeTo(FROMPATH(GetGinkgoDicomDir()))) {
917
 
                return std::string(TOPATH(fileName.GetFullPath()));
918
 
        } else {
919
 
                return absolutePath;
920
 
        }
 
1047
std::string GNC::GCS::HistoryController::GetRelativePath(const std::string& absolutePath)
 
1048
{
 
1049
        wxFileName fileName(FROMPATH(absolutePath));
 
1050
        if (fileName.MakeRelativeTo(FROMPATH(GetGinkgoDicomDir()))) {
 
1051
                return std::string(TOPATH(fileName.GetFullPath()));
 
1052
        } else {
 
1053
                return absolutePath;
 
1054
        }
921
1055
}
922
1056
 
923
 
std::string GNC::GCS::HistoryController::GetAbsolutePath(const std::string& relativePath)
924
 
{
925
 
        wxFileName fileName(FROMPATH(relativePath));
926
 
        if (fileName.IsRelative() && fileName.MakeAbsolute(FROMPATH(GetGinkgoDicomDir(true)))) {
927
 
                return std::string(TOPATH(fileName.GetFullPath()));
928
 
        } else {
929
 
                return relativePath;
930
 
        }
 
1057
std::string GNC::GCS::HistoryController::GetAbsolutePath(const std::string& relativePath)
 
1058
{
 
1059
        wxFileName fileName(FROMPATH(relativePath));
 
1060
        if (fileName.IsRelative() && fileName.MakeAbsolute(FROMPATH(GetGinkgoDicomDir(true)))) {
 
1061
                return std::string(TOPATH(fileName.GetFullPath()));
 
1062
        } else {
 
1063
                return relativePath;
 
1064
        }
931
1065
}
932
1066
 
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 "
937
1071
                "FROM File "
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);
 
1081
                }
946
1082
                number_instances += resultados.GetInt64(wxT("numberOfFiles")).GetValue();
947
1083
        }
 
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) "
 
1086
                "FROM File "
 
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());
 
1093
        }
948
1094
        //
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);
952
1098
}
953
1099
 
963
1109
        long number_instances = 0;
964
1110
        while (resultados.NextRow()) {
965
1111
                std::string sop(resultados.GetAsString(wxT("sopcuid")).ToUTF8());
966
 
                sopclasses.push_back(sop);
 
1112
                if (!sop.empty()) {
 
1113
                        sopclasses.push_back(sop);
 
1114
                }
967
1115
                number_instances += resultados.GetInt64(wxT("numberOfFiles")).GetValue();
968
1116
        }
969
1117
        bufSQL.Format("SELECT Series.modality, count(*) as numberOfSeries "
978
1126
                modalities.push_back(mod);
979
1127
                number_series += resultados.GetInt64(wxT("numberOfSeries")).GetValue();
980
1128
        }
 
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) "
 
1131
                "FROM Series "
 
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());
 
1138
        }
981
1139
        //
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);
985
1143
}
986
1144
 
1006
1164
                seriesModel.tsuids = StringToList(resultados.GetAsString(wxT("tuids_in_series")));
1007
1165
                seriesModel.created_time = GetDateTimeFromWx(resultados.GetAsString(wxT("created_time")));
1008
1166
                seriesModel.updated_time = GetDateTimeFromWx(resultados.GetAsString(wxT("updated_time")));
 
1167
                seriesModel.location = GNC::GCS::IHistoryController::CharToLocation(*resultados.GetString(wxT("location")).ToUTF8());
1009
1168
        }
1010
1169
        const long task_pk = resultados.GetInt64(wxT("task_pk")).GetValue();
1011
1170
        if (task_pk > 0) {
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, "
1025
1184
                        "task_pk "
1026
1185
                        "FROM Series "
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, "
1074
1233
                        "task_pk "
1075
1234
                        "FROM Series "
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, "
1118
1277
                        "task_pk "
1119
1278
                        "FROM Series "
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()) {
1158
1317
        studyModel.created_time = GetDateTimeFromWx(resultados.GetAsString(wxT("created_time")));
1159
1318
        studyModel.updated_time = GetDateTimeFromWx(resultados.GetAsString(wxT("updated_time")));
1160
1319
        studyModel.pending_tasks = resultados.GetInt(wxT("pending_tasks"));
 
1320
        studyModel.location = GNC::GCS::IHistoryController::CharToLocation(*resultados.GetString(wxT("location")).ToUTF8());
1161
1321
}
1162
1322
 
1163
1323
GNC::GCS::HistoryController::StudyModel GNC::GCS::HistoryController::GetStudyModel(long study_pk)
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 "
1173
1333
                        "FROM Study "
1174
1334
                        "LEFT OUTER JOIN ("
1188
1348
        return studyModel;
1189
1349
}
1190
1350
 
 
1351
 
 
1352
void GNC::GCS::HistoryController::GetStudyModelFromUID(const std::string& uid, GNC::GCS::HistoryController::StudyModelList& studies)
 
1353
{
 
1354
        try {
 
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, "
 
1360
                        "pending_tasks "
 
1361
                        "FROM Study "
 
1362
                        "LEFT OUTER JOIN ("
 
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 "
 
1366
                                ") on study_fk=pk "
 
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]);
 
1373
                }
 
1374
                for (std::map<long, StudyModel>::const_iterator it = mapOfStudies.begin(); it != mapOfStudies.end(); ++it) {
 
1375
                        studies.push_back((*it).second);
 
1376
                }
 
1377
        }catch (wxSQLite3Exception& ex) {
 
1378
                LOG_ERROR("BBDD", "SeriesModel "<<ex.GetMessage().ToUTF8());
 
1379
        }
 
1380
}
 
1381
 
1191
1382
void GNC::GCS::HistoryController::GetDatabaseDatasetFromStudy(long study_pk, GIL::DICOM::DicomDataset& dataset)
1192
1383
{
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 "
1234
1425
                                "FROM Study "
1235
1426
                                "LEFT OUTER JOIN ("
1292
1483
        fileModel.spacing = resultados.GetAsString(wxT("spacing")).ToUTF8();
1293
1484
        fileModel.created_time = GetDateTimeFromWx(resultados.GetAsString(wxT("created_time")));
1294
1485
        fileModel.updated_time = GetDateTimeFromWx(resultados.GetAsString(wxT("updated_time")));
 
1486
        fileModel.location = GNC::GCS::IHistoryController::CharToLocation(*resultados.GetString(wxT("location")).ToUTF8());
1295
1487
}
1296
1488
 
1297
1489
GNC::GCS::HistoryController::FileModel GNC::GCS::HistoryController::GetFrameOfReference(const std::string& series_pk)
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);
1315
1507
 
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);
1320
1512
        } else {
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 "
1340
1532
                        "FROM File "
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);
1346
1538
                }
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 "
1363
1555
                                "FROM File "
1364
1556
                                "WHERE File.file_sopiuid = '%q'", sopInstanceUID.c_str());
1365
1557
                } else {
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);
1372
1564
                }
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);
1377
1569
                }
1378
1570
        }catch (wxSQLite3Exception& ex) {
1379
1571
                LOG_ERROR("BBDD", "FileModel "<<ex.GetMessage().ToUTF8());
1418
1610
        }
1419
1611
}
1420
1612
 
 
1613
bool GNC::GCS::HistoryController::ExistsStudyWithUID(const std::string& studyUID)
 
1614
{
 
1615
        try {
 
1616
                wxSQLite3StatementBuffer bufSQL;
 
1617
                bufSQL.Format("Select count(*) from Study where study_iuid = '%q'",studyUID.c_str());
 
1618
                if(m_pConexion->ExecuteScalar(bufSQL)>0){
 
1619
                        return true;
 
1620
                } else {
 
1621
                        return false;
 
1622
                }
 
1623
        } catch (wxSQLite3Exception& ex) {
 
1624
                LOG_ERROR("BBDD", "ExistsStudyWithUID "<<ex.GetMessage().ToUTF8())
 
1625
                        return false;
 
1626
        }
 
1627
}
 
1628
 
1421
1629
inline std::string GetFileOrderBySentence(char orientacion)
1422
1630
{
1423
1631
        std::ostringstream ostr;
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' "
1479
1687
                        ,series_pk);
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);
 
1696
                        if (onlyFirst) {
 
1697
                                return;
 
1698
                        }
 
1699
                }
 
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);
 
1704
        }
 
1705
}
 
1706
 
 
1707
 
 
1708
inline void FillInLightFileModel(wxSQLite3ResultSet& resultados, GNC::GCS::HistoryController::LightFileModel& fileModel)
 
1709
{
 
1710
        fileModel.pk = resultados.GetInt64(wxT("pk")).GetValue();
 
1711
        fileModel.series_fk = resultados.GetInt64(wxT("series_fk")).GetValue();
 
1712
        {
 
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);
 
1716
        }
 
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());
 
1721
}
 
1722
 
 
1723
 
 
1724
void GNC::GCS::HistoryController::GetSeriesSortedFileModels(long series_pk, GNC::GCS::HistoryController::LightFileModelList& fileList, bool onlyFirst)
 
1725
{
 
1726
        try {
 
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 "
 
1730
                        "FROM File WHERE "
 
1731
                        "File.series_fk='%ld' "
 
1732
                        ,series_pk);
 
1733
                sentencia << GetFileOrderBySentence(GetSeriesOrientation(series_pk));
 
1734
 
 
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) {
1489
1742
                                return;
1633
1886
        return result;
1634
1887
}
1635
1888
 
 
1889
bool GNC::GCS::HistoryController::DeleteSopInstanceUIDs(const StringList& sopInstanceUIds)
 
1890
{
 
1891
        bool result = true;
 
1892
        if (sopInstanceUIds.size() == 0) {
 
1893
                return true;
 
1894
        }
 
1895
        try {
 
1896
                std::list<std::string> listOfPaths;
 
1897
                std::list<long> listOfThumbnails;
 
1898
                wxSQLite3StatementBuffer bufSQL;
 
1899
                {
 
1900
                        std::ostringstream ostrSelect;
 
1901
                        ostrSelect << "SELECT DISTINCT File.pk, File.file_path FROM File "
 
1902
                                "WHERE ";
 
1903
 
 
1904
                        for (StringList::const_iterator it = sopInstanceUIds.begin(); it != sopInstanceUIds.end(); ++it) {
 
1905
                                if (it != sopInstanceUIds.begin()) {
 
1906
                                        ostrSelect << " OR";
 
1907
                                }
 
1908
                                ostrSelect << bufSQL.Format(" File.file_sopiuid = '%q'", (*it).c_str());
 
1909
                        }
 
1910
 
 
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);
 
1919
                                }
 
1920
                        }
 
1921
                }
 
1922
                RemoveFilesFromDisk(listOfPaths);
 
1923
                DeleteThumbnails(listOfThumbnails);
 
1924
 
 
1925
                {
 
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";
 
1931
                                }
 
1932
                                ostrDelete << bufSQL.Format(" File.file_sopiuid = '%q'", (*it).c_str());
 
1933
                        }
 
1934
                        wxSQLite3ResultSet resultados = m_pConexion->ExecuteQuery(ostrDelete.str().c_str());
 
1935
                }
 
1936
                
 
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);
 
1941
                result = false;
 
1942
        }
 
1943
        return result;
 
1944
}
 
1945
 
1636
1946
bool GNC::GCS::HistoryController::EmptyHistory(bool eliminarDelDisco)
1637
1947
{       
1638
1948
        wxCriticalSectionLocker locker(*m_pCriticalSection);
1669
1979
        }
1670
1980
}
1671
1981
//
 
1982
bool GNC::GCS::HistoryController::ReadFile(DICOMFileModel& modelo,const std::string& pathAbsoluto, TAddErrorList& errorList, TAddAction action)
 
1983
{
 
1984
        switch (action) {
 
1985
                case TAA_MOVE:
 
1986
                case TAA_COPY:
 
1987
                        modelo.study.location = modelo.series.location = modelo.file.location = TL_LocalDatabase;
 
1988
                        break;
 
1989
                case TAA_LINK:
 
1990
                        modelo.study.location = modelo.series.location = modelo.file.location = TL_LocalLinked;
 
1991
                        break;
 
1992
        }
 
1993
        return ReadFile(modelo, pathAbsoluto, errorList);
 
1994
}
 
1995
 
1672
1996
bool GNC::GCS::HistoryController::ReadFile(DICOMFileModel& modeloDCM, const std::string& pathAbsoluto, TAddErrorList& errorList)
1673
1997
{
1674
1998
        GIL::DICOM::IDICOMManager*      pDICOMManager= GNC::Entorno::Instance()->GetPACSController()->CrearInstanciaDeDICOMManager();
1934
2258
        }
1935
2259
 
1936
2260
        GNC::Entorno::Instance()->GetPACSController()->LiberarInstanciaDeDICOMManager(pDICOMManager);
 
2261
 
 
2262
        
1937
2263
        return true;
1938
2264
}
1939
2265