<commit_before>/*
 * Copyright (c) 2008-2016 the MRtrix3 contributors
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/
 * 
 * MRtrix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * For more details, see www.mrtrix.org
 * 
 */

#include "file/dicom/patient.h"
#include "file/dicom/study.h"
#include "file/dicom/series.h"

namespace MR {
  namespace File {
    namespace Dicom {

      namespace {
        bool series_time_mismatch_warning_issued = false;
      }

      std::shared_ptr<Series> Study::find (const std::string& series_name, size_t series_number,
          const std::string& series_modality, const std::string& series_date, const std::string& series_time)
      {
        for (size_t n = 0; n < size(); n++) {
          bool match = true;
          if (series_name == (*this)[n]->name) {
            if (series_number == (*this)[n]->number) {
              if (series_modality.size() && (*this)[n]->modality.size()) 
                if (series_modality != (*this)[n]->modality) 
                  match = false;
              if (match) {
                if (series_date.size() && (*this)[n]->date.size()) 
                  if (series_date != (*this)[n]->date) 
                    match = false;
              }
              if (match && !series_time_mismatch_warning_issued) {
                if (to<float> (series_time) != to<float> ((*this)[n]->time)) {
                  INFO ("WARNING: series times do not match - this may cause problem with series grouping");
                  series_time_mismatch_warning_issued = true;
                }
              }
              if (match)
                return (*this)[n];
            }
          }
        }

        push_back (std::shared_ptr<Series> (new Series (this, series_name, series_number, series_modality, series_date, series_time)));
        return back();
      }







<commit_msg>DICOM: fix import of data when series time is empty<commit_after>/*
 * Copyright (c) 2008-2016 the MRtrix3 contributors
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/
 * 
 * MRtrix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * For more details, see www.mrtrix.org
 * 
 */

#include "file/dicom/patient.h"
#include "file/dicom/study.h"
#include "file/dicom/series.h"

namespace MR {
  namespace File {
    namespace Dicom {

      namespace {
        bool series_time_mismatch_warning_issued = false;
      }

      std::shared_ptr<Series> Study::find (const std::string& series_name, size_t series_number,
          const std::string& series_modality, const std::string& series_date, const std::string& series_time)
      {
        for (size_t n = 0; n < size(); n++) {
          bool match = true;
          if (series_name == (*this)[n]->name) {
            if (series_number == (*this)[n]->number) {
              if (series_modality.size() && (*this)[n]->modality.size()) 
                if (series_modality != (*this)[n]->modality) 
                  match = false;
              if (match) {
                if (series_date.size() && (*this)[n]->date.size()) 
                  if (series_date != (*this)[n]->date) 
                    match = false;
              }
              if (match && !series_time_mismatch_warning_issued) {
                float stime = NaN, stime_ref = NaN;
                try {
                  stime = to<float> (series_time);
                  stime_ref = to<float> ((*this)[n]->time);
                }
                catch (Exception& E) {
                  INFO ("error reading DICOM series time - field does not exist or is empty?");
                }
                if (stime != stime_ref) {
                  INFO ("WARNING: series times do not match - this may cause problem with series grouping");
                  series_time_mismatch_warning_issued = true;
                }
              }
              if (match)
                return (*this)[n];
            }
          }
        }

        push_back (std::shared_ptr<Series> (new Series (this, series_name, series_number, series_modality, series_date, series_time)));
        return back();
      }








{'fraction_non_alphanumeric': 0.11659866867081813, 'fraction_numerical': 0.006012454369765944, 'mean_word_length': 1.9706632653061225, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1325591', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1301, 'n_words': 395}