def test_get_change_details(self, monitored_object_identifier_stem): identifier_stem = monitored_object_identifier_stem[0] id_value = monitored_object_identifier_stem[1] extractor = CredibleFrontEndDriver(identifier_stem.retrieve('id_source')) with extractor as extractor: field_values = extractor.get_change_details(identifier_stem, id_value) print()
def test_emp_id_search(self, employee_name): id_source = employee_name[2] last_name = employee_name[0] first_initial = employee_name[1] extractor = CredibleFrontEndDriver(id_source) with extractor as extractor: results = extractor.search_employees(last_name, first_initial) print()
def creep(self): with CredibleFrontEndDriver(self._id_source) as driver: for entry in self._leech_driver.get_propagated_vertexes( self._propagation_id): if not self._driving_identifier_stem: self._driving_identifier_stem = IdentifierStem.from_raw( entry['driving_identifier_stem']) if not self._extracted_identifier_stem: self._extracted_identifier_stem = IdentifierStem.from_raw( entry['extracted_identifier_stem']) if not self._propagation_identifier_stem: self._propagation_identifier_stem = IdentifierStem.from_raw( entry['identifier_stem']) try: self._creep( entry, identifier_stem=self._extracted_identifier_stem, driving_identifier_stem=self._driving_identifier_stem, context=self._context, driver=driver) except InsufficientOperationTimeException: return False return { 'propagation_id': self._propagation_id, 'id_source': self._id_source }
def work_remote_id_change_type(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver from toll_booth.alg_obj.graph.ogm.regulators import IdentifierStem driving_identifier_stem = IdentifierStem.from_raw( kwargs['driving_identifier_stem']) identifier_stem = IdentifierStem.from_raw(kwargs['identifier_stem']) changelog_types = kwargs['changelog_types'] change_category = changelog_types.categories[kwargs['category_id']] with CredibleFrontEndDriver( driving_identifier_stem.get('id_source')) as driver: extraction_args = { 'driving_id_type': driving_identifier_stem.get('id_type'), 'driving_id_name': driving_identifier_stem.get('id_name'), 'driving_id_value': kwargs['id_value'], 'local_max_value': kwargs['local_max_value'], 'category_id': change_category.category_id, 'driving_identifier_stem': driving_identifier_stem, 'identifier_stem': identifier_stem, 'category': change_category } remote_changes = driver.get_change_logs(**extraction_args) sorted_changes = {} for remote_change in remote_changes: change_action = remote_change['Action'] if change_action not in sorted_changes: sorted_changes[change_action] = [] sorted_changes[change_action].append(remote_change) return {'change_actions': sorted_changes}
def get_client_encounters(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver id_source = kwargs['id_source'] client_search_kwargs = { } with CredibleFrontEndDriver(id_source) as driver: client_data = driver.process_advanced_search('Client', )
def _retrieve_credible_download(cls, id_source, id_type, selected_fields, start_date=None, end_date=None): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver with CredibleFrontEndDriver(id_source) as driver: return driver.process_advanced_search(id_type, selected_fields, start_date, end_date)
def get_remote_ids(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver from datetime import datetime link_utc_timestamp = datetime.utcnow() remote_id_extractor = _build_remote_id_extractor(**kwargs) with CredibleFrontEndDriver(remote_id_extractor['id_source']) as driver: remote_ids = driver.get_monitor_extraction(**remote_id_extractor) results = set([Decimal(x) for x in remote_ids]) return { 'remote_id_values': results, 'link_utc_timestamp': link_utc_timestamp }
def post_process_get_encounters(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver from toll_booth.alg_obj.graph.ogm.regulators import IdentifierStem encounter_id = kwargs['id_value'] id_type = kwargs['id_type'] if id_type != 'ClientVisit': raise NotImplementedError( f'cannot post process an encounter off id_type: {id_type}') driving_identifier_stem = IdentifierStem.from_raw( kwargs['driving_identifier_stem']) id_source = driving_identifier_stem.get('id_source') with CredibleFrontEndDriver(id_source) as driver: results = driver.retrieve_client_encounter(encounter_id) return {'encounter_results': results}
def run_credible_command(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver logging.info(f'started run credible task with kwargs: {kwargs}') command = kwargs['command'] command_args = kwargs['command_args'] id_source = kwargs['id_source'] credentials = kwargs.get('credible_credentials') if isinstance(credentials, list): credentials = credentials[-1] with CredibleFrontEndDriver(id_source, credentials=credentials) as driver: credible_function = getattr(driver, command) function_result = credible_function(**command_args) return { command: function_result, 'credible_credentials': driver.credentials }
def get_client_encounter_documentation(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver import re id_source = kwargs['id_source'] encounter_ids = kwargs['encounter_ids'] patterns = { 'goal': re.compile('Goal:[\s]+(?P<target>.+)Start'), 'objective': re.compile('Objective:[\s]+(?P<target>.+)Start'), 'intervention': re.compile('Intervention:[\s]+(?P<target>.+)Start'), 'description': re.compile('Description:[\s]+(?P<target>.+)') } encounters = {} with CredibleFrontEndDriver(id_source) as driver: for encounter_id in encounter_ids: raw_encounter = driver.retrieve_client_encounter(encounter_id) encounters[encounter_id] = _parse_encounter(raw_encounter, patterns) return {'encounters': encounters}
def _lash_driver(self): logging.debug('starting the threaded driver') with CredibleFrontEndDriver(self._id_source) as driver: logging.debug('got the tokens, going to work with the threaded driver') while True: assignment = self._driver_work.get() if assignment is None: logging.debug('work is done, credible driver leaving') return function_name = assignment['fn_name'] function_kwargs = assignment['fn_kwargs'] logging.debug('the credible driver got an assignment: %s' % function_name) function_kwargs['driver'] = driver try: getattr(self, function_name)(**function_kwargs) except Exception as e: print(e) logging.debug('the credible driver finished an assignment: %s' % function_name) self._driver_work.task_done()
def test_get_emp_ext_id(self, employee_ext_id_identifier_stem): with CredibleFrontEndDriver(employee_ext_id_identifier_stem.retrieve('id_source')) as driver: results = driver.get_employee_ext_ids()
def get_payroll_data(**kwargs): from toll_booth.alg_obj.aws.snakes.stored_statics import StaticCsv from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver import dateutil credible_date_format = '%m/%d/%Y' id_source = kwargs['id_source'] check_date = kwargs['check_date'] check_date_value = dateutil.parser.parse(check_date) check_dates = StaticCsv.for_check_dates(id_source) check_row = check_dates[check_date_value][0] sample_start_date = check_row['Sample Start'] sample_end_date = check_row['Sample End'] check_row_index = check_dates.index(check_row) previous_row = check_dates.get_by_index(check_row_index - 1) previous_sample_date = previous_row['Sample Date'] staff_search_data = { 'emp_status_f': 'ACTIVE', 'first_name': 1, 'last_name': 1, 'emp_id': 1, 'profile_code': 1, 'asgn_supervisors': 1, 'asgn_supervisees': 1 } client_search_data = { 'teams': 1, 'client_id': 1, 'last_name': 1, 'first_name': 1, 'text28': 1, 'dob': 1, 'ssn': 1, 'primary_assigned': 1, 'client_status_f': 'ALL ACTIVE' } sample_search_data = { 'clientvisit_id': 1, 'service_type': 1, 'consumer_name': 1, 'staff_name': 1, 'client_int_id': 1, 'emp_int_id': 1, 'non_billable1': 0, 'visittype': 1, 'orig_rate_amount': 1, 'timein': 1, 'timeout': 1, 'orig_units': 1, 'wh_fld1': 'cv.transfer_date', 'wh_cmp1': '>=', 'wh_val1': sample_start_date.strftime(credible_date_format), 'wh_andor': 'AND', 'wh_fld2': 'cv.transfer_date', 'wh_cmp2': '<=', 'wh_val2': sample_end_date.strftime(credible_date_format), 'data_dict_ids': [80, 81, 82, 87, 83], 'show_unappr': 1 } recovery_search_data = sample_search_data.copy() recovery_search_data.update({ 'wh_fld1': 'cv.transfer_data', 'wh_cmp1': '<', 'wh_val1': sample_start_date.strftime(credible_date_format), 'wh_fld2': 'cv.appr_date', 'wh_cmp2': '>', 'wh_val2': previous_sample_date.strftime(credible_date_format), 'show_unappr': 0 }) report_args = { 'emp_data': ('Employees', staff_search_data), 'client_data': ('Clients', client_search_data), 'sample_data': ('ClientVisit', sample_search_data), 'recovery_data': ('ClientVisit', recovery_search_data) } results = {'sampled_days': (sample_end_date-sample_start_date).days} with CredibleFrontEndDriver(id_source) as driver: for report_name, report_arg in report_args.items(): try: results[report_name] = driver.process_advanced_search(*report_arg) except RuntimeError: results[report_name] = [] if not results: return return results
def get_da_tx_data(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver id_source = kwargs['id_source'] with CredibleFrontEndDriver(id_source) as driver: pass
def test_post_process_visit_enrichment(self): encounter_id = '1147912' id_source = 'MBI' data_fields = [] fields_of_interest = { 'Service Type:': { 'field_name': 'visit_type', 'data_type': 'String' }, 'Program:': { 'field_name': 'program', 'data_type': 'String' }, 'Location:': { 'field_name': 'location', 'data_type': 'String' }, 'Recipient:': { 'field_name': 'recipient', 'data_type': 'String' }, 'Time In:': { 'field_name': 'time_in', 'data_type': 'Time' }, 'Time Out:': { 'field_name': 'time_out', 'data_type': 'Time' }, 'Date:': { 'field_name': 'encounter_date', 'data_type': 'Date' }, 'Duration:': { 'field_name': 'duration', 'data_type': 'Number' }, 'CPT Code:': { 'field_name': 'cpt_code', 'data_type': 'String' }, 'Non Billable:': { 'field_name': 'non_billable', 'data_type': 'Boolean' }, 'Transferred:': { 'field_name': 'transfer_date', 'data_type': 'DateTime' }, 'Approved': { 'field_name': 'appr', 'data_type': 'Boolean' } } header_data = {} encounter_data = [] encounter_documentation = [] with CredibleFrontEndDriver(id_source) as driver: results = driver.retrieve_client_encounter(encounter_id) encounter_soup = bs4.BeautifulSoup(results) tables = encounter_soup.find_all('table') encounter_header_table = tables[3] encounter_documentation_table = tables[7] encounter_data.extend(_filter_string(x) for x in encounter_header_table.strings if _filter_string(x)) encounter_documentation.extend(_filter_string(x) for x in encounter_documentation_table.strings if _filter_string(x)) for entry in encounter_data: if entry in fields_of_interest: entry_index = encounter_data.index(entry) entry_index += 1 next_field = encounter_data[entry_index] field_name = fields_of_interest[entry]['field_name'] data_type = fields_of_interest[entry]['data_type'] header_data[field_name] = next_field data_fields.append({ 'field_name': field_name, 'field_value': next_field, 'field_data_type': data_type, 'source_id_value': encounter_id, 'source_id_type': 'ClientVisit', 'source_id_source': id_source }) datetime_in = dateutil.parser.parse(f"{header_data['encounter_date']} {header_data['time_in']}") data_fields.append({ 'field_name': 'datetime_in', 'field_value': datetime_in.isoformat(), 'field_data_type': 'DateTime', 'source_id_value': encounter_id, 'source_id_type': 'ClientVisit', 'source_id_source': id_source }) datetime_out = dateutil.parser.parse(f"{header_data['encounter_date']} {header_data['time_out']}") data_fields.append({ 'field_name': 'datetime_out', 'field_value': datetime_out.isoformat(), 'field_data_type': 'DateTime', 'source_id_value': encounter_id, 'source_id_type': 'ClientVisit', 'source_id_source': id_source }) return {'data_fields': data_fields}
def test_get_data_dict(self): extractor = CredibleFrontEndDriver('MBI') with extractor as extractor: data_dict_data = extractor.get_data_dict_field_values('Clients', 8250, 14) print()
def get_productivity_report_data(**kwargs): from toll_booth.alg_obj.forge.extractors.credible_fe import CredibleFrontEndDriver from datetime import datetime, timedelta logging.info(f'called a get_productivity report data, kwargs: {kwargs}') credible_date_format = '%m/%d/%Y' today = datetime.utcnow() encounter_start_date = today - timedelta(days=90) unapproved_start_date = today - timedelta(days=365) staff_search_data = { 'emp_status_f': 'ACTIVE', 'first_name': 1, 'last_name': 1, 'emp_id': 1, 'profile_code': 1, 'asgn_supervisors': 1, 'asgn_supervisees': 1 } client_search_data = { 'teams': 1, 'client_id': 1, 'last_name': 1, 'first_name': 1, 'text28': 1, 'dob': 1, 'ssn': 1, 'primary_assigned': 1, 'client_status_f': 'ALL ACTIVE' } encounter_search_data = { 'clientvisit_id': 1, 'service_type': 1, 'non_billable': 1, 'consumer_name': 1, 'staff_name': 1, 'client_int_id': 1, 'emp_int_id': 1, 'non_billable1': 3, 'visittype': 1, 'orig_rate_amount': 1, 'timein': 1, 'wh_fld1': 'cv.transfer_date', 'wh_cmp1': '>=', 'wh_val1': encounter_start_date.strftime(credible_date_format), 'data_dict_ids': 83 } unapproved_search_data = encounter_search_data.copy() unapproved_search_data.update({ 'non_billable1': 0, 'show_unappr': 1, 'wh_fld1': 'cv.appr', 'wh_cmp1': '=', 'wh_val1': False, 'data_dict_ids': 641 }) tx_plan_args = encounter_search_data.copy() tx_plan_args['visittype_id'] = 3 da_args = encounter_search_data.copy() da_args['visittype_id'] = 5 id_source = kwargs['id_source'] report_args = { 'emp_data': ('Employees', staff_search_data), 'client_data': ('Clients', client_search_data), 'encounter_data': ('ClientVisit', encounter_search_data), 'unapproved_data': ('ClientVisit', unapproved_search_data, unapproved_start_date, today), 'tx_data': ('ClientVisit', tx_plan_args, unapproved_start_date, today), 'da_data': ('ClientVisit', da_args, unapproved_start_date, today) } results = {} with CredibleFrontEndDriver(id_source) as driver: for report_name, report_arg in report_args.items(): results[report_name] = driver.process_advanced_search(*report_arg) if not results: return return results