Commit df51c9bd authored by Jeff Webb's avatar Jeff Webb
Browse files

Hooked up respiratory overrides and model outputs.

Fixed enum change in python files.
parent 5404cceb
{
"Name": "PressureControlContinuousMandatoryVentilationARDS",
"Description": "Apply a P-CMV mode ventilator to treat a patient with ARDS.",
"Description": "Apply a PM-CMV mode ventilator to treat a patient with ARDS.",
"StartType": { "PatientConfiguration": { "PatientFile": "StandardMale.json",
"Conditions": { "AnyCondition": [ {
"PatientCondition": {
......@@ -147,7 +147,7 @@
"InspiratoryExpiratoryRatio": { "Value": 0.5, "Unit": "" }
},
"Connection": "Tube",
"Control": "P_CMV",
"Control": "PM_CMV",
"DriverWaveform": "Square",
"PeakInspiratoryPressure": { "ScalarPressure": { "Value": 25.0, "Unit": "cmH2O" } },
"PositiveEndExpiredPressure": { "ScalarPressure": { "Value": 10.0, "Unit": "cmH2O" } },
......@@ -181,7 +181,7 @@
"InspiratoryExpiratoryRatio": { "Value": 0.5, "Unit": "" }
},
"Connection": "Tube",
"Control": "P_CMV",
"Control": "PM_CMV",
"DriverWaveform": "Square",
"PeakInspiratoryPressure": { "ScalarPressure": { "Value": 32.0, "Unit": "cmH2O" } },
"PositiveEndExpiredPressure": { "ScalarPressure": { "Value": 15.0, "Unit": "cmH2O" } },
......
{
"Name": "PressureControlContinuousMandatoryVentilationVaried",
"Description": "Apply a P-CMV mode ventilator.",
"Description": "Apply a PM-CMV mode ventilator.",
"StartType": { "PatientConfiguration": { "PatientFile": "StandardMale.json" }},
"DataRequestManager":
{
......
......@@ -273,6 +273,8 @@ void Respiratory::Initialize()
GetPulmonaryElastance().SetValue(1.0 / 0.1, PressurePerVolumeUnit::cmH2O_Per_L);
GetTotalRespiratoryModelCompliance().SetValue(0.1, VolumePerPressureUnit::L_Per_cmH2O);
//Aaron - add this one
//GetTotalRespiratoryModelResistance().SetValue(1.5, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
// Muscle Pressure Waveform
m_InspiratoryRiseFraction = 0;
......@@ -286,6 +288,10 @@ void Respiratory::Initialize()
//Conscious Respiration
m_ActiveConsciousRespirationCommand = false;
//Overrides
m_RespiratoryResistanceOverride_cmH2O_s_Per_L = -1.0;
m_RespiratoryComplianceOverride_L_Per_cmH2O = -1.0;
//Get the fluid mechanics to a good starting point
TuneCircuit();
}
......@@ -389,7 +395,6 @@ void Respiratory::SetUp()
m_ConnectionToMouth = m_data.GetCircuits().GetRespiratoryAndMechanicalVentilationCircuit().GetPath(pulse::MechanicalVentilationPath::ConnectionToMouth);
m_GroundToConnection = m_data.GetCircuits().GetRespiratoryAndMechanicalVentilationCircuit().GetPath(pulse::MechanicalVentilationPath::GroundToConnection);
//jbw & Aaron
/// \todo figure out how to modify these resistances without getting the cv circuit - maybe add a parameter, like baroreceptors does
//Venous Return
m_RightPulmonaryCapillary = m_data.GetCircuits().GetCardiovascularCircuit().GetPath(pulse::CardiovascularPath::RightPulmonaryCapillariesToRightPulmonaryVeins);
......@@ -459,18 +464,19 @@ void Respiratory::AtSteadyState()
//--------------------------------------------------------------------------------------------------
void Respiratory::PreProcess()
{
//jbw
if (m_data.HasOverride())
{
// Look for any known overrides
for (auto& o : m_data.GetOverrides())
{
if (o.name == "LungCompliance")
// Aaron - How do these get cleared?
if (o.name == "RespiratoryResistance")
{
m_RespiratoryResistanceOverride_cmH2O_s_Per_L = Convert(o.value, PressureTimePerVolumeUnit::GetCompoundUnit(o.unit), PressureTimePerVolumeUnit::cmH2O_s_Per_L);
}
else if (o.name == "RespiratoryCompliance")
{
// String compares are expensive, set your own flag if need to remeber this.
// The overrides will be cleared after this time step
// Get the value from the override in the unit we want
double v = Convert(o.value, VolumePerPressureUnit::GetCompoundUnit(o.unit), VolumePerPressureUnit::L_Per_cmH2O);
m_RespiratoryComplianceOverride_L_Per_cmH2O = Convert(o.value, VolumePerPressureUnit::GetCompoundUnit(o.unit), VolumePerPressureUnit::L_Per_cmH2O);
}
}
}
......@@ -494,6 +500,10 @@ void Respiratory::PreProcess()
SupplementalOxygen();
RespiratoryDriver();
//Do the overrides
SetRespiratoryResistance();
SetRespiratoryCompliance();
}
//--------------------------------------------------------------------------------------------------
......@@ -538,7 +548,26 @@ void Respiratory::Process(bool solve_and_transport)
}
void Respiratory::ComputeExposedModelParameters()
{
GetTotalRespiratoryModelCompliance().SetValue(0, VolumePerPressureUnit::L_Per_cmH2O); // jbw
double leftChestWallCompliance_L_Per_cmH2O = m_LeftPleuralToRespiratoryMuscle->GetNextCompliance(VolumePerPressureUnit::L_Per_cmH2O);
double rightChestWallCompliance_L_Per_cmH2O = m_RightPleuralToRespiratoryMuscle->GetNextCompliance(VolumePerPressureUnit::L_Per_cmH2O);
double leftLungCompliance_L_Per_cmH2O = m_LeftAlveoliToLeftPleuralConnection->GetNextCompliance(VolumePerPressureUnit::L_Per_cmH2O);
double rightLungCompliance_L_Per_cmH2O = m_RightAlveoliToRightPleuralConnection->GetNextCompliance(VolumePerPressureUnit::L_Per_cmH2O);
double leftSideCompliance_L_Per_cmH2O = 1.0 / (1.0 / leftChestWallCompliance_L_Per_cmH2O + 1.0 / leftLungCompliance_L_Per_cmH2O);
double rightSideCompliance_L_Per_cmH2O = 1.0 / (1.0 / rightChestWallCompliance_L_Per_cmH2O + 1.0 / rightLungCompliance_L_Per_cmH2O);
double totalCompliance_L_Per_cmH2O = leftSideCompliance_L_Per_cmH2O + rightSideCompliance_L_Per_cmH2O;
GetTotalRespiratoryModelCompliance().SetValue(totalCompliance_L_Per_cmH2O, VolumePerPressureUnit::L_Per_cmH2O);
double airwayResistance_cmH2O_s_Per_L = m_MouthToCarina->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double leftBronchiResistance_cmH2O_s_Per_L = m_CarinaToLeftAnatomicDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double rightBronchiResistance_cmH2O_s_Per_L = m_CarinaToRightAnatomicDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double leftAlveoliDuctResistance_cmH2O_s_Per_L = m_LeftAnatomicDeadSpaceToLeftAlveolarDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double rightAlveoliDuctResistance_cmH2O_s_Per_L = m_RightAnatomicDeadSpaceToRightAlveolarDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double leftSideResistance_cmH2O_s_Per_L = leftBronchiResistance_cmH2O_s_Per_L + leftAlveoliDuctResistance_cmH2O_s_Per_L;
double rightSideResistance_cmH2O_s_Per_L = rightBronchiResistance_cmH2O_s_Per_L + rightAlveoliDuctResistance_cmH2O_s_Per_L;
double totalDownstreamResistance_cmH2O_s_Per_L = 1.0 / (1.0 / leftSideResistance_cmH2O_s_Per_L + 1.0 / rightSideResistance_cmH2O_s_Per_L);
double totalResistance_cmH2O_s_Per_L = airwayResistance_cmH2O_s_Per_L + totalDownstreamResistance_cmH2O_s_Per_L;
//Aaron - add this one
//GetTotalRespiratoryModelResistance().SetValue(totalResistance_cmH2O_s_Per_L, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
}
//--------------------------------------------------------------------------------------------------
......@@ -2999,14 +3028,14 @@ void Respiratory::UpdatePulmonaryCapillary()
double dSlopePulResist = 1.66666; // hard-coded slope for line
double dPulmonaryResistanceMultiplier = 1.0 + (dMaxSeverity*dSlopePulResist);
double dRightPulmonaryCapillaryResistance = m_RightPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double dLeftPulmonaryCapillaryResistance = m_LeftPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double dRightPulmonaryCapillaryResistance = m_RightPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
double dLeftPulmonaryCapillaryResistance = m_LeftPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
dRightPulmonaryCapillaryResistance *= dPulmonaryResistanceMultiplier;
dLeftPulmonaryCapillaryResistance *= dPulmonaryResistanceMultiplier;
m_RightPulmonaryCapillary->GetNextResistance().SetValue(dRightPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_LeftPulmonaryCapillary->GetNextResistance().SetValue(dLeftPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_RightPulmonaryCapillary->GetNextResistance().SetValue(dRightPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
m_LeftPulmonaryCapillary->GetNextResistance().SetValue(dLeftPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
}
//-------------------------------------------------------------------------------------------------------------------
......@@ -3022,14 +3051,14 @@ void Respiratory::UpdatePulmonaryCapillary()
double dSlopePulResist = 1.66666; // hard-coded slope for line
double dPulmonaryResistanceMultiplier = 1.0 + (Severity*dSlopePulResist);
double dRightPulmonaryCapillaryResistance = m_RightPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double dLeftPulmonaryCapillaryResistance = m_LeftPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double dRightPulmonaryCapillaryResistance = m_RightPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
double dLeftPulmonaryCapillaryResistance = m_LeftPulmonaryCapillary->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
dRightPulmonaryCapillaryResistance *= dPulmonaryResistanceMultiplier;
dLeftPulmonaryCapillaryResistance *= dPulmonaryResistanceMultiplier;
m_RightPulmonaryCapillary->GetNextResistance().SetValue(dRightPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_LeftPulmonaryCapillary->GetNextResistance().SetValue(dLeftPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_RightPulmonaryCapillary->GetNextResistance().SetValue(dRightPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
m_LeftPulmonaryCapillary->GetNextResistance().SetValue(dLeftPulmonaryCapillaryResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
}
}
......@@ -3050,8 +3079,6 @@ void Respiratory::UpdatePulmonaryShunt()
if (m_data.GetConditions().HasPulmonaryShunt() || m_PatientActions->HasPulmonaryShuntExacerbation())
{
double severity = 0.0;
double leftLungFraction = 0.0;
double rightLungFraction = 0.0;
if (m_PatientActions->HasPulmonaryShuntExacerbation())
{
severity = m_PatientActions->GetLobarPneumoniaExacerbation()->GetSeverity().GetValue();
......@@ -3125,14 +3152,14 @@ void Respiratory::UpdatePulmonaryShunt()
double pulmonaryShuntScalingFactor = GeneralMath::ExponentialDecayFunction(10, 0.01, 1.0, combinedSeverity);
double rightPulmonaryShuntResistance = m_RightPulmonaryArteriesToVeins->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double leftPulmonaryShuntResistance = m_LeftPulmonaryArteriesToVeins->GetNextResistance().GetValue(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double rightPulmonaryShuntResistance = m_RightPulmonaryArteriesToVeins->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
double leftPulmonaryShuntResistance = m_LeftPulmonaryArteriesToVeins->GetNextResistance().GetValue(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
rightPulmonaryShuntResistance *= pulmonaryShuntScalingFactor;
leftPulmonaryShuntResistance *= pulmonaryShuntScalingFactor;
m_RightPulmonaryArteriesToVeins->GetNextResistance().SetValue(rightPulmonaryShuntResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_LeftPulmonaryArteriesToVeins->GetNextResistance().SetValue(leftPulmonaryShuntResistance, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_RightPulmonaryArteriesToVeins->GetNextResistance().SetValue(rightPulmonaryShuntResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
m_LeftPulmonaryArteriesToVeins->GetNextResistance().SetValue(leftPulmonaryShuntResistance, PressureTimePerVolumeUnit::mmHg_s_Per_mL);
}
//--------------------------------------------------------------------------------------------------
......@@ -3280,6 +3307,51 @@ void Respiratory::ModifyDriverPressure()
#endif
}
void Respiratory::SetRespiratoryResistance()
{
if (m_RespiratoryResistanceOverride_cmH2O_s_Per_L < 0.0)
{
return;
}
//Set the Airway resistance to get achieve this given value
double leftBronchiResistance_cmH2O_s_Per_L = m_CarinaToLeftAnatomicDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double rightBronchiResistance_cmH2O_s_Per_L = m_CarinaToRightAnatomicDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double leftAlveoliDuctResistance_cmH2O_s_Per_L = m_LeftAnatomicDeadSpaceToLeftAlveolarDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
double rightAlveoliDuctResistance_cmH2O_s_Per_L = m_RightAnatomicDeadSpaceToRightAlveolarDeadSpace->GetNextResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
//Do the circuit math
double leftSideResistance_cmH2O_s_Per_L = leftBronchiResistance_cmH2O_s_Per_L + leftAlveoliDuctResistance_cmH2O_s_Per_L;
double rightSideResistance_cmH2O_s_Per_L = rightBronchiResistance_cmH2O_s_Per_L + rightAlveoliDuctResistance_cmH2O_s_Per_L;
double totalDownstreamResistance_cmH2O_s_Per_L = 1.0 / (1.0 / leftSideResistance_cmH2O_s_Per_L + 1.0 / rightSideResistance_cmH2O_s_Per_L);
double airwayResistance_cmH2O_s_Per_L = m_RespiratoryResistanceOverride_cmH2O_s_Per_L - totalDownstreamResistance_cmH2O_s_Per_L;
if (airwayResistance_cmH2O_s_Per_L <= 0)
{
//jbw - add error
}
m_MouthToCarina->GetNextResistance().SetValue(airwayResistance_cmH2O_s_Per_L, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
}
void Respiratory::SetRespiratoryCompliance()
{
if (m_RespiratoryComplianceOverride_L_Per_cmH2O < 0.0)
{
return;
}
//Set all compliances the same
double RespiratorySideCompliance_L_Per_cmH2O = m_RespiratoryComplianceOverride_L_Per_cmH2O / 2.0;
double LungCompliance_L_Per_cmH2O = 2.0 * RespiratorySideCompliance_L_Per_cmH2O;
double ChestWallCompliance_L_Per_cmH2O = LungCompliance_L_Per_cmH2O;
m_LeftAlveoliToLeftPleuralConnection->GetNextCompliance().SetValue(LungCompliance_L_Per_cmH2O, VolumePerPressureUnit::L_Per_cmH2O);
m_RightAlveoliToRightPleuralConnection->GetNextCompliance().SetValue(LungCompliance_L_Per_cmH2O, VolumePerPressureUnit::L_Per_cmH2O);
m_LeftPleuralToRespiratoryMuscle->GetNextCompliance().SetValue(ChestWallCompliance_L_Per_cmH2O, VolumePerPressureUnit::L_Per_cmH2O);
m_RightPleuralToRespiratoryMuscle->GetNextCompliance().SetValue(ChestWallCompliance_L_Per_cmH2O, VolumePerPressureUnit::L_Per_cmH2O);
}
//--------------------------------------------------------------------------------------------------
/// \brief
/// Output data tracks for debugging purposes
......
......@@ -72,6 +72,9 @@ protected:
void UpdateDiffusion();
void UpdatePulmonaryCapillary();
void UpdatePulmonaryShunt();
//Overrides
void SetRespiratoryResistance();
void SetRespiratoryCompliance();
//Actions
void Pneumothorax();
......@@ -144,6 +147,10 @@ protected:
//Conscious Respiration
bool m_ActiveConsciousRespirationCommand;
//Overrides
double m_RespiratoryResistanceOverride_cmH2O_s_Per_L; //Aaron serialize
double m_RespiratoryComplianceOverride_L_Per_cmH2O; //Aaron serialize
// Stateless member variable (Set in SetUp())
double m_dt_s;
double m_dt_min;
......
......@@ -40,18 +40,18 @@ std::string to_scientific_notation(float f)
//--------------------------------------------------------------------------------------------------
bool GenerateStabilizedPatients()
{
int minCompliance = 10;
int maxCompliance = 50;
int stepCompliance = 5;
int minCompliance_L_Per_cmH2O = 0.010;
int maxCompliance_L_Per_cmH2O = 0.050;
int stepCompliance_L_Per_cmH2O = 0.005;
float minImpairment = 0.0;
float maxImpairment = 1.0;
float stepImpairment = 0.2f;
int minPEEP = 10;
int maxPEEP = 20;
int stepPEEP = 2;
int minPIP = 10;
int maxPIP = 40;
int stepPIP = 2;
int minPEEP_cmH2O = 10;
int maxPEEP_cmH2O = 20;
int stepPEEP_cmH2O = 2;
int minPIP_cmH2O = 10;
int maxPIP_cmH2O = 40;
int stepPIP_cmH2O = 2;
float minFiO2 = 0.10f;
float maxFiO2 = 0.60f;
float stepFiO2 = 0.05f;
......@@ -72,6 +72,8 @@ bool GenerateStabilizedPatients()
SEImpairedAlveolarExchangeExacerbation impairedAlveolarExchange;
SEPulmonaryShuntExacerbation pulmonaryShunt;
overrides.AddScalarProperty("RespiratoryResistance", 5.0, PressureTimePerVolumeUnit::cmH2O_s_Per_L);
SEMechanicalVentilatorConfiguration mvc(subMgr);
auto& mv = mvc.GetConfiguration();
mv.SetConnection(eMechanicalVentilator_Connection::Tube);
......@@ -95,17 +97,17 @@ bool GenerateStabilizedPatients()
std::cout << "[" << level << "] " << filename << "::" << line << " " << message;
});
for (int c=minCompliance; c<=maxCompliance; c+=stepCompliance)
for (int c=minCompliance_L_Per_cmH2O; c<=maxCompliance_L_Per_cmH2O; c+=stepCompliance_L_Per_cmH2O)
{
overrides.AddScalarProperty("LungCompliance", c, VolumePerPressureUnit::L_Per_cmH2O);
overrides.AddScalarProperty("RespiratoryCompliance", c, VolumePerPressureUnit::L_Per_cmH2O);
for (float i=minImpairment; i<=maxImpairment; i+=stepImpairment)
{
// jbw Convert i to the appropriate action severity
impairedAlveolarExchange.GetSeverity().SetValue(i);// jbw support severity!
impairedAlveolarExchange.GetSeverity().SetValue(i);
pulmonaryShunt.GetSeverity().SetValue(i);
for (int peep=minPEEP; peep<=maxPEEP; peep+=stepPEEP)
for (int peep=minPEEP_cmH2O; peep<=maxPEEP_cmH2O; peep+=stepPEEP_cmH2O)
{
mv.GetInspiratoryExpiratoryRatio().SetValue(peep);
......@@ -116,7 +118,7 @@ bool GenerateStabilizedPatients()
pulse->SerializeFromFile("./states/StandardMale@0s.json", SerializationFormat::JSON);
// Step the PIP until we get a TidalVolume between 6-8 mL
for (int pip=minPIP; pip<maxPIP; pip+=stepPIP)
for (int pip=minPIP_cmH2O; pip<maxPIP_cmH2O; pip+=stepPIP_cmH2O)
{
mv.GetPeakInspiratoryPressure().SetValue(pip, PressureUnit::cmH2O);
}
......
......@@ -18,7 +18,7 @@ namespace Pulse.CDM
public enum Control : int
{
NullControl = 0,/** Signals not provided, or no change */
P_CMV
PM_CMV
}
// Keep enums in sync with appropriate schema/cdm/MechanicalVentilator.proto file !!
public enum DriverWaveform : int
......
......@@ -16,7 +16,7 @@ class eConnection(Enum):
class eControl(Enum):
NullControl = 0
P_CMV = 1
PM_CMV = 1
class eDriverWaveform(Enum):
NullDriverWaveform = 0
......
......@@ -33,7 +33,7 @@ def HowTo_MechanicalVentilator():
# Not all properties have to be set
# Properties not included will retain their current value
mechanical_ventilator.set_connection(eConnection.Off)
mechanical_ventilator.set_control(eControl.P_CMV)
mechanical_ventilator.set_control(eControl.PM_CMV)
mechanical_ventilator.set_driver_waveform(eDriverWaveform.Square)
# You can set a breath profile by setting the respiration rate OR breath period
mechanical_ventilator.get_respiration_rate().set_value(17, FrequencyUnit.Per_min)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment