diff --git a/go.mod b/go.mod index b51ba68..0f2ec14 100644 --- a/go.mod +++ b/go.mod @@ -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 ) @@ -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 diff --git a/go.sum b/go.sum index 6cca69b..b74da34 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..90600b0 --- /dev/null +++ b/utils.go @@ -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 + } +} diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..fe1d173 --- /dev/null +++ b/utils_test.go @@ -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) + } + }) + } +}