def check_consumer_db_entries_for_dependent_info(rqst_dependent_dict, rqst_errors): """ This function takes a dictionary populated with dependent information and checks to see if there are any PICConsumer database entries that exist for it. :param rqst_dependent_dict: (type: dictionary) dependent information :param rqst_errors: (type: list) list of error messages :return: (type: list) list of id's for found PICConsumer entries """ found_consumer_entries = [] rqst_dependent_f_name = clean_string_value_from_dict_object( rqst_dependent_dict, "dependent_info", "first_name", rqst_errors) rqst_dependent_l_name = clean_string_value_from_dict_object( rqst_dependent_dict, "dependent_info", "last_name", rqst_errors) if not rqst_errors: consumer_entry_query = PICConsumer.objects.filter( first_name__iexact=rqst_dependent_f_name, last_name__iexact=rqst_dependent_l_name) for consumer_entry in consumer_entry_query: found_consumer_entries.append(consumer_entry.id) return found_consumer_entries
def validate_create_row_params(rqst_body, validated_params, rqst_errors): validated_params['step_name'] = clean_string_value_from_dict_object( rqst_body, "root", "step_name", rqst_errors) validated_params['step_class_name'] = clean_string_value_from_dict_object( rqst_body, "root", "step_class_name", rqst_errors) if 'step_table_name' in rqst_body: validated_params[ 'step_table_name'] = clean_string_value_from_dict_object( rqst_body, "root", "step_tables_name", rqst_errors, empty_string_allowed=True, none_allowed=True) validated_params['step_number'] = clean_int_value_from_dict_object( rqst_body, "root", "step_number", rqst_errors) if validated_params['step_number'] and validated_params['step_number'] < 0: rqst_errors.append( "Value for 'step_number' must be greater than 0. Given value is: {}" .format(validated_params['step_number'])) if 'rest_url' in rqst_body: validated_params['rest_url'] = clean_string_value_from_dict_object( rqst_body, "root", "rest_url", rqst_errors, empty_string_allowed=True, none_allowed=True)
def validate_create_row_params(rqst_body, validated_params, rqst_errors): validated_params['consumer_id'] = clean_int_value_from_dict_object( rqst_body, "root", "consumer_id", rqst_errors) validated_params['navigator_id'] = clean_int_value_from_dict_object( rqst_body, "root", "navigator_id", rqst_errors) validated_params['cm_client_id'] = clean_int_value_from_dict_object( rqst_body, "root", "cm_client_id", rqst_errors, none_allowed=True) validated_params['cm_sequence_id'] = clean_int_value_from_dict_object( rqst_body, "root", "cm_sequence_id", rqst_errors, none_allowed=True) if 'notes' in rqst_body: validated_params['notes'] = clean_string_value_from_dict_object( rqst_body, "root", "notes", rqst_errors, empty_string_allowed=True, none_allowed=True) if "datetime_completed" in rqst_body: datetime_completed = clean_string_value_from_dict_object( rqst_body, "root", "datetime_completed", rqst_errors, none_allowed=True) validated_datetime_completed = None if datetime_completed: try: validated_datetime_completed = datetime.datetime.strptime( datetime_completed, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'datetime_completed must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}' .format(datetime_completed)) validated_params['datetime_completed'] = validated_datetime_completed if "client_appointment_datetime" in rqst_body: client_appointment_datetime = clean_string_value_from_dict_object( rqst_body, "root", "client_appointment_datetime", rqst_errors, none_allowed=True) validated_client_appointment_datetime = None if client_appointment_datetime: try: validated_client_appointment_datetime = datetime.datetime.strptime( client_appointment_datetime, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'client_appointment_datetime must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}' .format(client_appointment_datetime)) validated_params[ 'client_appointment_datetime'] = validated_client_appointment_datetime
def validate_create_row_params(rqst_body, validated_params, rqst_errors): rqst_carrier_name = clean_string_value_from_dict_object( rqst_body, "root", "name", rqst_errors) rqst_carrier_state = clean_string_value_from_dict_object( rqst_body, "root", "state_province", rqst_errors) validated_params["name"] = rqst_carrier_name validated_params["state"] = rqst_carrier_state
def validate_update_job_row_params(job_row_dict, job_row_index, rqst_errors): validated_job_row_dict = { 'id': clean_int_value_from_dict_object( job_row_dict, "update_job_row[{}]".format(job_row_index), "id", rqst_errors ) } if 'title' in job_row_dict: validated_job_row_dict['title'] = clean_string_value_from_dict_object( job_row_dict, "update_job_row[{}]".format(job_row_index), "title", rqst_errors, ) if 'company' in job_row_dict: validated_job_row_dict['company'] = clean_string_value_from_dict_object( job_row_dict, "update_job_row[{}]".format(job_row_index), "company", rqst_errors, ) if 'description' in job_row_dict: validated_job_row_dict['description'] = clean_string_value_from_dict_object( job_row_dict, "update_job_row[{}]".format(job_row_index), "description", rqst_errors, none_allowed=True ) if "start_year_datetime" in job_row_dict: start_year_datetime = clean_string_value_from_dict_object(job_row_dict, "root", "start_year_datetime", rqst_errors, none_allowed=True) validated_start_year_datetime = None if start_year_datetime: try: validated_start_year_datetime = datetime.datetime.strptime(start_year_datetime, "%Y").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'start_year_datetime must be a properly formatted datetime string in UTC, eg. YYYY. Value is : {}'.format( start_year_datetime) ) validated_job_row_dict['start_year_datetime'] = validated_start_year_datetime if "end_year_datetime" in job_row_dict: end_year_datetime = clean_string_value_from_dict_object(job_row_dict, "root", "end_year_datetime", rqst_errors, none_allowed=True) validated_end_year_datetime = None if end_year_datetime: try: validated_end_year_datetime = datetime.datetime.strptime(end_year_datetime, "%Y").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'end_year_datetime must be a properly formatted datetime string in UTC, eg. YYYY. Value is : {}'.format( end_year_datetime) ) validated_job_row_dict['end_year_datetime'] = validated_end_year_datetime return validated_job_row_dict
def validate_create_education_row_params(education_row_dict, education_row_index, rqst_errors): validated_education_row_dict = { 'school': clean_string_value_from_dict_object( education_row_dict, "create_education_row[{}]".format(education_row_index), "school", rqst_errors, ), 'major': clean_string_value_from_dict_object( education_row_dict, "create_education_row[{}]".format(education_row_index), "major", rqst_errors, none_allowed=True ), 'degree_type': clean_string_value_from_dict_object( education_row_dict, "create_education_row[{}]".format(education_row_index), "degree_type", rqst_errors, none_allowed=True ), } if not validated_education_row_dict['degree_type']: validated_education_row_dict['degree_type'] = "Not Available" if "start_year_datetime" in education_row_dict: start_year_datetime = clean_string_value_from_dict_object(education_row_dict, "root", "start_year_datetime", rqst_errors, none_allowed=True) validated_start_year_datetime = None if start_year_datetime: try: validated_start_year_datetime = datetime.datetime.strptime(start_year_datetime, "%Y").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'start_year_datetime must be a properly formatted datetime string in UTC, eg. YYYY. Value is : {}'.format( start_year_datetime) ) validated_education_row_dict['start_year_datetime'] = validated_start_year_datetime if "end_year_datetime" in education_row_dict: end_year_datetime = clean_string_value_from_dict_object(education_row_dict, "root", "end_year_datetime", rqst_errors, none_allowed=True) validated_end_year_datetime = None if end_year_datetime: try: validated_end_year_datetime = datetime.datetime.strptime(end_year_datetime, "%Y").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'end_year_datetime must be a properly formatted datetime string in UTC, eg. YYYY. Value is : {}'.format( end_year_datetime) ) validated_education_row_dict['end_year_datetime'] = validated_end_year_datetime return validated_education_row_dict
def validate_update_row_params(rqst_body, validated_params, rqst_errors): if "name" in rqst_body: rqst_provider_location_name = clean_string_value_from_dict_object( rqst_body, "root", "name", rqst_errors) validated_params["name"] = rqst_provider_location_name if 'state_province' in rqst_body: state_province = clean_string_value_from_dict_object( rqst_body, "root", "state_province", rqst_errors, none_allowed=True, empty_string_allowed=True) if not state_province: state_province = 'not available' validated_params["state_province"] = state_province if "provider_network_id" in rqst_body: rqst_provider_network_id = clean_int_value_from_dict_object( rqst_body, "root", "provider_network_id", rqst_errors, none_allowed=True) validated_params["provider_network_id"] = rqst_provider_network_id if "add_accepted_plans" in rqst_body: rqst_add_accepted_plans_ids = clean_list_value_from_dict_object( rqst_body, "root", "add_accepted_plans", rqst_errors, ) if rqst_add_accepted_plans_ids: add_accepted_plan_objects = validate_accepted_plans_params( rqst_add_accepted_plans_ids, rqst_errors) validated_params[ "add_accepted_plans_objects"] = add_accepted_plan_objects elif "remove_accepted_plans" in rqst_body: rqst_remove_accepted_plans_ids = clean_list_value_from_dict_object( rqst_body, "root", "remove_accepted_plans", rqst_errors, ) if rqst_remove_accepted_plans_ids: remove_accepted_plan_objects = validate_accepted_plans_params( rqst_remove_accepted_plans_ids, rqst_errors) validated_params[ "remove_accepted_plans_objects"] = remove_accepted_plan_objects
def validate_create_row_params(rqst_body, validated_params, rqst_errors): validated_params["rqst_general_concern_name"] = clean_string_value_from_dict_object( rqst_body, "root", "name", rqst_errors )
def validate_create_row_params(rqst_body, validated_params, rqst_errors): validated_params[ "rqst_specific_concern_question"] = clean_string_value_from_dict_object( rqst_body, "root", "question", rqst_errors) rqst_specific_concern_research_weight = clean_int_value_from_dict_object( rqst_body, "root", "research_weight", rqst_errors, no_key_allowed=True) if not rqst_specific_concern_research_weight: rqst_specific_concern_research_weight = ConsumerSpecificConcern.RESEARCH_WEIGHT_DEFAULT elif rqst_specific_concern_research_weight > 100: rqst_errors.append( "Value for 'research_weight' must be less than 100. Given value is: {}" .format(rqst_specific_concern_research_weight)) validated_params[ "rqst_specific_concern_research_weight"] = rqst_specific_concern_research_weight if "add_related_general_concerns" in rqst_body: rqst_add_related_general_concerns_names = clean_list_value_from_dict_object( rqst_body, "root", "add_related_general_concerns", rqst_errors, empty_list_allowed=True) add_related_general_concerns_objects = [] if rqst_add_related_general_concerns_names: validate_related_gen_concern_names( rqst_add_related_general_concerns_names, rqst_errors) if not rqst_errors: add_related_general_concerns_objects = ConsumerGeneralConcern.retrieve_related_gen_concern_rows_by_name( rqst_add_related_general_concerns_names, rqst_errors) validated_params[ "add_related_general_concerns_objects"] = add_related_general_concerns_objects
def add_nav_apt_to_google_calendar(post_data, post_errors): """ This function takes a dictionary populated with data about a consumer appointment with a navigator, adds it to the navigator's 'Navigator-Consumer Appointments (DO NOT CHANGE)' calendar, and sends an email notification to the consumer :param post_data: (type: dictionary) dictionary with Patient Assist appointment info :param post_errors: (type: list) list of error messages :return: """ scheduled_appointment = {} rqst_nav_id = clean_int_value_from_dict_object(post_data, "root", "Navigator ID", post_errors) rqst_apt_datetime = clean_string_value_from_dict_object(post_data, "root", "Appointment Date and Time", post_errors) if not isinstance(rqst_apt_datetime, str): post_errors.append("{!s} is not a string, Preferred Times must be a string iso formatted date and time".format(str(rqst_apt_datetime))) consumer_info = create_consumer_instance_from_apt_rqst(rqst_nav_id, post_data, post_errors) try: picstaff_object = Navigators.objects.get(id=rqst_nav_id) credentials_object = CredentialsModel.objects.get(id=picstaff_object) nav_info = picstaff_object.return_values_dict() if credentials_object.credential.invalid: credentials_object.delete() post_errors.append('Google Credentials database entry is invalid for the navigator with id: {!s}'.format(str(rqst_nav_id))) else: scheduled_appointment = send_add_apt_rqst_to_google_and_email_consumer(credentials_object.credential, rqst_apt_datetime, consumer_info, nav_info, post_errors) except Navigators.DoesNotExist: post_errors.append('Navigator database entry does not exist for the id: {!s}'.format(str(rqst_nav_id))) except CredentialsModel.DoesNotExist: post_errors.append('Google Credentials database entry does not exist for the navigator with id: {!s}'.format(str(rqst_nav_id))) return scheduled_appointment, consumer_info
def validate_add_staff_params(rqst_body, validated_params, rqst_errors): rqst_usr_email = clean_string_value_from_dict_object( rqst_body, "root", "email", rqst_errors) if rqst_usr_email and not rqst_errors: try: validate_email(rqst_usr_email) except forms.ValidationError: rqst_errors.append( "{!s} must be a valid email address".format(rqst_usr_email)) rqst_usr_f_name = clean_string_value_from_dict_object( rqst_body, "root", "first_name", rqst_errors) rqst_usr_l_name = clean_string_value_from_dict_object( rqst_body, "root", "last_name", rqst_errors) rqst_county = clean_string_value_from_dict_object(rqst_body, "root", "county", rqst_errors) rqst_usr_type = clean_string_value_from_dict_object( rqst_body, "root", "type", rqst_errors) rqst_base_locations = clean_list_value_from_dict_object( rqst_body, "root", "base_locations", rqst_errors, empty_list_allowed=True) base_location_objects = [] location_errors = [] if rqst_base_locations: rqst_base_locations = list(set(rqst_base_locations)) for base_location_name in rqst_base_locations: try: base_location_object = NavMetricsLocation.objects.get( name=base_location_name) base_location_objects.append(base_location_object) except NavMetricsLocation.DoesNotExist: location_errors.append( "No Nav Hub Location Database entry found for name: {!s}". format(base_location_name)) for location_error in location_errors: rqst_errors.append(location_error) validated_params["rqst_usr_email"] = rqst_usr_email validated_params["rqst_usr_f_name"] = rqst_usr_f_name validated_params["rqst_usr_l_name"] = rqst_usr_l_name validated_params["rqst_county"] = rqst_county validated_params["rqst_usr_type"] = rqst_usr_type validated_params["base_location_objects"] = base_location_objects
def validate_create_row_params(rqst_body, validated_params, rqst_errors): rqst_location_name = clean_string_value_from_dict_object(rqst_body, "root", "Location Name", rqst_errors) rqst_address_line_1 = clean_string_value_from_dict_object(rqst_body, "root", "Address Line 1", rqst_errors) rqst_address_line_2 = clean_string_value_from_dict_object(rqst_body, "root", "Address Line 2", rqst_errors, empty_string_allowed=True) if rqst_address_line_2 is None: rqst_address_line_2 = '' rqst_city = clean_string_value_from_dict_object(rqst_body, "root", "City", rqst_errors) rqst_state = clean_string_value_from_dict_object(rqst_body, "root", "State", rqst_errors) rqst_zipcode = clean_string_value_from_dict_object(rqst_body, "root", "Zipcode", rqst_errors) rqst_cps_location = clean_bool_value_from_dict_object(rqst_body, "root", "cps_location", rqst_errors, no_key_allowed=True) if not rqst_cps_location: rqst_cps_location = False rqst_country = clean_string_value_from_dict_object(rqst_body, "root", "Country", rqst_errors) country_row = None if rqst_country: try: country_row = Country.objects.get(name__iexact=rqst_country) except Country.DoesNotExist: rqst_errors.append('Row does not exist in database for the country name: {!s}'.format(str(rqst_country))) validated_params["rqst_location_name"] = rqst_location_name validated_params["rqst_address_line_1"] = rqst_address_line_1 validated_params["rqst_address_line_2"] = rqst_address_line_2 validated_params["rqst_city"] = rqst_city validated_params["rqst_state"] = rqst_state validated_params["rqst_zipcode"] = rqst_zipcode validated_params["country_row"] = country_row validated_params["rqst_cps_location"] = rqst_cps_location
def validate_create_resume_row_params(resume_row_params, rqst_errors): validated_resume_row_params = { 'profile_description': clean_string_value_from_dict_object( resume_row_params, "create_resume_row", "profile_description", rqst_errors, empty_string_allowed=True, none_allowed=True ), } if "create_education_rows" in resume_row_params: education_row_params = clean_list_value_from_dict_object( resume_row_params, "create_resume_row", "create_education_rows", rqst_errors, empty_list_allowed=True ) validated_education_row_params = [] if education_row_params: for education_row_index, education_row_dict in enumerate(education_row_params): validated_education_row_dict = validate_create_education_row_params( education_row_dict, education_row_index, rqst_errors ) validated_education_row_params.append(validated_education_row_dict) validated_resume_row_params['create_education_rows'] = validated_education_row_params if "create_job_rows" in resume_row_params: job_row_params = clean_list_value_from_dict_object( resume_row_params, "create_resume_row", "create_job_rows", rqst_errors, empty_list_allowed=True ) validated_job_row_params = [] if job_row_params: for job_row_index, job_row_dict in enumerate(job_row_params): validated_job_row_dict = validate_create_job_row_params( job_row_dict, job_row_index, rqst_errors ) validated_job_row_params.append(validated_job_row_dict) validated_resume_row_params['create_job_rows'] = validated_job_row_params return validated_resume_row_params
def validate_update_row_params(rqst_body, validated_params, rqst_errors): if 'consumer_id' in rqst_body: validated_params['consumer_id'] = clean_int_value_from_dict_object( rqst_body, "root", "consumer_id", rqst_errors) if 'navigator_id' in rqst_body: validated_params['navigator_id'] = clean_int_value_from_dict_object( rqst_body, "root", "navigator_id", rqst_errors) if 'notes' in rqst_body: validated_params['notes'] = clean_string_value_from_dict_object( rqst_body, "root", "notes", rqst_errors, empty_string_allowed=True, none_allowed=True) if 'status' in rqst_body: validated_params['status'] = clean_string_value_from_dict_object( rqst_body, "root", "status", rqst_errors, empty_string_allowed=True, none_allowed=True) if not validated_params['status']: validated_params['status'] = "not available" if 'severity' in rqst_body: validated_params['severity'] = clean_string_value_from_dict_object( rqst_body, "root", "severity", rqst_errors, empty_string_allowed=True, none_allowed=True) if not validated_params['severity']: validated_params['severity'] = "not available"
def validate_params_for_create_row(rqst_body, validated_params, rqst_errors): validated_params['full_name'] = clean_string_value_from_dict_object( rqst_body, "root", "full_name", rqst_errors) rqst_email = clean_string_value_from_dict_object(rqst_body, "root", "email", rqst_errors) if rqst_email is not None: try: validate_email(rqst_email) except forms.ValidationError: rqst_errors.append( "{} must be a valid email address".format(rqst_email)) rqst_email = None validated_params['email'] = rqst_email validated_params['company_name'] = clean_string_value_from_dict_object( rqst_body, "root", "company_name", rqst_errors) rqst_phone_number = clean_string_value_from_dict_object( rqst_body, "root", "phone_number", rqst_errors) if rqst_phone_number is not None: validate_phone_number(rqst_phone_number, rqst_errors) validated_params['phone_number'] = rqst_phone_number
def validate_nav_sign_up_params(rqst_body, rqst_errors): validated_params = { 'rqst_action': clean_string_value_from_dict_object(rqst_body, "root", "db_action", rqst_errors) } rqst_action = validated_params['rqst_action'] if rqst_action == 'create': validate_nav_sign_up_create_params(rqst_body, validated_params, rqst_errors) return validated_params
def validate_create_row_params(rqst_body, validated_params, rqst_errors): rqst_provider_location_name = clean_string_value_from_dict_object( rqst_body, "root", "name", rqst_errors) validated_params["name"] = rqst_provider_location_name state_province = clean_string_value_from_dict_object( rqst_body, "root", "state_province", rqst_errors, none_allowed=True, empty_string_allowed=True) if not state_province: state_province = 'not available' validated_params["state_province"] = state_province rqst_provider_network_id = clean_int_value_from_dict_object( rqst_body, "root", "provider_network_id", rqst_errors, none_allowed=True) validated_params["provider_network_id"] = rqst_provider_network_id rqst_add_accepted_plans_ids = clean_list_value_from_dict_object( rqst_body, "root", "add_accepted_plans", rqst_errors, empty_list_allowed=True) add_accepted_plan_objects = [] if rqst_add_accepted_plans_ids: add_accepted_plan_objects = validate_accepted_plans_params( rqst_add_accepted_plans_ids, rqst_errors) validated_params["add_accepted_plans_objects"] = add_accepted_plan_objects
def validate_put_rqst_params(rqst_body, rqst_errors): validated_params = { 'rqst_action': clean_string_value_from_dict_object(rqst_body, "root", "db_action", rqst_errors) } rqst_action = validated_params['rqst_action'] if rqst_action == 'create': validate_create_row_params(rqst_body, validated_params, rqst_errors) elif rqst_action == 'update': validated_params['rqst_id'] = clean_int_value_from_dict_object(rqst_body, "root", "id", rqst_errors) validate_update_row_params(rqst_body, validated_params, rqst_errors) elif rqst_action == 'delete': validated_params['rqst_id'] = clean_int_value_from_dict_object(rqst_body, "root", "id", rqst_errors) return validated_params
def delete_nav_apt_from_google_calendar(post_data, post_errors): """ This function takes a dictionary populated with data about a consumer appointment with a navigator and deletes it from the navigator's 'Navigator-Consumer Appointments (DO NOT CHANGE)' calendar. :param post_data: (type: dictionary) dictionary with Patient Assist appointment info :param post_errors: (type: list) list of error messages :return: """ google_apt_deleted = False rqst_nav_id = clean_int_value_from_dict_object(post_data, "root", "Navigator ID", post_errors) rqst_apt_datetime = clean_string_value_from_dict_object(post_data, "root", "Appointment Date and Time", post_errors) if not isinstance(rqst_apt_datetime, str): post_errors.append("{!s} is not a string, Preferred Times must be a string iso formatted date and time".format(str(rqst_apt_datetime))) try: picstaff_object = Navigators.objects.get(id=rqst_nav_id) credentials_object = CredentialsModel.objects.get(id=picstaff_object) nav_info = picstaff_object.return_values_dict() if credentials_object.credential.invalid: credentials_object.delete() post_errors.append('Google Credentials database entry is invalid for the navigator with id: {!s}'.format(str(rqst_nav_id))) else: service = build_authorized_cal_http_service_object(credentials_object.credential) navigator_calendar_found, navigator_calendar_id = check_cal_objects_for_nav_cal(service, post_errors) if not navigator_calendar_found: post_errors.append("Navigator calendar not found for this navigator, creating it...") navigator_calendar_id = add_nav_cal_to_google_cals(service, post_errors) google_apt_id = check_google_cal_for_apt(credentials_object, rqst_apt_datetime, post_errors, navigator_calendar_id) if google_apt_id: google_apt_deleted = send_delete_apt_rqst_to_google(credentials_object, google_apt_id, navigator_calendar_id, post_errors) else: post_errors.append('Appointment with consumer at {!s}, was not found in Navigator\'s Google Calendar'.format(rqst_apt_datetime)) except Navigators.DoesNotExist: post_errors.append('Navigator database entry does not exist for the id: {!s}'.format(str(rqst_nav_id))) except CredentialsModel.DoesNotExist: post_errors.append('Google Credentials database entry does not exist for the navigator with id: {!s}'.format(str(rqst_nav_id))) return google_apt_deleted
def validate_put_rqst_params(rqst_body, rqst_errors): validated_params = { 'db_action': clean_string_value_from_dict_object(rqst_body, "root", "db_action", rqst_errors) } if validated_params['db_action'] == 'create': validate_params_for_create_row(rqst_body, validated_params, rqst_errors) elif validated_params['db_action'] == 'update': validated_params['id'] = clean_int_value_from_dict_object( rqst_body, "root", "id", rqst_errors) validate_params_for_update_row(rqst_body, validated_params, rqst_errors) elif validated_params['db_action'] == 'delete': validated_params['id'] = clean_int_value_from_dict_object( rqst_body, "root", "id", rqst_errors) else: rqst_errors.append("No valid 'db_action' provided.") return validated_params
def validate_update_row_params(rqst_body, validated_params, rqst_errors): if "name" in rqst_body: rqst_name = clean_string_value_from_dict_object( rqst_body, "root", "name", rqst_errors, empty_string_allowed=True) validated_params["name"] = rqst_name if 'add_steps' in rqst_body: add_cm_steps = clean_list_value_from_dict_object( rqst_body, "root", "add_steps", rqst_errors, empty_list_allowed=True) validated_cm_steps = [] for step_id in add_cm_steps: if not isinstance(step_id, int): rqst_errors.append( 'Error: An step_id in \'add_steps\' is not an integer.') continue validated_cm_steps.append(step_id) validated_params['add_steps'] = validated_cm_steps elif 'remove_steps' in rqst_body: remove_cm_steps = clean_list_value_from_dict_object( rqst_body, "root", "remove_steps", rqst_errors) validated_cm_steps = [] for step_id in remove_cm_steps: if not isinstance(step_id, int): rqst_errors.append( 'Error: An step_id in \'remove_steps\' is not an integer.') continue validated_cm_steps.append(step_id) validated_params['remove_steps'] = validated_cm_steps
def fetch_and_parse_pokit_elig_data(post_data, post_errors): raw_eligibility_results = {} parsed_eligibility_results = {} rqst_consumer_f_name = clean_string_value_from_dict_object(post_data, "root", "First Name", post_errors, none_allowed=True) rqst_consumer_l_name = clean_string_value_from_dict_object(post_data, "root", "Last Name", post_errors, none_allowed=True) rqst_consumer_birth = clean_string_value_from_dict_object(post_data, "root", "Birth Date", post_errors, none_allowed=True) rqst_consumer_plan_id = clean_string_value_from_dict_object(post_data, "root", "Consumer Plan ID", post_errors, none_allowed=True) rqst_consumer_gender = clean_string_value_from_dict_object(post_data, "root", "Gender", post_errors, none_allowed=True) rqst_consumer_trading_partner = clean_string_value_from_dict_object(post_data, "root", "Trading Partner ID", post_errors) # if no errors, make request to pokitdok if not post_errors: eligibility_request_data = { "member": {}, "provider":{"npi": "1649703620", "organization_name": "PATIENT INNOVATION CENTER NFP"}, "trading_partner_id": rqst_consumer_trading_partner } if rqst_consumer_f_name: eligibility_request_data["member"]["first_name"] = rqst_consumer_f_name if rqst_consumer_l_name: eligibility_request_data["member"]["last_name"] = rqst_consumer_l_name if rqst_consumer_birth: eligibility_request_data["member"]["birth_date"] = rqst_consumer_birth if rqst_consumer_plan_id: eligibility_request_data["member"]["id"] = rqst_consumer_plan_id if rqst_consumer_gender: eligibility_request_data["member"]["gender"] = rqst_consumer_gender pd = pokitdok.api.connect('fbSgQ0sM3xQNI5m8TyxR', 'du6JkRfNcHt8wNashtpf7Mdr96thZyn8Kilo9xoB') raw_eligibility_results = pd.eligibility(eligibility_request_data) raw_eligibility_results = check_elig_results_for_errors(raw_eligibility_results, post_errors) if "No Data in response from Pokitdok" not in post_errors and "Errors in Pokitdok Data" not in post_errors: if rqst_consumer_trading_partner == "united_health_care": parse_united_health_care_data(raw_eligibility_results, parsed_eligibility_results, post_errors) elif rqst_consumer_trading_partner == "ambetter": parse_ambetter_data(raw_eligibility_results, parsed_eligibility_results, post_errors) else: parse_united_health_care_data(raw_eligibility_results, parsed_eligibility_results, post_errors) return raw_eligibility_results, parsed_eligibility_results
def validate_navigator_nav_sign_up_fields(rqst_body, validated_params, rqst_errors): if 'add_healthcare_locations_worked' in rqst_body: add_healthcare_locations_worked = clean_list_value_from_dict_object( rqst_body, "root", "add_healthcare_locations_worked", rqst_errors, empty_list_allowed=True) validated_location_info = [] for location_dict in add_healthcare_locations_worked: if not isinstance(location_dict, dict): rqst_errors.append( 'Error: A location object in \'add_healthcare_locations_worked\' is not a object.' ) else: location_info = { "name": clean_string_value_from_dict_object( location_dict, "add_location_object", 'name', rqst_errors), "state_province": clean_string_value_from_dict_object(location_dict, "add_location_object", 'state_province', rqst_errors, none_allowed=True) } if not location_info['state_province']: location_info['state_province'] = 'not available' validated_location_info.append(location_info) validated_params[ 'add_healthcare_locations_worked'] = validated_location_info if 'add_healthcare_service_expertises' in rqst_body: add_healthcare_service_expertises = clean_list_value_from_dict_object( rqst_body, "root", "add_healthcare_service_expertises", rqst_errors, empty_list_allowed=True) validated_service_expertise_info = [] for service_expertise in add_healthcare_service_expertises: if not isinstance(service_expertise, str): rqst_errors.append( 'Error: A service_expertise in \'add_healthcare_service_expertises\' is not a string.' ) continue validated_service_expertise_info.append(service_expertise) validated_params[ 'add_healthcare_service_expertises'] = validated_service_expertise_info if 'add_insurance_carrier_specialties' in rqst_body: add_insurance_carrier_specialties = clean_list_value_from_dict_object( rqst_body, "root", "add_insurance_carrier_specialties", rqst_errors, empty_list_allowed=True) validated_insurance_carrier_info = [] for carrier_dict in add_insurance_carrier_specialties: if not isinstance(carrier_dict, dict): rqst_errors.append( 'Error: An insurance_carrier object in \'add_insurance_carrier_specialties\' is not a object.' ) else: validated_carrier_info = { "name": clean_string_value_from_dict_object( carrier_dict, "insurance_carrier_object", 'name', rqst_errors, empty_string_allowed=True), "state_province": clean_string_value_from_dict_object( carrier_dict, "insurance_carrier_object", 'state_province', rqst_errors, empty_string_allowed=True) } if not validated_carrier_info['state_province']: validated_carrier_info['state_province'] = 'not available' validated_insurance_carrier_info.append(validated_carrier_info) validated_params[ 'add_insurance_carrier_specialties'] = validated_insurance_carrier_info if "address_line_1" in rqst_body: address_line_1 = clean_string_value_from_dict_object( rqst_body, "root", "address_line_1", rqst_errors, empty_string_allowed=True) validated_params["address_line_1"] = address_line_1 if "address_line_2" in rqst_body: address_line_2 = clean_string_value_from_dict_object( rqst_body, "root", "address_line_2", rqst_errors, empty_string_allowed=True) if address_line_2 is None: address_line_2 = '' validated_params["address_line_2"] = address_line_2 if "city" in rqst_body: city = clean_string_value_from_dict_object(rqst_body, "root", "city", rqst_errors, empty_string_allowed=True) validated_params["city"] = city if "state_province" in rqst_body: state_province = clean_string_value_from_dict_object( rqst_body, "root", "state_province", rqst_errors, empty_string_allowed=True) validated_params["state_province"] = state_province if "zipcode" in rqst_body: zipcode = clean_string_value_from_dict_object( rqst_body, "root", "zipcode", rqst_errors, empty_string_allowed=True) validated_params["zipcode"] = zipcode if "phone" in rqst_body: phone = clean_string_value_from_dict_object(rqst_body, "root", "phone", rqst_errors, none_allowed=True) validated_params["phone"] = phone if "reported_region" in rqst_body: reported_region = clean_string_value_from_dict_object( rqst_body, "root", "reported_region", rqst_errors, none_allowed=True) validated_params["reported_region"] = reported_region if "video_link" in rqst_body: video_link = clean_string_value_from_dict_object(rqst_body, "root", "video_link", rqst_errors, none_allowed=True) if video_link: validate = URLValidator() try: validate(video_link) except ValidationError: rqst_errors.append( "'video_link' is not a valid url. value is: {}".format( video_link)) validated_params["video_link"] = video_link if "navigator_organization" in rqst_body: navigator_organization = clean_string_value_from_dict_object( rqst_body, "root", "navigator_organization", rqst_errors, none_allowed=True) validated_params["navigator_organization"] = navigator_organization validate_nav_sign_up_navigator_resume_params(rqst_body, validated_params, rqst_errors)
def validate_nav_sign_up_create_params(rqst_body, validated_params, rqst_errors): email = clean_string_value_from_dict_object(rqst_body, "root", "email", rqst_errors) if email and not rqst_errors: try: validate_email(email) except forms.ValidationError: rqst_errors.append( "{!s} must be a valid email address".format(email)) validated_params["email"] = email if 'mpn' in rqst_body: mpn = clean_string_value_from_dict_object(rqst_body, "root", "mpn", rqst_errors, empty_string_allowed=True, none_allowed=True) if mpn is None: mpn = '' validated_params["mpn"] = mpn else: validated_params["mpn"] = '' first_name = clean_string_value_from_dict_object(rqst_body, "root", "first_name", rqst_errors) validated_params["first_name"] = first_name last_name = clean_string_value_from_dict_object(rqst_body, "root", "last_name", rqst_errors) validated_params["last_name"] = last_name if "county" in rqst_body: county = clean_string_value_from_dict_object(rqst_body, "root", "county", rqst_errors) validated_params["county"] = county else: validated_params["county"] = '' if "type" in rqst_body: rqst_type = clean_string_value_from_dict_object( rqst_body, "root", "type", rqst_errors) validated_params["type"] = rqst_type else: validated_params["type"] = '' if 'add_base_locations' in rqst_body: add_base_location_names = clean_list_value_from_dict_object( rqst_body, "root", "add_base_locations", rqst_errors, empty_list_allowed=True) validated_base_location_names = [] for base_location_name in add_base_location_names: if not isinstance(base_location_name, str): rqst_errors.append( 'Error: A base_location_name in \'add_base_locations\' is not a string.' ) continue validated_base_location_names.append(base_location_name) validated_params['add_base_locations'] = validated_base_location_names validate_navigator_nav_sign_up_fields(rqst_body, validated_params, rqst_errors)
def validate_create_row_params(rqst_body, validated_params, rqst_errors): """ This function parses the BODY of requests for PIC consumer management PUT requests, checks for errors, and returns relevant information as a dictionary :param rqst_body: (type: dictionary) Carrier information to be parsed :param rqst_errors: (type: list) list of error messages :return: (type: dictionary) dictionary with relevant consumer information """ # Summary report fields validated_params["medical_deductible_individual_standard"] = clean_float_value_from_dict_object( rqst_body, "root", "medical_deductible_individual_standard", rqst_errors, none_allowed=True, no_key_allowed=True ) validated_params["medical_out_of_pocket_max_individual_standard"] = clean_float_value_from_dict_object( rqst_body, "root", "medical_out_of_pocket_max_individual_standard", rqst_errors, none_allowed=True, no_key_allowed=True ) rqst_primary_care_physician_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "primary_care_physician_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "primary_care_physician_individual_standard_cost", rqst_errors ) validated_params["primary_care_physician_standard_cost"] = rqst_primary_care_physician_standard_cost # Detailed report fields validated_params["rqst_plan_name"] = clean_string_value_from_dict_object(rqst_body, "root", "name", rqst_errors) validated_params["rqst_carrier_id"] = clean_int_value_from_dict_object( rqst_body, "root", "Carrier Database ID", rqst_errors ) validated_params["rqst_plan_premium_type"] = clean_string_value_from_dict_object( rqst_body, "root", "premium_type", rqst_errors, none_allowed=True, no_key_allowed=True ) validated_params["rqst_plan_metal_level"] = clean_string_value_from_dict_object( rqst_body, "root", "metal_level", rqst_errors, none_allowed=True, no_key_allowed=True ) validated_params["county"] = clean_string_value_from_dict_object( rqst_body, "root", "county", rqst_errors, none_allowed=True, no_key_allowed=True ) rqst_specialist_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "specialist_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "specialist_standard_cost", rqst_errors ) validated_params["specialist_standard_cost"] = rqst_specialist_standard_cost rqst_emergency_room_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "emergency_room_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "emergency_room_standard_cost", rqst_errors ) validated_params["emergency_room_standard_cost"] = rqst_emergency_room_standard_cost rqst_inpatient_facility_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "inpatient_facility_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "inpatient_facility_standard_cost", rqst_errors ) validated_params["inpatient_facility_standard_cost"] = rqst_inpatient_facility_standard_cost rqst_generic_drugs_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "generic_drugs_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "generic_drugs_standard_cost", rqst_errors ) validated_params["generic_drugs_standard_cost"] = rqst_generic_drugs_standard_cost rqst_preferred_brand_drugs_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "preferred_brand_drugs_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "preferred_brand_drugs_standard_cost", rqst_errors ) validated_params["preferred_brand_drugs_standard_cost"] = rqst_preferred_brand_drugs_standard_cost rqst_non_preferred_brand_drugs_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "non_preferred_brand_drugs_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "non_preferred_brand_drugs_standard_cost", rqst_errors ) validated_params["non_preferred_brand_drugs_standard_cost"] = rqst_non_preferred_brand_drugs_standard_cost rqst_specialty_drugs_standard_cost = create_healthcare_service_cost_instances_from_string( clean_string_value_from_dict_object( rqst_body, "root", "specialty_drugs_standard_cost", rqst_errors, none_allowed=True, no_key_allowed=True ), "specialty_drugs_standard_cost", rqst_errors ) validated_params["specialty_drugs_standard_cost"] = rqst_specialty_drugs_standard_cost # Extra benefit report fields validated_params["medical_deductible_family_standard"] = clean_float_value_from_dict_object( rqst_body, "root", "medical_deductible_family_standard", rqst_errors, none_allowed=True, no_key_allowed=True ) validated_params["medical_out_of_pocket_max_family_standard"] = clean_float_value_from_dict_object( rqst_body, "root", "medical_out_of_pocket_max_family_standard", rqst_errors, none_allowed=True, no_key_allowed=True )
def validate_params_for_create_row(rqst_body, validated_params, rqst_errors): validated_params['company_name'] = clean_string_value_from_dict_object( rqst_body, "root", "company_name", rqst_errors) if "address_line_1" in rqst_body: address_line_1 = clean_string_value_from_dict_object( rqst_body, "root", "address_line_1", rqst_errors, empty_string_allowed=True) validated_params["address_line_1"] = address_line_1 if "address_line_2" in rqst_body: address_line_2 = clean_string_value_from_dict_object( rqst_body, "root", "address_line_2", rqst_errors, empty_string_allowed=True) if address_line_2 is None: address_line_2 = '' validated_params["address_line_2"] = address_line_2 if "city" in rqst_body: city = clean_string_value_from_dict_object(rqst_body, "root", "city", rqst_errors, empty_string_allowed=True) validated_params["city"] = city if "state_province" in rqst_body: state_province = clean_string_value_from_dict_object( rqst_body, "root", "state_province", rqst_errors, empty_string_allowed=True) validated_params["state_province"] = state_province if "zipcode" in rqst_body: zipcode = clean_string_value_from_dict_object( rqst_body, "root", "zipcode", rqst_errors, empty_string_allowed=True) validated_params["zipcode"] = zipcode estimated_monthly_caseload = clean_int_value_from_dict_object( rqst_body, 'root', "estimated_monthly_caseload", rqst_errors) if estimated_monthly_caseload: validator = MinValueValidator(0) try: validator(estimated_monthly_caseload) except ValidationError: rqst_errors.append( "estimated_monthly_caseload must be more than 0. Value is : {}" .format(estimated_monthly_caseload)) validated_params["estimated_monthly_caseload"] = estimated_monthly_caseload contact_first_name = clean_string_value_from_dict_object( rqst_body, "root", "contact_first_name", rqst_errors) validated_params["contact_first_name"] = contact_first_name contact_last_name = clean_string_value_from_dict_object( rqst_body, "root", "contact_last_name", rqst_errors) validated_params["contact_last_name"] = contact_last_name contact_email = clean_string_value_from_dict_object( rqst_body, "root", "contact_email", rqst_errors) if contact_email is not None: try: validate_email(contact_email) except forms.ValidationError: rqst_errors.append( "contact_email must be a valid email address. Value is : {}". format(contact_email)) contact_email = None validated_params['contact_email'] = contact_email contact_phone = clean_string_value_from_dict_object( rqst_body, "root", "contact_phone", rqst_errors) if contact_phone: validate_phone_number(contact_phone, rqst_errors) validated_params["contact_phone"] = contact_phone appointment_datetime = clean_string_value_from_dict_object( rqst_body, "root", "appointment_datetime", rqst_errors) validated_appointment_datetime = None if appointment_datetime: try: validated_appointment_datetime = datetime.datetime.strptime( appointment_datetime, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'appointment_datetime must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}' .format(appointment_datetime)) validated_params['appointment_datetime'] = validated_appointment_datetime if "appointment_datetime_2" in rqst_body: appointment_datetime_2 = clean_string_value_from_dict_object( rqst_body, "root", "appointment_datetime_2", rqst_errors, none_allowed=True) validated_appointment_datetime_2 = None if appointment_datetime_2: try: validated_appointment_datetime_2 = datetime.datetime.strptime( appointment_datetime_2, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'appointment_datetime_2 must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}' .format(appointment_datetime_2)) validated_params[ 'appointment_datetime_2'] = validated_appointment_datetime_2 if "appointment_datetime_3" in rqst_body: appointment_datetime_3 = clean_string_value_from_dict_object( rqst_body, "root", "appointment_datetime_3", rqst_errors, none_allowed=True) validated_appointment_datetime_3 = None if appointment_datetime_3: try: validated_appointment_datetime_3 = datetime.datetime.strptime( appointment_datetime_3, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'appointment_datetime_3 must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}' .format(appointment_datetime_3)) validated_params[ 'appointment_datetime_3'] = validated_appointment_datetime_3
def validate_create_row_params(rqst_body, validated_params, rqst_errors): validated_params['consumer_id'] = clean_int_value_from_dict_object( rqst_body, "root", "consumer_id", rqst_errors ) validated_params['navigator_id'] = clean_int_value_from_dict_object( rqst_body, "root", "navigator_id", rqst_errors ) validated_params['cm_client_id'] = clean_int_value_from_dict_object( rqst_body, "root", "cm_client_id", rqst_errors, none_allowed=True ) validated_params['cm_sequence_id'] = clean_int_value_from_dict_object( rqst_body, "root", "cm_sequence_id", rqst_errors, none_allowed=True ) if 'notes' in rqst_body: validated_params['notes'] = clean_string_value_from_dict_object( rqst_body, "root", "notes", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'tracking_no' in rqst_body: validated_params['tracking_no'] = clean_string_value_from_dict_object( rqst_body, "root", "tracking_no", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'user_name' in rqst_body: validated_params['user_name'] = clean_string_value_from_dict_object( rqst_body, "root", "user_name", rqst_errors, empty_string_allowed=True, none_allowed=True ) if "datetime_completed" in rqst_body: datetime_completed = clean_string_value_from_dict_object( rqst_body, "root", "datetime_completed", rqst_errors, none_allowed=True ) validated_datetime_completed = None if datetime_completed: try: validated_datetime_completed = datetime.datetime.strptime(datetime_completed, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'datetime_completed must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}'.format( datetime_completed) ) validated_params['datetime_completed'] = validated_datetime_completed if 'primary_care_physician' in rqst_body: validated_params['primary_care_physician'] = clean_string_value_from_dict_object( rqst_body, "root", "primary_care_physician", rqst_errors, empty_string_allowed=True, none_allowed=True ) if "appointment_datetime" in rqst_body: appointment_datetime = clean_string_value_from_dict_object( rqst_body, "root", "appointment_datetime", rqst_errors, none_allowed=True ) validated_appointment_datetime = None if appointment_datetime: try: validated_appointment_datetime = datetime.datetime.strptime(appointment_datetime, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=pytz.UTC) except ValueError: rqst_errors.append( 'appointment_datetime must be a properly formatted datetime string in UTC, eg. YYYY-MM-DDTHH:MM:SS. Value is : {}'.format( appointment_datetime ) ) validated_params['appointment_datetime'] = validated_appointment_datetime if 'policy_number' in rqst_body: validated_params['policy_number'] = clean_string_value_from_dict_object( rqst_body, "root", "policy_number", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'resource_case_number' in rqst_body: validated_params['resource_case_number'] = clean_string_value_from_dict_object( rqst_body, "root", "resource_case_number", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'expedite_benefits_organization_contact_name' in rqst_body: validated_params['expedite_benefits_organization_contact_name'] = clean_string_value_from_dict_object( rqst_body, "root", "expedite_benefits_organization_contact_name", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'expedite_benefits_organization_contact_phone' in rqst_body: validated_params['expedite_benefits_organization_contact_phone'] = clean_string_value_from_dict_object( rqst_body, "root", "expedite_benefits_organization_contact_phone", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'customer_service_success' in rqst_body: validated_params['customer_service_success'] = clean_string_value_from_dict_object( rqst_body, "root", "customer_service_success", rqst_errors, empty_string_allowed=True, none_allowed=True ) if 'case_status' in rqst_body: validated_params['case_status'] = clean_string_value_from_dict_object( rqst_body, "root", "case_status", rqst_errors, empty_string_allowed=True, none_allowed=True ) if not rqst_errors and not validated_params['case_status']: validated_params['case_status'] = 'Not Available'
def validate_update_row_params(rqst_body, validated_params, rqst_errors): if "name" in rqst_body: rqst_provider_network_name = clean_string_value_from_dict_object(rqst_body, "root", "name", rqst_errors) validated_params["name"] = rqst_provider_network_name
def validate_create_or_update_row_params(rqst_body, validated_params, rqst_errors): consumer_metrics = clean_dict_value_from_dict_object( rqst_body, "root", "Consumer Metrics", rqst_errors) if not consumer_metrics: consumer_metrics = {} rqst_no_cps_consumers = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_cps_consumers", rqst_errors, no_key_allowed=True) if rqst_no_cps_consumers is None: rqst_no_cps_consumers = 0 rqst_metrics_location = clean_string_value_from_dict_object( consumer_metrics, "Consumer Metrics", "Location", rqst_errors) location_instance = None try: location_instance = NavMetricsLocation.objects.get( name=rqst_metrics_location) except NavMetricsLocation.DoesNotExist: rqst_errors.append( "Location instance does not exist for given location name: {!s}.". format(rqst_metrics_location)) except NavMetricsLocation.MultipleObjectsReturned: rqst_errors.append( "Multiple location instances exist for given location name: {!s}". format(rqst_metrics_location)) metrics_date_dict = clean_dict_value_from_dict_object( consumer_metrics, "Consumer Metrics", "Metrics Date", rqst_errors) metrics_date = None if metrics_date_dict is not None: month = clean_int_value_from_dict_object(metrics_date_dict, "Metrics Date", "Month", rqst_errors) if month: if month < 1 or month > 12: rqst_errors.append("Month must be between 1 and 12 inclusive") day = clean_int_value_from_dict_object(metrics_date_dict, "Metrics Date", "Day", rqst_errors) if day: if day < 1 or day > 31: rqst_errors.append("Day must be between 1 and 31 inclusive") year = clean_int_value_from_dict_object(metrics_date_dict, "Metrics Date", "Year", rqst_errors) if year: if year < 1 or year > 9999: rqst_errors.append("Year must be between 1 and 9999 inclusive") if not rqst_errors: metrics_date = datetime.date(year, month, day) rqst_plan_stats = clean_list_value_from_dict_object( consumer_metrics, "Consumer Metrics", "Plan Stats", rqst_errors, empty_list_allowed=True) unsaved_plan_stat_objs = [] if rqst_plan_stats: for rqst_plan_stat_dict in rqst_plan_stats: planstatobject = PlanStat() planstatobject.plan_name = clean_string_value_from_dict_object( rqst_plan_stat_dict, "Plans Dict", "Issuer Name", rqst_errors) planstatobject.premium_type = clean_string_value_from_dict_object( rqst_plan_stat_dict, "Plans Dict", "Premium Type", rqst_errors) planstatobject.metal_level = clean_string_value_from_dict_object( rqst_plan_stat_dict, "Plans Dict", "Metal Level", rqst_errors) planstatobject.enrollments = clean_int_value_from_dict_object( rqst_plan_stat_dict, "Plans Dict", "Enrollments", rqst_errors) plan_name_valid = planstatobject.check_plan_choices() premium_type_valid = planstatobject.check_premium_choices() metal_level_valid = planstatobject.check_metal_choices() if not plan_name_valid: rqst_errors.append( "Plan: {!s} is not part of member plans".format( planstatobject.plan_name)) if not premium_type_valid: rqst_errors.append( "Premium Type: {!s} is not a valid premium type".format( planstatobject.premium_type)) if not metal_level_valid: rqst_errors.append( "Metal: {!s} is not a valid metal level".format( planstatobject.metal_level)) if plan_name_valid and premium_type_valid and metal_level_valid: unsaved_plan_stat_objs.append(planstatobject) validated_params["rqst_usr_email"] = clean_string_value_from_dict_object( rqst_body, "root", "Email", rqst_errors) validated_params[ "rqst_no_general_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_general_assis", rqst_errors) validated_params[ "rqst_no_plan_usage_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_plan_usage_assis", rqst_errors) validated_params[ "rqst_no_locating_provider_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_locating_provider_assis", rqst_errors) validated_params[ "rqst_no_billing_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_billing_assis", rqst_errors) validated_params[ "rqst_no_enroll_apps_started"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_enroll_apps_started", rqst_errors) validated_params["rqst_no_enroll_qhp"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_enroll_qhp", rqst_errors) validated_params[ "rqst_no_enroll_abe_chip"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_enroll_abe_chip", rqst_errors) validated_params["rqst_no_enroll_shop"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_enroll_shop", rqst_errors) validated_params[ "rqst_no_referrals_agents_brokers"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_referrals_agents_brokers", rqst_errors) validated_params[ "rqst_no_referrals_ship_medicare"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_referrals_ship_medicare", rqst_errors) validated_params[ "rqst_no_referrals_other_assis_programs"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_referrals_other_assis_programs", rqst_errors) validated_params[ "rqst_no_referrals_issuers"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_referrals_issuers", rqst_errors) validated_params[ "rqst_no_referrals_doi"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_referrals_doi", rqst_errors) validated_params[ "rqst_no_mplace_tax_form_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_mplace_tax_form_assis", rqst_errors) validated_params[ "rqst_no_mplace_exempt_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_mplace_exempt_assis", rqst_errors) validated_params[ "rqst_no_qhp_abe_appeals"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_qhp_abe_appeals", rqst_errors) validated_params[ "rqst_no_data_matching_mplace_issues"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_data_matching_mplace_issues", rqst_errors) validated_params[ "rqst_no_sep_eligible"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_sep_eligible", rqst_errors) validated_params[ "rqst_no_employ_spons_cov_issues"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_employ_spons_cov_issues", rqst_errors) validated_params[ "rqst_no_aptc_csr_assis"] = clean_int_value_from_dict_object( consumer_metrics, "Consumer Metrics", "no_aptc_csr_assis", rqst_errors) validated_params[ "rqst_cmplx_cases_mplace_issues"] = clean_string_value_from_dict_object( consumer_metrics, "Consumer Metrics", "cmplx_cases_mplace_issues", rqst_errors, empty_string_allowed=True) validated_params["rqst_no_cps_consumers"] = rqst_no_cps_consumers validated_params[ "rqst_metrics_county"] = clean_string_value_from_dict_object( consumer_metrics, "Consumer Metrics", "County", rqst_errors) validated_params["location_instance_for_metrics"] = location_instance validated_params["unsaved_plan_stat_objs"] = unsaved_plan_stat_objs validated_params["metrics_date"] = metrics_date
def validate_modify_staff_params(rqst_body, validated_params, rqst_errors): if "email" in rqst_body: rqst_usr_email = clean_string_value_from_dict_object( rqst_body, "root", "email", rqst_errors) if rqst_usr_email and not rqst_errors: try: validate_email(rqst_usr_email) validated_params["rqst_usr_email"] = rqst_usr_email except forms.ValidationError: rqst_errors.append("{!s} must be a valid email address".format( rqst_usr_email)) if "first_name" in rqst_body: rqst_usr_f_name = clean_string_value_from_dict_object( rqst_body, "root", "first_name", rqst_errors) validated_params["rqst_usr_f_name"] = rqst_usr_f_name if "last_name" in rqst_body: rqst_usr_l_name = clean_string_value_from_dict_object( rqst_body, "root", "last_name", rqst_errors) validated_params["rqst_usr_l_name"] = rqst_usr_l_name if "county" in rqst_body: rqst_county = clean_string_value_from_dict_object( rqst_body, "root", "county", rqst_errors) validated_params["rqst_county"] = rqst_county if "type" in rqst_body: rqst_usr_type = clean_string_value_from_dict_object( rqst_body, "root", "type", rqst_errors) validated_params["rqst_usr_type"] = rqst_usr_type if "base_locations" in rqst_body: rqst_base_locations = clean_list_value_from_dict_object( rqst_body, "root", "base_locations", rqst_errors, empty_list_allowed=True) rqst_base_locations = list(set(rqst_base_locations)) base_location_objects = [] location_errors = [] if rqst_base_locations: for base_location_name in rqst_base_locations: try: base_location_object = NavMetricsLocation.objects.get( name=base_location_name) base_location_objects.append(base_location_object) except NavMetricsLocation.DoesNotExist: location_errors.append( "No Nav Hub Location Database entry found for name: {!s}" .format(base_location_name)) for location_error in location_errors: rqst_errors.append(location_error) validated_params["base_location_objects"] = base_location_objects if len(validated_params.keys()) < 2: rqst_errors.append( 'Not enough given parameters to modify staff instance.')