Work on exhibit tracking
This commit is contained in:
@@ -270,6 +270,73 @@ def get_event_registrants(
|
|||||||
# ### END ### API Impexium Methods ### get_event_registrants() ###
|
# ### END ### API Impexium Methods ### get_event_registrants() ###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API External Impexium Methods ### get_individual_profile() ###
|
||||||
|
# Updated 2022-04-22
|
||||||
|
@logger_reset
|
||||||
|
def get_individual_profile(
|
||||||
|
individual_id: str,
|
||||||
|
details: bool = False,
|
||||||
|
page = 1 # page: int = 0,
|
||||||
|
):
|
||||||
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if result := authenticate():
|
||||||
|
log.debug(result)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
endpoint = f'/Individuals/Profile/{individual_id}/{page}'
|
||||||
|
uri = api['base_url']+endpoint
|
||||||
|
params = { 'IncludeDetails': details }
|
||||||
|
|
||||||
|
impexium_individual_profile = None
|
||||||
|
|
||||||
|
try_request = True
|
||||||
|
max_tries = 5
|
||||||
|
try_count = 0
|
||||||
|
while try_request and try_count <= max_tries:
|
||||||
|
try_count = try_count + 1
|
||||||
|
|
||||||
|
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
||||||
|
|
||||||
|
log.debug(f'Status Code: {resp.status_code}')
|
||||||
|
log.debug(f'Headers: {resp.headers}')
|
||||||
|
# log.debug(f'Encoding: {resp.encoding}')
|
||||||
|
# log.debug('Text:')
|
||||||
|
# log.debug(resp.text)
|
||||||
|
# log.debug(resp.json())
|
||||||
|
|
||||||
|
if resp.status_code == 200:
|
||||||
|
log.debug(resp.json())
|
||||||
|
|
||||||
|
impexium_individual_profile_raw = resp.json() # .get('data').get('dataList')[0]
|
||||||
|
# log.debug(impexium_individual_profile_raw)
|
||||||
|
|
||||||
|
impexium_individual_profile = impexium_individual_profile_raw.get('dataList')[0]
|
||||||
|
log.debug(impexium_individual_profile)
|
||||||
|
|
||||||
|
try_request = False
|
||||||
|
elif resp.status_code == 404:
|
||||||
|
log.info('No results returned.')
|
||||||
|
try_request = False
|
||||||
|
impexium_individual_profile = None
|
||||||
|
elif resp.status_code == 429:
|
||||||
|
log.warning('Hit rate limit. Sleeping for .1 seconds...')
|
||||||
|
time.sleep(.1)
|
||||||
|
try_request = True
|
||||||
|
impexium_individual_profile = False
|
||||||
|
else:
|
||||||
|
try_request = False
|
||||||
|
impexium_event_registration_list = False
|
||||||
|
|
||||||
|
return impexium_individual_profile
|
||||||
|
# ### END ### API External Impexium Methods ### get_individual_profile() ###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API External Impexium Methods ### get_individual_registrations() ###
|
# ### BEGIN ### API External Impexium Methods ### get_individual_registrations() ###
|
||||||
# Updated 2022-02-18
|
# Updated 2022-02-18
|
||||||
@logger_reset
|
@logger_reset
|
||||||
|
|||||||
@@ -190,19 +190,19 @@ def load_event_exhibit_tracking_obj(
|
|||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if inc_event_exhibit:
|
# if inc_event_exhibit:
|
||||||
log.info('Need to include Event Exhibit data...')
|
# log.info('Need to include Event Exhibit data...')
|
||||||
event_exhibit_id = event_exhibit_tracking_rec.get('event_exhibit_id', None)
|
# event_exhibit_id = event_exhibit_tracking_rec.get('event_exhibit_id', None)
|
||||||
log.debug(event_exhibit_id)
|
# log.debug(event_exhibit_id)
|
||||||
from app.methods.event_exhibit_methods import load_event_exhibit_obj
|
# from app.methods.event_exhibit_methods import load_event_exhibit_obj
|
||||||
if event_exhibit_result := load_event_exhibit_obj(
|
# if event_exhibit_result := load_event_exhibit_obj(
|
||||||
event_exhibit_id = event_exhibit_id,
|
# event_exhibit_id = event_exhibit_id,
|
||||||
by_alias = by_alias,
|
# by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
# exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
# model_as_dict = model_as_dict,
|
||||||
):
|
# ):
|
||||||
event_exhibit_tracking_obj.event_exhibit = event_exhibit_result
|
# event_exhibit_tracking_obj.event_exhibit = event_exhibit_result
|
||||||
else: event_exhibit_tracking_obj.event_exhibit = {} # None
|
# else: event_exhibit_tracking_obj.event_exhibit = {} # None
|
||||||
|
|
||||||
if inc_event_person:
|
if inc_event_person:
|
||||||
log.info('Need to include Event Person data...')
|
log.info('Need to include Event Person data...')
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
|||||||
|
|
||||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||||
|
|
||||||
from app.methods.e_impexium_methods import get_custom_fields, get_events, get_event_registrants, get_individual_custom_fields
|
from app.methods.e_impexium_methods import get_custom_fields, get_events, get_event_registrants, get_individual_custom_fields, get_individual_profile
|
||||||
|
|
||||||
from app.methods.event_person_methods import create_event_person_obj, create_update_event_person_obj_v4, get_event_person_rec_list, load_event_person_obj, update_event_person_obj, update_event_person_obj_v3
|
from app.methods.event_person_methods import create_event_person_obj, create_update_event_person_obj_v4, get_event_person_rec_list, load_event_person_obj, update_event_person_obj, update_event_person_obj_v3
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ async def event_import_reg(
|
|||||||
event_code = e_impexium_event_id,
|
event_code = e_impexium_event_id,
|
||||||
registered_since = registered_since,
|
registered_since = registered_since,
|
||||||
details = details,
|
details = details,
|
||||||
page = page
|
page = page,
|
||||||
)
|
)
|
||||||
log.info(f'Total record count: {len(event_registrant_li)}')
|
log.info(f'Total record count: {len(event_registrant_li)}')
|
||||||
if event_registrant_li: pass
|
if event_registrant_li: pass
|
||||||
@@ -80,7 +80,6 @@ async def event_import_reg(
|
|||||||
event_person_summary_data = {}
|
event_person_summary_data = {}
|
||||||
event_person_summary_data['external_id'] = external_id_v3
|
event_person_summary_data['external_id'] = external_id_v3
|
||||||
|
|
||||||
|
|
||||||
event_person_data = {}
|
event_person_data = {}
|
||||||
event_person_data['enable'] = True
|
event_person_data['enable'] = True
|
||||||
event_person_data['account_id'] = account_id
|
event_person_data['account_id'] = account_id
|
||||||
@@ -460,6 +459,263 @@ async def event_import_reg(
|
|||||||
# ### END ### API Impexium ### event_import_reg() ###
|
# ### END ### API Impexium ### event_import_reg() ###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Impexium ### event_check_individual() ###
|
||||||
|
# Updated 2022-04-33
|
||||||
|
# @router.get('/event/{e_impexium_event_id}/{e_impexium_individual_id}/import_individual', response_model=Resp_Body_Base)
|
||||||
|
# @router.get('/event/{event_badge_id}/check_individual', response_model=Resp_Body_Base)
|
||||||
|
@router.get('/event/{e_impexium_individual_id}/check_individual', response_model=Resp_Body_Base)
|
||||||
|
async def event_check_individual(
|
||||||
|
e_impexium_individual_id: str = Query(..., min_length=50, max_length=55),
|
||||||
|
# event_badge_id: str = Query(..., min_length=11, max_length=22),
|
||||||
|
details: bool = False,
|
||||||
|
|
||||||
|
inc_membership_fields: bool = True,
|
||||||
|
page: int = 1, # 250 per page from Impexium
|
||||||
|
event_id: str = Query(..., min_length=11, max_length=22), # For ISHLT: ZDzTBlevhZs (2022-04)
|
||||||
|
# Account ID For ISHLT: d8TqXqf1EOg
|
||||||
|
|
||||||
|
refresh_record: bool = False,
|
||||||
|
|
||||||
|
return_detail: bool = False,
|
||||||
|
|
||||||
|
commons: Common_Route_Params = Depends(common_route_params),
|
||||||
|
):
|
||||||
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
log.info('Starting Impexium event registration import...')
|
||||||
|
|
||||||
|
account_id = commons.x_account_id
|
||||||
|
|
||||||
|
individual_profile_result = get_individual_profile(
|
||||||
|
individual_id = e_impexium_individual_id,
|
||||||
|
details = details,
|
||||||
|
page = page,
|
||||||
|
)
|
||||||
|
log.debug(individual_profile_result)
|
||||||
|
|
||||||
|
if individual_profile_result: pass
|
||||||
|
else: return mk_resp(data=None, status_code=404, status_message=f'Checked for individual profile in Impexium. No Impexium individual found.', response=commons.response)
|
||||||
|
|
||||||
|
individual_profile = individual_profile_result
|
||||||
|
|
||||||
|
event_person_summary_data = {}
|
||||||
|
event_person_summary_data['external_sys_id'] = e_impexium_individual_id
|
||||||
|
|
||||||
|
event_person_data = {}
|
||||||
|
event_person_data['external_sys_id'] = e_impexium_individual_id # The Impexium individual ID
|
||||||
|
|
||||||
|
email = None
|
||||||
|
city = None
|
||||||
|
country_subdivision_code = None
|
||||||
|
state_province = None
|
||||||
|
state_province_abb = None
|
||||||
|
country_alpha_2_code = None
|
||||||
|
country = None
|
||||||
|
|
||||||
|
if details:
|
||||||
|
if emails := individual_profile.get('emails'):
|
||||||
|
if isinstance(emails, list) and len(emails):
|
||||||
|
email = emails[0].get('address')
|
||||||
|
event_person_summary_data['email'] = email
|
||||||
|
|
||||||
|
if addresses := individual_profile.get('addresses'):
|
||||||
|
if isinstance(addresses, list) and len(addresses):
|
||||||
|
for address in addresses:
|
||||||
|
if primary_address := address.get('primary'):
|
||||||
|
city = address.get('city')
|
||||||
|
country_subdivision_code = address.get('stateISOCode')
|
||||||
|
state_province = address.get('state')
|
||||||
|
state_province_abb = address.get('stateAbbreviation')
|
||||||
|
|
||||||
|
if country_data := address.get('countryData'):
|
||||||
|
country_alpha_3_code = country_data.get('threeLetterIsoCode')
|
||||||
|
country_alpha_2_code = country_data.get('twoLetterIsoCode')
|
||||||
|
country = address.get('country')
|
||||||
|
|
||||||
|
degrees = None
|
||||||
|
organization_name = None
|
||||||
|
if inc_membership_fields:
|
||||||
|
# individual_custom_fields_li = get_individual_custom_fields(individual_id=individual_profile.get('id'))
|
||||||
|
individual_custom_fields_li = individual_profile.get('customFields')
|
||||||
|
|
||||||
|
for individual_custom_field in individual_custom_fields_li:
|
||||||
|
if individual_custom_field.get('name') == 'degree':
|
||||||
|
degrees = individual_custom_field.get('value')
|
||||||
|
if individual_custom_field.get('name') == 'organization_name':
|
||||||
|
organization_name = individual_custom_field.get('value')
|
||||||
|
|
||||||
|
log.debug(f'Degrees: {degrees}; Organization Name: {organization_name}')
|
||||||
|
|
||||||
|
|
||||||
|
event_person_profile_data = {}
|
||||||
|
event_person_profile_data['enable'] = True
|
||||||
|
event_person_profile_data['pronouns'] = individual_profile.get('gender')
|
||||||
|
event_person_profile_data['informal_name'] = individual_profile.get('preferredFirstName')
|
||||||
|
|
||||||
|
event_person_profile_data['title_names'] = individual_profile.get('prefix')
|
||||||
|
event_person_profile_data['given_name'] = individual_profile.get('firstName')
|
||||||
|
event_person_profile_data['middle_name'] = individual_profile.get('middleName')
|
||||||
|
event_person_profile_data['family_name'] = individual_profile.get('lastName')
|
||||||
|
event_person_profile_data['designations'] = individual_profile.get('suffix')
|
||||||
|
|
||||||
|
if degrees:
|
||||||
|
event_person_profile_data['professional_title'] = degrees # Ideally should be degrees for ISHLT
|
||||||
|
else:
|
||||||
|
event_person_profile_data['professional_title'] = None # individual_profile.get('title') # Should this be None if no degrees found above???
|
||||||
|
|
||||||
|
# event_person_profile_data['full_name'] = individual_profile.get('badgeName')
|
||||||
|
# event_person_summary_data['full_name'] = individual_profile.get('badgeName')
|
||||||
|
event_person_summary_data['full_name'] = individual_profile.get('firstName') + ' ' + individual_profile.get('lastName')
|
||||||
|
|
||||||
|
if organization_name:
|
||||||
|
event_person_profile_data['affiliations'] = organization_name # Ideally should be organization_name for ISHLT
|
||||||
|
else:
|
||||||
|
# event_person_profile_data['affiliations'] = individual_profile.get('badgeOrganization') # Should this be None if no organization_name found above???
|
||||||
|
pass
|
||||||
|
|
||||||
|
if email: event_person_profile_data['email'] = email
|
||||||
|
|
||||||
|
event_person_data['event_person_profile'] = {}
|
||||||
|
event_person_data['event_person_profile'] = event_person_profile_data
|
||||||
|
|
||||||
|
event_badge_data = {}
|
||||||
|
# event_badge_data['enable'] = True
|
||||||
|
# event_badge_data['event_id'] = event_id
|
||||||
|
# event_badge_data['external_id'] = external_id_v3
|
||||||
|
# event_badge_data['external_sys_id'] = external_sys_id
|
||||||
|
# event_badge_data['external_reg_id'] = external_reg_id
|
||||||
|
|
||||||
|
event_badge_data['pronouns'] = individual_profile.get('gender')
|
||||||
|
event_badge_data['informal_name'] = individual_profile.get('preferredFirstName')
|
||||||
|
|
||||||
|
event_badge_data['title_names'] = individual_profile.get('prefix')
|
||||||
|
event_badge_data['given_name'] = individual_profile.get('firstName')
|
||||||
|
event_badge_data['middle_name'] = individual_profile.get('middleName')
|
||||||
|
event_badge_data['family_name'] = individual_profile.get('lastName')
|
||||||
|
event_badge_data['designations'] = individual_profile.get('suffix')
|
||||||
|
|
||||||
|
if degrees:
|
||||||
|
event_badge_data['professional_title'] = degrees # Ideally should be degrees for ISHLT
|
||||||
|
else:
|
||||||
|
event_badge_data['professional_title'] = None # individual_profile.get('title') # Should this be None if no degrees found above???
|
||||||
|
|
||||||
|
# event_badge_data['full_name'] = individual_profile.get('badgeName')
|
||||||
|
|
||||||
|
if organization_name:
|
||||||
|
event_badge_data['affiliations'] = organization_name # Ideally should be organization_name for ISHLT
|
||||||
|
else:
|
||||||
|
# event_badge_data['affiliations'] = individual_profile.get('badgeOrganization') # Should this be None if no organization_name found above???
|
||||||
|
pass
|
||||||
|
|
||||||
|
if email: event_badge_data['email'] = email
|
||||||
|
|
||||||
|
# event_badge_data['city'] = individual_profile.get('badgeCity')
|
||||||
|
# event_badge_data['state_province'] = individual_profile.get('badgeState')
|
||||||
|
|
||||||
|
# if not event_badge_data['city'] and city:
|
||||||
|
# event_badge_data['city'] = city
|
||||||
|
if country_subdivision_code:
|
||||||
|
event_badge_data['country_subdivision_code'] = country_subdivision_code
|
||||||
|
# if not event_badge_data['state_province'] and state_province:
|
||||||
|
# event_badge_data['state_province'] = state_province
|
||||||
|
if state_province_abb:
|
||||||
|
event_badge_data['state_province_abb'] = state_province_abb
|
||||||
|
if country_alpha_2_code:
|
||||||
|
event_badge_data['country_alpha_2_code'] = country_alpha_2_code
|
||||||
|
if country:
|
||||||
|
event_badge_data['country'] = country
|
||||||
|
|
||||||
|
# location = None
|
||||||
|
# if event_badge_data['city'] and state_province_abb and country_alpha_2_code and country_alpha_2_code == 'US':
|
||||||
|
# city = event_badge_data['city']
|
||||||
|
# location = f'{city}, {state_province_abb} {country_alpha_2_code}'
|
||||||
|
# elif event_badge_data['city'] and state_province_abb and country and country == 'United States':
|
||||||
|
# city = event_badge_data['city']
|
||||||
|
# location = f'{city}, {state_province_abb} {country}'
|
||||||
|
# elif event_badge_data['city'] and event_badge_data['state_province'] and country:
|
||||||
|
# city = event_badge_data['city']
|
||||||
|
# state_province = event_badge_data['state_province']
|
||||||
|
# location = f'{city}, {state_province} {country}'
|
||||||
|
# elif event_badge_data['city'] and country:
|
||||||
|
# city = event_badge_data['city']
|
||||||
|
# location = f'{city}, {country}'
|
||||||
|
# elif event_badge_data['city']:
|
||||||
|
# city = event_badge_data['city']
|
||||||
|
# location = f'{city}'
|
||||||
|
# elif country:
|
||||||
|
# location = f'{country}'
|
||||||
|
|
||||||
|
# if location: event_badge_data['location'] = location
|
||||||
|
|
||||||
|
sql_select_event_person = f"""
|
||||||
|
SELECT id AS event_person_id, id_random AS event_person_id_random, external_id AS event_person_external_id, external_sys_id AS event_person_external_sys_id, event_badge_id AS event_badge_id, event_person_profile_id AS event_person_profile_id
|
||||||
|
FROM `event_person` AS `event_person`
|
||||||
|
WHERE event_person.event_id = :event_id
|
||||||
|
AND event_person.external_sys_id = :external_sys_id
|
||||||
|
/*LIMIT 1*/;
|
||||||
|
"""
|
||||||
|
|
||||||
|
if event_person_result := sql_select(sql=sql_select_event_person, data=event_person_data):
|
||||||
|
if isinstance(event_person_result, list):
|
||||||
|
log.error(f'Found more than one Event Person with the same External ID. Count: {len(event_person_result)}')
|
||||||
|
# return False
|
||||||
|
else:
|
||||||
|
event_person_id = event_person_result.get('event_person_id')
|
||||||
|
event_badge_id = event_person_result.get('event_badge_id')
|
||||||
|
event_person_profile_id = event_person_result.get('event_person_profile_id')
|
||||||
|
log.info(f'Found Event Person. Updating existing... Event Person ID: {event_person_id}')
|
||||||
|
if create_event_person_obj_result := create_update_event_person_obj_v4(
|
||||||
|
event_person_dict_obj = event_person_data,
|
||||||
|
event_person_id = event_person_id,
|
||||||
|
account_id = account_id,
|
||||||
|
event_id = event_id,
|
||||||
|
event_badge_id = event_badge_id,
|
||||||
|
event_person_profile_id = event_person_profile_id,
|
||||||
|
# create_sub_obj = create_sub_obj,
|
||||||
|
# fail_any = fail_any,
|
||||||
|
# return_outline = False,
|
||||||
|
):
|
||||||
|
event_person_id = create_event_person_obj_result
|
||||||
|
log.warning(f'Event Person updated. Event Person ID: {event_person_id}')
|
||||||
|
else:
|
||||||
|
log.warning(f'Event Person not updated. Event Person ID: {event_person_id}')
|
||||||
|
log.debug(event_badge_obj_in_result)
|
||||||
|
# return False
|
||||||
|
else:
|
||||||
|
log.info('No Event Person found. Creating new...')
|
||||||
|
|
||||||
|
if create_event_person_obj_result := create_update_event_person_obj_v4(
|
||||||
|
event_person_dict_obj = event_person_data,
|
||||||
|
account_id = account_id,
|
||||||
|
event_id = event_id,
|
||||||
|
# create_sub_obj = create_sub_obj,
|
||||||
|
# fail_any = fail_any,
|
||||||
|
# return_outline = False,
|
||||||
|
):
|
||||||
|
event_person_id = create_event_person_obj_result
|
||||||
|
log.warning(f'Event Person created. Event Person ID: {event_person_id}')
|
||||||
|
else:
|
||||||
|
log.warning(f'Event Person not created.')
|
||||||
|
log.debug(event_badge_obj_in_result)
|
||||||
|
# return False
|
||||||
|
|
||||||
|
if return_detail:
|
||||||
|
return mk_resp(data=individual_profile, status_message=f'Checked for individual profile in Impexium. Found. Returning details.', response=commons.response)
|
||||||
|
else:
|
||||||
|
return mk_resp(data=event_person_summary_data, status_message=f'Checked for individual profile in Impexium. Found. Returning summary.', response=commons.response)
|
||||||
|
|
||||||
|
return mk_resp(data=individual_profile, status_code=200, response=commons.response)
|
||||||
|
# ### END ### API Impexium ### event_check_individual() ###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Impexium ### testing() ###
|
# ### BEGIN ### API Impexium ### testing() ###
|
||||||
# Updated 2022-03-22
|
# Updated 2022-03-22
|
||||||
@router.get('/event/{e_impexium_event_id}/testing', response_model=Resp_Body_Base)
|
@router.get('/event/{e_impexium_event_id}/testing', response_model=Resp_Body_Base)
|
||||||
|
|||||||
Reference in New Issue
Block a user