Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pulse Physiology Suite
engine
Commits
e2a4315f
Commit
e2a4315f
authored
Jun 23, 2020
by
Aaron Bray
Browse files
Add CPR, ConsumeNutrients, and Urinate actions to python
parent
40a2f401
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/python/pulse/cdm/io/engine.py
View file @
e2a4315f
...
...
@@ -183,6 +183,14 @@ def serialize_actions_to_string(actions: [], fmt: eSerializationFormat):
serialize_cardiac_arrest_to_bind
(
action
,
any_action
.
PatientAction
.
CardiacArrest
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEChestCompressionForce
):
serialize_chest_compression_force_to_bind
(
action
,
any_action
.
PatientAction
.
ChestCompressionForce
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEChestCompressionForceScale
):
serialize_chest_compression_force_scale_to_bind
(
action
,
any_action
.
PatientAction
.
ChestCompressionForceScale
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEChestOcclusiveDressing
):
serialize_chest_occlusive_dressing_to_bind
(
action
,
any_action
.
PatientAction
.
ChestOcclusiveDressing
)
action_list
.
AnyAction
.
append
(
any_action
)
...
...
@@ -195,6 +203,10 @@ def serialize_actions_to_string(actions: [], fmt: eSerializationFormat):
serialize_conscious_respiration_to_bind
(
action
,
any_action
.
PatientAction
.
ConsciousRespiration
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEConsumeNutrients
):
serialize_consume_nutrients_to_bind
(
action
,
any_action
.
PatientAction
.
ConsumeNutrients
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEDyspnea
):
serialize_dsypnea_to_bind
(
action
,
any_action
.
PatientAction
.
Dyspnea
)
action_list
.
AnyAction
.
append
(
any_action
)
...
...
@@ -259,6 +271,10 @@ def serialize_actions_to_string(actions: [], fmt: eSerializationFormat):
serialize_tension_pneumothorax_to_bind
(
action
,
any_action
.
PatientAction
.
TensionPneumothorax
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEUrinate
):
serialize_urinate_to_bind
(
action
,
any_action
.
PatientAction
.
Urinate
)
action_list
.
AnyAction
.
append
(
any_action
)
continue
if
isinstance
(
action
,
SEEnvironmentAction
):
if
isinstance
(
action
,
SEChangeEnvironmentalConditions
):
serialize_change_environmental_conditions_to_bind
(
action
,
any_action
.
EnvironmentAction
.
ChangeEnvironmentalConditions
)
...
...
src/python/pulse/cdm/io/environment_actions.py
View file @
e2a4315f
...
...
@@ -17,6 +17,8 @@ def serialize_environment_action_to_bind(src: SEEnvironmentAction, dst: Environm
def
serialize_environment_action_from_bind
(
src
:
EnvironmentActionData
,
dst
:
SEEnvironmentAction
):
serialize_action_from_bind
(
src
.
Action
,
dst
)
#################################################################
def
serialize_change_environmental_conditions_to_bind
(
src
:
SEChangeEnvironmentalConditions
,
dst
:
ChangeEnvironmentalConditionsData
):
serialize_environment_action_to_bind
(
src
,
dst
.
EnvironmentAction
)
if
src
.
has_environmental_conditions_file
():
...
...
@@ -28,6 +30,8 @@ def serialize_change_environmental_conditions_from_bind(src: ChangeEnvironmental
serialize_environment_action_from_bind
(
src
.
EnvironmentAction
,
dst
)
raise
Exception
(
"serialize_change_environmental_conditions_from_bind not implemented"
)
#################################################################
def
serialize_thermal_application_to_bind
(
src
:
SEThermalApplication
,
dst
:
ThermalApplicationData
):
serialize_environment_action_to_bind
(
src
,
dst
.
EnvironmentAction
)
dst
.
AppendToPrevious
=
not
src
.
get_clear_contents
()
...
...
@@ -42,3 +46,4 @@ def serialize_thermal_application_from_bind(src: ThermalApplicationData, dst: SE
serialize_environment_action_from_bind
(
src
.
EnvironmentAction
,
dst
)
raise
Exception
(
"serialize_thermal_application_from_bind not implemented"
)
#################################################################
src/python/pulse/cdm/io/patient.py
View file @
e2a4315f
...
...
@@ -4,8 +4,9 @@
from
pulse.cdm.engine
import
eSerializationFormat
from
google.protobuf
import
json_format
from
pulse.cdm.patient
import
SEPatient
,
eSex
from
pulse.cdm.patient
import
SEPatient
,
eSex
,
SENutrition
from
pulse.cdm.bind.Patient_pb2
import
PatientData
from
pulse.cdm.bind.PatientNutrition_pb2
import
NutritionData
from
pulse.cdm.io.scalars
import
*
...
...
@@ -147,3 +148,64 @@ def serialize_patient_from_bind(src: PatientData, dst: SEPatient):
if
src
.
HasField
(
"VitalCapacity"
):
serialize_scalar_volume_from_bind
(
src
.
VitalCapacity
,
dst
.
get_vital_capacity
())
def
serialize_nutrition_to_string
(
src
:
SENutrition
,
fmt
:
eSerializationFormat
):
dst
=
NutritionData
()
serialize_nutrition_to_bind
(
src
,
dst
)
return
json_format
.
MessageToJson
(
dst
,
True
,
True
)
def
serialize_nutrition_to_file
(
src
:
SENutrition
,
filename
:
str
):
string
=
serialize_nutrition_to_string
(
src
,
eSerializationFormat
.
JSON
)
file
=
open
(
filename
,
"w"
)
n
=
file
.
write
(
string
)
file
.
close
()
def
serialize_nutrition_from_string
(
string
:
str
,
dst
:
SENutrition
,
fmt
:
eSerializationFormat
):
src
=
NutritionData
()
json_format
.
Parse
(
string
,
src
)
serialize_nutrition_from_bind
(
src
,
dst
)
def
serialize_nutrition_from_file
(
filename
:
str
,
dst
:
SENutrition
):
with
open
(
filename
)
as
f
:
string
=
f
.
read
()
serialize_nutrition_from_string
(
string
,
dst
,
eSerializationFormat
.
JSON
)
def
serialize_nutrition_to_bind
(
src
:
SENutrition
,
dst
:
NutritionData
):
if
src
.
has_carbohydrate
():
serialize_scalar_mass_to_bind
(
src
.
get_carbohydrate
(),
dst
.
Carbohydrate
)
if
src
.
has_carbohydrate_digestion_rate
():
serialize_scalar_mass_per_time_to_bind
(
src
.
get_carbohydrate_digestion_rate
(),
dst
.
CarbohydrateDigestionRate
)
if
src
.
has_fat
():
serialize_scalar_mass_to_bind
(
src
.
get_fat
(),
dst
.
Fat
)
if
src
.
has_fat_digestion_rate
():
serialize_scalar_mass_per_time_to_bind
(
src
.
get_fat_digestion_rate
(),
dst
.
FatDigestionRate
)
if
src
.
has_protein
():
serialize_scalar_mass_to_bind
(
src
.
get_protein
(),
dst
.
Protein
)
if
src
.
has_protein_digestion_rate
():
serialize_scalar_mass_per_time_to_bind
(
src
.
get_protein_digestion_rate
(),
dst
.
ProteinDigestionRate
)
if
src
.
has_calcium
():
serialize_scalar_mass_to_bind
(
src
.
get_calcium
(),
dst
.
Calcium
)
if
src
.
has_sodium
():
serialize_scalar_mass_to_bind
(
src
.
get_sodium
(),
dst
.
Sodium
)
if
src
.
has_water
():
serialize_scalar_volume_to_bind
(
src
.
get_water
(),
dst
.
Water
)
def
serialize_nutrition_from_bind
(
src
:
NutritionData
,
dst
:
SENutrition
):
dst
.
clear
()
if
src
.
HasField
(
"Carbohydrate"
):
serialize_scalar_mass_from_bind
(
src
.
Carbohydrate
,
dst
.
get_age
())
if
src
.
HasField
(
"CarbohydrateDigestionRate"
):
serialize_scalar_mass_per_time_from_bind
(
src
.
CarbohydrateDigestionRate
,
dst
.
get_weight
())
if
src
.
HasField
(
"Fat"
):
serialize_scalar_mass_from_bind
(
src
.
Fat
,
dst
.
get_height
())
if
src
.
HasField
(
"FatDigestionRate"
):
serialize_scalar_mass_per_time_from_bind
(
src
.
FatDigestionRate
,
dst
.
get_body_density
())
if
src
.
HasField
(
"Protein"
):
serialize_scalar_mass_from_bind
(
src
.
Protein
,
dst
.
get_body_fat_fraction
())
if
src
.
HasField
(
"ProteinDigestionRate"
):
serialize_scalar_mass_per_time_from_bind
(
src
.
ProteinDigestionRate
,
dst
.
get_ideal_body_weight
())
if
src
.
HasField
(
"Calcium"
):
serialize_scalar_mass_from_bind
(
src
.
Calcium
,
dst
.
get_lean_body_mass
())
if
src
.
HasField
(
"Sodium"
):
serialize_scalar_mass_from_bind
(
src
.
Sodium
,
dst
.
get_alveoli_surface_area
())
if
src
.
HasField
(
"Water"
):
serialize_scalar_volume_from_bind
(
src
.
Water
,
dst
.
get_right_lung_ratio
())
src/python/pulse/cdm/io/patient_actions.py
View file @
e2a4315f
...
...
@@ -5,6 +5,7 @@ from pulse.cdm.io.action import serialize_action_from_bind, serialize_action_to_
from
pulse.cdm.patient_actions
import
*
from
pulse.cdm.bind.PatientActions_pb2
import
*
from
pulse.cdm.io.patient
import
*
from
pulse.cdm.io.scalars
import
*
def
serialize_patient_action_to_bind
(
src
:
SEPatientAction
,
dst
:
PatientActionData
):
...
...
@@ -99,6 +100,30 @@ def serialize_cardiac_arrest_from_bind(src: CardiacArrestData, dst: SECardiacArr
#################################################################
def
serialize_chest_compression_force_to_bind
(
src
:
SEChestCompressionForce
,
dst
:
ChestCompressionForceData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
if
src
.
has_force
():
serialize_scalar_force_to_bind
(
src
.
get_force
(),
dst
.
Force
)
def
serialize_chest_compression_force_from_bind
(
src
:
ChestCompressionForceData
,
dst
:
SEChestCompressionForce
):
serialize_patient_action_from_bind
(
src
.
PatientAction
,
dst
)
raise
Exception
(
"serialize_chest_compression_force_from_bind not implemented"
)
#################################################################
def
serialize_chest_compression_force_scale_to_bind
(
src
:
SEChestCompressionForceScale
,
dst
:
ChestCompressionForceScaleData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
if
src
.
has_force_period
():
serialize_scalar_time_to_bind
(
src
.
get_force_period
(),
dst
.
ForcePeriod
)
if
src
.
has_force_scale
():
serialize_scalar_0to1_to_bind
(
src
.
get_force_scale
(),
dst
.
ForceScale
)
def
serialize_chest_compression_force_scale_from_bind
(
src
:
ChestCompressionForceScaleData
,
dst
:
SEChestCompressionForceScale
):
serialize_patient_action_from_bind
(
src
.
PatientAction
,
dst
)
raise
Exception
(
"serialize_chest_compression_force_scale_from_bind not implemented"
)
#################################################################
def
serialize_chest_occlusive_dressing_to_bind
(
src
:
SEChestOcclusiveDressing
,
dst
:
ChestOcclusiveDressingData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
if
src
.
has_side
():
...
...
@@ -193,6 +218,19 @@ def serialize_conscious_respiration_command_from_bind(src: AnyConsciousRespirati
#################################################################
def
serialize_consume_nutrients_to_bind
(
src
:
SEConsumeNutrients
,
dst
:
ConsumeNutrientsData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
if
src
.
has_nutrition_file
():
dst
.
NutritionFile
=
src
.
get_nutrition_file
()
elif
src
.
has_nutrition
():
serialize_nutrition_to_bind
(
src
.
get_nutrition
(),
dst
.
Nutrition
)
def
serialize_consume_nutrients_from_bind
(
src
:
ConsumeNutrientsData
,
dst
:
ConsumeNutrientsData
):
serialize_patient_action_from_bind
(
src
.
PatientAction
,
dst
)
raise
Exception
(
"serialize_consume_nutrients_from_bind not implemented"
)
#################################################################
def
serialize_dsypnea_to_bind
(
src
:
SEDyspnea
,
dst
:
DyspneaData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
if
src
.
has_severity
():
...
...
@@ -401,4 +439,13 @@ def serialize_tension_pneumothorax_to_bind(src: SETensionPneumothorax, dst: Tens
def
serialize_tension_pneumothorax_from_bind
(
src
:
TensionPneumothoraxData
,
dst
:
SETensionPneumothorax
):
serialize_patient_action_from_bind
(
src
.
PatientAction
,
dst
)
raise
Exception
(
"serialize_patient_condition_from_bind not implemented"
)
\ No newline at end of file
raise
Exception
(
"serialize_patient_condition_from_bind not implemented"
)
#################################################################
def
serialize_urinate_to_bind
(
src
:
SEUrinate
,
dst
:
UrinateData
):
serialize_patient_action_to_bind
(
src
,
dst
.
PatientAction
)
def
serialize_urinate_from_bind
(
src
:
UrinateData
,
dst
:
SEUrinate
):
serialize_patient_action_from_bind
(
src
.
PatientAction
,
dst
)
raise
Exception
(
"serialize_urinate_from_bind not implemented"
)
src/python/pulse/cdm/io/scalars.py
View file @
e2a4315f
...
...
@@ -3,6 +3,7 @@
from
pulse.cdm.scalars
import
SEScalar
,
SEScalar0To1
,
SEScalarNegative1To1
,
\
SEScalarArea
,
AreaUnit
,
\
SEScalarForce
,
ForceUnit
,
\
SEScalarFrequency
,
FrequencyUnit
,
\
SEScalarHeatResistanceArea
,
HeatResistanceAreaUnit
,
\
SEScalarInversePressure
,
InversePressureUnit
,
\
...
...
@@ -24,7 +25,7 @@ from pulse.cdm.scalars import SEScalar, SEScalar0To1, SEScalarNegative1To1, \
SEScalarVolumePerTimeMass
,
VolumePerTimeMassUnit
,
\
SEScalarVolumePerTimePressure
,
VolumePerTimePressureUnit
from
pulse.cdm.bind.Properties_pb2
import
ScalarData
,
Scalar0To1Data
,
ScalarNegative1To1Data
,
\
ScalarAreaData
,
ScalarFrequencyData
,
ScalarHeatResistanceAreaData
,
\
ScalarAreaData
,
ScalarForceData
,
ScalarFrequencyData
,
ScalarHeatResistanceAreaData
,
\
ScalarInversePressureData
,
ScalarLengthData
,
ScalarLengthPerTimeData
,
\
ScalarMassData
,
ScalarMassPerAmountData
,
ScalarMassPerAreaTimeData
,
\
ScalarMassPerTimeData
,
ScalarMassPerVolumeData
,
ScalarPowerData
,
\
...
...
@@ -54,6 +55,12 @@ def serialize_scalar_area_to_bind(src: SEScalarArea, dst: ScalarAreaData):
def
serialize_scalar_area_from_bind
(
src
:
ScalarAreaData
,
dst
:
SEScalarArea
):
dst
.
set_value
(
src
.
ScalarArea
.
Value
,
AreaUnit
.
from_string
(
src
.
ScalarArea
.
Unit
))
def
serialize_scalar_force_to_bind
(
src
:
SEScalarForce
,
dst
:
ScalarForceData
):
dst
.
ScalarForce
.
Value
=
src
.
get_value
()
dst
.
ScalarForce
.
Unit
=
src
.
get_unit
().
get_string
()
def
serialize_scalar_force_from_bind
(
src
:
ScalarForceData
,
dst
:
SEScalarForce
):
dst
.
set_value
(
src
.
ScalarForce
.
Value
,
ForceUnit
.
from_string
(
src
.
ScalarForce
.
Unit
))
def
serialize_scalar_frequency_to_bind
(
src
:
SEScalarFrequency
,
dst
:
ScalarFrequencyData
):
dst
.
ScalarFrequency
.
Value
=
src
.
get_value
()
dst
.
ScalarFrequency
.
Unit
=
src
.
get_unit
().
get_string
()
...
...
src/python/pulse/cdm/patient.py
View file @
e2a4315f
...
...
@@ -2,7 +2,7 @@
# See accompanying NOTICE file for details.
from
enum
import
Enum
from
pulse.cdm.scalars
import
SEScalar0To1
,
SEScalarArea
,
SEScalarFrequency
,
SEScalarLength
,
\
SEScalarMass
,
SEScalarMassPerVolume
,
SEScalarPower
,
\
SEScalarMass
,
SEScalarMassPerTime
,
SEScalarMassPerVolume
,
SEScalarPower
,
\
SEScalarPressure
,
SEScalarTime
,
SEScalarVolume
,
SEScalarProperty
from
pulse.cdm.engine
import
SEConditionManager
...
...
@@ -383,3 +383,108 @@ class SEPatient():
if
self
.
_vital_capacity
is
None
:
self
.
_vital_capacity
=
SEScalarVolume
()
return
self
.
_vital_capacity
class
SENutrition
():
__slots__
=
[
"_carbohydrate"
,
"_carbohydrate_digestion_rate"
,
"_fat"
,
"_fat_digestion_rate"
,
"_protein"
,
"_protein_digestion_rate"
,
"_calcium"
,
"_sodium"
,
"_water"
,]
def
__init__
(
self
):
self
.
_carbohydrate
=
None
self
.
_carbohydrate_digestion_rate
=
None
self
.
_fat
=
None
self
.
_fat_digestion_rate
=
None
self
.
_protein
=
None
self
.
_protein_digestion_rate
=
None
self
.
_calcium
=
None
self
.
_sodium
=
None
self
.
_water
=
None
def
clear
(
self
):
if
self
.
_carbohydrate
is
not
None
:
self
.
_carbohydrate
.
invalidate
()
if
self
.
_carbohydrate_digestion_rate
is
not
None
:
self
.
_carbohydrate_digestion_rate
.
invalidate
()
if
self
.
_fat
is
not
None
:
self
.
_fat
.
invalidate
()
if
self
.
_fat_digestion_rate
is
not
None
:
self
.
_fat_digestion_rate
.
invalidate
()
if
self
.
_protein
is
not
None
:
self
.
_protein
.
invalidate
()
if
self
.
_protein_digestion_rate
is
not
None
:
self
.
_protein_digestion_rate
.
invalidate
()
if
self
.
_calcium
is
not
None
:
self
.
_calcium
.
invalidate
()
if
self
.
_sodium
is
not
None
:
self
.
_sodium
.
invalidate
()
if
self
.
_water
is
not
None
:
self
.
_water
.
invalidate
()
def
copy
(
self
,
src
):
if
not
isinstance
(
SENutrition
,
src
):
raise
Exception
(
"Provided argument must be a SENutrition"
)
self
.
clear
()
if
src
.
has_carbohydrate
():
self
.
get_carbohydrate
().
set
(
src
.
_carbohydrate
)
if
src
.
has_carbohydrate_digestion_rate
():
self
.
get_carbohydrate_digestion_rate
().
set
(
src
.
_carbohydrate_digestion_rate
)
if
src
.
has_fat
():
self
.
get_fat
().
set
(
src
.
_fat
)
if
src
.
has_fat_digestion_rate
():
self
.
get_fat_digestion_rate
().
set
(
src
.
_fat_digestion_rate
)
if
src
.
has_protein
():
self
.
get_protein
().
set
(
src
.
_protein
)
if
src
.
has_protein_digestion_rate
():
self
.
get_protein_digestion_rate
().
set
(
src
.
_protein_digestion_rate
)
if
src
.
has_calcium
():
self
.
get_calcium
().
set
(
src
.
_calcium
)
if
src
.
has_sodium
():
self
.
get_sodium
().
set
(
src
.
_sodium
)
if
src
.
has_water
():
self
.
get_water
().
set
(
src
.
_water
)
def
has_carbohydrate
(
self
):
return
False
if
self
.
_carbohydrate
is
None
else
self
.
_carbohydrate
.
is_valid
()
def
get_carbohydrate
(
self
):
if
self
.
_carbohydrate
is
None
:
self
.
_carbohydrate
=
SEScalarMass
()
return
self
.
_carbohydrate
def
has_carbohydrate_digestion_rate
(
self
):
return
False
if
self
.
_carbohydrate_digestion_rate
is
None
else
self
.
_carbohydrate_digestion_rate
.
is_valid
()
def
get_carbohydrate_digestion_rate
(
self
):
if
self
.
_carbohydrate_digestion_rate
is
None
:
self
.
_carbohydrate_digestion_rate
=
SEScalarMassPerTime
()
return
self
.
_carbohydrate_digestion_rate
def
has_fat
(
self
):
return
False
if
self
.
_fat
is
None
else
self
.
_fat
.
is_valid
()
def
get_fat
(
self
):
if
self
.
_fat
is
None
:
self
.
_fat
=
SEScalarMass
()
return
self
.
_fat
def
has_fat_digestion_rate
(
self
):
return
False
if
self
.
_fat_digestion_rate
is
None
else
self
.
_fat_digestion_rate
.
is_valid
()
def
get_fat_digestion_rate
(
self
):
if
self
.
_fat_digestion_rate
is
None
:
self
.
_fat_digestion_rate
=
SEScalarMassPerTime
()
return
self
.
_fat_digestion_rate
def
has_protein
(
self
):
return
False
if
self
.
_protein
is
None
else
self
.
_protein
.
is_valid
()
def
get_protein
(
self
):
if
self
.
_protein
is
None
:
self
.
_protein
=
SEScalarMass
()
return
self
.
_protein
def
has_protein_digestion_rate
(
self
):
return
False
if
self
.
_protein_digestion_rate
is
None
else
self
.
_protein_digestion_rate
.
is_valid
()
def
get_protein_digestion_rate
(
self
):
if
self
.
_protein_digestion_rate
is
None
:
self
.
_protein_digestion_rate
=
SEScalarMassPerTime
()
return
self
.
_protein_digestion_rate
def
has_calcium
(
self
):
return
False
if
self
.
_calcium
is
None
else
self
.
_calcium
.
is_valid
()
def
get_calcium
(
self
):
if
self
.
_calcium
is
None
:
self
.
_calcium
=
SEScalarMass
()
return
self
.
_calcium
def
has_sodium
(
self
):
return
False
if
self
.
_sodium
is
None
else
self
.
_sodium
.
is_valid
()
def
get_sodium
(
self
):
if
self
.
_sodium
is
None
:
self
.
_sodium
=
SEScalarMass
()
return
self
.
_sodium
def
has_water
(
self
):
return
False
if
self
.
_water
is
None
else
self
.
_water
.
is_valid
()
def
get_water
(
self
):
if
self
.
_water
is
None
:
self
.
_water
=
SEScalarVolume
()
return
self
.
_water
src/python/pulse/cdm/patient_actions.py
View file @
e2a4315f
# Distributed under the Apache License, Version 2.0.
# See accompanying NOTICE file for details.
from
enum
import
Enum
from
pulse.cdm.patient
import
SENutrition
from
pulse.cdm.engine
import
SEAction
,
eSwitch
,
eSide
,
eGate
from
pulse.cdm.scalars
import
SEScalar0To1
,
SEScalarArea
,
\
from
pulse.cdm.scalars
import
SEScalar0To1
,
SEScalarArea
,
SEScalarForce
,
\
SEScalarMassPerVolume
,
SEScalarPressure
,
\
SEScalarTime
,
SEScalarVolumePerTime
,
SEScalarVolume
...
...
@@ -229,6 +230,69 @@ class SECardiacArrest(SEPatientAction):
return
(
"Cardiac Arrest
\n
"
" State: {}"
).
format
(
self
.
_state
)
class
SEChestCompressionForce
(
SEPatientAction
):
__slots__
=
[
"_force"
]
def
__init__
(
self
):
super
().
__init__
()
self
.
_force
=
None
def
clear
(
self
):
super
().
clear
()
if
self
.
_force
is
not
None
:
self
.
_force
.
invalidate
()
def
is_valid
(
self
):
return
self
.
has_force
()
def
has_force
(
self
):
return
self
.
_force
is
not
None
def
get_force
(
self
):
if
self
.
_force
is
None
:
self
.
_force
=
SEScalarForce
()
return
self
.
_force
def
__repr__
(
self
):
return
(
"Chest Compression
\n
"
" Force: {}"
).
format
(
self
.
_force
)
class
SEChestCompressionForceScale
(
SEPatientAction
):
__slots__
=
[
"_force_scale"
,
"_force_period"
]
def
__init__
(
self
):
super
().
__init__
()
self
.
_force_scale
=
None
self
.
_force_period
=
None
def
clear
(
self
):
super
().
clear
()
if
self
.
_force_scale
is
not
None
:
self
.
_force_scale
.
invalidate
()
if
self
.
_force_period
is
not
None
:
self
.
_force_period
.
invalidate
()
def
is_valid
(
self
):
return
self
.
has_force_scale
()
and
self
.
has_force_period
()
def
has_force_scale
(
self
):
return
self
.
_force_scale
is
not
None
def
get_force_scale
(
self
):
if
self
.
_force_scale
is
None
:
self
.
_force_scale
=
SEScalar0To1
()
return
self
.
_force_scale
def
has_force_period
(
self
):
return
self
.
_force_period
is
not
None
def
get_force_period
(
self
):
if
self
.
_force_period
is
None
:
self
.
_force_period
=
SEScalarTime
()
return
self
.
_force_period
def
__repr__
(
self
):
return
(
"Chest Compression
\n
"
" Force Scale: {}
\n
"
" Force Period: {}"
).
format
(
self
.
_force_scale
,
self
.
_force_period
)
class
SEChestOcclusiveDressing
(
SEPatientAction
):
__slots__
=
[
"_state"
,
"_side"
]
...
...
@@ -496,6 +560,46 @@ class SEForcedExhale(AnyConsciousRespirationCommand):
" Release Period: {}"
).
format
(
self
.
_expiratory_capacity_fraction
,
self
.
_exhale_period
,
self
.
_hold_period
,
self
.
_release_period
)
class
SEConsumeNutrients
(
SEPatientAction
):
__slots__
=
[
"_nutrition_file"
,
"_nutrition"
]
def
__init__
(
self
):
super
().
__init__
()
self
.
_nutrition_file
=
None
self
.
_nutrition
=
None
def
clear
(
self
):
self
.
_nutrition_file
=
None
self
.
_nutrition
=
None
def
copy
(
self
,
src
):
if
not
isinstance
(
SEConsumeNutrients
,
src
):
raise
Exception
(
"Provided argument must be a SEConsumeNutrients"
)
self
.
clear
()
self
.
_nutrition_file
=
src
.
_nutrition_file
self
.
_nutrition
.
copy
(
src
.
_nutrition
)
def
is_valid
(
self
):
return
self
.
has_nutrition
()
or
self
.
has_nutrition_file
()
def
is_active
(
self
):
return
True
;
def
has_nutrition_file
(
self
):
return
self
.
_nutrition_file
is
not
None
def
get_nutrition_file
(
self
):
return
self
.
_nutrition_file
def
set_nutrition_file
(
self
,
filename
:
str
):
self
.
_nutrition_file
=
filename
def
has_nutrition
(
self
):
return
self
.
_nutrition
is
not
None
def
get_nutrition
(
self
):
if
self
.
_nutrition
is
None
:
self
.
_nutrition
=
SENutrition
()
return
self
.
_nutrition
class
SEDyspnea
(
SEPatientAction
):
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -516,6 +620,7 @@ class SEDyspnea(SEPatientAction):
if
self
.
_severity
is
None
:
self
.
_severity
=
SEScalar0To1
()
return
self
.
_severity
def
__repr__
(
self
):
return
(
"Dyspnea
\n
"
" Severity: {}"
).
format
(
self
.
_severity
)
...
...
@@ -1115,3 +1220,16 @@ class SETensionPneumothorax(SEPatientAction):
" Type: {}
\n
"
" Side: {}
\n
"
" Severity: {}"
).
format
(
self
.
_type
,
self
.
_side
,
self
.
_severity
)
class
SEUrinate
(
SEPatientAction
):
def
__init__
(
self
):
super
().
__init__
()
def
clear
(
self
):
super
().
clear
()
def
is_valid
(
self
):
return
True
def
__repr__
(
self
):
return
(
"Urinate
\n
"
)
\ No newline at end of file
src/python/pulse/howto/HowTo_CardiacArrest_CPR.py
0 → 100644
View file @
e2a4315f
# Distributed under the Apache License, Version 2.0.
# See accompanying NOTICE file for details.
from
pulse.cdm.patient_actions
import
SECardiacArrest
,
eSwitch
,
\
SEChestCompressionForceScale
,
SEChestCompressionForce
from
pulse.cdm.scalars
import
ForceUnit
,
TimeUnit
from
pulse.cpm.PulsePhysiologyEngine
import
PulsePhysiologyEngine
def
HowTo_CardiacArrest
():
pulse
=
PulsePhysiologyEngine
()
pulse
.
set_log_filename
(
"./test_results/pypulse_cardiac_arrest.log"
)
pulse
.
log_to_console
(
True
)
# NOTE: No data requests are being provided, so Pulse will return the default vitals data
if
not
pulse
.
serialize_from_file
(
"./states/Soldier@0s.pbb"
,
None
):
print
(
"Unable to load initial state file"
)
return
# Get some data from the engine
results
=
pulse
.
pull_data
()
print
(
results
)
arrest
=
SECardiacArrest
()
arrest
.
set_comment
(
"Patient experiences cardiac arrest"
)
arrest
.
set_state
(
eSwitch
.
On
)
pulse
.
process_action
(
arrest
)
# Advance some time and print out the vitals
pulse
.
advance_time_s
(
10
)
results
=
pulse
.
pull_data
()
print
(
results
)
# If you are using a sensor, you can directly pass over a force
# You should pass the sensor readings over at a decent rate continuously
cpr_force
=
SEChestCompressionForce
()
cpr_force
.
set_comment
(
"Press and hold the chest"
)
cpr_force
.
get_force
().
set_value
(
400
,
ForceUnit
.
N
)
pulse
.
process_action
(
cpr_force
)
pulse
.
advance_time_s
(
1
)
results
=
pulse
.
pull_data
()
print
(
results
)
cpr_force
.
set_comment
(
"Stop pressing"
)
cpr_force
.
get_force
().
set_value
(
0
,
ForceUnit
.
N
)
pulse
.
process_action
(
cpr_force
)
# If you are in software, you can pass in a scaled force value for a time period
cpr_scale
=
SEChestCompressionForceScale
()
cpr_scale
.
set_comment
(
"Press and hold the chest"
)
cpr_scale
.
get_force_scale
().
set_value
(
0.8
)
# Pretty hard!
cpr_scale
.
get_force_period
().
set_value
(
1
,
TimeUnit
.
s
)
pulse
.
process_action
(
cpr_scale
)
pulse
.
advance_time_s
(
10
)
results
=
pulse
.
pull_data
()
print
(
results
)
HowTo_CardiacArrest
()
src/python/pulse/howto/HowTo_ConsumeNutrients.py
0 → 100644
View file @
e2a4315f
# Distributed under the Apache License, Version 2.0.
# See accompanying NOTICE file for details.
from
pulse.cdm.patient_actions
import
SEConsumeNutrients
from
pulse.cdm.scalars
import
MassUnit
,
MassPerTimeUnit
,
VolumeUnit
from
pulse.cpm.PulsePhysiologyEngine
import
PulsePhysiologyEngine
def
HowTo_ConsumeNutrients
():
pulse
=
PulsePhysiologyEngine
()
pulse
.
set_log_filename
(
"./test_results/pypulse_ConsumeNutrients.log"
)
pulse
.
log_to_console
(
True
)
# NOTE: No data requests are being provided, so Pulse will return the default vitals data
if
not
pulse
.
serialize_from_file
(
"./states/Soldier@0s.pbb"
,
None
):
print
(
"Unable to load initial state file"
)
return
# Get some data from the engine
results
=
pulse
.
pull_data
()