Upstream sync
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
package visitroute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
b64 "encoding/base64"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/third/eligibility/bcbsi"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/tncservice"
|
||||
@@ -20,7 +17,6 @@ import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/server/validation"
|
||||
"github.com/labstack/echo"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"googlemaps.github.io/maps"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -81,103 +77,34 @@ func (c *controller) handleRide(ctx echo.Context) error {
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
visit.User.PhoneNumber = ride.User.PhoneNumber
|
||||
visit.User.Email = ride.User.Email
|
||||
visit.User.Consent = true
|
||||
|
||||
ride.Visit = visit
|
||||
|
||||
user, err := c.svc.Users.GetByMemberID(*visit.User.Member)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
user.PhoneNumber = ride.User.PhoneNumber
|
||||
user.Email = ride.User.Email
|
||||
|
||||
ride.Visit.User = user
|
||||
if ride.Visit.User.Type == nil {
|
||||
subscriber := "S"
|
||||
ride.Visit.User.Type = &subscriber
|
||||
}
|
||||
|
||||
var provider viewmodel.ProviderResp
|
||||
provider, err = c.svc.Provider.GetByUUID(ride.Visit.Provider.ProviderUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
visit.Provider = provider
|
||||
ride.Visit.Provider = provider
|
||||
|
||||
eligibility := viewmodel.Eligibility{}
|
||||
eligibility.Provider.ProviderNPI = provider.InternalID
|
||||
eligibility.Provider.ProviderName = provider.OrganizatioName
|
||||
eligibility.TrackingID = c.rangeIn(1000000, 9999999)
|
||||
eligibility.Subscriber.SubscriberID = *ride.Visit.User.Member
|
||||
eligibility.Subscriber.PatientType = *ride.Visit.User.Type
|
||||
eligibility.Subscriber.Name.First = ride.Visit.User.First
|
||||
eligibility.Subscriber.Name.Last = ride.Visit.User.Last
|
||||
eligibility.Subscriber.DemographicInfo.DateOfBirth = *ride.Visit.User.BirthDate
|
||||
eligibility.Subscriber.DemographicInfo.Gender = *ride.Visit.User.Gender
|
||||
loc, _ := time.LoadLocation("America/Chicago")
|
||||
eligibility.ServiceInfo.DateOfService = time.Now().In(loc)
|
||||
eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"}
|
||||
|
||||
resp271, err := c.bcbsi.BXE.Get271(eligibility)
|
||||
user, err := c.svc.Users.CheckAndCreateMember(ride.Visit.User, provider, authUser)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return routeutils.ResponseAPIValidationError(ctx, err.Error())
|
||||
}
|
||||
|
||||
address := viewmodel.Address{}
|
||||
header := resp271.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N3_0950
|
||||
body := resp271.Division.HealthCareEligibilityResponse.LoopHL0030[0].HL_0460[0].HL_0890[0].NM1_0920[0].N4_0960
|
||||
zipCode := strings.TrimSpace(body.N403)
|
||||
|
||||
address.AddressTypeName = "Home"
|
||||
address.AddressType = "home"
|
||||
address.Name = fmt.Sprintf("%s, %s", header.N301, body.N401)
|
||||
address.Address = fmt.Sprintf("%s, %s (%s)", header.N301, body.N401, zipCode)
|
||||
address.CreatedUserUUID = authUser.ID
|
||||
address.User = user
|
||||
address.Type = "provider"
|
||||
|
||||
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.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
r := &maps.GeocodingRequest{
|
||||
Address: address.Address + " " + body.N402 + ", " + zipCode,
|
||||
}
|
||||
|
||||
result, err := googleMapsAPI.Geocode(context.Background(), r)
|
||||
if err != nil {
|
||||
fmt.Println("Error to instantiate googles api: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if len(result) > 0 {
|
||||
address.Latitude = result[0].Geometry.Location.Lat
|
||||
address.Longitude = result[0].Geometry.Location.Lng
|
||||
}
|
||||
|
||||
if address.Latitude != 0 && address.Longitude != 0 {
|
||||
if len(user.Addresses) > 0 {
|
||||
for _, a := range user.Addresses {
|
||||
if a.AddressType == "home" {
|
||||
err := c.svc.Users.RemoveAddress(a.UUID)
|
||||
if err != nil {
|
||||
fmt.Println("Error to remove old address: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
}
|
||||
if validationError, ok := err.(*viewmodel.ValidationError); ok {
|
||||
if len(validationError.Errors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, validationError.Message, validationError.Errors)
|
||||
} else {
|
||||
return routeutils.ResponseAPIServiceError(ctx, validationError.Message)
|
||||
}
|
||||
}
|
||||
|
||||
address, err = c.svc.Users.SaveAddress(address)
|
||||
if err != nil {
|
||||
fmt.Println("Error to save address: ", err.Error())
|
||||
} else {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
user.Addresses = append(user.Addresses, address)
|
||||
}
|
||||
ride.Visit.User = user
|
||||
ride.User = user
|
||||
|
||||
homeAddress := viewmodel.Address{}
|
||||
for _, a := range visit.User.Addresses {
|
||||
@@ -226,7 +153,7 @@ func (c *controller) handleRide(ctx echo.Context) error {
|
||||
ride.Destination = newOrigin
|
||||
}
|
||||
|
||||
if c.cfg.LyftProd.UserUUID != authUser.ID {
|
||||
if authUser.Test {
|
||||
resp, err = c.tnc.Lyft.RequestRide(ride)
|
||||
} else {
|
||||
fmt.Println("In Production")
|
||||
@@ -340,7 +267,7 @@ func (c *controller) handleRide(ctx echo.Context) error {
|
||||
newRide.Passenger.LastName = " "
|
||||
newRide.Passenger.PhoneNumber = *visit.User.PhoneNumber
|
||||
|
||||
if c.cfg.LyftProd.UserUUID != authUser.ID {
|
||||
if authUser.Test {
|
||||
newRide, err = c.tnc.Lyft.RequestRide(newRide)
|
||||
} else {
|
||||
fmt.Println("In Production")
|
||||
@@ -471,154 +398,19 @@ func (c *controller) handle(ctx echo.Context) error {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, "visit validation failed", validationErrors)
|
||||
}
|
||||
|
||||
eligibility := viewmodel.Eligibility{}
|
||||
eligibility.Provider.ProviderNPI = provider.InternalID
|
||||
eligibility.Provider.ProviderName = provider.OrganizatioName
|
||||
eligibility.TrackingID = c.rangeIn(1000000, 9999999)
|
||||
eligibility.Subscriber.SubscriberID = *visit.User.Member
|
||||
eligibility.Subscriber.PatientType = *visit.User.Type
|
||||
eligibility.Subscriber.Name.First = visit.User.First
|
||||
eligibility.Subscriber.Name.Last = visit.User.Last
|
||||
eligibility.Subscriber.DemographicInfo.DateOfBirth = *visit.User.BirthDate
|
||||
eligibility.Subscriber.DemographicInfo.Gender = *visit.User.Gender
|
||||
loc, _ := time.LoadLocation("America/Chicago")
|
||||
eligibility.ServiceInfo.DateOfService = time.Now().In(loc)
|
||||
eligibility.ServiceInfo.ServiceTypeCodes = []string{"30"}
|
||||
|
||||
resp, err := c.bcbsi.BXE.Get271(eligibility)
|
||||
user, err := c.svc.Users.CheckAndCreateMember(visit.User, provider, authUser)
|
||||
if err != nil {
|
||||
fmt.Println("Error to get eligibility: ", err.Error())
|
||||
return routeutils.ResponseAPIValidationError(ctx, err.Error())
|
||||
}
|
||||
|
||||
user, err := c.svc.Users.GetByMemberID(*visit.User.Member)
|
||||
if err != nil {
|
||||
fmt.Println("Error to get user by memberID: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if user.ID == "" {
|
||||
if len(user.Pass) == 0 {
|
||||
user.Pass = c.generatePassword(8)
|
||||
if validationError, ok := err.(*viewmodel.ValidationError); ok {
|
||||
if len(validationError.Errors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, validationError.Message, validationError.Errors)
|
||||
} else {
|
||||
return routeutils.ResponseAPIServiceError(ctx, validationError.Message)
|
||||
}
|
||||
} else {
|
||||
pass, err := b64.StdEncoding.DecodeString(user.Pass)
|
||||
if err != nil {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "Invalid password", false)
|
||||
}
|
||||
user.Pass = string(pass)
|
||||
}
|
||||
|
||||
if user.BirthDate == nil || user.BirthDate.IsZero() {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "birthdate is required", false)
|
||||
}
|
||||
|
||||
if user.Member == nil || len(*user.Member) == 0 {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "member is required", false)
|
||||
}
|
||||
|
||||
if user.Gender == nil || len(*user.Gender) == 0 || (*user.Gender != "M" && *user.Gender != "F" && *user.Gender != "U") {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "gender is required", false)
|
||||
}
|
||||
|
||||
if len(user.Name) == 0 && len(user.First) == 0 && len(user.Last) == 0 {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "name is required", false)
|
||||
}
|
||||
|
||||
if len(user.First) != 0 && len(user.Last) != 0 {
|
||||
user.Name = fmt.Sprintf("%s %s", user.First, user.Last)
|
||||
}
|
||||
|
||||
if user.PhoneNumber != nil && len(*user.PhoneNumber) == 10 && !strings.Contains(*user.PhoneNumber, "+1") {
|
||||
phoneNumber := fmt.Sprintf("+1%s", *user.PhoneNumber)
|
||||
user.PhoneNumber = &phoneNumber
|
||||
}
|
||||
|
||||
profile, err := c.svc.Profile.GetByKey("US")
|
||||
if err != nil {
|
||||
fmt.Println("Error to get Profile: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
user.Profiles = append(user.Profiles, profile)
|
||||
|
||||
user, err = c.svc.Users.Create(user, authUser)
|
||||
if err != nil {
|
||||
fmt.Println("Error to create the user: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
} else {
|
||||
if visit.User.Email != nil && len(*visit.User.Email) > 0 {
|
||||
user.Email = visit.User.Email
|
||||
}
|
||||
|
||||
if visit.User.PhoneNumber != nil {
|
||||
if len(*visit.User.PhoneNumber) == 10 && !strings.Contains(*visit.User.PhoneNumber, "+1") {
|
||||
phoneNumber := fmt.Sprintf("+1%s", *visit.User.PhoneNumber)
|
||||
visit.User.PhoneNumber = &phoneNumber
|
||||
}
|
||||
user.PhoneNumber = visit.User.PhoneNumber
|
||||
}
|
||||
|
||||
err = c.svc.Users.UpdateLogin(user)
|
||||
if err != nil {
|
||||
fmt.Println("Error to update login: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
zipCode := strings.TrimSpace(body.N403)
|
||||
|
||||
address.AddressTypeName = "Home"
|
||||
address.AddressType = "home"
|
||||
address.Name = fmt.Sprintf("%s, %s", header.N301, body.N401)
|
||||
address.Address = fmt.Sprintf("%s, %s (%s)", header.N301, body.N401, zipCode)
|
||||
address.CreatedUserUUID = authUser.ID
|
||||
address.User = user
|
||||
address.Type = "provider"
|
||||
|
||||
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.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
r := &maps.GeocodingRequest{
|
||||
Address: address.Address + " " + body.N402 + ", " + zipCode,
|
||||
}
|
||||
|
||||
result, err := googleMapsAPI.Geocode(context.Background(), r)
|
||||
if err != nil {
|
||||
fmt.Println("Error to instantiate googles api: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if len(result) > 0 {
|
||||
address.Latitude = result[0].Geometry.Location.Lat
|
||||
address.Longitude = result[0].Geometry.Location.Lng
|
||||
}
|
||||
|
||||
if address.Latitude != 0 && address.Longitude != 0 {
|
||||
if len(user.Addresses) > 0 {
|
||||
for _, a := range user.Addresses {
|
||||
if a.AddressType == "home" {
|
||||
err := c.svc.Users.RemoveAddress(a.UUID)
|
||||
if err != nil {
|
||||
fmt.Println("Error to remove old address: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
address, err = c.svc.Users.SaveAddress(address)
|
||||
if err != nil {
|
||||
fmt.Println("Error saving address: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
user.Addresses = append(user.Addresses, address)
|
||||
}
|
||||
visit.User = user
|
||||
|
||||
visit.TripType = viewmodel.TripType{
|
||||
Key: "no_trip",
|
||||
@@ -634,7 +426,11 @@ func (c *controller) handle(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
return routeutils.ResponseAPIOK(ctx, visit)
|
||||
if authUser.Profiles[0].Key == "VIRPT" {
|
||||
return routeutils.ResponseNoContent(ctx, nil)
|
||||
} else {
|
||||
return routeutils.ResponseAPIOK(ctx, visit)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *controller) handleGetByID(ctx echo.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user