Skip to content

Commit

Permalink
Merge pull request #14 from openhealthalgorithms/OHAS-4-who-lookup
Browse files Browse the repository at this point in the history
Ohas 4 who lookup
  • Loading branch information
samhq committed May 17, 2021
2 parents b0f2cb2 + 360d06f commit dc9433d
Show file tree
Hide file tree
Showing 24 changed files with 18,791 additions and 1,922 deletions.
38 changes: 34 additions & 4 deletions actions/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"strings"

Expand All @@ -24,13 +25,14 @@ import (
)

var (
dbFile = filepath.Join(tools.GetCurrentDirectory(), "logs.db")
sqlite *database.SqliteDb
dbFile = filepath.Join(tools.GetCurrentDirectory(), "logs.db")
sqlite *database.SqliteDb
currentSettings config.Settings
)

func load(c echo.Context) error {
var err error
currentSettings := c.Get("current_config").(config.Settings)
currentSettings = c.Get("current_config").(config.Settings)
dbFile = currentSettings.LogFile
sqlite, err = database.InitDb(dbFile)
if err != nil {
Expand All @@ -56,6 +58,27 @@ func AlgorithmHandler(c echo.Context) error {
if *o.Config.Algorithm != "hearts" {
return ErrorResponse(c, errors.New("algorithm not found"), 404)
}

if o.Config.RiskModelVersion == nil {
rmVersion := "who_ish_2007"
o.Config.RiskModelVersion = &rmVersion
}

if o.Config.LabBased == nil {
lab := false
o.Config.LabBased = &lab
}

colorChartPath := filepath.Join(currentSettings.ColorChart, *o.Config.RiskModel, *o.Config.RiskModelVersion, "charts.json")
if _, e := os.Stat(colorChartPath); e != nil {
return ErrorResponse(c, e, 400)
}

countriesPath := filepath.Join(currentSettings.ColorChart, *o.Config.RiskModel, *o.Config.RiskModelVersion, "countries.json")
if _, e := os.Stat(countriesPath); e != nil {
return ErrorResponse(c, e, 400)
}

guideFiles, err := tools.ParseGuidesFiles(c)
if err != nil {
return ErrorResponse(c, err, 500)
Expand All @@ -73,7 +96,7 @@ func AlgorithmHandler(c echo.Context) error {
GoalContent: *glc,
}

hs, hg, hr, hd, hrs, err := hearts.Process(*o)
hs, hg, hr, hd, hrs, err := hearts.Process(*o, colorChartPath, countriesPath)
if err != nil {
return ErrorResponse(c, err, 500)
}
Expand All @@ -84,11 +107,17 @@ func AlgorithmHandler(c echo.Context) error {
output.Referrals = hr
output.Errors = make([]string, 0)
output.Errors = append(output.Errors, hrs...)
output.Meta.Debug = false
output.Meta.CarePlan = false
output.Meta.RiskModelVersion = *o.Config.RiskModelVersion
output.Meta.LabBased = *o.Config.LabBased

if o.Config.Debug != nil && *o.Config.Debug {
output.Debug = make(map[string]interface{})
for k, v := range hd {
output.Debug[k] = v
}
output.Meta.Debug = true
}

if o.Config.CarePlan != nil && *o.Config.CarePlan {
Expand Down Expand Up @@ -171,6 +200,7 @@ func AlgorithmHandler(c echo.Context) error {
CarePlanOutputActivities: outActivities,
}
output.CarePlan = &carePlan
output.Meta.CarePlan = true
}

tx, err := sqlite.DB.Begin()
Expand Down
52 changes: 44 additions & 8 deletions algorithms/hearts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Hearts struct {
}

// Process function
func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORRReferrals, map[string]interface{}, []string, error) {
func (h *Hearts) Process(o m.OHARequest, colorChartPath, countriesPath string) (*m.ORRAssessments, []m.ORRGoal, *m.ORRReferrals, map[string]interface{}, []string, error) {
var err error
assessments := m.NewORRAssessments()
goals := make([]m.ORRGoal, 0)
Expand Down Expand Up @@ -404,9 +404,9 @@ func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORR
}

// Blood Pressure
diab = false
if diabetes.Value == "diabetes" {
diab = true
diab = true
if diabetes.Code == "DM-NONE" || diabetes.Code == "DM-PRE-DIABETES" {
diab = false
}
bp, err := h.Guideline.Body.BloodPressure.Process(diab, sbp, dbp, age, medications)
if err != nil {
Expand All @@ -431,9 +431,9 @@ func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORR
}
}

countries := tools.Countries()
countries := tools.Countries(countriesPath)
region := ""
if code, ok := countries[*o.Params.Demographics.BirthCountryCode]; ok {
if code, ok := countries.Countries[*o.Params.Demographics.BirthCountryCode]; ok {
if code.Region != "#N/A" {
region = code.Region
} else {
Expand All @@ -442,11 +442,24 @@ func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORR

return assessments, goals, referrals, debug, errs, err
}
} else {
errr := errors.New("invalid country/region")
errs = append(errs, errr.Error())

return assessments, goals, referrals, debug, errs, err
}

// CVD
bmiValue, err := strconv.ParseFloat(bmi.Value, 64)
if err != nil {
errr := errors.New("invalid BMI value")
errs = append(errs, errr.Error())
return assessments, goals, referrals, debug, errs, err
}

cvdScore := ""
cvd, dbg, err := h.Guideline.Body.CVD.Guidelines.Process(
*o.Config.RiskModelVersion,
conditions,
age,
*h.Guideline.Body.CVD.PreProcessing,
Expand All @@ -459,10 +472,13 @@ func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORR
diab,
cSm,
debugInputValue,
colorChartPath,
*o.Config.LabBased,
bmiValue,
)
if err == nil {
cvdScore = cvd.Value
res := GetResults(cvd, *h.GuidelineContent.Body.Contents)
res := GetResultWithVersion(cvd, *h.GuidelineContent.Body.Contents, *o.Config.RiskModelVersion)
assessments.CVD = &res
if res.Refer != nil && *res.Refer != "no" {
referral = referral || true
Expand Down Expand Up @@ -614,7 +630,7 @@ func (h *Hearts) Process(o m.OHARequest) (*m.ORRAssessments, []m.ORRGoal, *m.ORR
if assessments.Cholesterol != nil && assessments.Cholesterol.Components.TChol != nil {
lTChol = *assessments.Cholesterol.Components.TChol.Code
}
if assessments.CVD != nil {
if assessments.CVD != nil && assessments.CVD.Code != nil {
lCVD = *assessments.CVD.Code
}

Expand Down Expand Up @@ -648,3 +664,23 @@ func GetResults(response a.Response, contents a.Contents) m.ORRAssessment {

return assessment
}

// GetResultWithVersion from response
func GetResultWithVersion(response a.Response, contents a.Contents, version string) m.ORRAssessment {
assessment := m.ORRAssessment{}

code := response.Code + "-" + strings.ToUpper(version)

if output, ok := contents[code]; ok {
assessment.Code = &response.Code
assessment.Value = &response.Value
assessment.Target = &response.Target

assessment.Eval = output.Eval
assessment.TFL = output.TFL
assessment.Message = output.Message
assessment.Refer = output.Refer
}

return assessment
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func configSettings(v *viper.Viper) Settings {
settings.CareplanConditionsFile = filepath.Join(v.GetString("directories.careplan_path"), v.GetString("files.careplan_file"))
settings.CareplanContentFile = filepath.Join(v.GetString("directories.careplan_path"), v.GetString("files.careplan_content_file"))
settings.LogFile = filepath.Join(v.GetString("directories.log_file_path"), v.GetString("files.log_file"))
settings.ColorChart = v.GetString("directories.guideline_path")

cloudEnable := v.GetBool("cloud.cloud_enable")
if cloudEnable {
Expand Down
1 change: 1 addition & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Settings struct {
CareplanConditionsFile string
CareplanContentFile string
LogFile string
ColorChart string
CloudEnable bool
CloudBucket string
CloudConfigFile string
Expand Down
Loading

0 comments on commit dc9433d

Please sign in to comment.