Files
medicallib/src/Patient.cpp
T
google-labs-jules[bot] dbe8490cb1 feat: Implement detailed mechanical heart simulation
This commit introduces a major enhancement to the heart simulation, adding a detailed mechanical model of the cardiac cycle that is synchronized with the existing EKG waveform.

Key features:
- The Heart class is refactored to include data structures for the four chambers (atria and ventricles) and four valves (mitral, tricuspid, aortic, pulmonary).
- The `update` method now simulates the phases of the cardiac cycle, including atrial and ventricular systole and diastole.
- Chamber pressures and volumes are dynamically updated based on the phase of the cycle.
- Valve statuses (open/closed) are determined by pressure gradients between chambers.
- Ejection Fraction is now calculated based on the simulated end-diastolic and end-systolic volumes of the left ventricle.
- The example program has been updated to display a live, detailed summary of the heart's mechanical status, showing pressures, volumes, and valve states as they change over time.
2025-08-20 06:22:24 +00:00

94 lines
3.2 KiB
C++

#include "MedicalLib/Patient.h"
#include "MedicalLib/Heart.h"
#include "MedicalLib/Lungs.h"
#include "MedicalLib/Brain.h"
#include "MedicalLib/Liver.h"
#include "MedicalLib/Kidneys.h"
#include "MedicalLib/Bladder.h"
#include "MedicalLib/Stomach.h"
#include "MedicalLib/Intestines.h"
#include "MedicalLib/Gallbladder.h"
#include "MedicalLib/Pancreas.h"
#include "MedicalLib/Esophagus.h"
#include "MedicalLib/Spleen.h"
#include "MedicalLib/SpinalCord.h"
#include <memory>
/**
* @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.
*/
Patient initializePatient(int patientId, int numHeartLeads) {
Patient patient;
patient.patientId = patientId;
// Initialize default organs
patient.organs.push_back(std::make_unique<Heart>(1, numHeartLeads));
patient.organs.push_back(std::make_unique<Lungs>(2));
patient.organs.push_back(std::make_unique<Brain>(3));
patient.organs.push_back(std::make_unique<Liver>(4));
patient.organs.push_back(std::make_unique<Kidneys>(5));
patient.organs.push_back(std::make_unique<Bladder>(6));
patient.organs.push_back(std::make_unique<Stomach>(7));
patient.organs.push_back(std::make_unique<Intestines>(8));
patient.organs.push_back(std::make_unique<Gallbladder>(9));
patient.organs.push_back(std::make_unique<Pancreas>(10));
patient.organs.push_back(std::make_unique<Esophagus>(11));
patient.organs.push_back(std::make_unique<Spleen>(12));
patient.organs.push_back(std::make_unique<SpinalCord>(13));
return patient;
}
/**
* @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.
*/
Patient initializePatient(int patientId) {
return initializePatient(patientId, 12);
}
/**
* @brief Updates the patient's state by updating the state of all their organs.
* @param patient The patient to update.
* @param deltaTime_s The time elapsed in seconds.
*/
void updatePatient(Patient& patient, double deltaTime_s) {
// Update all organs
for (auto& organ : patient.organs) {
organ->update(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.
*/
std::string getOrganSummary(const Patient& patient, const std::string& organType) {
for (const auto& organ : patient.organs) {
if (organ->getType() == organType) {
return organ->getSummary();
}
}
return "";
}
/**
* @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.
*/
std::string getPatientSummary(const Patient& patient) {
std::string summary;
for (const auto& organ : patient.organs) {
summary += organ->getSummary() + "\n";
}
return summary;
}