Updates will be applied on October 27th between 12pm - 12:45pm EDT (UTC-0400). Gitlab may be slow during the maintenance window.

Commit 43780ece authored by Aaron Bray's avatar Aaron Bray
Browse files

Model specific data request support, Major bug in returning the incorrect patient state

parent ecd3af7c
......@@ -31,4 +31,11 @@ Macro EngineUnitTest=EngineUnitTestDriver FastPlot Baseline=unit_tests/pulse/ Co
Macro EngineUnitTestFull=EngineUnitTestDriver FullPlot Baseline=unit_tests/pulse/ Computed=./test_results/unit_tests/pulse
Macro ScenarioTest=ScenarioTestDriver FastPlot Baseline=scenarios/ Computed=./test_results/scenarios
patient/BasicStandard.json = ScenarioTest
#patient/BasicStandard.json = ScenarioTest
#RespiratoryWithMechanicalVentilationCircuitAndTransport = EngineUnitTest Results=RespiratoryAndMechanicalVentilationCircuitOutput,RespiratoryAndMechanicalVentilationTransportOutput,AerosolMechanicalVentilationTransportOutput
#AnesthesiaMachineCircuitAndTransport = EngineUnitTest Results=AnesthesiaMachineCircuitOutput,AnesthesiaMachineTransportOutput
#RespiratoryWithAnesthesiaMachineCircuitAndTransport = EngineUnitTest Results=RespiratoryAndAnesthesiaMachineCircuitOutput,RespiratoryAndAnesthesiaMachineTransportOutput
#RespiratoryWithInhalerCircuitAndTransport = EngineUnitTest Results=RespiratoryAndInhalerCircuitOutput,RespiratoryAndInhalerTransportOutput,AerosolInhalerTransportOutput
patient/COPDExacerbation.json = ScenarioTest
\ No newline at end of file
......@@ -47,8 +47,8 @@ RespiratoryWithAnesthesiaMachineCircuitAndTransport = EngineUnitTest Results=Res
@group Inhaler
RespiratoryWithInhalerCircuitAndTransport = EngineUnitTest Results=RespiratoryAndInhalerCircuitOutput,RespiratoryAndInhalerTransportOutput,AerosolInhalerTransportOutput
@group MechanicalVentilator
RespiratoryWithMechanicalVentilatorCircuitAndTransport = EngineUnitTest Results=RespiratoryAndMechanicalVentilatorCircuitOutput,RespiratoryAndMechanicalVentilatorTransportOutput,AerosolMechanicalVentilatorTransportOutput
@group MechanicalVentilation
RespiratoryWithMechanicalVentilationCircuitAndTransport = EngineUnitTest Results=RespiratoryAndMechanicalVentilationCircuitOutput,RespiratoryAndMechanicalVentilationTransportOutput,AerosolMechanicalVentilationTransportOutput
@group Environment
InternalTemperatureVariableBMRCircuitTest = EngineUnitTest Results=InternalTemperatureVariableBMRCircuitOutput
......
......@@ -87,7 +87,7 @@ bool SEDataRequest::IsValid()
return true;
}
default:
return true;//??
return true;//Equipment
}
}
......
......@@ -257,6 +257,7 @@ bool SEEngineTracker::TrackRequest(SEDataRequest& dr)
case eDataRequest_Category::AnesthesiaMachine:
case eDataRequest_Category::ECG:
case eDataRequest_Category::Inhaler:
case eDataRequest_Category::MechanicalVentilator:
{
if (!dr.GetUnit())
m_ss << dr.GetPropertyName();
......
......@@ -273,3 +273,61 @@ inline void IncrementOverride(SEScalarQuantity<Unit>& s, double value, const Uni
s.IncrementValue(value, unit);
s.SetReadOnly(b);
}
#define DEFINE_SCALAR_PTR(name, type) \
public: \
bool Has##name() const \
{ \
return m_##name==nullptr?false:m_##name->IsValid(); \
} \
SEScalar##type& Get##name() \
{ \
if(m_##name==nullptr) \
m_##name = new SE##type(); \
return *m_##name; \
} \
double Get##name() const \
{ \
if (m_##name == nullptr) \
return SEScalar::dNaN(); \
return m_##name->GetValue(); \
} \
protected: \
SEScalar##type m_##name;
#define DEFINE_UNIT_SCALAR_PTR(name, type) \
public: \
bool Has##name() const \
{ \
return m_##name==nullptr?false:m_##name->IsValid(); \
} \
SEScalar##type& Get##name() \
{ \
if(m_##name==nullptr) \
m_##name = new SE##type(); \
return *m_##name; \
} \
double Get##name(const type##Unit& unit) const \
{ \
if (m_##name == nullptr) \
return SEScalar::dNaN(); \
return m_##name->GetValue(unit); \
} \
protected: \
SEScalar##type m_##name;
#define DEFINE_SCALAR(name, type) \
public: \
bool Has##name() const { return m_##name.IsValid(); } \
SEScalar##type& Get##name() { return m_##name; } \
double Get##name() const { return m_##name.GetValue(); } \
protected: \
SEScalar##type m_##name;
#define DEFINE_UNIT_SCALAR(name, type) \
public: \
bool Has##name() const { return m_##name.IsValid(); } \
SEScalar##type& Get##name() { return m_##name; } \
double Get##name(const type##Unit& unit) const { return m_##name.GetValue(unit); } \
protected: \
SEScalar##type m_##name;
......@@ -20,7 +20,7 @@
SEScenarioExec::SEScenarioExec(PhysiologyEngine& engine) : Loggable(engine.GetLogger()), m_Engine(engine)
{
m_Cancel = false;
m_Cancel = false;
m_EngineConfiguration = nullptr;//Derived class will manage this pointer
}
......
......@@ -86,9 +86,10 @@ void SEMechanicalVentilator::Merge(const SEMechanicalVentilator& from)
{
double amt;
double total = 0;
RemoveFractionInspiredGases();
SESubstance* sub;
SESubstanceFraction* sf;
for (auto my_sf : m_FractionInspiredGases)
my_sf->GetFractionAmount().SetValue(0);
for (SESubstanceFraction* osf : from.m_FractionInspiredGases)
{
if (&m_Substances != &from.m_Substances)
......@@ -104,16 +105,25 @@ void SEMechanicalVentilator::Merge(const SEMechanicalVentilator& from)
else
sub = &osf->GetSubstance();
sf = new SESubstanceFraction(*sub);
sf = &GetFractionInspiredGas(*sub);
sf->GetFractionAmount().Set(osf->GetFractionAmount());
amt = sf->GetFractionAmount().GetValue();
total += amt;
m_FractionInspiredGases.push_back(sf);
m_cFractionInspiredGases.push_back(sf);
m_Substances.AddActiveSubstance((SESubstance&)sf->m_Substance);
}
// It's Ok if you ONLY set Oxygen, i.e. FiO2
// Ventilator models should understand that common setting
if (!SEScalar::IsValue(1, total))
Error("Mechanical Ventilator substance fractions do not sum to 1");
{
bool err = false;
if (m_FractionInspiredGases.size() != 1)
err = true;
else if (m_FractionInspiredGases[0]->GetSubstance().GetName() != "Oxygen")
err = true;
if(err)
Error("Mechanical Ventilator substance fractions do not sum to 1");
}
}
if (from.HasConcentrationInspiredAerosol())
......
......@@ -3,120 +3,364 @@ See accompanying NOTICE file for details.*/
#pragma once
#include "controller/System.h"
#include "system/physiology/SEBloodChemistrySystem.h"
#include "system/physiology/SECardiovascularSystem.h"
#include "system/physiology/SEDrugSystem.h"
#include "system/physiology/SEEndocrineSystem.h"
#include "system/physiology/SEEnergySystem.h"
#include "system/physiology/SEGastrointestinalSystem.h"
#include "system/physiology/SEHepaticSystem.h"
#include "system/physiology/SENervousSystem.h"
#include "system/physiology/SERenalSystem.h"
#include "system/physiology/SERespiratorySystem.h"
#include "system/physiology/SETissueSystem.h"
#include "system/environment/SEEnvironment.h"
#include "system/equipment/anesthesia_machine/SEAnesthesiaMachine.h"
#include "system/equipment/electrocardiogram/SEElectroCardioGram.h"
#include "system/equipment/inhaler/SEInhaler.h"
#include "system/equipment/mechanical_ventilator/SEMechanicalVentilator.h"
#include "properties/SEScalarVolumePerPressure.h"
// These classes are used to expose any methodology specific data to end users
// This data would not belong in the cdm, and it's not a clinical assessment, nor on a compartment
// It is data specific to the system implementation
// Users only get this data if they are using the pulse engine
// They should only contain const pure vitrual methods
class PULSE_DECL PulseBloodChemistrySystem
class PULSE_DECL PulseBloodChemistrySystem : public SEBloodChemistrySystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseBloodChemistrySystem(Logger* logger) : SEBloodChemistrySystem(logger) {}
virtual ~PulseBloodChemistrySystem() = default;
virtual const SEScalar* GetScalar(const std::string& name) override
{
const SEScalar* s = SEBloodChemistrySystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters()=0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseCardiovascularSystem
class PULSE_DECL PulseCardiovascularSystem : public SECardiovascularSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseCardiovascularSystem(Logger* logger) : SECardiovascularSystem(logger) {}
virtual ~PulseCardiovascularSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SECardiovascularSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseDrugsSystem
class PULSE_DECL PulseDrugSystem : public SEDrugSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseDrugSystem(Logger* logger) : SEDrugSystem(logger) {}
virtual ~PulseDrugSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEDrugSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseEndocrineSystem
class PULSE_DECL PulseEndocrineSystem : public SEEndocrineSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseEndocrineSystem(Logger* logger) : SEEndocrineSystem(logger) {}
virtual ~PulseEndocrineSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEEndocrineSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseEnergySystem
class PULSE_DECL PulseEnergySystem : public SEEnergySystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseEnergySystem(Logger* logger) : SEEnergySystem(logger) {}
virtual ~PulseEnergySystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEEnergySystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseEnvironmentSystem
class PULSE_DECL PulseGastrointestinalSystem : public SEGastrointestinalSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseGastrointestinalSystem(Logger* logger) : SEGastrointestinalSystem(logger) {}
virtual ~PulseGastrointestinalSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEGastrointestinalSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseGastrointestinalSystem
class PULSE_DECL PulseHepaticSystem : public SEHepaticSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseHepaticSystem(Logger* logger) : SEHepaticSystem(logger) {}
virtual ~PulseHepaticSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEHepaticSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseHepaticSystem
class PULSE_DECL PulseNervousSystem : public SENervousSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseNervousSystem(Logger* logger) : SENervousSystem(logger) {}
virtual ~PulseNervousSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SENervousSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseNervousSystem
class PULSE_DECL PulseRenalSystem : public SERenalSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseRenalSystem(Logger* logger) : SERenalSystem(logger) {}
virtual ~PulseRenalSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SERenalSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseRenalSystem
class PULSE_DECL PulseRespiratorySystem : public SERespiratorySystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseRespiratorySystem(Logger* logger) : SERespiratorySystem(logger) {}
virtual ~PulseRespiratorySystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SERespiratorySystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
if (name.compare("TotalRespiratoryModelCompliance") == 0)
return &m_TotalRespiratoryModelCompliance;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
DEFINE_UNIT_SCALAR(TotalRespiratoryModelCompliance, VolumePerPressure);
};
class PULSE_DECL PulseRespiratorySystem
class PULSE_DECL PulseTissueSystem : public SETissueSystem, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseTissueSystem(Logger* logger) : SETissueSystem(logger) {}
virtual ~PulseTissueSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SETissueSystem::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseTissueSystem
class PULSE_DECL PulseEnvironmentSystem : public SEEnvironment, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseEnvironmentSystem(SESubstanceManager& substances) : SEEnvironment(substances) {}
virtual ~PulseEnvironmentSystem() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEEnvironment::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseAnesthesiaMachine
class PULSE_DECL PulseAnesthesiaMachine : public SEAnesthesiaMachine, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseAnesthesiaMachine(SESubstanceManager& substances) : SEAnesthesiaMachine(substances) {}
virtual ~PulseAnesthesiaMachine() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEAnesthesiaMachine::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseElectroCardioGram
class PULSE_DECL PulseElectroCardioGram : public SEElectroCardioGram, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseElectroCardioGram(Logger* logger) : SEElectroCardioGram(logger) {}
virtual ~PulseElectroCardioGram() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEElectroCardioGram::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseInhaler
class PULSE_DECL PulseInhaler : public SEInhaler, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseInhaler(SESubstanceManager& substances) : SEInhaler(substances) {}
virtual ~PulseInhaler() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEInhaler::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
class PULSE_DECL PulseMechanicalVentilator
class PULSE_DECL PulseMechanicalVentilator : public SEMechanicalVentilator, public PulseSystem
{
public:
// Pure virtual methods to expose methodology data with
// virtual double GetXXX(const ScalarUnit& unit) const = 0;
PulseMechanicalVentilator(SESubstanceManager& substances) : SEMechanicalVentilator(substances) {}
virtual ~PulseMechanicalVentilator() = default;
virtual const SEScalar* GetScalar(const std::string & name) override
{
const SEScalar* s = SEMechanicalVentilator::GetScalar(name);
if (s != nullptr)
return s;
// Check to see if this a model specific request
//if (name.compare("ModelParameter") == 0)
// return m_ModelParameter;
return nullptr;
}
virtual void ComputeExposedModelParameters() = 0;
protected:
//SEScalar m_ModelParameter;
};
\ No newline at end of file
......@@ -198,8 +198,8 @@ SaturationCalculator& PulseData::GetSaturationCalculator() const { return *m_Sat
PulseSubstances& PulseData::GetSubstances() const { return *m_Substances; }
const SEPatient& PulseData::GetInitialPatient() const { return *m_CurrentPatient; }
SEPatient& PulseData::GetCurrentPatient() const { return *m_InitialPatient; }
const SEPatient& PulseData::GetInitialPatient() const { return *m_InitialPatient; }
SEPatient& PulseData::GetCurrentPatient() const { return *m_CurrentPatient; }
SEBloodChemistrySystem& PulseData::GetBloodChemistry() const { return *m_BloodChemistrySystem; }
SECardiovascularSystem& PulseData::GetCardiovascular() const { return *m_CardiovascularSystem; }
......
......@@ -182,7 +182,7 @@ protected:
/**
* @brief Manages and controls execution of all data/systems in %Pulse
*/
class PULSE_DECL PulseController : protected PulseData
class PULSE_DECL PulseController : public PulseData
{
friend class PulseEngine;
friend class PulseEngineTest;
......
......@@ -2,7 +2,6 @@
See accompanying NOTICE file for details.*/
#pragma once
#include "PulsePhysiologySystems.h"
/**
* @brief Generic class for handling the %Pulse stabilization methodology
......