Upstream sync

This commit is contained in:
Senad Uka
2018-05-21 18:47:13 +02:00
parent 157b23da3c
commit 39c614fb98
5 changed files with 74 additions and 14 deletions

View File

@@ -80,4 +80,7 @@ secret = "hK4Yc9jtBrxaZTr4UU2VsfX9"
[blue365]
url = "https://api-cloud.bcbs.com/blue365deals-stg/v1/validatePrefix/"
key = "jcn5xjxvarc96rtjxp25dctj"
secret = "6XdEusG2w2PWWXsfXVyweQnY"
secret = "6XdEusG2w2PWWXsfXVyweQnY"
[eligibility]
url = "https://portal-api.dev.bcbsinstitute.com/v1/nemt/eligibility"

View File

@@ -81,3 +81,6 @@ secret = "vFhNeWE8JdJpbDZQtcm6AHjX"
url = "https://api-cloud.bcbs.com/blue365deals-stg/v1/validatePrefix/"
key = "jcn5xjxvarc96rtjxp25dctj"
secret = "6XdEusG2w2PWWXsfXVyweQnY"
[eligibility]
url = "https://portal-api.bcbsinstitute.com/v1/nemt/eligibility"

View File

@@ -24,7 +24,7 @@ func (c *zipcodeRepo) getQuery() string {
a.participating_zip_code_id,
a.participating_zip_code_uuid,
a.zipcode,
a.participating
(IFNULL(a.participating, b'0') = b'1') participating
FROM
tab_participating_zip_code a `
)

View File

@@ -25,6 +25,7 @@ type Config struct {
Blue365 Blue365Config
Email EmailConfig
GoogleShortener GoogleShortenerConfig
Eligibility EligibilityConfig
}
// AppConfig represents the configuration values about the application.
@@ -137,6 +138,10 @@ type GoogleShortenerConfig struct {
SecretKey string
}
type EligibilityConfig struct {
Url string
}
// Read returns the configuration values,
// based on the configuration files and environment variables.
func Read() (*Config, error) {
@@ -238,6 +243,9 @@ func Read() (*Config, error) {
ClientID: viper.GetString("google-shortener.client-id"),
SecretKey: viper.GetString("google-shortener.secret-key"),
},
Eligibility : EligibilityConfig{
Url : viper.GetString("eligibility.url"),
},
}, nil
}

View File

@@ -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)
}
}