Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit e9e8e0f

Browse files
committed
Updating SDK examples to support new functionality for 6.3 release
1 parent 1a91af3 commit e9e8e0f

10 files changed

+694
-61
lines changed

library/src/BioGearsEngineHowTo.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,33 @@ specific language governing permissions and limitations under the License.
1616
#include "scenario/requests/SEDataRequest.h"
1717
#include "properties/SEScalarTime.h"
1818

19+
1920
int main()
2021
{
2122
// Uncomment a method to execute fuctionality!
2223

23-
//HowToEngineUse();
24-
//HowToCreateAPatient();
25-
26-
//HowToAirwayObstruction();
27-
//HowToAnesthesiaMachine();
28-
//HowToAsthmaAttack();
29-
//HowToBrainInjury();
30-
//HowToBolusDrug();
31-
//HowToConsumeNutrients();
32-
//HowToCOPD();
33-
//HowToCPR();
34-
//HowToEnvironmentChange();
35-
//HowToExercise();
36-
//HowToHemorrhage();
37-
//HowToLobarPneumonia();
38-
HowToMechanicalVentilation();
39-
//HowToPulmonaryFunctionTest();
40-
//HowToSmoke();
41-
//HowToTensionPneumothorax();
24+
//HowToEngineUse();
25+
//HowToCreateAPatient();
26+
//HowToAirwayObstruction();
27+
//HowToAnesthesiaMachine();
28+
//HowToAsthmaAttack();
29+
//HowToBrainInjury();
30+
//HowToBolusDrug();
31+
//HowToConsumeNutrients();
32+
//HowToCOPD();
33+
//HowToCPR();
34+
//HowToEnvironmentChange();
35+
//HowToExercise();
36+
//HowToFasciculation();
37+
//HowToHemorrhage();
38+
//HowToInfusionDrug();
39+
//HowToLobarPneumonia();
40+
//HowToMechanicalVentilation();
41+
//HowToPulmonaryFunctionTest();
42+
//HowToSarinExposure();
43+
//HowToSmoke();
44+
//HowToTensionPneumothorax();
45+
HowToVasopressinShockTherapy();
4246

4347
// This one does not really run, is a pure example
4448
//HowToRunScenario();

library/src/BioGearsEngineHowTo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ void HowToCOPD();
3131
void HowToCPR();
3232
void HowToEnvironmentChange();
3333
void HowToExercise();
34+
void HowToFasciculation();
3435
void HowToHemorrhage();
36+
void HowToInfusionDrug();
3537
void HowToLobarPneumonia();
3638
void HowToMechanicalVentilation();
3739
void HowToPulmonaryFunctionTest();
40+
void HowToSarinExposure();
3841
void HowToSmoke();
3942
void HowToTensionPneumothorax();
43+
void HowToVasopressinShockTherapy();
4044

4145
void HowToConcurrentEngines();
4246
void HowToRunScenario();

library/src/HowTo-BolusDrug.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ specific language governing permissions and limitations under the License.
1515
// Include the various types you will be using in your code
1616
#include "utils/SEEventHandler.h"
1717
#include "patient/actions/SESubstanceBolus.h"
18+
#include "patient/actions/SESubstanceInfusion.h"
1819
#include "system/physiology/SEBloodChemistrySystem.h"
1920
#include "system/physiology/SECardiovascularSystem.h"
2021
#include "system/physiology/SEEnergySystem.h"
2122
#include "system/physiology/SERespiratorySystem.h"
23+
#include "system/physiology/SEDrugSystem.h"
2224
#include "substance/SESubstanceManager.h"
2325
#include "patient/SEPatient.h"
2426
#include "properties/SEScalarFraction.h"
@@ -28,9 +30,10 @@ specific language governing permissions and limitations under the License.
2830
#include "properties/SEScalarTemperature.h"
2931
#include "properties/SEScalarTime.h"
3032
#include "properties/SEScalarVolume.h"
33+
#include "properties/SEScalarMass.h"
3134
#include "properties/SEScalarVolumePerTime.h"
35+
#include "properties/SEScalarOsmolality.h"
3236
#include "engine/PhysiologyEngineTrack.h"
33-
#include "compartment/SECompartmentManager.h"
3437

3538
//--------------------------------------------------------------------------------------------------
3639
/// \brief
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**************************************************************************************
2+
Copyright 2015 Applied Research Associates, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the License
5+
at:
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
**************************************************************************************/
12+
13+
#include "BioGearsEngineHowTo.h"
14+
15+
// Include the various types you will be using in your code
16+
#include "patient/actions/SEExercise.h"
17+
#include "patient/SEPatient.h"
18+
#include "system/physiology/SEBloodChemistrySystem.h"
19+
#include "system/physiology/SECardiovascularSystem.h"
20+
#include "system/physiology/SEEnergySystem.h"
21+
#include "system/physiology/SERespiratorySystem.h"
22+
#include "substance/SESubstanceManager.h"
23+
#include "substance/SESubstanceCompound.h"
24+
#include "properties/SEScalarAmountPerVolume.h"
25+
#include "properties/SEScalarFraction.h"
26+
#include "properties/SEScalarFrequency.h"
27+
#include "properties/SEScalarMass.h"
28+
#include "properties/SEScalarMassPerVolume.h"
29+
#include "properties/SEScalarPressure.h"
30+
#include "properties/SEScalarTemperature.h"
31+
#include "properties/SEScalarTime.h"
32+
#include "properties/SEScalarVolume.h"
33+
#include "properties/SEScalarVolumePerTime.h"
34+
#include "properties/SEScalarPower.h"
35+
#include "properties/SEScalar0To1.h"
36+
#include "engine/PhysiologyEngineTrack.h"
37+
#include "compartment/SECompartmentManager.h"
38+
39+
//--------------------------------------------------------------------------------------------------
40+
/// \brief
41+
/// Demonstrates how to set concentrations of ionic compounds in bloodstream and tissue and call events
42+
/// based on changes in concentrations
43+
///
44+
/// \details
45+
/// Refer to the SEEnvironmentChange class
46+
/// Refer to the SEDrug Class
47+
//--------------------------------------------------------------------------------------------------
48+
49+
void HowToFasciculation()
50+
{
51+
// Create the engine and load the patient
52+
std::unique_ptr<PhysiologyEngine> bg = CreateBioGearsEngine("HowToFasciculation.log");
53+
bg->GetLogger()->Info("HowToFasciculation");
54+
55+
if (!bg->LoadState("./states/[email protected]"))
56+
{
57+
bg->GetLogger()->Error("Could not load state, check the error");
58+
return;
59+
}
60+
61+
//---Initialize all variables needed for scenario
62+
SESubstance* Na = bg->GetSubstanceManager().GetSubstance("Sodium");
63+
SESubstance* K = bg->GetSubstanceManager().GetSubstance("Potassium");
64+
SESubstance* Cl = bg->GetSubstanceManager().GetSubstance("Chloride");
65+
SESubstance* Ca = bg->GetSubstanceManager().GetSubstance("Calcium");
66+
67+
double monitorTime = 200.0; //how long we're going to be on the look out for ion imbalances in the blood
68+
CDM::enumOnOff::value lowKActive;
69+
lowKActive = CDM::enumOnOff::Off;
70+
71+
// The tracker is responsible for advancing the engine time and outputting the data requests below at each time step
72+
HowToTracker tracker(*bg);
73+
74+
bg->GetEngineTrack()->GetDataRequestManager().CreateLiquidCompartmentDataRequest().Set("VenaCava", *Na, "Molarity", AmountPerVolumeUnit::mmol_Per_L);
75+
bg->GetEngineTrack()->GetDataRequestManager().CreateLiquidCompartmentDataRequest().Set("VenaCava", *K, "Molarity", AmountPerVolumeUnit::mmol_Per_L);
76+
bg->GetEngineTrack()->GetDataRequestManager().CreateLiquidCompartmentDataRequest().Set("VenaCava", *Cl, "Molarity", AmountPerVolumeUnit::mmol_Per_L);
77+
bg->GetEngineTrack()->GetDataRequestManager().CreateLiquidCompartmentDataRequest().Set("VenaCava", *Ca, "Molarity", AmountPerVolumeUnit::mmol_Per_L);
78+
79+
bg->GetEngineTrack()->GetDataRequestManager().SetResultsFilename("HowToFasciculation.txt");
80+
81+
// Advance some time to get some resting data
82+
tracker.AdvanceModelTime(60);
83+
84+
bg->GetLogger()->Info("The patient is nice and healthy");
85+
std::string message = "";
86+
message = "Increase membrane resistance to potassium";
87+
bg->GetLogger()->Info(message);
88+
K->GetMembraneResistance().SetValue(5.0, ElectricResistanceUnit::Ohm);
89+
90+
91+
while (bg->GetSimulationTime(TimeUnit::s) < monitorTime + 60.0)
92+
{
93+
if (bg->GetPatient().IsEventActive(CDM::enumPatientEvent::MildHypokalemia) && (lowKActive == CDM::enumOnOff::Off))
94+
{
95+
lowKActive = CDM::enumOnOff::On;
96+
message = "Patient has low serum potassium, muscle fasciculation may occur";
97+
bg->GetLogger()->Info(message);
98+
}
99+
tracker.AdvanceModelTime(10.0);
100+
}
101+
message = "Return membrane resistance to potassium to baseline";
102+
bg->GetLogger()->Info(message);
103+
K->GetMembraneResistance().SetValue(0.248, ElectricResistanceUnit::Ohm);
104+
105+
tracker.AdvanceModelTime(300);
106+
}

library/src/HowTo-Hemorrhage.cpp

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ specific language governing permissions and limitations under the License.
3030
#include "properties/SEScalarTime.h"
3131
#include "properties/SEScalarVolume.h"
3232
#include "properties/SEScalarVolumePerTime.h"
33+
#include "properties/SEScalar0To1.h"
3334
#include "engine/PhysiologyEngineTrack.h"
3435
#include "compartment/SECompartmentManager.h"
3536

3637
//--------------------------------------------------------------------------------------------------
3738
/// \brief
38-
/// Usage for applying a Hemorrhage insult to the patient
39+
/// Usage for applying a Hemorrhage insult to the patient and also demonstrate how injury code can be used to initiate a hemorrhage if desired
3940
///
4041
/// \details
4142
/// Refer to the SEHemorrhage class
4243
/// Refer to the SESubstanceManager class
4344
/// Refer to the SESubstanceIVFluids class for applying an IV to the patient
4445
//--------------------------------------------------------------------------------------------------
46+
std::string ParseMCIS(std::vector<unsigned int> &mcis);
47+
4548
void HowToHemorrhage()
4649
{
4750
// Create the engine and load the patient
@@ -78,26 +81,35 @@ void HowToHemorrhage()
7881
bg->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << bg->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
7982
bg->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << bg->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;
8083

81-
// Hemorrhage Starts - instantiate a hemorrhage action and have the engine process it
82-
/*MCIS Code Brief :
83-
Digit 1 = Severity
84-
Digit 2 = Body Region(1 = Head, 2 = Torso, 3 = Arms, 4 = Legs, 5 = Multiple(not currently supported)
85-
Digit 3 = Subregion(not requied for arms or legs)
86-
In Head : 6 = Vessels
87-
In Torso : 6 = Vessels, 7 = Chest, 8 = Abdomen, 9 = Pelvis(not currently supported)
88-
Digit 4
89-
In Vessels : 1 = Intracranial, 3 - 5 = Carotid / Thoracic / Abdominal arteries(all currently removed from aorta compartment), 6 = VenaCava
90-
In Chest : 1 = Lungs, 2 = Heart In Abdomen : 1 = Liver, 2 = Spleen, 3 = Pancreas(Splanchnic), 4 = Kidney, 5 = SmallIntestine, 6 = LargeIntestine
91-
Digit 5 : Wound information too specific for BioGears(any number fine, 0 used here)
92-
93-
Stopping a hemorrhage requires Severity = 0 and remainder of code consistent with original wound*/
84+
//We are going to create a hemorrhage in two different ways. One way will be to specify the location and a severity on a scale of 0-1.
85+
//The other way will be to parse an injury code and derive the location and severity
86+
//Set the choice variable below either to 1 to run with location/severity or to 2 to run with injury code
87+
int choice = 2;
9488

95-
SEHemorrhage hemorrhageAbdominal;
96-
std::vector<unsigned int> hemorrhageStart = {4,2,6,5,0 };
97-
hemorrhageAbdominal.SetMCIS(hemorrhageStart);
98-
hemorrhageAbdominal.ProcessMCIS(); //Extracts the injury severity and injury location from the mcis code
89+
//Create variables for scenario
90+
SEHemorrhage hemorrhageSpleen; //hemorrhage object
91+
std::string location; //location of hemorrhage, valid options are "Major Artery", "Vena Cava", "Head", "Myocardium", "Lung", "Spleen", "Splanchnic", "Small Intestine", "Large Intestine", "Kidney", "Liver", "Arm", "Leg"
92+
double severity; //severity (scale 0-1)
93+
std::vector<unsigned int> mcisCode; //injury code if using option 2, see ParseMCIS method below for more details
94+
//Let's create an internal hemorrhage in the spleen (maybe it ruptured...)
95+
switch (choice) {
96+
case 1:
97+
location = "Spleen";
98+
severity = 0.8;
99+
break;
100+
case 2:
101+
mcisCode = { 4,2,8,2,0 }; //This injury code is a high severity hemorrhage in the spleen
102+
severity = mcisCode[0] / 5.0; //Digit 1 of mcis is severity on 0-5 scale. Convert it to a 0-1 scale
103+
location = ParseMCIS(mcisCode);
104+
break;
105+
}
106+
//Set up hemorrhage with the location and severity info
107+
hemorrhageSpleen.SetCompartment(location);
108+
hemorrhageSpleen.GetSeverity().SetValue(severity);
109+
hemorrhageSpleen.SetBleedPath(); //This is needed to tell engine which circuit pathway to set the hemorrhage on
99110

100-
bg->ProcessAction(hemorrhageAbdominal);
111+
// Hemorrhage Starts - instantiate a hemorrhage action and have the engine process it. Note that BioGears will output the injury code regardless of which method was used
112+
bg->ProcessAction(hemorrhageSpleen);
101113

102114
// Advance some time to let the body bleed out a bit
103115
tracker.AdvanceModelTime(300);
@@ -111,11 +123,10 @@ void HowToHemorrhage()
111123
bg->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << bg->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
112124
bg->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << bg->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;
113125

114-
// Hemorrhage is sealed
115-
std::vector<unsigned int> hemorrhageEnd = { 0,2,6,5,0 };
116-
hemorrhageAbdominal.SetMCIS(hemorrhageEnd);
117-
hemorrhageAbdominal.ProcessMCIS();
118-
bg->ProcessAction(hemorrhageAbdominal);
126+
//Assume that the hemorrhage has been stopped somehow. We do this by setting the severity of our hemorrhage object to 0
127+
hemorrhageSpleen.GetSeverity().SetValue(0);
128+
//Process update to hemorrhage action
129+
bg->ProcessAction(hemorrhageSpleen);
119130

120131

121132
// Advance some time while the medic gets the drugs ready
@@ -151,3 +162,57 @@ void HowToHemorrhage()
151162
bg->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << bg->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;
152163
bg->GetLogger()->Info("Finished");
153164
}
165+
166+
std::string ParseMCIS(std::vector<unsigned int> &mcis)
167+
{
168+
/*MCIS Code Brief :
169+
Digit 1 = Severity
170+
Digit 2 = Body Region(1 = Head, 2 = Torso, 3 = Arms, 4 = Legs, 5 = Multiple(not currently supported)
171+
Digit 3 = Subregion(not required for arms or legs)
172+
In Head : 6 = Vessels
173+
In Torso : 6 = Vessels, 7 = Chest, 8 = Abdomen, 9 = Pelvis(not currently supported)
174+
Digit 4
175+
In Vessels : 1 = Intracranial (if in head), 4 = Major Artery (if in torso), 6 = "Vena Cava" (if in torso)
176+
In Chest : 1 = Lungs, 2 = Heart In Abdomen : 1 = Liver, 2 = Spleen, 3 = Pancreas(Splanchnic), 4 = Kidney, 5 = SmallIntestine, 6 = LargeIntestine
177+
Digit 5 : Wound information too specific for BioGears(any number fine, 0 used here) */
178+
179+
std::string comp = "";
180+
enum region {Head =1, Torso = 2, Arm = 3, Leg = 4}; //This will decide which region to look for compartment based on digit 2 of code
181+
std::map<std::vector<unsigned int>, std::string> torsoMap; //There are so many compartments in the torso, it is easier to map them
182+
//Populate torso map (codes with second digit = 2) so that digits 3-4 of code are key to correct compartment
183+
torsoMap[{6, 4}] = "Major Artery";
184+
torsoMap[{6, 6}] = "Vena Cava";
185+
torsoMap[{7, 1}] = "Lung";
186+
torsoMap[{7, 2}] = "Myocardium";
187+
torsoMap[{8, 1}] = "Liver";
188+
torsoMap[{8, 2}] = "Spleen";
189+
torsoMap[{8, 3}] = "Splanchnic";
190+
torsoMap[{8, 4}] = "Kidney";
191+
torsoMap[{8, 5}] = "Small Intestine";
192+
torsoMap[{8, 6}] = "Large Intestine";
193+
194+
int caseKey = mcis[1]; //Need 2nd digit of mcis code to decide in which region to place hemorrhage
195+
196+
switch (caseKey) {
197+
case Head:
198+
comp = "Head";
199+
break;
200+
case Torso:
201+
if (torsoMap.find({ mcis.begin() + 2,mcis.end() - 1 }) != torsoMap.end()) //Check to see if subvector made from digits 3-4 is in map.
202+
comp = torsoMap[{mcis.begin() + 2, mcis.end() - 1}]; // If yes, get compartment that goes with these digits
203+
else
204+
comp = "Major Artery"; //If no, we messed up somewhere and we'll put it on the artery so that the sim doesn't crash
205+
break;
206+
case Arm:
207+
comp = "Arm";
208+
break;
209+
case Leg:
210+
comp = "Leg";
211+
break;
212+
default:
213+
comp = "Major Artery"; //Default to artery in case anything goes wrong
214+
}
215+
216+
217+
return comp;
218+
}

0 commit comments

Comments
 (0)