Upstream sync
This commit is contained in:
@@ -6,6 +6,10 @@ import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/third/eligibility/bcbsi"
|
||||
@@ -22,6 +26,10 @@ import (
|
||||
"googlemaps.github.io/maps"
|
||||
)
|
||||
|
||||
const (
|
||||
zipcodeTrimLength = 5
|
||||
)
|
||||
|
||||
var (
|
||||
instance *controller
|
||||
once sync.Once
|
||||
@@ -395,15 +403,52 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
||||
eligibility.ServiceInfo.DateOfService = time.Now()
|
||||
eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"}
|
||||
|
||||
/*
|
||||
resp, err := c.bcbsi.BXE.Get271(eligibility)
|
||||
if err != nil {
|
||||
fmt.Println("Eligibility Not Found or Error: ", err.Error())
|
||||
return routeutils.ResponseAPINotEligibleError(ctx)
|
||||
}
|
||||
*/
|
||||
|
||||
//This part is emulating eligibility check for testing purposes
|
||||
client := &http.Client{}
|
||||
eligibilityJson, err := json.Marshal(eligibility)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
req, _ := http.NewRequest("POST", c.cfg.Eligibility.Url, bytes.NewBuffer(eligibilityJson))
|
||||
req.Header.Add("App", c.cfg.HTTP.Auth.AppKey)
|
||||
req.Header.Add("Token", ctx.Request().Header.Get("Token"))
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 300 {
|
||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
|
||||
}
|
||||
|
||||
eligibilityResponse := viewmodel.Interchange271{}
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
err = decoder.Decode(&eligibilityResponse)
|
||||
if err != nil {
|
||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
|
||||
}
|
||||
//================================================================
|
||||
|
||||
if len(eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030) < 1 {
|
||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Cannot check eligibility")
|
||||
}
|
||||
|
||||
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
|
||||
//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
|
||||
header := eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N3_0950
|
||||
body := eligibilityResponse.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N4_0960
|
||||
|
||||
address.AddressTypeName = "Home"
|
||||
address.AddressType = "home"
|
||||
@@ -412,21 +457,22 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
||||
address.CreatedUserUUID = authUser.ID
|
||||
address.User = user
|
||||
|
||||
zipCodeFromAddress := body.N403
|
||||
zipCodeObj, err := c.svc.Zipcodes.GetByParticipatingZipcode(zipCodeFromAddress)
|
||||
cleanZipcode := strings.TrimSpace(body.N403)
|
||||
trimmedZipcode := cleanZipcode
|
||||
if len(cleanZipcode) > zipcodeTrimLength {
|
||||
trimmedZipcode = cleanZipcode[:zipcodeTrimLength]
|
||||
}
|
||||
|
||||
_, err = c.svc.Zipcodes.GetByParticipatingZipcode(trimmedZipcode)
|
||||
|
||||
if err != nil{
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Member's Home zipcode, " + trimmedZipcode + ", is not currently eligible for participation in this program")
|
||||
}
|
||||
|
||||
if !zipCodeObj.Participating {
|
||||
return routeutils.ResponseAPINotEligibleWithMessageError(ctx, "Member's Home zipcode, " + zipCodeFromAddress + ", is not currently eligible for participation in this program")
|
||||
}
|
||||
|
||||
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)
|
||||
return routeutils.HandleAPIError(ctx,err)
|
||||
}
|
||||
|
||||
r := &maps.GeocodingRequest{
|
||||
@@ -436,7 +482,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
||||
result, err := googleMapsAPI.Geocode(context.Background(), r)
|
||||
if err != nil {
|
||||
fmt.Println("Error to instantiate googles api: ", err.Error())
|
||||
return routeutils.ResponseAPINotEligibleError(ctx)
|
||||
return routeutils.HandleAPIError(ctx,err)
|
||||
}
|
||||
|
||||
if len(result) > 0 {
|
||||
@@ -446,7 +492,7 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
||||
_, err := c.svc.Users.SaveAddress(address)
|
||||
if err != nil {
|
||||
fmt.Println("Error to save address: ", err.Error())
|
||||
return routeutils.ResponseAPINotEligibleError(ctx)
|
||||
return routeutils.HandleAPIError(ctx,err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user