Upstream sync

This commit is contained in:
Senad Uka
2018-05-22 12:40:22 +02:00
parent 39c614fb98
commit 6e903b4d57
31 changed files with 948 additions and 83 deletions

View File

@@ -214,7 +214,11 @@ func (c *organizationRepo) parseEntity(row scanner) (retVal entity.Organization,
err = row.Scan(
&retVal.ID, &retVal.UUID, &retVal.Type.ID, &retVal.Type.Name, &retVal.Type.Key, &retVal.Name, &retVal.Description, &retVal.ReferenceID, &retVal.ParentID, &retVal.Main, &retVal.Created, &retVal.Updated, &retVal.Active, &retVal.Suspended, &retVal.Blocked, &retVal.Author.ID, &retVal.Author.UUID, &retVal.Author.Name, &retVal.LastEditor.ID, &retVal.LastEditor.UUID, &retVal.LastEditor.Name)
return retVal, errors.Wrap(err)
if err == sql.ErrNoRows {
return retVal, nil
} else {
return retVal, errors.Wrap(err)
}
}
// parseSet parses a result set result to an entity array
@@ -352,6 +356,17 @@ func (c *organizationRepo) GetByID(organizationID int64, user entity.User) (enti
return c.parseEntity(c.conn.QueryRow(query, organizationID))
}
func (c *organizationRepo) GetByTypeAndReferenceID(typeKey string, referenceID int64, user entity.User) (entity.Organization, error) {
query, where, err := c.getProfileQuery(user)
if err != nil {
return entity.Organization{}, err
}
query = c.getQuery() + query + " WHERE b.organization_type_key = ? AND a.organization_reference_id = ? " + where
return c.parseEntity(c.conn.QueryRow(query, typeKey, referenceID))
}
func (c *organizationRepo) GetChildsByID(organizationID int64, user entity.User) ([]entity.Organization, error) {
query, where, err := c.getProfileQuery(user)
if err != nil {

View File

@@ -72,44 +72,44 @@ func (c *providerRepo) getSelectQueryBaseKey() string {
func (c *providerRepo) getSelectQueryBase() string {
return `SELECT DISTINCT
a.provider_id,
a.provider_uuid,
a.provider_internal_id,
a.provider_internal_id_suffix,
a.provider_muk_id,
a.organization_name,
a.gender,
a.accept_new_patients,
a.provider_name,
a.first_name,
a.last_name,
a.middle_name,
a.provider_title,
a.street_name1,
a.street_name2,
a.city_name,
a.state,
a.zipcode,
a.country,
a.latitude,
a.longitude,
a.phone_number,
a.create_at,
a.update_at,
a.active,
a.enabled,
a.created_user,
(3959 * acos (
cos ( radians(?) )
* cos( radians( a.latitude ) )
* cos( radians( a.longitude ) - radians(?) )
+ sin ( radians(?) )
* sin( radians( a.latitude ) )
)) AS distance_in_miles
FROM
tab_provider a
INNER JOIN tab_provider_key b
ON a.provider_id = b.provider_id `
a.provider_id,
a.provider_uuid,
a.provider_internal_id,
IFNULL(a.provider_internal_id_suffix, '') provider_internal_id_suffix,
IFNULL(a.provider_muk_id, '') provider_muk_id,
IFNULL(a.organization_name, '') organization_name,
IFNULL(a.gender, '') gender,
IFNULL(a.accept_new_patients, '') accept_new_patients,
IFNULL(a.provider_name, '') provider_name,
IFNULL(a.first_name, '') first_name,
IFNULL(a.last_name, '') last_name,
IFNULL(a.middle_name, '') middle_name,
IFNULL(a.provider_title, '') provider_title,
IFNULL(a.street_name1, '') street_name1,
IFNULL(a.street_name2, '') street_name2,
IFNULL(a.city_name, '') city_name,
IFNULL(a.state, '') state,
IFNULL(a.zipcode, '') zipcode,
IFNULL(a.country, '') country,
IFNULL(a.latitude, 0) latitude,
IFNULL(a.longitude, 0) longitude,
IFNULL(a.phone_number, '') phone_number,
a.create_at,
a.update_at,
a.active,
a.enabled,
a.created_user,
(3959 * acos (
cos ( radians(?) )
* cos( radians( IFNULL(a.latitude, 0) ) )
* cos( radians( IFNULL(a.longitude, 0) ) - radians(?) )
+ sin ( radians(?) )
* sin( radians( IFNULL(a.latitude, 0) ) )
)) AS distance_in_miles
FROM
tab_provider a
INNER JOIN tab_provider_key b
ON a.provider_id = b.provider_id `
}
func (c *providerRepo) GetAll(user entity.User) ([]entity.Provider, error) {
@@ -159,6 +159,20 @@ func (c *providerRepo) GetByMukID(mukID string, user entity.User) (entity.Provid
return c.parseEntity(c.conn.QueryRow(query, lat, long, lat, mukID))
}
func (c *providerRepo) GetByNPI(NPI string, user entity.User) (entity.Provider, error) {
lat := 41.886406
long := -87.624225
query, where, err := c.getProfileQuery(user)
if err != nil {
return entity.Provider{}, err
}
query = c.getSelectQueryBase() + query + " WHERE a.provider_internal_id = ? " + where
return c.parseEntity(c.conn.QueryRow(query, lat, long, lat, NPI))
}
func (c *providerRepo) Get(query string, lat float64, long float64, distance int64, planCode string, productID string, mukID string, internalID string, sort string, user entity.User) ([]entity.Provider, error) {
filter := " WHERE 1 = 1 "
params := make([]interface{}, 0)
@@ -307,7 +321,11 @@ func (c *providerRepo) parseEntity(row scanner) (retVal entity.Provider, err err
err = row.Scan(
&retVal.ProviderID, &retVal.ProviderUUID, &retVal.InternalID, &retVal.InternalSuffixID, &retVal.MukID, &retVal.OrganizatioName, &retVal.Gender, &retVal.AcceptNewPatients, &retVal.Name, &retVal.FirstName, &retVal.LastName, &retVal.MiddleName, &retVal.Title, &retVal.Address.StreetAddress1, &retVal.Address.StreetAddress2, &retVal.Address.CityName, &retVal.Address.State, &retVal.Address.ZipCode, &retVal.Address.Country, &retVal.Address.Latitude, &retVal.Address.Longitude, &retVal.Address.PhoneNumber, &retVal.CreateDate, &retVal.UpdateDate, &retVal.Active, &retVal.Enabled, &retVal.CreatedUser.ID, &retVal.Distance)
return retVal, errors.Wrap(err)
if err == sql.ErrNoRows {
return retVal, nil
} else {
return retVal, errors.Wrap(err)
}
}
func (c *providerRepo) Save(providers []entity.ProviderResponse, user entity.User) ([]entity.Provider, error) {