Skip to content

Commit

Permalink
feat: add gender conversion from enumutils to healthCRM gender types
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmuhia committed Sep 5, 2024
1 parent 42c4f2f commit 87e0d00
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module github.com/savannahghi/healthcrm

go 1.21
go 1.22.1

toolchain go1.23.0

require (
github.com/brianvoe/gofakeit v3.18.0+incompatible
github.com/jarcoal/httpmock v1.3.1
github.com/savannahghi/authutils v0.0.10
github.com/savannahghi/enumutils v0.0.6
github.com/savannahghi/serverutils v0.0.7
)

Expand Down Expand Up @@ -50,7 +53,6 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/savannahghi/enumutils v0.0.3 // indirect
github.com/savannahghi/errorcodeutil v0.0.5 // indirect
github.com/savannahghi/firebasetools v0.0.19 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/savannahghi/authutils v0.0.10 h1:FgrTsqZ+v9OMYVtB32zmfAnnR1iL9FIHNPRTgXLVJcc=
github.com/savannahghi/authutils v0.0.10/go.mod h1:msRa8zWvgf9r3/eZB+cV6Fol76C0pZ+IUt5YGb53dwc=
github.com/savannahghi/enumutils v0.0.3 h1:0IPGS/Q27B8mZw+0YOb1r7Au1MgJQldfuwYid3byUx0=
github.com/savannahghi/enumutils v0.0.3/go.mod h1:DDdjQBO1qyf5BxLzhTs1uN91drCIHH2Lvr8aLdJwu/o=
github.com/savannahghi/enumutils v0.0.6 h1:jRXk8my+mV+0CEwJASK7PCWIRsHl+OTCroWE/W6UKUk=
github.com/savannahghi/enumutils v0.0.6/go.mod h1:TVTHCb8JWHIUPiGWl233Ux/+8wy4prEzEmKzBQueh6Q=
github.com/savannahghi/errorcodeutil v0.0.5 h1:LrOLsEW1ZgA8PhJIXFCVOofm0hJFVOdd0+jvq3PGnRE=
github.com/savannahghi/errorcodeutil v0.0.5/go.mod h1:l2OVW1VE45rmEOLKQHnGnJ0gsSo60VCyErfm2Vfl4v0=
github.com/savannahghi/firebasetools v0.0.19 h1:NIsC2NRdk8DhgQ4J7dGd5jeV9fiHoYiBYw7DTVjwskQ=
Expand Down
26 changes: 26 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package healthcrm

import "github.com/savannahghi/enumutils"

// ConvertEnumutilsGenderToCRMGender converts an enumutils Gender to a CRM gender type
func ConvertEnumutilsGenderToCRMGender(gender enumutils.Gender) GenderType {
switch gender {
case enumutils.GenderMale:
return GenderTypeMale

case enumutils.GenderFemale:
return GenderTypeFemale

case enumutils.GenderAgender, enumutils.GenderBigender, enumutils.GenderGenderQueer,
enumutils.GenderNonBinary, enumutils.GenderTransGender, enumutils.GenderTwoSpirit, enumutils.GenderOther:
return GenderTypeOther

case enumutils.GenderPreferNotToSay:
return GenderTypeASKU

case enumutils.GenderUnknown:
return GenderTypeUNK
default:
return GenderTypeUNK
}
}
69 changes: 69 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package healthcrm

import (
"testing"

"github.com/savannahghi/enumutils"
)

func TestConvertEnumutilsGenderToCRMGender(t *testing.T) {
type args struct {
gender enumutils.Gender
}

tests := []struct {
name string
args args
want GenderType
}{
{
name: "success: get male gender",
args: args{
gender: enumutils.Gender("male"),
},
want: GenderTypeMale,
},
{
name: "success: get female gender",
args: args{
gender: enumutils.GenderFemale,
},
want: GenderTypeFemale,
},
{
name: "success: get other gender",
args: args{
gender: enumutils.GenderBigender,
},
want: GenderTypeOther,
},
{
name: "success: get ask but not unknown",
args: args{
gender: enumutils.GenderPreferNotToSay,
},
want: GenderTypeASKU,
},
{
name: "success: get unknown gender",
args: args{
gender: enumutils.GenderUnknown,
},
want: GenderTypeUNK,
},
{
name: "success: get unknown gender",
args: args{
gender: enumutils.Gender("invalide"),
},
want: GenderTypeUNK,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ConvertEnumutilsGenderToCRMGender(tt.args.gender); got != tt.want {
t.Errorf("ConvertEnumutilsGenderToCRMGender() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 87e0d00

Please sign in to comment.