Files
medicallib/include/MedicalLib/Patient.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

108 lines
3.3 KiB
C++

#pragma once
#include <vector>
#include <memory>
#include <string>
// Forward-declare the Organ class to avoid circular dependencies
class Organ;
/**
* @brief Represents the composition of the patient's blood.
*/
struct Blood {
double oxygenSaturation = 98.0; // Normal SpO2
double co2PartialPressure_mmHg = 40.0; // Normal PaCO2
double glucose_mg_per_dL = 100.0; // Normal fasting glucose
double toxins_au = 0.0; // Arbitrary units, 0 is clean
};
/**
* @brief Holds all the vital signs and other medical information for a patient.
*/
struct Patient {
int patientId;
Blood blood;
std::vector<std::unique_ptr<Organ>> organs;
};
// Define MEDICAL_LIB_EXPORT for exporting symbols from the DLL
#if defined(_WIN32)
#if defined(MEDICAL_LIB_EXPORT)
#define MEDICAL_LIB_API __declspec(dllexport)
#else
#define MEDICAL_LIB_API __declspec(dllimport)
#endif
#else
#define MEDICAL_LIB_API
#endif
/**
* @brief Initializes a new patient with baseline vital signs and a 12-lead heart.
* @param patientId The ID for the new patient.
* @return A Patient struct with default healthy values.
*/
MEDICAL_LIB_API Patient initializePatient(int patientId);
/**
* @brief Initializes a new patient with a specific number of heart leads.
* @param patientId The ID for the new patient.
* @param numHeartLeads The number of EKG leads for the heart.
* @return A Patient struct with default healthy values.
*/
MEDICAL_LIB_API Patient initializePatient(int patientId, int numHeartLeads);
/**
* @brief Updates the patient's vital signs based on the time elapsed.
* @param patient The patient to update.
* @param deltaTime_s The time elapsed in seconds.
*/
MEDICAL_LIB_API void updatePatient(Patient& patient, double deltaTime_s);
/**
* @brief Gets a summary of a specific organ's vitals.
* @param patient The patient to get the organ summary from.
* @param organType The type of the organ to get the summary for.
* @return A string containing the organ's vital signs, or an empty string if not found.
*/
MEDICAL_LIB_API std::string getOrganSummary(const Patient& patient, const std::string& organType);
/**
* @brief Gets a consolidated summary of all the patient's organ vitals.
* @param patient The patient to get the summary from.
* @return A string containing the vital signs of all the patient's organs.
*/
MEDICAL_LIB_API std::string getPatientSummary(const Patient& patient);
/**
* @brief Gets a pointer to a specific organ by its type.
* @tparam T The type of the organ to get.
* @param patient The patient to get the organ from.
* @return A pointer to the organ if found, otherwise nullptr.
*/
template<typename T>
T* getOrgan(Patient& patient) {
for (auto& organ : patient.organs) {
if (T* specificOrgan = dynamic_cast<T*>(organ.get())) {
return specificOrgan;
}
}
return nullptr;
}
/**
* @brief Gets a const pointer to a specific organ by its type.
* @tparam T The type of the organ to get.
* @param patient The patient to get the organ from.
* @return A const pointer to the organ if found, otherwise nullptr.
*/
template<typename T>
const T* getOrgan(const Patient& patient) {
for (const auto& organ : patient.organs) {
if (const T* specificOrgan = dynamic_cast<const T*>(organ.get())) {
return specificOrgan;
}
}
return nullptr;
}