Skip to content

Commit

Permalink
Add EvaluateParameters operation.
Browse files Browse the repository at this point in the history
This operation is used to expose the global paramter table directly to the user. It can be used for controlling program
flow in scripts, or continually trying operations until a desired condition is present.
  • Loading branch information
Hal Clark committed Nov 14, 2024
1 parent b4dbc8c commit 14d5db2
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Operation_Dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#include "Operations/EQDXTable.h"
#include "Operations/EvaluateDoseVolumeStats.h"
#include "Operations/EvaluateNTCPModels.h"
#include "Operations/EvaluateParameters.h"
#include "Operations/EvaluateTCPModels.h"
#include "Operations/ExecuteShell.h"
#include "Operations/ExplodeImages.h"
Expand Down Expand Up @@ -370,6 +371,7 @@ std::map<std::string, op_packet_t> Known_Operations(){
out["EQDXTable"] = std::make_pair(OpArgDocEQDXTable, EQDXTable);
out["EvaluateDoseVolumeStats"] = std::make_pair(OpArgDocEvaluateDoseVolumeStats, EvaluateDoseVolumeStats);
out["EvaluateNTCPModels"] = std::make_pair(OpArgDocEvaluateNTCPModels, EvaluateNTCPModels);
out["EvaluateParameters"] = std::make_pair(OpArgDocEvaluateParameters, EvaluateParameters);
out["EvaluateTCPModels"] = std::make_pair(OpArgDocEvaluateTCPModels, EvaluateTCPModels);
out["ExecuteShell"] = std::make_pair(OpArgDocExecuteShell, ExecuteShell);
out["ExplodeImages"] = std::make_pair(OpArgDocExplodeImages, ExplodeImages);
Expand Down
1 change: 1 addition & 0 deletions src/Operations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ add_library(Operations_objs OBJECT
EQDXTable.cc
EvaluateDoseVolumeStats.cc
EvaluateNTCPModels.cc
EvaluateParameters.cc
EvaluateTCPModels.cc
ExecuteShell.cc
ExplodeImages.cc
Expand Down
92 changes: 92 additions & 0 deletions src/Operations/EvaluateParameters.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//EvaluateParameters.cc - A part of DICOMautomaton 2024. Written by hal clark.

#include <algorithm>
#include <optional>
#include <fstream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <regex>
#include <set>
#include <stdexcept>
#include <string>
#include <utility> //Needed for std::pair.
#include <vector>
#include <filesystem>

#include "YgorImages.h"
#include "YgorMath.h" //Needed for vec3 class.
#include "YgorMisc.h" //Needed for FUNCINFO, FUNCWARN, FUNCERR macros.
#include "YgorLog.h"
#include "YgorStats.h" //Needed for Stats:: namespace.
#include "YgorString.h" //Needed for GetFirstRegex(...)

#include "Explicator.h" //Needed for Explicator class.

#include "../Structs.h"
#include "../Regex_Selectors.h"
#include "../Metadata.h"

#include "EvaluateParameters.h"


OperationDoc OpArgDocEvaluateParameters(){
OperationDoc out;
out.name = "EvaluateParameters";

out.desc =
"Exposes the global parameter metadata table for query and evaluation.";

out.args.emplace_back();
out.args.back().name = "Contains";
out.args.back().desc = "Key@value pairs that can be used to check for the presence of specific metadata."
" Keys are interpretted verbatim, but values are interpretted as regex."
"\n\n"
"Note that if the key is absent in the table, the value will never match."
"\n\n"
"Note to query if a given key is present, regardless of the value, use a regex"
" that matches any input, e.g., 'key@.*'."
"";
out.args.back().default_val = "";
out.args.back().expected = false;
out.args.back().examples = { "Modality@CT",
"StudyDate@.*2024.*",
"SomeMetadataKey@.*" };

return out;
}

bool EvaluateParameters(Drover& /*DICOM_data*/,
const OperationArgPkg& OptArgs,
std::map<std::string, std::string>& InvocationMetadata,
const std::string& /*FilenameLex*/){

//---------------------------------------------- User Parameters --------------------------------------------------
const auto ContainsOpt = OptArgs.getValueStr("Contains");

//-----------------------------------------------------------------------------------------------------------------
bool ret = false;

if(ContainsOpt){
auto tokens = SplitStringToVector(ContainsOpt.value(),'@','d');
if(tokens.size() != 2UL){
throw std::invalid_argument("'Contains' parameter not understood");
}
const auto l_key = tokens.at(0);
const auto l_val = tokens.at(1);

const auto im_val = get_as<std::string>(InvocationMetadata, l_key);

if(im_val){
const auto regex_l_val = Compile_Regex(l_val);

const bool matches = std::regex_match(im_val.value(), regex_l_val);
ret = matches;
}
}

return ret;
}

16 changes: 16 additions & 0 deletions src/Operations/EvaluateParameters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// EvaluateParameters.h.

#pragma once

#include <map>
#include <string>

#include "../Structs.h"


OperationDoc OpArgDocEvaluateParameters();

bool EvaluateParameters(Drover &DICOM_data,
const OperationArgPkg& /*OptArgs*/,
std::map<std::string, std::string>& /*InvocationMetadata*/,
const std::string& /*FilenameLex*/);

0 comments on commit 14d5db2

Please sign in to comment.