This commit enhances the Patient class by adding several helper functions to improve access to organ data.

- Adds `getOrganSummary` and `getPatientSummary` to retrieve human-readable string summaries of organ vitals.
- Adds a templated function `getOrgan<T>` which allows for type-safe, direct access to specific organ objects. This enables calling organ-specific methods to retrieve raw data values (e.g., `heart->getHeartRate()`).

The example `main.cpp` has been updated to demonstrate the usage of all new functions.
This commit is contained in:
google-labs-jules[bot]
2025-08-20 02:11:03 +00:00
parent 62a04a76f6
commit c3432e4178
3 changed files with 74 additions and 30 deletions
+28
View File
@@ -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;
}