Files
medicallib/include/MedicalLib/Brain.h
T
google-labs-jules[bot] ede2dee772 Feat: Implement interconnected organ simulation
This commit refactors the organ simulation to enable dynamic interactions between organs, replacing the previous "faked" or hardcoded connections.

Key changes include:
- Major Refactoring: Changed the `Organ::update` method signature to `update(Patient& patient, double deltaTime_s)`, allowing organs to access the shared patient state and other organs. This was propagated to all organ classes.
- Blood Chemistry Model: Introduced a central `Blood` struct in the `Patient` model to track shared resources like oxygen, CO2, glucose, and toxins.
- Organ System Interconnections:
    - Lungs & Brain: Lungs now perform gas exchange affecting the blood. The brain consumes O2, produces CO2, and its GCS is affected by hypoxia/hypercapnia.
    - Liver-Gallbladder: Gallbladder now receives bile directly from the liver's production rate.
    - Digestive System: Stomach passes chyme to the intestines, which absorb glucose into the blood. The pancreas responds to blood glucose changes.
    - Renal System: Kidneys' GFR is now influenced by the heart's aortic pressure, and they produce urine that fills the bladder directly.
    - Cardiovascular & Neurological: The heart rate responds to hypoxia, and the brain uses live aortic pressure from the heart.
- Comprehensive Test Scenario: Updated the main example to include a 60-second simulation with a meal and a lung injury event to verify the new interconnected system.

This creates a more realistic and scalable physiological simulation framework where organ behaviors are emergent from their interactions.
2025-08-20 08:30:53 +00:00

82 lines
2.2 KiB
C++

#pragma once
#include "Organ.h"
#include <vector>
#include <string>
#include <deque>
#include <map>
/**
* @brief Represents a specific region of the brain.
*/
struct BrainRegion {
std::string name;
double activityLevel; // 0.0 to 1.0
double bloodFlow_ml_100g_min;
};
/**
* @brief Represents the Brain organ with a more detailed physiological model.
*/
class MEDICAL_LIB_API Brain : public Organ {
public:
/**
* @brief Constructor for the Brain class.
* @param id The ID of the organ.
*/
Brain(int id);
/**
* @brief Updates the brain's 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 brain's vitals.
* @return A string containing the brain's vital signs.
*/
std::string getSummary() const override;
// --- Getters for Key Neurological Vitals ---
/** @brief Gets the Glasgow Coma Scale score (simplified). */
int getGCS() const;
/** @brief Gets the intracranial pressure in mmHg. */
double getIntracranialPressure() const;
/** @brief Gets the cerebral perfusion pressure in mmHg. */
double getCerebralPerfusionPressure() const;
/** @brief Gets the data for a simplified EEG waveform. */
const std::deque<double>& getEegWaveform() const;
private:
// --- Private Helper Methods ---
void updateActivity(double deltaTime_s);
void updatePressures(double meanArterialPressure);
double generateEegValue();
// --- Physiological Parameters ---
int gcsScore; ///< Glasgow Coma Scale (3-15)
double intracranialPressure_mmHg; ///< ICP
double cerebralPerfusionPressure_mmHg; ///< CPP
double meanArterialPressure_mmHg; ///< MAP (placeholder, needs to be linked to Heart)
// --- Simulation State ---
double totalTime_s;
// --- Anatomical Components ---
BrainRegion frontalLobe;
BrainRegion temporalLobe;
BrainRegion parietalLobe;
BrainRegion occipitalLobe;
BrainRegion cerebellum;
// --- Waveform Data ---
std::deque<double> eegData;
size_t eegHistorySize;
};