Skip to content

Commit

Permalink
Update cholesterol calculation for unit conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
samhq committed Jul 4, 2019
1 parent bddcce8 commit d5cb1df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
14 changes: 7 additions & 7 deletions contents/guideline_hearts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@
"from": 8.0,
"unit": "mmol/L"
},
"target": "< 90mg/dL (5 mmol/L)"
"target": "< 195mg/dL (5 mmol/L)"
}],
"code": "CHOL-REFER"
},
Expand All @@ -1056,7 +1056,7 @@
"from": 31,
"unit": "%"
},
"target": "<90mg/dL (5mmol/L)"
"target": "<195mg/dL (5mmol/L)"
}],
"code": "CHOL-VERY-HIGH-CVD-RISK"
},
Expand All @@ -1074,7 +1074,7 @@
"to": 7.9,
"unit": "mmol/L"
},
"target": "< 90mg/dL (5 mmol/L)"
"target": "< 195mg/dL (5 mmol/L)"
}],
"code": "CHOL-ELEVATED-WITH-HIGH-CVD-RISK"
},
Expand All @@ -1087,7 +1087,7 @@
"to": 20,
"unit": "%"
},
"target": "< 90mg/dL (5 mmol/L)"
"target": "< 195mg/dL (5 mmol/L)"
}],
"code": "CHOL-MOD-CVD-RISK"
},
Expand All @@ -1100,7 +1100,7 @@
"to": 10,
"unit": "%"
},
"target": "Below 90mg/dL (5 mmol/L)"
"target": "Below 195mg/dL (5 mmol/L)"
}],
"code": "CHOL-LOW-CVD-RISK"
},
Expand All @@ -1112,14 +1112,14 @@
"to": 1,
"unit": "%"
},
"target": "Below 90mg/dL (5 mmol/L)"
"target": "Below 195mg/dL (5 mmol/L)"
},
{
"range": {
"to": 8.0,
"unit": "mmol/L"
},
"target": "Below 90mg/dL (5 mmol/L)"
"target": "Below 195mg/dL (5 mmol/L)"
}
],
"code": "CHOL-NO-CVD-RISK"
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/cholesterol.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CholesterolGuidelines []CholesterolGuideline

// Process function
func (b *CholesterolGuidelines) Process(cvd, age, chol float64, cholUnit, cholType string, medications map[string]bool) (Response, error) {
cholesterol := tools.CalculateMMOLValue(chol, cholUnit)
cholesterol := tools.CalculateCholMMOLValue(chol, cholUnit)

code := ""
value := fmt.Sprintf("%.1f%s", chol, cholUnit)
Expand Down Expand Up @@ -81,10 +81,10 @@ func (b *CholesterolGuidelines) Process(cvd, age, chol float64, cholUnit, cholTy

if c.Range != nil {
if c.Range.From != nil {
cholFrom = tools.CalculateMMOLValue(*c.Range.From, *c.Range.Unit)
cholFrom = tools.CalculateCholMMOLValue(*c.Range.From, *c.Range.Unit)
}
if c.Range.To != nil {
cholTo = tools.CalculateMMOLValue(*c.Range.To, *c.Range.Unit)
cholTo = tools.CalculateCholMMOLValue(*c.Range.To, *c.Range.Unit)
}
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/tools/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func CalculateMMOLValue(value float64, unit string) float64 {
return value
}

// CalculateCholMMOLValue to convert value into mmol/L
func CalculateCholMMOLValue(value float64, unit string) float64 {
if strings.ToLower(unit) == "mg/dl" {
return value / 38.67
}

return value
}

// CalculateLength to convert units
func CalculateLength(value float64, unit, toUnit string) float64 {
result := value
Expand Down

0 comments on commit d5cb1df

Please sign in to comment.