From 2a2ff7587a011df2df88b25434d7cbc3b2309fb1 Mon Sep 17 00:00:00 2001 From: Rainer Leuschke Date: Thu, 20 Jul 2023 13:12:44 -0700 Subject: [PATCH 1/2] add nasal cannula physmod --- CMakeLists.txt | 2 +- src/AMM/BiogearsThread.cpp | 13 +++++++++++++ src/AMM/BiogearsThread.h | 3 +++ src/AMM/PhysiologyEngineManager.cpp | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aecfcd..82ccde3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project("AMM_Physiology_Manager") set(VERSION_TYPE "beta" CACHE STRING "version type" FORCE) set(PROJECT_VERSION_MAJOR 1) set(PROJECT_VERSION_MINOR 2) -set(PROJECT_VERSION_PATCH 1) +set(PROJECT_VERSION_PATCH 2) site_name(VERSION_HOST) # read hostname to VERSION_HOST set(VERSION_HOST "${VERSION_HOST}" CACHE STRING "host of build" FORCE) diff --git a/src/AMM/BiogearsThread.cpp b/src/AMM/BiogearsThread.cpp index a2f357f..44ce582 100644 --- a/src/AMM/BiogearsThread.cpp +++ b/src/AMM/BiogearsThread.cpp @@ -1709,6 +1709,19 @@ void BiogearsThread::SetHemorrhage(const std::string& location, double flow) } } +void BiogearsThread::SetNasalCannula(double flowRate, const std::string& unit) +{ + try { + biogears::SENasalCannula nasalcannula; + if (unit == "L/min") { + nasalcannula.GetFlowRate().SetValue(flowRate, biogears::VolumePerTimeUnit::L_Per_min); + m_pe->ProcessAction(nasalcannula); + } + } catch (std::exception& e) { + LOG_ERROR << "Error processing nasal cannula action: " << e.what(); + } +} + void BiogearsThread::SetNeedleDecompression(const std::string& state, const std::string& side) { try { diff --git a/src/AMM/BiogearsThread.h b/src/AMM/BiogearsThread.h index 76685fc..2e7d90e 100644 --- a/src/AMM/BiogearsThread.h +++ b/src/AMM/BiogearsThread.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -217,6 +218,8 @@ class BiogearsThread { void SetMechanicalVentilation(const std::string& actionSettings); + void SetNasalCannula(double flowRate, const std::string& unit); + void SetNeedleDecompression(const std::string& state, const std::string& side); void SetPain(const std::string& location, double severity); diff --git a/src/AMM/PhysiologyEngineManager.cpp b/src/AMM/PhysiologyEngineManager.cpp index 25e9276..0ee34ae 100644 --- a/src/AMM/PhysiologyEngineManager.cpp +++ b/src/AMM/PhysiologyEngineManager.cpp @@ -248,6 +248,18 @@ void PhysiologyEngineManager:: } else if (pmType == "infection") { } else if (pmType == "intubation") { } else if (pmType == "mechanicalventilation") { + } else if (pmType == "nasalcannula") { + tinyxml2::XMLElement* pRate = pRoot->FirstChildElement("Rate")->ToElement(); + double rate; + if (pRate->Attribute("value") != NULL) { + rate = stod(pRate->Attribute("value")); + } else { + rate = stod(pRate->GetText()); + } + std::string pUnit = pRate->Attribute("unit"); + + m_pe->SetNasalCannula(rate, pUnit); + return; } else if (pmType == "needledecompression") { std::string pState = pRoot->FirstChildElement("State")->ToElement()->GetText(); std::string pSide = pRoot->FirstChildElement("Side")->ToElement()->GetText(); From b56020a865d8e041a966baeb81f21a42d2ab1f27 Mon Sep 17 00:00:00 2001 From: Rainer Leuschke Date: Mon, 18 Dec 2023 13:21:53 -0800 Subject: [PATCH 2/2] add patient state render mods --- CMakeLists.txt | 2 +- src/AMM/BiogearsThread.cpp | 16 ++++++++++- src/AMM/BiogearsThread.h | 4 +++ src/AMM/PhysiologyEngineManager.cpp | 42 +++++++++++++++++++++++++++-- src/AMM/PhysiologyEngineManager.h | 2 ++ 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ccde3..a6b20b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project("AMM_Physiology_Manager") set(VERSION_TYPE "beta" CACHE STRING "version type" FORCE) set(PROJECT_VERSION_MAJOR 1) set(PROJECT_VERSION_MINOR 2) -set(PROJECT_VERSION_PATCH 2) +set(PROJECT_VERSION_PATCH 3) site_name(VERSION_HOST) # read hostname to VERSION_HOST set(VERSION_HOST "${VERSION_HOST}" CACHE STRING "host of build" FORCE) diff --git a/src/AMM/BiogearsThread.cpp b/src/AMM/BiogearsThread.cpp index 44ce582..5d51e17 100644 --- a/src/AMM/BiogearsThread.cpp +++ b/src/AMM/BiogearsThread.cpp @@ -10,6 +10,10 @@ class EventHandler : public SEEventHandler { bool paralyzedSent = false; bool irreversible = false; bool irreversibleSent = false; + bool tachypnea = false; + bool tachypneaSent = false; + bool tachycardia = false; + bool tachycardiaSent = false; bool startOfExhale = false; bool startOfInhale = false; bool pneumothoraxLClosed = false; @@ -49,9 +53,17 @@ class EventHandler : public SEEventHandler { if (active) { switch (type) { case CDM::enumPatientEvent::IrreversibleState: - LOG_INFO << " Patient has entered irreversible state"; + LOG_INFO << " Patient has entered irreversible state."; irreversible = true; break; + case CDM::enumPatientEvent::Tachypnea: + LOG_INFO << " Patient has entered state: Tachypnea."; + tachypnea = true; + break; + case CDM::enumPatientEvent::Tachycardia: + LOG_INFO << " Patient has entered state: Tachycardia."; + tachycardia = true; + break; case CDM::enumPatientEvent::StartOfCardiacCycle: break; case CDM::enumPatientEvent::StartOfExhale: @@ -607,6 +619,8 @@ void BiogearsThread::AdvanceTimeTick() irreversible = true; } + tachypnea = myEventHandler->tachypnea; + tachycardia = myEventHandler->tachycardia; startOfInhale = myEventHandler->startOfInhale; startOfExhale = myEventHandler->startOfExhale; } diff --git a/src/AMM/BiogearsThread.h b/src/AMM/BiogearsThread.h index 2e7d90e..56ff9e6 100644 --- a/src/AMM/BiogearsThread.h +++ b/src/AMM/BiogearsThread.h @@ -273,6 +273,10 @@ class BiogearsThread { bool paralyzedSent = false; bool irreversible = false; bool irreversibleSent = false; + bool tachypnea = false; + bool tachypneaSent = false; + bool tachycardia = false; + bool tachycardiaSent = false; bool startOfExhale = false; bool startOfInhale = false; bool pneumothoraxLClosed = false; diff --git a/src/AMM/PhysiologyEngineManager.cpp b/src/AMM/PhysiologyEngineManager.cpp index 0ee34ae..27aa321 100644 --- a/src/AMM/PhysiologyEngineManager.cpp +++ b/src/AMM/PhysiologyEngineManager.cpp @@ -478,6 +478,32 @@ void PhysiologyEngineManager::StartSimulation() { m_pe->StartSimulation(); } void PhysiologyEngineManager::StopSimulation() { m_pe->StopSimulation(); } +/** + * @brief send patient states rendermod + * + */ + +void PhysiologyEngineManager::SendPatientStateRendMod(std::string rendModType) +{ + AMM::UUID erID; + erID.id(m_mgr->GenerateUuidString()); + FMA_Location fma; + AMM::UUID agentID; + + AMM::EventRecord er; + er.id(erID); + er.location(fma); + er.agent_id(agentID); + er.type(rendModType); + m_mgr->WriteEventRecord(er); + + AMM::RenderModification renderMod; + renderMod.event_id(erID); + renderMod.type(rendModType); + renderMod.data(""); + m_mgr->WriteRenderModification(renderMod); +} + /** * @brief processes patient states in biogears (defined by the biogears physiology) * @@ -523,8 +549,20 @@ void PhysiologyEngineManager::ProcessStates() m_pe->irreversibleSent = true; } + if (m_pe->tachypnea && !m_pe->tachypneaSent) { + LOG_DEBUG << "Patient has entered state Tachypnea, sending render mod."; + SendPatientStateRendMod("PATIENT_STATE_TACHYPNEA"); + m_pe->tachypneaSent = true; + } + + if (m_pe->tachycardia && !m_pe->tachycardiaSent) { + LOG_DEBUG << "Patient has entered state Tachycardia, sending render mod."; + SendPatientStateRendMod("PATIENT_STATE_TACHYCARDIA"); + m_pe->tachycardiaSent = true; + } + if (m_pe->paralyzed && !m_pe->paralyzedSent) { - LOG_DEBUG << "Patient is paralyzed but we haven't sent the render mod."; + LOG_DEBUG << "Patient is paralyzed, sending render mod."; AMM::UUID erID; erID.id(m_mgr->GenerateUuidString()); FMA_Location fma; @@ -581,7 +619,7 @@ void PhysiologyEngineManager::ProcessStates() er.id(erID); er.location(fma); er.agent_id(agentID); - er.type("PATIENT_STATE_IRREVERSIBLE"); + er.type("PNEUMOTHORAX_OPEN_L_SEVERE"); m_mgr->WriteEventRecord(er); AMM::RenderModification renderMod; diff --git a/src/AMM/PhysiologyEngineManager.h b/src/AMM/PhysiologyEngineManager.h index b645021..b01bfe4 100644 --- a/src/AMM/PhysiologyEngineManager.h +++ b/src/AMM/PhysiologyEngineManager.h @@ -70,6 +70,8 @@ namespace AMM { void InitializeBiogears(); + void SendPatientStateRendMod(std::string rendModType); + void ProcessStates(); bool paused = false;