diff --git a/server/router/routeutils/response.go b/server/router/routeutils/response.go index f4981ac..3903fae 100644 --- a/server/router/routeutils/response.go +++ b/server/router/routeutils/response.go @@ -92,6 +92,11 @@ func ResponseAPINotFoundError(c echo.Context) error { return ResponseAPIError(c, http.StatusNotFound, "Not Found", false) } +//ResponseAPINotEligible returns a standard API not eligible to the response +func ResponseAPINotEligibleError(c echo.Context) error { + return ResponseAPIError(c, http.StatusForbidden, "Eligibility Not Found or Error", false) +} + func ignoreDefaultWrappedErrors(c echo.Context, errorToHandle *errors.WrappedError, handler func(echo.Context, error) error) error { err := errorToHandle.GetOriginalError() diff --git a/server/router/usersroute/controller.go b/server/router/usersroute/controller.go index 06e8bb2..49079e3 100644 --- a/server/router/usersroute/controller.go +++ b/server/router/usersroute/controller.go @@ -332,6 +332,7 @@ func (c *controller) handleGetPortal(ctx echo.Context) error { } func (c *controller) handleMember(ctx echo.Context) error { + fmt.Println("\n\nHandle member\n\n") var user viewmodel.User if err := ctx.Bind(&user); err != nil { return routeutils.HandleAPIError(ctx, err) @@ -382,11 +383,6 @@ func (c *controller) handleMember(ctx echo.Context) error { } user.Profiles = append(user.Profiles, profile) - user, err = c.svc.Users.Create(user, authUser) - if err != nil { - return routeutils.HandleAPIError(ctx, err) - } - eligibility := viewmodel.Eligibility{} eligibility.Provider.ProviderNPI = "1699849786" eligibility.Provider.ProviderName = "LITHOLINK CORPORATION" @@ -400,44 +396,57 @@ func (c *controller) handleMember(ctx echo.Context) error { eligibility.ServiceInfo.DateOfService = time.Now() eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"} + fmt.Println("\n\nGet271\n\n") resp, err := c.bcbsi.BXE.Get271(eligibility) if err != nil { fmt.Println("Eligibility Not Found or Error: ", err.Error()) - } else { - address := viewmodel.Address{} - header := resp.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N3_0950 - body := resp.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N4_0960 + return routeutils.ResponseAPINotEligibleError(ctx) + } + + address := viewmodel.Address{} + header := resp.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N3_0950 + body := resp.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N4_0960 - address.AddressTypeName = "Home" - address.AddressType = "home" - address.Name = fmt.Sprintf("%s, %s", header.N301, body.N401) - address.Address = fmt.Sprintf("%s, %s", header.N301, body.N401) - address.CreatedUserUUID = authUser.ID - address.User = user + fmt.Println("\n\n",header.N301,"\n\n---\n",body.N401) + return routeutils.ResponseAPIAuthError(ctx, "STOPPED HERE INTENTIONALLY", false) - googleMapsAPI, err := maps.NewClient(maps.WithClientIDAndSignature("gme-bluecrossandblue1", "msqgD-jdqCyR0M_1u5C1HION5iI=")) + address.AddressTypeName = "Home" + address.AddressType = "home" + address.Name = fmt.Sprintf("%s, %s", header.N301, body.N401) + address.Address = fmt.Sprintf("%s, %s", header.N301, body.N401) + address.CreatedUserUUID = authUser.ID + address.User = user + + googleMapsAPI, err := maps.NewClient(maps.WithClientIDAndSignature("gme-bluecrossandblue1", "msqgD-jdqCyR0M_1u5C1HION5iI=")) + if err != nil { + fmt.Println("Error to instantiate googles api: ", err.Error()) + return routeutils.ResponseAPINotEligibleError(ctx) + } + + r := &maps.GeocodingRequest{ + Address: address.Address + " " + body.N402 + ", " + body.N403, + } + + result, err := googleMapsAPI.Geocode(context.Background(), r) + if err != nil { + fmt.Println("Error to instantiate googles api: ", err.Error()) + return routeutils.ResponseAPINotEligibleError(ctx) + } + + if len(result) > 0 { + address.Latitude = result[0].Geometry.Location.Lat + address.Longitude = result[0].Geometry.Location.Lng + + _, err := c.svc.Users.SaveAddress(address) if err != nil { - fmt.Println("Error to instantiate googles api: ", err.Error()) + fmt.Println("Error to save address: ", err.Error()) + return routeutils.ResponseAPINotEligibleError(ctx) } + } - r := &maps.GeocodingRequest{ - Address: address.Address + " " + body.N402 + ", " + body.N403, - } - - result, err := googleMapsAPI.Geocode(context.Background(), r) - if err != nil { - fmt.Println("Error to instantiate googles api: ", err.Error()) - } - - if len(result) > 0 { - address.Latitude = result[0].Geometry.Location.Lat - address.Longitude = result[0].Geometry.Location.Lng - - _, err := c.svc.Users.SaveAddress(address) - if err != nil { - fmt.Println("Error to save address: ", err.Error()) - } - } + user, err = c.svc.Users.Create(user, authUser) + if err != nil { + return routeutils.HandleAPIError(ctx, err) } return routeutils.ResponseAPIOK(ctx, user)