diff --git a/apcd-cms/src/apps/admin_regis_table/views.py b/apcd-cms/src/apps/admin_regis_table/views.py index 7a5d35ff..ace03c2a 100644 --- a/apcd-cms/src/apps/admin_regis_table/views.py +++ b/apcd-cms/src/apps/admin_regis_table/views.py @@ -4,6 +4,7 @@ from apps.utils.apcd_database import get_registrations, get_registration_contacts, get_registration_entities, create_submitter, update_registration, update_registration_contact, update_registration_entity from apps.utils.apcd_groups import is_apcd_admin from apps.utils.utils import table_filter +from apps.utils.registrations_data_formatting import _set_registration from apps.components.paginator.paginator import paginator import logging from dateutil import parser @@ -83,143 +84,6 @@ def dispatch(self, request, *args, **kwargs): def get_context_data(self, registrations_content, registrations_entities, registrations_contacts, *args, **kwargs): context = super(RegistrationsTable, self).get_context_data(*args, **kwargs) - def _set_registration(reg, reg_ents, reg_conts): - org_types = { - 'carrier': 'Insurance Carrier', - 'tpa_aso': 'Plan Administrator¹ (TPA/ASO)', - 'pbm': 'Pharmacy Benefit Manager (PBM)' - } - return { - 'biz_name': reg[7], - 'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None, - 'location': '{city}, {state}'.format - ( - city=reg[9], - state=reg[10] - ), - 'reg_status': reg[5].title(), - 'reg_id': reg[0], - 'view_modal_content': _set_modal_content(reg, reg_ents, reg_conts, org_types) - } - def _set_entities(reg_ent): - return { - 'claim_val': reg_ent[0], - 'ent_id': reg_ent[3], - 'claim_and_enc_vol': reg_ent[2], - 'license': reg_ent[4] if reg_ent[4] else None, - 'naic': reg_ent[5] if reg_ent[5] else None, - 'no_covered': reg_ent[6], - 'ent_name': reg_ent[7], - 'fein': reg_ent[8] if reg_ent[8] else None, - 'plans_type': { - "Commercial": reg_ent[9], - "Medicare": reg_ent[10], - "Medicaid": reg_ent[11], - }, - 'files_type': { - "Eligibility/Enrollment": reg_ent[12], - "Provider": reg_ent[13], - "Medical": reg_ent[14], - "Pharmacy": reg_ent[15], - "Dental": reg_ent[16] - } - } - def _set_contacts(reg_cont): - - def format_phone_number(num): - formatted_num_list = list(reversed(num)) - last_four_digits = 3 - last_seven_digits = 7 - all_ten_digits = 11 - placement_corrector = 1 #To add formatting chars in correct places - for curr_position in range(len(formatted_num_list) + 1): - placement_position = curr_position + placement_corrector - if curr_position == last_four_digits or curr_position == last_seven_digits: - formatted_num_list.insert(placement_position,'-') - if curr_position == all_ten_digits and len(num) > 10: - formatted_num_list.insert(placement_position,' ') - formatted_num_list.append('+') - return ''.join(reversed(formatted_num_list)) - - return { - 'cont_id': reg_cont[0], - 'notif': reg_cont[2], - 'role': reg_cont[3], - 'name': reg_cont[4], - 'phone': format_phone_number(reg_cont[5]), - 'email': reg_cont[6], - } - def _set_modal_content(reg, reg_ent, reg_cont, org_types): - return { - 'biz_name': reg[7], - 'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None, - 'city': reg[9], - 'state': reg[10], - 'address': reg[8], - 'zip': reg[11], - 'for_self': reg[4], - 'entities': [_set_entities(ent) for ent in reg_ent], - 'contacts': [_set_contacts(cont) for cont in reg_cont], - 'org_types': org_types, - 'us_state_list': [ - 'AL - Alabama', - 'AK - Alaska', - 'AS - American Samoa', - 'AR - Arkansas', - 'AZ - Arizona', - 'CA - California', - 'CO - Colorado', - 'CT - Connecticut', - 'DE - Delaware', - 'DC - District of Columbia', - 'FL - Florida', - 'GA - Georgia', - 'GU - Guam', - 'HI - Hawaii', - 'ID - Idaho', - 'IL - Illinois', - 'IN - Indiana', - 'IA - Iowa', - 'KS - Kansas', - 'KY - Kentucky', - 'LA - Louisiana', - 'ME - Maine', - 'MD - Maryland', - 'MA - Massachusetts', - 'MI - Michigan', - 'MN - Minnesota', - 'MS - Mississippi', - 'MO - Missouri', - 'MT - Montana', - 'NE - Nebraska', - 'NH - New Hampshire', - 'NJ - New Jersey', - 'NM - New Mexico', - 'NV - Nevada', - 'NY - New York', - 'NC - North Carolina', - 'ND - North Dakota', - 'MP - Northern Mariana Islands', - 'OH - Ohio', - 'OK - Oklahoma', - 'OR - Oregon', - 'PA - Pennsylvania', - 'RI - Rhode Island', - 'SC - South Carolina', - 'SD - South Dakota', - 'TN - Tennessee', - 'TX - Texas', - 'UT - Utah', - 'VT - Vermont', - 'VA - Virginia', - 'VI - Virgin Islands', - 'WA - Washington', - 'WV - West Virginia', - 'WI - Wisconsin', - 'WY - Wyoming' - ], - } - context['header'] = ['Business Name', 'Type', 'Location', 'Registration Status', 'Actions'] context['status_options'] = ['All', 'Received', 'Processing', 'Complete'] context['org_options'] = ['All'] diff --git a/apcd-cms/src/apps/registrations/templates/submission_form/registration_form_body.html b/apcd-cms/src/apps/registrations/templates/submission_form/registration_form_body.html index 6a652d2b..f418bd1e 100644 --- a/apcd-cms/src/apps/registrations/templates/submission_form/registration_form_body.html +++ b/apcd-cms/src/apps/registrations/templates/submission_form/registration_form_body.html @@ -423,7 +423,7 @@
inputmode="numeric" min="1" step="1" - value="{{ entity.no_covered }}" + value="{% if not renew %}{{ entity.no_covered }}{% endif %}" /> @@ -442,7 +442,7 @@
id="claims_encounters_volume_{{ent_no}}_{{r.reg_id}}" inputmode="numeric" min="1" - value="{{ entity.claim_and_enc_vol }}" + value="{% if not renew %}{{ entity.claim_and_enc_vol }}{% endif %}" /> @@ -463,7 +463,7 @@
inputmode="numeric" step="0.01" min="0.01" - value="{{ entity.claim_val }}" + value="{% if not renew %}{{ entity.claim_val }}{% endif %}" /> diff --git a/apcd-cms/src/apps/registrations/views.py b/apcd-cms/src/apps/registrations/views.py index 9096c8aa..5f3d21ef 100644 --- a/apcd-cms/src/apps/registrations/views.py +++ b/apcd-cms/src/apps/registrations/views.py @@ -1,5 +1,6 @@ from apps.utils import apcd_database from apps.utils.apcd_groups import has_apcd_group +from apps.utils.registrations_data_formatting import _set_registration from django.conf import settings from django.http import HttpResponse, HttpResponseRedirect from django.template import loader @@ -18,14 +19,26 @@ class SubmissionFormView(View): def get(self, request): + formatted_reg_data = [] + renew = False + if 'reg_id' in request.GET: + reg_id = request.GET.get('reg_id') + renew = True + registration_content = apcd_database.get_registrations(reg_id)[0] + registration_entities = apcd_database.get_registration_entities(reg_id) + registration_contacts = apcd_database.get_registration_contacts(reg_id) + formatted_reg_data = _set_registration(registration_content, registration_entities, registration_contacts) if (request.user.is_authenticated and has_apcd_group(request.user)): template = loader.get_template('submission_form/submission_form.html') - return HttpResponse(template.render({}, request)) + return HttpResponse(template.render({'r': formatted_reg_data, 'renew': renew}, request)) return HttpResponseRedirect('/') def post(self, request): form = request.POST.copy() + old_reg_id = None + if 'reg_id' in form: + old_reg_id = form['reg_id'] errors = [] if (request.user.is_authenticated): @@ -39,8 +52,8 @@ def post(self, request): reg_resp = apcd_database.create_registration(form) if not _err_msg(reg_resp) and type(reg_resp) == int: for iteration in range(1,6): - contact_resp = apcd_database.create_registration_contact(form, reg_resp, iteration) - entity_resp = apcd_database.create_registration_entity(form, reg_resp, iteration) + contact_resp = apcd_database.create_registration_contact(form, reg_resp, iteration, old_reg_id=old_reg_id) + entity_resp = apcd_database.create_registration_entity(form, reg_resp, iteration, old_reg_id=old_reg_id) if _err_msg(contact_resp): errors.append(_err_msg(contact_resp)) if _err_msg(entity_resp): diff --git a/apcd-cms/src/apps/utils/apcd_database.py b/apcd-cms/src/apps/utils/apcd_database.py index d1a8f0eb..668b8854 100644 --- a/apcd-cms/src/apps/utils/apcd_database.py +++ b/apcd-cms/src/apps/utils/apcd_database.py @@ -317,14 +317,14 @@ def get_registration_entities(reg_id=None): conn.close() -def create_registration_entity(form, reg_id, iteration, from_update_reg=None): +def create_registration_entity(form, reg_id, iteration, from_update_reg=None, old_reg_id=None): cur = None conn = None values = () try: - if not _acceptable_entity(form, iteration, reg_id if from_update_reg else None): + if not _acceptable_entity(form, iteration, reg_id if from_update_reg else (old_reg_id if old_reg_id else None)): return - str_end = f'{iteration}{ f"_{reg_id}" if from_update_reg else "" }' + str_end = f'{iteration}{ f"_{reg_id}" if from_update_reg else (f"_{old_reg_id}" if old_reg_id else "") }' values = ( reg_id, float(form['total_claims_value_{}'.format(str_end)]), @@ -397,7 +397,7 @@ def update_registration_entity(form, reg_id, iteration, no_entities): return delete_registration_entity(reg_id, form['ent_id_{}'.format(str_end)]) return if iteration > no_entities: # entity is in form but not in original list -> need to create - return create_registration_entity(form, reg_id, iteration, True) + return create_registration_entity(form, reg_id, iteration, from_update_reg=True) values = ( float(form['total_claims_value_{}'.format(str_end)]), _set_int(form['claims_encounters_volume_{}'.format(str_end)]), @@ -527,15 +527,15 @@ def get_registration_contacts(reg_id=None): conn.close() -def create_registration_contact(form, reg_id, iteration, from_update_reg=None): +def create_registration_contact(form, reg_id, iteration, from_update_reg=None, old_reg_id=None): cur = None conn = None values = () try: if iteration > 1: - if not _acceptable_contact(form, iteration, reg_id if from_update_reg else None): + if not _acceptable_contact(form, iteration, reg_id if from_update_reg else (old_reg_id if old_reg_id else None)): return - str_end = f'{iteration}{ f"_{reg_id}" if from_update_reg else "" }' + str_end = f'{iteration}{ f"_{reg_id}" if from_update_reg else (f"_{old_reg_id}" if old_reg_id else "") }' values = ( reg_id, True if 'contact_notifications_{}'.format(str_end) in form else False, @@ -545,7 +545,7 @@ def create_registration_contact(form, reg_id, iteration, from_update_reg=None): _clean_email(form['contact_email_{}'.format(str_end)]) ) else: - str_end = f'_{iteration}_{reg_id}' if from_update_reg else '' + str_end = f'_{iteration}_{reg_id}' if from_update_reg else (f"_{iteration}_{old_reg_id}" if old_reg_id else "") values = ( reg_id, True if f'contact_notifications{str_end}' in form else False, @@ -597,7 +597,7 @@ def update_registration_contact(form, reg_id, iteration, no_contacts): return delete_registration_contact(reg_id, form[f'cont_id_{iteration}']) return if iteration > no_contacts: # contact is in form but not in original list -> need to create - return create_registration_contact(form, reg_id, iteration, True) + return create_registration_contact(form, reg_id, iteration, from_update_reg=True) str_end = f'{iteration}_{reg_id}' values = ( True if 'contact_notifications_{}'.format(str_end) in form else False, diff --git a/apcd-cms/src/apps/utils/registrations_data_formatting.py b/apcd-cms/src/apps/utils/registrations_data_formatting.py new file mode 100644 index 00000000..60050fbf --- /dev/null +++ b/apcd-cms/src/apps/utils/registrations_data_formatting.py @@ -0,0 +1,136 @@ +def _set_registration(reg, reg_ents, reg_conts): + org_types = { + 'carrier': 'Insurance Carrier', + 'tpa_aso': 'Plan Administrator¹ (TPA/ASO)', + 'pbm': 'Pharmacy Benefit Manager (PBM)' + } + return { + 'biz_name': reg[7], + 'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None, + 'location': '{city}, {state}'.format + ( + city=reg[9], + state=reg[10] + ), + 'reg_status': reg[5].title(), + 'reg_id': reg[0], + 'view_modal_content': _set_modal_content(reg, reg_ents, reg_conts, org_types) + } +def _set_entities(reg_ent): + return { + 'claim_val': reg_ent[0], + 'ent_id': reg_ent[3], + 'claim_and_enc_vol': reg_ent[2], + 'license': reg_ent[4] if reg_ent[4] else None, + 'naic': reg_ent[5] if reg_ent[5] else None, + 'no_covered': reg_ent[6], + 'ent_name': reg_ent[7], + 'fein': reg_ent[8] if reg_ent[8] else None, + 'plans_type': { + "Commercial": reg_ent[9], + "Medicare": reg_ent[10], + "Medicaid": reg_ent[11], + }, + 'files_type': { + "Eligibility/Enrollment": reg_ent[12], + "Provider": reg_ent[13], + "Medical": reg_ent[14], + "Pharmacy": reg_ent[15], + "Dental": reg_ent[16] + } + } +def _set_contacts(reg_cont): + + def format_phone_number(num): + formatted_num_list = list(reversed(num)) + last_four_digits = 3 + last_seven_digits = 7 + all_ten_digits = 11 + placement_corrector = 1 #To add formatting chars in correct places + for curr_position in range(len(formatted_num_list) + 1): + placement_position = curr_position + placement_corrector + if curr_position == last_four_digits or curr_position == last_seven_digits: + formatted_num_list.insert(placement_position,'-') + if curr_position == all_ten_digits and len(num) > 10: + formatted_num_list.insert(placement_position,' ') + formatted_num_list.append('+') + return ''.join(reversed(formatted_num_list)) + + return { + 'cont_id': reg_cont[0], + 'notif': reg_cont[2], + 'role': reg_cont[3], + 'name': reg_cont[4], + 'phone': format_phone_number(reg_cont[5]), + 'email': reg_cont[6], + } +def _set_modal_content(reg, reg_ent, reg_cont, org_types): + return { + 'biz_name': reg[7], + 'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None, + 'city': reg[9], + 'state': reg[10], + 'address': reg[8], + 'zip': reg[11], + 'for_self': reg[4], + 'entities': [_set_entities(ent) for ent in reg_ent], + 'contacts': [_set_contacts(cont) for cont in reg_cont], + 'org_types': org_types, + 'us_state_list': [ + 'AL - Alabama', + 'AK - Alaska', + 'AS - American Samoa', + 'AR - Arkansas', + 'AZ - Arizona', + 'CA - California', + 'CO - Colorado', + 'CT - Connecticut', + 'DE - Delaware', + 'DC - District of Columbia', + 'FL - Florida', + 'GA - Georgia', + 'GU - Guam', + 'HI - Hawaii', + 'ID - Idaho', + 'IL - Illinois', + 'IN - Indiana', + 'IA - Iowa', + 'KS - Kansas', + 'KY - Kentucky', + 'LA - Louisiana', + 'ME - Maine', + 'MD - Maryland', + 'MA - Massachusetts', + 'MI - Michigan', + 'MN - Minnesota', + 'MS - Mississippi', + 'MO - Missouri', + 'MT - Montana', + 'NE - Nebraska', + 'NH - New Hampshire', + 'NJ - New Jersey', + 'NM - New Mexico', + 'NV - Nevada', + 'NY - New York', + 'NC - North Carolina', + 'ND - North Dakota', + 'MP - Northern Mariana Islands', + 'OH - Ohio', + 'OK - Oklahoma', + 'OR - Oregon', + 'PA - Pennsylvania', + 'RI - Rhode Island', + 'SC - South Carolina', + 'SD - South Dakota', + 'TN - Tennessee', + 'TX - Texas', + 'UT - Utah', + 'VT - Vermont', + 'VA - Virginia', + 'VI - Virgin Islands', + 'WA - Washington', + 'WV - West Virginia', + 'WI - Wisconsin', + 'WY - Wyoming' + ], + }