def get_values_list(response_list): values_list = [] for item in response_list: values_list.extend( xmlmanip.XMLSchema( item.encode('utf-8')).search(siteid__contains='')) return values_list
def test_get_provider_info(self): from tangier_api.api import ProviderConnection, TESTING_NPI provider = ProviderConnection() provider_response = xmlmanip.XMLSchema( provider.get_provider_info(provider_ids=[TESTING_NPI])) provider_list = provider_response.search(emp_id__contains='') self.assertTrue( len(provider_list) != 0, generate_empty_list_error_response(sys._getframe().f_code.co_name, 'provider_list'))
def location_info_values_list(self, site_ids=None): """ Returns a Searchable List object (subclass of list) of all locations returned by get_locations_info :param provider_ids: (list) of all emp_ids corresponding to desired locations info :return: (SearchableList) of all locations returned by get_locations_info """ xml_string = self.get_locations_info(site_ids) schema = xmlmanip.XMLSchema(xml_string) # kind of hacky way to get every element with a site_id tag location_list = schema.search(site_id__contains='') return location_list
def provider_info_values_list(self, provider_ids=None): """ Returns a Searchable List object (subclass of list) of all providers returned by get_provider_info :param provider_ids: (list) of all emp_ids corresponding to desired provider info :return: (SearchableList) of all providers returned by get_provider_info """ xml_string = self.get_provider_info(provider_ids) schema = xmlmanip.XMLSchema(xml_string) # kind of hacky way to get every element with an emp_id tag provider_list = schema.search(emp_id__contains='') return provider_list
def store_good(result, file_name): import pandas df = pandas.DataFrame() for i, item in enumerate(result): if not issubclass(item.__class__, Exception): temp_list = xmlmanip.XMLSchema( item.encode('utf-8')).search(siteid__contains='') good_list = list(map(lambda x: {'request': i, **x}, temp_list)) if good_list: temp_df = pandas.DataFrame(good_list) df = df.append(temp_df) df.to_pickle(file_name)
def test_get_schedule(self): from tangier_api.api import ScheduleConnection, TESTING_SITE connection = ScheduleConnection() today = moment.utcnow().strftime("%Y-%m-%d") three_months_ago = moment.utcnow().add(months=-2).strftime("%Y-%m-%d") schedule = xmlmanip.XMLSchema( connection.get_schedule(site_id=TESTING_SITE, start_date=three_months_ago, end_date=today)) schedule_list = schedule.search(location__contains='') self.assertTrue( len(schedule_list) != 0, generate_empty_list_error_response(sys._getframe().f_code.co_name, 'schedule_list'))
def get_schedule_values_list(self, start_date=None, end_date=None, site_ids=None, xml_string="", **tags): """ Wrapper for the get_schedules function that returns the retrieved schedules as a list of dicts. This can easily be converted into a DataFrame :param start_date: (str) %Y-%m-%d date string indicating the beginning of the range from which to pull the schedule :param end_date: (str) %Y-%m-%d date string indicating the ending of the range from which to pull the schedule :param site_ids: (list or None) list of ids corresponding to the site(s) that the schedule will be pulled from, defaults to the list pulled from site_file in the __init__ function :param xml_string: (xml string) overrides the default credential and/or schedule injection into base_xml :param tags: (kwargs) things to be injected into the request. :return: (OrderedDict) filled with schedules. """ if not site_ids and not self.site_ids: raise APICallError("kwarg site_ids is required.") elif not site_ids: site_ids = self.site_ids elif not issubclass(site_ids.__class__, list): site_ids = [site_ids] xml_string = xml_string if xml_string else self.base_xml schedule_values_list = [] for site_id in site_ids: schedule_response = self.get_schedule(xml_string=xml_string, start_date=start_date, end_date=end_date, site_id=site_id, **tags) temp_values_list = xmlmanip.XMLSchema(schedule_response).search( '@shiftdate', "", comparison='ne') for shifts in temp_values_list: schedule_values_list.extend(self._extract_shifts(shifts)) return schedule_values_list