-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmhg2lunu
executable file
·135 lines (131 loc) · 3.86 KB
/
mmhg2lunu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# This script's framework was created using makescript
# version v1.0.0, dated 2019-06-01
# Makescript and its accompanying scripts are copyrighted
# by Aetesaki (c) 2018
#
# mmhg2lunu (c) 2019 aetesaki
#
# ##################################################
# HISTORY:
# ##################################################
#
# * 2019-07-17 - v0.0.0 - First Creation
# * 2019-07-17 - v0.0.1 - added piping
# * 2019-07-17 - v1.0.0 - release version
# * 2019-07-18 - v1.0.1 - error corrections
# * 2019-08-10 - v1.0.2 - a lunu is 3mm
#
# ##################################################
# Initializing constants and variables
# ##################################################
# Setting constants
version="v1.0.2" # Sets version variable
lastEdited="2019-08-10" # Sets last edited variable
[ ! -t 0 ] && pipe=$(cat) # if stdin is open dump stdin to $pipe
# Declaring variables
declare systolic asystolic temp
# Declare all variables to be used in the script
# ##################################################
# short help function
# ##################################################
shorthelp() {
# Edit as required
cat << EOF
Usage: mmhg2lunu systolic/asystolic
mmhg2lunu --help
mmhg2lunu --version"
EOF
}
# ##################################################
# no arguments gives short help
# ##################################################
if [ "$#" == "0" ]; then
# check if $pipe is empty
if [ -z "$pipe" ]; then
# display shorthelp and exit
shorthelp
exit 1
else
# else set arguments to $pipe
set -- "$pipe"
fi
fi
# ##################################################
# -- help
# ##################################################
if [ "$1" == "--help" ]; then
shorthelp
# Write options and explanations
cat << EOF
--help Displays this text and exit.
--version Displays the version of the script and exit.
EOF
# Write information on arguments afterwards
# Write examples as required
exit 0
fi
# ##################################################
# -- version
# ##################################################
if [ "$1" == "--version" ]; then
cat << EOF
mmhg2lunu ${version}, dated ${lastEdited}
(c) 2019 aetesaki
EOF
exit 0
fi
# ##################################################
# Main section
# ##################################################
# Write your script here
# Check for valid argument
if [[ "$1" != *"/"* ]]; then
echo "No systolic/asystolic separator" >&2
exit 1
fi
# Grab the parts of the bloodpressure measurement
systolic=$(echo "$1" | cut -d"/" -f1)
asystolic=$(echo "$1" | cut -d"/" -f2)
# Check for valid systolis value
if ! [[ $systolic =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then
echo "Systolic measurement is not a number" >&2
exit 1
fi
# check for valid asystolic value
if ! [[ $asystolic =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then
echo "Asystolic measurement is not a number" >&2
exit 1
fi
# convert systolic
# convert systolic to testable value
temp=$(awk "BEGIN {print ($systolic*100)}")
# if systolic is above baseline
if [[ $temp -gt 12500 ]]; then
# then compute hypertention
systolic=$(awk "BEGIN {printf \"%.2f\n\", ($systolic-125)/3}")
# else if systolic is below baseline
elif [[ $temp -lt 11000 ]]; then
# then compute hypotention
systolic=$(awk "BEGIN {printf \"%.2f\n\", ($systolic-110)/3}")
# else use baseline
else
systolic=0
fi
# convert asystolic
# convert systolic to testable value
temp=$(awk "BEGIN {print ($asystolic*100)}")
# if asystolic is above baseline
if [[ $temp -gt 8500 ]]; then
# then compute hypotention
asystolic=$(awk "BEGIN {printf \"%.2f\n\", ($asystolic-85)/3}")
# else if asystolic is below baseline
elif [[ $temp -lt 7500 ]]; then
# then compute hypotention
asystolic=$(awk "BEGIN {printf \"%.2f\n\", ($asystolic-75)/3}")
# else use baseline
else
asystolic=0
fi
# export bloodpressure in lunu
echo "$systolic/$asystolic"