fb0962ff95
This commit re-implements several critical physiological feedback loops that were lost, enhancing the realism of the simulation.
The following systems have been added:
1. **Full Digestive Loop:**
- The Gallbladder now has a `releaseBile` method, triggered by chyme in the intestines.
- The Pancreas has a `releaseEnzymes` method, also triggered by chyme.
- The Intestines' digestion logic has been updated to be more effective when bile and enzymes are present.
2. **Autonomic Nervous System Control:**
- The Brain now monitors blood gas (O2/CO2) and blood pressure levels.
- It dynamically adjusts the respiration rate of the Lungs via a new `setRespirationRate` method in response to blood gas changes.
- It controls the heart rate via a new `setHeartRate` method in response to blood pressure changes, simulating the baroreceptor reflex.
- The previous hardcoded rate control logic in the Lungs and Heart has been removed.
3. **Kidney Blood Pressure Regulation (RAAS):**
- A simplified Renin-Angiotensin-Aldosterone System has been implemented.
- The Kidneys now secrete renin in response to low blood pressure.
- The Liver produces a constant supply of angiotensinogen.
- A new `angiotensin_au` value in the Blood struct is calculated in the main patient update loop.
- This hormone now acts as a vasoconstrictor, directly affecting the blood pressure calculation in the Heart.
These changes significantly increase the complexity and fidelity of the medical simulation by modeling the interconnectedness of the major organ systems.
123 lines
3.4 KiB
C++
123 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include "Organ.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <deque>
|
|
|
|
/**
|
|
* @brief Enum for the current state of the respiratory cycle.
|
|
*/
|
|
enum class RespiratoryState {
|
|
INSPIRATION,
|
|
EXPIRATION,
|
|
PAUSE
|
|
};
|
|
|
|
/**
|
|
* @brief Represents a single lobe of the lung.
|
|
*/
|
|
struct Lobe {
|
|
std::string name;
|
|
double volume_mL;
|
|
double compliance; // How easily it inflates
|
|
};
|
|
|
|
/**
|
|
* @brief Represents a major airway.
|
|
*/
|
|
struct Bronchus {
|
|
std::string name;
|
|
double resistance; // Airflow resistance
|
|
};
|
|
|
|
/**
|
|
* @brief Represents the Lungs organ with a more detailed physiological model.
|
|
*/
|
|
class MEDICAL_LIB_API Lungs : public Organ {
|
|
public:
|
|
/**
|
|
* @brief Constructor for the Lungs class.
|
|
* @param id The ID of the organ.
|
|
*/
|
|
Lungs(int id);
|
|
|
|
/**
|
|
* @brief Updates the lungs' state over a time interval.
|
|
* @param patient A reference to the patient object.
|
|
* @param deltaTime_s The time elapsed in seconds.
|
|
*/
|
|
void update(Patient& patient, double deltaTime_s) override;
|
|
|
|
/**
|
|
* @brief Gets a string summary of the lungs' vitals.
|
|
* @return A string containing the lungs' vital signs.
|
|
*/
|
|
std::string getSummary() const override;
|
|
|
|
/**
|
|
* @brief Inflicts damage on the lungs, reducing their compliance.
|
|
* @param damage The amount of damage to inflict (0-1).
|
|
*/
|
|
void inflictDamage(double damage);
|
|
|
|
// --- Setters for External Control ---
|
|
|
|
/**
|
|
* @brief Sets the respiration rate.
|
|
* @param newRate_bpm The new rate in breaths per minute.
|
|
*/
|
|
void setRespirationRate(double newRate_bpm);
|
|
|
|
// --- Getters for Key Respiratory Vitals ---
|
|
|
|
/** @brief Gets the current respiration rate in breaths per minute. */
|
|
double getRespirationRate() const;
|
|
|
|
/** @brief Gets the current oxygen saturation (SpO2) as a percentage. */
|
|
double getOxygenSaturation() const;
|
|
|
|
/** @brief Gets the volume of air in a normal breath (tidal volume) in mL. */
|
|
double getTidalVolume() const;
|
|
|
|
/** @brief Gets the end-tidal CO2 (etCO2) value in mmHg. */
|
|
double getEndTidalCO2() const;
|
|
|
|
/** @brief Gets the peak airway pressure during inspiration in cmH2O. */
|
|
double getPeakInspiratoryPressure() const;
|
|
|
|
/** @brief Gets the data for the capnography waveform (etCO2 over time). */
|
|
const std::deque<double>& getCapnographyWaveform() const;
|
|
|
|
private:
|
|
// --- Private Helper Methods ---
|
|
void updateRespiratoryMechanics(double deltaTime_s);
|
|
void updateGasLevels(double deltaTime_s);
|
|
double generateCapnographyValue();
|
|
|
|
// --- Physiological Parameters ---
|
|
double respirationRate; ///< Breaths per minute
|
|
double oxygenSaturation; ///< SpO2 percentage
|
|
double tidalVolume_mL; ///< Volume of air per breath
|
|
double endTidalCO2_mmHg; ///< End-tidal CO2
|
|
double peakInspiratoryPressure_cmH2O; ///< Peak airway pressure
|
|
double totalLungCapacity_mL; ///< Total lung capacity
|
|
|
|
// --- Simulation State ---
|
|
RespiratoryState currentState;
|
|
double cyclePosition_s; ///< Current position in the respiratory cycle (seconds)
|
|
double totalTime_s; ///< Total simulation time
|
|
|
|
// --- Anatomical Components ---
|
|
Lobe rightUpperLobe;
|
|
Lobe rightMiddleLobe;
|
|
Lobe rightLowerLobe;
|
|
Lobe leftUpperLobe;
|
|
Lobe leftLowerLobe;
|
|
Bronchus mainBronchus;
|
|
|
|
// --- Waveform Data ---
|
|
std::deque<double> capnographyData;
|
|
size_t capnographyHistorySize;
|
|
};
|