Display Isolated Systolic Hypertension
authorMikael Berthe <mikael@lilotux.net>
Wed, 15 Mar 2017 21:17:46 +0100
changeset 23 7be02d3facf4
parent 22 853f58e76ba5
child 24 260a31dbfda5
Display Isolated Systolic Hypertension
gobm65.go
--- a/gobm65.go	Wed Mar 15 20:41:49 2017 +0100
+++ b/gobm65.go	Wed Mar 15 21:17:46 2017 +0100
@@ -91,9 +91,15 @@
 	BPOptimal              = iota // < 120,80:  Optimal
 	BPNormal                      // < 130,85:  Normal
 	BPHighNormal                  // < 140,90:  High-Normal
-	BPMildHypertension            // < 160,100: Mild Hypertension
-	BPModerateHypertension        // < 180,110: Moderate Hypertension
-	BPSevereHypertension          // >=180,110: Severe Hypertension
+	BPMildHypertension            // < 160,100: Grade 1 Mild Hypertension
+	BPModerateHypertension        // < 180,110: Grade 2 Moderate Hypertension
+	BPSevereHypertension          // >=180,110: Grade 3 Severe Hypertension
+)
+
+// Special cases that do not fit in the previous classification
+const (
+	// >=140, <90: Isolated Systolic Hypertension
+	IsolatedSystolicHypertension = 1
 )
 
 // WHOPressureClassification contains the World Health Organization blood
@@ -107,6 +113,12 @@
 	"Severe Hypertension",
 }
 
+// WHOPressureFlag is an array of special cases
+var WHOPressureFlag = []string{
+	"",
+	"Isolated Systolic Hypertension",
+}
+
 func getData(s io.ReadWriteCloser, buf []byte, size int) (int, error) {
 	t := 0
 	b := buf
@@ -447,36 +459,50 @@
 	return dev, nil
 }
 
-func (m measurement) WHOClass() int {
+func (m measurement) WHOClass() (int, int) {
+	flag := 0
+
+	if m.Systolic >= 140 && m.Diastolic < 90 {
+		flag = IsolatedSystolicHypertension
+	}
+
 	switch {
 	case m.Systolic < 120 && m.Diastolic < 80:
-		return BPOptimal
+		return BPOptimal, flag
 	case m.Systolic < 130 && m.Diastolic < 85:
-		return BPNormal
+		return BPNormal, flag
 	case m.Systolic < 140 && m.Diastolic < 90:
-		return BPHighNormal
+		return BPHighNormal, flag
 	case m.Systolic < 160 && m.Diastolic < 100:
-		return BPMildHypertension
+		return BPMildHypertension, flag
 	case m.Systolic < 180 && m.Diastolic < 110:
-		return BPModerateHypertension
+		return BPModerateHypertension, flag
 	}
-	return BPSevereHypertension
+	return BPSevereHypertension, flag
 }
 
 func (m measurement) WHOClassString() string {
-	return WHOPressureClassification[m.WHOClass()]
+	flagStr := ""
+	class, flag := m.WHOClass()
+	if flag == IsolatedSystolicHypertension {
+		flagStr = " (" + WHOPressureFlag[flag] + ")"
+	}
+	return WHOPressureClassification[class] + flagStr
 }
 
 func displayWHOClassStats(items []measurement) {
-	sum := 0
+	sum := 0.0
 	classes := make(map[int]int)
 	for _, m := range items {
-		s := m.WHOClass()
+		s, flag := m.WHOClass()
 		classes[s]++
-		sum += s
+		sum += float64(s)
+		if flag == IsolatedSystolicHypertension {
+			sum += 0.5
+		}
 	}
 
-	avg := float64(sum) / float64(len(items))
+	avg := sum / float64(len(items))
 	fmt.Fprintf(os.Stderr, "Average WHO classification: %s (%.2f)\n",
 		WHOPressureClassification[int(0.5+avg)], avg)