Merge remote-tracking branch 'git/add-organ-access-functions'
This commit is contained in:
+14
-30
@@ -10,42 +10,26 @@
|
||||
#include "MedicalLib/Kidneys.h"
|
||||
#include "MedicalLib/Stomach.h"
|
||||
|
||||
void printPatientSummary(const Patient& patient) {
|
||||
std::cout << "--- Patient Summary (ID: " << patient.patientId << ") ---" << std::endl;
|
||||
for (const auto& organ_ptr : patient.organs) {
|
||||
// Print the general summary for each organ
|
||||
std::cout << organ_ptr->getSummary() << std::endl;
|
||||
|
||||
// Example of accessing specialized properties using dynamic_cast
|
||||
if (const Heart* heart = dynamic_cast<const Heart*>(organ_ptr.get())) {
|
||||
std::cout << " -> Specific: Patient Heart Rate is " << heart->getHeartRate() << " bpm." << std::endl;
|
||||
}
|
||||
if (const Lungs* lungs = dynamic_cast<const Lungs*>(organ_ptr.get())) {
|
||||
std::cout << " -> Specific: Patient SpO2 is " << lungs->getOxygenSaturation() << "%." << std::endl;
|
||||
}
|
||||
if (const Kidneys* kidneys = dynamic_cast<const Kidneys*>(organ_ptr.get())) {
|
||||
std::cout << " -> Specific: Kidney Filtration Rate is " << kidneys->getFiltrationRate() << " ml/min." << std::endl;
|
||||
}
|
||||
if (const Stomach* stomach = dynamic_cast<const Stomach*>(organ_ptr.get())) {
|
||||
std::cout << " -> Specific: Stomach pH is " << stomach->getPhLevel() << "." << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "------------------------------------" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Initialize a new patient
|
||||
Patient patient = initializePatient(1);
|
||||
std::cout << "Patient created with ID: " << patient.patientId << std::endl;
|
||||
|
||||
std::cout << "Initial State:" << std::endl;
|
||||
printPatientSummary(patient);
|
||||
// Simulate some time passing
|
||||
updatePatient(patient, 60.0);
|
||||
std::cout << "\nPatient state updated after 60 seconds." << std::endl;
|
||||
|
||||
// Simulate a time step
|
||||
double deltaTime_s = 1.0;
|
||||
updatePatient(patient, deltaTime_s);
|
||||
// Get a summary for a specific organ
|
||||
std::cout << "\nHeart Summary:\n" << getOrganSummary(patient, "Heart") << std::endl;
|
||||
|
||||
std::cout << "\nState after " << deltaTime_s << " second(s):" << std::endl;
|
||||
printPatientSummary(patient);
|
||||
// Get a summary for all organs
|
||||
std::cout << "\nFull Patient Summary:\n" << getPatientSummary(patient) << std::endl;
|
||||
|
||||
// Get a specific organ and call a method on it
|
||||
if (const Heart* heart = getOrgan<Heart>(patient)) {
|
||||
std::cout << "\nSuccessfully retrieved Heart organ." << std::endl;
|
||||
std::cout << "Direct access to heart rate: " << heart->getHeartRate() << " bpm" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// Forward-declare the Organ class to avoid circular dependencies
|
||||
class Organ;
|
||||
@@ -38,3 +39,34 @@ MEDICAL_LIB_API Patient initializePatient(int patientId);
|
||||
* @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 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;
|
||||
}
|
||||
|
||||
@@ -52,3 +52,31 @@ void updatePatient(Patient& patient, double deltaTime_s) {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user