Upstream sync
This commit is contained in:
@@ -20,6 +20,14 @@ func isSameOrganization(organizationA viewmodel.Organization, organizationB view
|
||||
}
|
||||
|
||||
func grabOrgFromUser(user viewmodel.User) (viewmodel.Organization, error) {
|
||||
if len(user.Profiles) < 1 {
|
||||
return viewmodel.Organization{}, fmt.Errorf("User has no organizations %v", user)
|
||||
}
|
||||
|
||||
return user.Profiles[0].Organization, nil
|
||||
}
|
||||
|
||||
func grabOrgFromUserDirectly(user viewmodel.User) (viewmodel.Organization, error) {
|
||||
if len(user.Organizations) < 1 {
|
||||
return viewmodel.Organization{}, fmt.Errorf("User has no organizations %v", user)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func CanCreateUser(currentUser viewmodel.User, updatingUser viewmodel.User) bool
|
||||
return false
|
||||
}
|
||||
|
||||
updatingUserOrganization, err := grabOrgFromUser(updatingUser)
|
||||
updatingUserOrganization, err := grabOrgFromUserDirectly(updatingUser)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package eligibilityroute
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"html"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
|
||||
@@ -42,8 +46,22 @@ func (c *controller) handleEligibility(ctx echo.Context) error {
|
||||
|
||||
ret, err := c.bcbsi.BXE.CheckEligibility(eligibility)
|
||||
if err != nil {
|
||||
fmt.Println("Error Here: ", err.Error())
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
return routeutils.ResponseAPIOK(ctx, ret)
|
||||
if ret.QueryResult.HIPPA271.T271 != "" {
|
||||
xmlString := html.UnescapeString(ret.QueryResult.HIPPA271.T271)
|
||||
xmlReader := strings.NewReader(xmlString)
|
||||
|
||||
var f viewmodel.Interchange271
|
||||
err = xml.NewDecoder(xmlReader).Decode(&f)
|
||||
if err != nil {
|
||||
fmt.Println("Error to unmarshal: ", err.Error())
|
||||
}
|
||||
|
||||
return ctx.JSON(200, f)
|
||||
} else {
|
||||
return routeutils.ResponseAPIOK(ctx, ret)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,18 @@ import (
|
||||
"time"
|
||||
|
||||
"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/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/auth"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/cache"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/config"
|
||||
"bitbucket.org/nemt/nemt-portal-api/server/authorization"
|
||||
"bitbucket.org/nemt/nemt-portal-api/server/validation"
|
||||
"bitbucket.org/nemt/nemt-portal-api/server/router/routeutils"
|
||||
"github.com/labstack/echo"
|
||||
"golang.org/x/net/context"
|
||||
"googlemaps.github.io/maps"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,15 +28,17 @@ var (
|
||||
)
|
||||
|
||||
type controller struct {
|
||||
svc *applicationservice.Service
|
||||
cfg *config.Config
|
||||
svc *applicationservice.Service
|
||||
cfg *config.Config
|
||||
bcbsi *bcbsi.Service
|
||||
}
|
||||
|
||||
func controllerInstance(svc *applicationservice.Service, cfg *config.Config) *controller {
|
||||
once.Do(func() {
|
||||
instance = &controller{
|
||||
svc: svc,
|
||||
cfg: cfg,
|
||||
svc: svc,
|
||||
cfg: cfg,
|
||||
bcbsi: bcbsi.New(cfg),
|
||||
}
|
||||
})
|
||||
return instance
|
||||
@@ -381,6 +387,59 @@ func (c *controller) handleMember(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
eligibility := viewmodel.Eligibility{}
|
||||
eligibility.Provider.ProviderNPI = "1699849786"
|
||||
eligibility.Provider.ProviderName = "LITHOLINK CORPORATION"
|
||||
eligibility.TrackingID = user.ID
|
||||
eligibility.Subscriber.SubscriberID = *user.Member
|
||||
eligibility.Subscriber.PatientType = "S"
|
||||
eligibility.Subscriber.Name.First = user.First
|
||||
eligibility.Subscriber.Name.Last = user.Last
|
||||
eligibility.Subscriber.DemographicInfo.DateOfBirth = *user.BirthDate
|
||||
eligibility.Subscriber.DemographicInfo.Gender = *user.Gender
|
||||
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())
|
||||
} 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
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return routeutils.ResponseAPIOK(ctx, user)
|
||||
}
|
||||
|
||||
@@ -472,6 +531,10 @@ func (c *controller) handlePortal(ctx echo.Context) error {
|
||||
}
|
||||
user.Pass = string(pass)
|
||||
|
||||
if passwordValidationErrors := validation.ValidatePassword(&user) ; len(passwordValidationErrors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, "Password not strong enough", passwordValidationErrors)
|
||||
}
|
||||
|
||||
if len(user.Name) == 0 && len(user.First) == 0 && len(user.Last) == 0 {
|
||||
return routeutils.ResponseAPIAuthError(ctx, "name is required", false)
|
||||
}
|
||||
|
||||
67
server/validation/user.go
Normal file
67
server/validation/user.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
|
||||
|
||||
)
|
||||
|
||||
func characterIsUpperCase(character rune) bool {
|
||||
return (character >= 65) && (character <= 90)
|
||||
}
|
||||
|
||||
func characterIsLowerCase(character rune) bool {
|
||||
return (character >= 97) && (character <= 122)
|
||||
}
|
||||
|
||||
func characterIsNumber(character rune) bool {
|
||||
return (character >= 48) && (character <= 57)
|
||||
}
|
||||
|
||||
func ValidatePassword(user *viewmodel.User) []errors.ValidationError {
|
||||
var result []errors.ValidationError
|
||||
|
||||
userOrganizationName := ""
|
||||
if len(user.Organizations) > 0{
|
||||
userOrganizationName = user.Organizations[0].Name
|
||||
}
|
||||
|
||||
if (len(user.Pass) < 8) {
|
||||
result = append(result, errors.ValidationError{Field : "password", Message : "Password must be at least 8 characters."})
|
||||
}
|
||||
|
||||
if (strings.Contains(user.Pass, user.First)){
|
||||
result = append(result, errors.ValidationError{Field : "password", Message : "Password cannot include your First Name."})
|
||||
}
|
||||
|
||||
if (strings.Contains(user.Pass, user.Last)){
|
||||
result = append(result, errors.ValidationError{Field : "password", Message : "Password cannot include your Last Name."})
|
||||
}
|
||||
|
||||
if (strings.Contains(user.Pass, userOrganizationName)){
|
||||
result = append(result, errors.ValidationError{Field : "password", Message : "Password cannot include your Organization Name."})
|
||||
}
|
||||
|
||||
containsUpperCaseLetter := false;
|
||||
containsLowerCaseLetter := false;
|
||||
containsNumber := false;
|
||||
|
||||
for _, character := range user.Pass {
|
||||
containsUpperCaseLetter = containsUpperCaseLetter || characterIsUpperCase(character)
|
||||
containsLowerCaseLetter = containsLowerCaseLetter || characterIsLowerCase(character)
|
||||
containsNumber = containsNumber || characterIsNumber(character)
|
||||
}
|
||||
|
||||
if !containsUpperCaseLetter || !containsLowerCaseLetter || !containsNumber {
|
||||
result = append(result, errors.ValidationError{Field : "password", Message : "Password must contain one of EACH :"})
|
||||
result = append(result, errors.ValidationError{Field : "password-tab", Message : "an uppercase letter"})
|
||||
result = append(result, errors.ValidationError{Field : "password-tab", Message : "a lowercase letter"})
|
||||
result = append(result, errors.ValidationError{Field : "password-tab", Message : "a number"})
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user