diff --git a/examples/main.cpp b/examples/main.cpp index 92f6f6d..9c5e7cb 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -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(organ_ptr.get())) { - std::cout << " -> Specific: Patient Heart Rate is " << heart->getHeartRate() << " bpm." << std::endl; - } - if (const Lungs* lungs = dynamic_cast(organ_ptr.get())) { - std::cout << " -> Specific: Patient SpO2 is " << lungs->getOxygenSaturation() << "%." << std::endl; - } - if (const Kidneys* kidneys = dynamic_cast(organ_ptr.get())) { - std::cout << " -> Specific: Kidney Filtration Rate is " << kidneys->getFiltrationRate() << " ml/min." << std::endl; - } - if (const Stomach* stomach = dynamic_cast(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(patient)) { + std::cout << "\nSuccessfully retrieved Heart organ." << std::endl; + std::cout << "Direct access to heart rate: " << heart->getHeartRate() << " bpm" << std::endl; + } return 0; } diff --git a/include/MedicalLib/Patient.h b/include/MedicalLib/Patient.h index 11984cc..9520bb6 100644 --- a/include/MedicalLib/Patient.h +++ b/include/MedicalLib/Patient.h @@ -2,6 +2,7 @@ #include #include +#include // 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 +const T* getOrgan(const Patient& patient) { + for (const auto& organ : patient.organs) { + if (const T* specificOrgan = dynamic_cast(organ.get())) { + return specificOrgan; + } + } + return nullptr; +} diff --git a/src/Patient.cpp b/src/Patient.cpp index 5deb88b..63165d9 100644 --- a/src/Patient.cpp +++ b/src/Patient.cpp @@ -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; +}