Exemplo n.º 1
0
        public static void apply_acute_stress(BioGearsEngine engine)
        {
            var on  = new SEAcuteStress();
            var off = new SEAcuteStress();

            on.GetSeverity().SetValue(0.5);
            off.GetSeverity().SetValue(0.0);

            apply_and_cancel_patient_action(engine, on, off);
        }
Exemplo n.º 2
0
        //!
        //! Very Terse testing of the SWIG_Bindings
        //!
        //! We will simply test the ability
        //!   1. Create a logger and log to a file
        //!   2. Initialize a BioGearsEngine
        //!   3. Advance Model Time
        //!   4. Apply Actions to an exsiting BioGearsEngine
        //!   5. Create and Apply all BioGears Actions

        static void Main(string[] args)
        {
            var logger = new Logger("");

            logger.Warning("Perfect Now lets Try to compliate things with two modules!");

            var percent = new SEScalar0To1();

            percent.SetValue(0.1);

            logger.Info(String.Format("{0}", percent.GetValue()));

            var time = new SEScalarTime();

            time.SetValue(4, TimeUnit.s);
            logger.Info(String.Format("{0}", time.GetValue()));


            var engine = new BioGearsEngine(logger);

            engine.InitializeEngine("StandardMale.xml");
            engine.AdvanceModelTime();
            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);

            var eh = new BioGearsEventHandler();

            engine.SetEventHandler(eh);

            var acuteStress = new SEAcuteStress();

            acuteStress.GetSeverity().SetValue(.75);

            logger.Warning(String.Format("AcuteStress @ Severity {0}", acuteStress.GetSeverity().GetValue()));
            engine.ProcessAction(acuteStress);

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);

            var severity = acuteStress.GetSeverity();

            severity.SetValue(0.5);

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);

            SEBurnWound m_burnWound = new SEBurnWound();

            m_burnWound.GetTotalBodySurfaceArea().SetValue(50.0 / 100.0);
            engine.ProcessAction(m_burnWound);
            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);

            var m_substances = engine.GetSubstanceManager();
            var m_albumine   = m_substances.GetSubstance("Albumin");
            var m_saline     = m_substances.GetCompound("Saline");

            try {
                var m_SubstanceBolus     = new SESubstanceBolus(m_albumine);
                var m_SubstanceInfusion  = new SESubstanceInfusion(m_albumine);
                var m_SubstanceNasalDose = new SESubstanceNasalDose(m_albumine);
                var m_SubstanceOralDose  = new SESubstanceOralDose(m_albumine);
            } catch (global::System.Exception /*ex*/) {
                logger.Error("Definition of Albumin is missing.  Unable to test Substance Actions");
            }

            try {
                var m_SubstanceCompoundInfusion = new SESubstanceCompoundInfusion(m_saline);
            } catch (global::System.Exception /*ex*/) {
                logger.Error("Definition of Saline is missing.  Unable to test SubstanceCompound  Actions");
            }

            var m_TensionPneumothorax = new SETensionPneumothorax();
            var m_Tourniquet          = new SETourniquet();
            var m_Urinate             = new SEUrinate();
            var m_UseInhaler          = new SEUseInhaler();

            var  patient        = engine.GetPatient();
            bool isTacycardia   = patient.IsEventActive(CDM.enumPatientEvent.value.Tachycardia);
            bool isAlive        = patient.IsEventActive(CDM.enumPatientEvent.value.IrreversibleState);
            bool isKetoacidosis = patient.IsEventActive(CDM.enumPatientEvent.value.Ketoacidosis);

            logger.Warning(String.Format("AcuteStress @ Severity {0}", acuteStress.GetSeverity().GetValue()));

            //!
            //! Very Quick Example of how to use Data Tracks to Poll data
            //! Performance wise this should really only be used for non PhysiologyDataRequest
            //!
            var HeartRateRequest = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); HeartRateRequest.Set("HeartRate", FrequencyUnit.Per_min);
            var SystolicArterialPressureRequest  = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); SystolicArterialPressureRequest.Set("SystolicArterialPressure", PressureUnit.mmHg);
            var DiastolicArterialPressureRequest = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); DiastolicArterialPressureRequest.Set("DiastolicArterialPressure", PressureUnit.mmHg);
            var RespirationRateRequest           = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); RespirationRateRequest.Set("RespirationRate", FrequencyUnit.Per_min);
            var TidalVolumeRequest      = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); TidalVolumeRequest.Set("TidalVolume", VolumeUnit.mL);
            var TotalLungVolumeRequest  = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); TotalLungVolumeRequest.Set("TotalLungVolume", VolumeUnit.mL);
            var OxygenSaturationRequest = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); OxygenSaturationRequest.Set("OxygenSaturation");

            //TODO: Get Substance and GetSubstanceCompound need better exception handeling
            var oxygen        = engine.GetSubstanceManager().GetSubstance("Oxygen");
            var carbonDioxide = engine.GetSubstanceManager().GetSubstance("CarbonDioxide");

            //Final exonicus data requests
            var ecg = engine.GetEngineTrack().GetDataRequestManager().CreateEquipmentDataRequest(); ecg.SetDataRequestType("ECG"); ecg.Set("Lead3ElectricPotential", ElectricPotentialUnit.mV);
            var MeanUrineRequest        = engine.GetEngineTrack().GetDataRequestManager().CreatePhysiologyDataRequest(); MeanUrineRequest.Set("MeanUrineOutput", VolumePerTimeUnit.mL_Per_hr);
            var BrainVasculatureRequest = engine.GetEngineTrack().GetDataRequestManager().CreateLiquidCompartmentDataRequest(); BrainVasculatureRequest.Set("BrainVasculature", oxygen, "PartialPressure", PressureUnit.mmHg);
            var TracheaPartialPressure  = engine.GetEngineTrack().GetDataRequestManager().CreateGasCompartmentDataRequest(); TracheaPartialPressure.Set("Trachea", carbonDioxide, "PartialPressure", PressureUnit.mmHg);

            engine.GetEngineTrack().SetupRequests();

            var HeartRate = engine.GetEngineTrack().GetScalar(HeartRateRequest);
            var SystolicArterialPressure  = engine.GetEngineTrack().GetScalar(HeartRateRequest);
            var DiastolicArterialPressure = engine.GetEngineTrack().GetScalar(DiastolicArterialPressureRequest);
            var RespirationRate           = engine.GetEngineTrack().GetScalar(RespirationRateRequest);
            var TidalVolume        = engine.GetEngineTrack().GetScalar(TidalVolumeRequest);
            var TotalLungVolume    = engine.GetEngineTrack().GetScalar(TotalLungVolumeRequest);
            var OxygenSaturation   = engine.GetEngineTrack().GetScalar(OxygenSaturationRequest);
            var PartialPressure    = engine.GetEngineTrack().GetScalar(BrainVasculatureRequest);
            var CO2PartialPressure = engine.GetEngineTrack().GetScalar(TracheaPartialPressure);
            var Urine   = engine.GetEngineTrack().GetScalar(MeanUrineRequest);
            var ecgData = engine.GetEngineTrack().GetScalar(ecg);


            apply_acute_respiratory_distress(engine);

            engine.GetEngineTrack().PullData();
            logger.Info(HeartRate.ToString());
            logger.Info(SystolicArterialPressure.ToString());
            logger.Info(DiastolicArterialPressure.ToString());
            logger.Info(RespirationRate.ToString());
            logger.Info(TidalVolume.ToString());
            logger.Info(TotalLungVolume.ToString());
            logger.Info(OxygenSaturation.ToString());
            logger.Info(PartialPressure.ToString());
            logger.Info(CO2PartialPressure.ToString());
            logger.Info(Urine.ToString());
            logger.Info("ecg: \n");
            logger.Info(ecgData.ToString());



            //!
            //!  Just to test most actions we will apply and unapply every action in 2 second sperts
            //!
            apply_acute_stress(engine);
            engine.GetEngineTrack().PullData();
            apply_airway_obstruction(engine);
            engine.GetEngineTrack().PullData();
            apply_apnea(engine);
            engine.GetEngineTrack().PullData();
            apply_asthma_attack(engine);
            engine.GetEngineTrack().PullData();
            apply_brain_injury(engine);
            engine.GetEngineTrack().PullData();
            apply_breath_hold(engine);
            engine.GetEngineTrack().PullData();
            apply_bronchoconstriction(engine);
            engine.GetEngineTrack().PullData();
            apply_burn_wound(engine);
            engine.GetEngineTrack().PullData();
            apply_cardiac_arrest(engine);
            engine.GetEngineTrack().PullData();

            logger.Info(HeartRate.ToString());
            logger.Info(SystolicArterialPressure.ToString());
            logger.Info(DiastolicArterialPressure.ToString());
            logger.Info(RespirationRate.ToString());
            logger.Info(TidalVolume.ToString());
            logger.Info(TotalLungVolume.ToString());
            logger.Info(OxygenSaturation.ToString());

            apply_chest_compression(engine);
            engine.GetEngineTrack().PullData();
            apply_chest_compression_force(engine);
            engine.GetEngineTrack().PullData();
            apply_chest_compression_force_scale(engine);
            engine.GetEngineTrack().PullData();
            apply_chest_occlusive_dressing(engine);
            engine.GetEngineTrack().PullData();
            apply_conscious_respiration(engine);
            engine.GetEngineTrack().PullData();
            apply_consume_nutrients(engine);
            engine.GetEngineTrack().PullData();
            apply_exercise(engine);
            engine.GetEngineTrack().PullData();
            apply_cycling_exercise(engine);
            engine.GetEngineTrack().PullData();
            apply_generic_exercise(engine);
            engine.GetEngineTrack().PullData();
            apply_running_exercise(engine);
            engine.GetEngineTrack().PullData();
            apply_strength_exercise(engine);
            engine.GetEngineTrack().PullData();
            apply_hemorrhage(engine);
            engine.GetEngineTrack().PullData();
            apply_infection(engine);
            engine.GetEngineTrack().PullData();
            apply_intubation(engine);
            engine.GetEngineTrack().PullData();
            apply_mechanical_ventilation(engine);
            engine.GetEngineTrack().PullData();
            apply_needle_decompression(engine);
            engine.GetEngineTrack().PullData();
            apply_override(engine);
            engine.GetEngineTrack().PullData();
            apply_pain_stimulus(engine);
            engine.GetEngineTrack().PullData();
            apply_patient_assessment_request(engine);
            engine.GetEngineTrack().PullData();
            apply_pericadial_effusion(engine);
            engine.GetEngineTrack().PullData();

            logger.Info(HeartRate.ToString());
            logger.Info(SystolicArterialPressure.ToString());
            logger.Info(DiastolicArterialPressure.ToString());
            logger.Info(RespirationRate.ToString());
            logger.Info(TidalVolume.ToString());
            logger.Info(TotalLungVolume.ToString());
            logger.Info(OxygenSaturation.ToString());

            apply_pulmonary_shunt(engine);
            engine.GetEngineTrack().PullData();
            apply_sleep(engine);

            engine.GetEngineTrack().PullData();
            logger.Info(HeartRate.ToString());
            logger.Info(SystolicArterialPressure.ToString());
            logger.Info(DiastolicArterialPressure.ToString());
            logger.Info(RespirationRate.ToString());
            logger.Info(TidalVolume.ToString());
            logger.Info(TotalLungVolume.ToString());
            logger.Info(OxygenSaturation.ToString());

            var AMConfig = new SEAnesthesiaMachineConfiguration(engine.GetSubstanceManager());
            var config   = AMConfig.GetConfiguration();

            config.SetConnection(CDM.enumAnesthesiaMachineConnection.value.Mask);
            config.GetInletFlow().SetValue(2.0, VolumePerTimeUnit.L_Per_min);
            config.GetInspiratoryExpiratoryRatio().SetValue(.5);
            config.GetOxygenFraction().SetValue(.5);
            config.SetOxygenSource(CDM.enumAnesthesiaMachineOxygenSource.value.Wall);
            config.GetPositiveEndExpiredPressure().SetValue(0.0, PressureUnit.cmH2O);
            config.SetPrimaryGas(CDM.enumAnesthesiaMachinePrimaryGas.value.Nitrogen);
            config.GetReliefValvePressure().SetValue(20.0, PressureUnit.cmH2O);
            config.GetRespiratoryRate().SetValue(12, FrequencyUnit.Per_min);
            config.GetVentilatorPressure().SetValue(0.0, PressureUnit.cmH2O);
            config.GetOxygenBottleOne().GetVolume().SetValue(660.0, VolumeUnit.L);
            config.GetOxygenBottleTwo().GetVolume().SetValue(660.0, VolumeUnit.L);
            engine.ProcessAction(AMConfig);

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);
            config.GetInletFlow().SetValue(5.0, VolumePerTimeUnit.L_Per_min);
            config.GetPositiveEndExpiredPressure().SetValue(3.0, PressureUnit.cmH2O);
            config.GetVentilatorPressure().SetValue(22.0, PressureUnit.cmH2O);
            engine.ProcessAction(AMConfig);

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);
            config.GetInspiratoryExpiratoryRatio().SetValue(1.0);
            config.GetPositiveEndExpiredPressure().SetValue(1.0, PressureUnit.cmH2O);
            config.GetRespiratoryRate().SetValue(18.0, FrequencyUnit.Per_min);
            config.GetVentilatorPressure().SetValue(10.0, PressureUnit.cmH2O);
            engine.ProcessAction(AMConfig);

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);
            var AMleak = new SEMaskLeak();

            AMleak.GetSeverity().SetValue(0.5);
            engine.ProcessAction(AMleak);
            engine.GetLogger().Info("Removing the mask leak.");

            engine.AdvanceModelTimeBy(2.0, TimeUnit.s);
            var AMpressureloss = new SEOxygenWallPortPressureLoss();

            AMpressureloss.SetActive(true);
            engine.ProcessAction(AMpressureloss);
            engine.GetLogger().Info("Testing the oxygen pressure loss failure mode. The oxygen pressure from the wall source is dropping.");

            AMpressureloss.SetActive(false);
            engine.ProcessAction(AMpressureloss);
            engine.GetLogger().Info("Removing the wall oxygen pressure loss action.");
            engine.AdvanceModelTimeBy(2, TimeUnit.s);

            engine.SaveStateToFile("*****@*****.**");

            Console.Write("Simulation Finished Press any key to continue");
            var testString = Console.ReadLine();
        }