@@ -380,6 +380,8 @@ void Driver::queue_Scenario(Executor exec, bool as_subprocess)
380380 const auto patient_file = scenario->InitialParameters ()->PatientFile ().get ();
381381 std::string nc_patient_file = patient_file;
382382 std::transform (nc_patient_file.begin (), nc_patient_file.end (), nc_patient_file.begin (), ::tolower);
383+ // When the user provides the ALL directive
384+ // We will load one file for every patient in patients/
383385 if (" all" == nc_patient_file) {
384386 auto patient_files = biogears::ListFiles (" patients" , R"( .*\.xml)" , false );
385387#if BIOGEARS_IO_PRESENT
@@ -390,20 +392,27 @@ void Driver::queue_Scenario(Executor exec, bool as_subprocess)
390392#endif
391393 queue_from_patient_files (exec, patient_files, scenario_launch);
392394 }
393- else if (filesystem::exists (scenario->InitialParameters ()->PatientFile ().get ())) {
394- if (filesystem::is_directory (scenario->InitialParameters ()->PatientFile ().get ())) {
395- auto patient_files = biogears::ListFiles (scenario->InitialParameters ()->PatientFile ().get (), R"( .*\.xml)" , false );
395+ // When the user provides a directory we treat it as an ALL
396+ // But for the directory given
397+ else if (filesystem::exists (patient_file)) {
398+ if (filesystem::is_directory (patient_file)) {
399+ auto patient_files = biogears::ListFiles (patient_file, R"( .*\.xml)" , false );
396400 queue_from_patient_files (exec, patient_files, scenario_launch);
397401 return ;
398- } else {
402+ }
403+ else {
399404 exec.Patient (patient_file);
400405 _pool.queue_work (std::bind (scenario_launch, std::move (exec), false ));
401406 ++_total_work;
402407 return ;
403408 }
404- } else if (filesystem::exists (" patients/" + scenario->InitialParameters ()->PatientFile ().get ())) {
405- if (filesystem::is_directory (" patients/" + scenario->InitialParameters ()->PatientFile ().get ())) {
406- auto patient_files = biogears::ListFiles (" patients/" + scenario->InitialParameters ()->PatientFile ().get (), R"( .*\.xml)" , false );
409+ }
410+ // Historically biogears auto falls back on a assumed directory structure
411+ // If the given exist in patients/ and is a directory we will treat it as
412+ // if ALL was given but for the provided directory
413+ else if (filesystem::exists (" patients/" + patient_file)) {
414+ if (filesystem::is_directory (" patients/" + patient_file)) {
415+ auto patient_files = biogears::ListFiles (" patients/" + patient_file, R"( .*\.xml)" , false );
407416 queue_from_patient_files (exec, patient_files, scenario_launch);
408417 return ;
409418 } else {
@@ -412,11 +421,21 @@ void Driver::queue_Scenario(Executor exec, bool as_subprocess)
412421 ++_total_work;
413422 return ;
414423 }
415- } else {
416- auto matching_patients = find_matching_files (scenario->InitialParameters ()->PatientFile ().get ());
424+ }
425+ // As the user has not provided ALL or given a directory we will now
426+ // find matching files across all the IO call backs and queue correctly.
427+ // We support some wild cards so we may have more then one result.
428+ else {
429+ auto matching_patients = find_matching_files (patient_file);
417430 if (matching_patients.empty ()) {
418- matching_patients = find_matching_files (" patients/" + scenario->InitialParameters ()->PatientFile ().get ());
431+ matching_patients = find_matching_files (" patients/" + patient_file);
432+ }
433+ if (matching_patients.empty ()){
434+ // As all fallback locations have failed we have no furtherways to process the patient and should abort processing.
435+ std::cout << " Error unable to process InitialParameter Patient " << patient_file << " no patient specified.\n " ;
436+ return ;
419437 }
438+
420439 queue_from_patient_files (exec, matching_patients, scenario_launch);
421440 }
422441 } else if (scenario->InitialParameters ().present () && scenario->InitialParameters ()->Patient ().present ()) {
@@ -460,7 +479,9 @@ void Driver::queue_from_sate_files(const Executor& exec, const std::vector<files
460479void Driver::queue_from_patient_files (const Executor& exec, const std::vector<filesystem::path>& patient_files, std::function<void (Executor, bool )> scenario_launch_func)
461480{
462481 for (auto & patient_file : patient_files) {
463- std::cout << " \t " << patient_file << std::endl;
482+ if (patient_files.size () != 1 ) {
483+ std::cout << " \t " << patient_file << std::endl;
484+ }
464485 Executor patientEx { exec };
465486 patientEx.Patient (patient_file);
466487
@@ -740,9 +761,9 @@ void Driver::async_execute(biogears::Executor& ex, bool multi_patient_run)
740761 // NOTE: This loses non relative prefixes as the split will eat the leading path_separator
741762 filesystem::path parent_dir = split_scenario_path.parent_path ();
742763
743- // if (multi_patient_run) {
744- // ex.Name(ex.Name() + "-" + patient_no_extension);
745- // }
764+ // if (multi_patient_run) {
765+ // ex.Name(ex.Name() + "-" + patient_no_extension);
766+ // }
746767
747768 std::string base_file_name = (multi_patient_run) ? scenario_no_extension + " -" + patient_no_extension : scenario_no_extension;
748769 std::string console_file = base_file_name + " .log" ;
0 commit comments