Skip to content

Commit

Permalink
Update referral section
Browse files Browse the repository at this point in the history
  • Loading branch information
samhq committed Jan 8, 2019
1 parent 962f750 commit ef7114d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 28 deletions.
89 changes: 64 additions & 25 deletions pkg/algorithms/hearts/hearts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"github.com/fatih/structs"
"github.com/pkg/errors"

"github.com/openhealthalgorithms/service/pkg/datastructure"
ds "github.com/openhealthalgorithms/service/pkg/datastructure"
"github.com/openhealthalgorithms/service/pkg/engine"
"github.com/openhealthalgorithms/service/pkg/tools"
"github.com/openhealthalgorithms/service/pkg/types"
)

// Data holds results of plugin.
type Data struct {
Algorithm datastructure.Result `json:"algorithm"`
Errors []string `json:"errors"`
Algorithm ds.Result `json:"algorithm"`
Errors []string `json:"errors"`
}

// New returns a ready to use instance of the plugin.
Expand Down Expand Up @@ -148,12 +148,12 @@ func (d *Data) get(ctx context.Context) error {
// fmt.Println(string(res2C))
// fmt.Printf("%+v\n", p)

assessment := datastructure.NewResult("Hearts Algorithm")
lifestyleActions := make([]datastructure.Action, 0)
medicationsActions := make([]datastructure.Action, 0)
followupActions := make([]datastructure.Action, 0)
assessment := ds.NewResult("Hearts Algorithm")
lifestyleActions := make([]ds.Action, 0)
medicationsActions := make([]ds.Action, 0)
followupActions := make([]ds.Action, 0)

var res datastructure.Assessment
var res ds.Assessment
errs := make([]string, 0)

lifestyleGrading := 0
Expand All @@ -162,7 +162,7 @@ func (d *Data) get(ctx context.Context) error {

referral := false
referralUrgent := false
referralReasons := make([]string, 0)
referralReasons := make([]ds.ReferralsResponse, 0)

// Smoking
sm, err := engineGuide.Body.Lifestyle.Smoking.Process(p.Smoker.CurrentSmoker, p.Smoker.ExSmoker, p.Smoker.QuitWithinYear)
Expand All @@ -174,10 +174,13 @@ func (d *Data) get(ctx context.Context) error {
lifestyleGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "smoking"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -191,10 +194,13 @@ func (d *Data) get(ctx context.Context) error {
lifestyleGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "alcohol"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -208,10 +214,13 @@ func (d *Data) get(ctx context.Context) error {
lifestyleGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "physical activity"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -227,10 +236,13 @@ func (d *Data) get(ctx context.Context) error {
dietGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "fruit"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -244,10 +256,13 @@ func (d *Data) get(ctx context.Context) error {
dietGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "vegetable"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -261,10 +276,13 @@ func (d *Data) get(ctx context.Context) error {
bodyCompositionGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "bmi"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -278,10 +296,13 @@ func (d *Data) get(ctx context.Context) error {
bodyCompositionGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "waist circumference"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -295,10 +316,13 @@ func (d *Data) get(ctx context.Context) error {
bodyCompositionGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "whr"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -312,10 +336,13 @@ func (d *Data) get(ctx context.Context) error {
bodyCompositionGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "body fat"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -339,10 +366,13 @@ func (d *Data) get(ctx context.Context) error {
assessment.AssessmentsAttributes.Diabetes = res
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "diabetes"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -359,10 +389,13 @@ func (d *Data) get(ctx context.Context) error {
assessment.AssessmentsAttributes.BloodPressure = res
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "blood pressure"
referralReasons = append(referralReasons, ref)
}
}

Expand All @@ -375,10 +408,13 @@ func (d *Data) get(ctx context.Context) error {
assessment.AssessmentsAttributes.CVD = res
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "cvd"
referralReasons = append(referralReasons, ref)
}
} else {
errs = append(errs, err.Error())
Expand Down Expand Up @@ -409,10 +445,13 @@ func (d *Data) get(ctx context.Context) error {
cholesterolGrading += res.Grading
if res.Refer != "no" {
referral = referral || true
ref := ds.ReferralsResponse{}
if res.Refer == "urgent" {
referralUrgent = referralUrgent || true
ref.RUrgent = true
}
referralReasons = append(referralReasons, res.Eval)
ref.RType = "total cholesterol"
referralReasons = append(referralReasons, ref)
}
}
}
Expand Down Expand Up @@ -489,8 +528,8 @@ func (d *Data) get(ctx context.Context) error {
}

// GetResults from response
func GetResults(response engine.Response, contents engine.Contents, advices datastructure.Actions) (datastructure.Assessment, datastructure.Actions) {
assessment := datastructure.Assessment{}
func GetResults(response engine.Response, contents engine.Contents, advices ds.Actions) (ds.Assessment, ds.Actions) {
assessment := ds.Assessment{}

assessment.Code = response.Code
assessment.Value = response.Value
Expand All @@ -503,7 +542,7 @@ func GetResults(response engine.Response, contents engine.Contents, advices data
assessment.Refer = *output.Refer
assessment.Grading = *output.Grading

advice := datastructure.Action{}
advice := ds.Action{}
advice.Goal = *output.Eval
advice.Messages = append(advice.Messages, *output.Message)
advices = append(advices, advice)
Expand Down
12 changes: 9 additions & 3 deletions pkg/datastructure/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,15 @@ type Action struct {

// AssessmentReferral object
type AssessmentReferral struct {
Refer bool `structs:"refer" json:"refer"`
Urgent bool `structs:"urgent" json:"urgent"`
Reasons []string `structs:"reasons" json:"reasons"`
Refer bool `structs:"refer" json:"refer"`
Urgent bool `structs:"urgent" json:"urgent"`
Reasons []ReferralsResponse `structs:"reasons" json:"reasons"`
}

// ReferralsResponse object
type ReferralsResponse struct {
RType string `structs:"type" json:"type"`
RUrgent bool `structs:"urgent" json:"urgent"`
}

// NewResult returns a Result object with meta information
Expand Down

0 comments on commit ef7114d

Please sign in to comment.