Skip to content

Commit

Permalink
task/WP-557: Cleaning up unused database fields + create submitter co…
Browse files Browse the repository at this point in the history
…de (#285)

* Remove read and write of 'applicable_period_start' and 'applicable_period_end' from registrations queries

* Re-index registrations formatting for removed query fields

* Remove unused 'create_submitter' db insert function

* Remove unused create submitter view function

* Clean up leftover code referencing create submitter action

* Remove unused 'get_submissions' and 'get_submission_logs' from database functions

---------

Co-authored-by: Garrett Edmonds <[email protected]>
  • Loading branch information
edmondsgarrett and Garrett Edmonds committed May 14, 2024
1 parent 7f7a916 commit 6fc7b8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 170 deletions.
19 changes: 3 additions & 16 deletions apcd-cms/src/apps/admin_regis_table/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic.base import TemplateView
from django.template import loader
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_database import get_registrations, get_registration_contacts, get_registration_entities, 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
Expand Down Expand Up @@ -30,18 +30,7 @@ def _err_msg(resp):
if isinstance(resp, Exception):
return str(resp)
return None

def _new_submitter(form, reg_data=reg_data):
errors = []

sub_resp = create_submitter(form, reg_data)
template = loader.get_template('create_submitter_success.html')
if _err_msg(sub_resp) or type(sub_resp) != int:
errors.append(_err_msg(sub_resp))
template = loader.get_template('create_submitter_error.html')

return template


def _edit_registration(form, reg_entities=reg_entities, reg_contacts=reg_contacts):
errors = []
reg_resp = update_registration(form, reg_id)
Expand All @@ -61,9 +50,7 @@ def _edit_registration(form, reg_entities=reg_entities, reg_contacts=reg_contact
template = loader.get_template('edit_registration_error.html')
return template

if 'create-submitter-form' in form:
template = _new_submitter(form)
elif 'edit-registration-form' in form:
if 'edit-registration-form' in form:
template = _edit_registration(form)
return HttpResponse(template.render({}, request))

Expand Down
142 changes: 2 additions & 140 deletions apcd-cms/src/apps/utils/apcd_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ def get_registrations(reg_id=None, submitter_code=None):
query = f"""SELECT DISTINCT
registrations.registration_id,
registrations.posted_date,
registrations.applicable_period_start,
registrations.applicable_period_end,
registrations.submitting_for_self,
registrations.registration_status,
registrations.org_type,
Expand Down Expand Up @@ -203,8 +201,6 @@ def create_registration(form, renewal=False):
cur = conn.cursor()
operation = """INSERT INTO registrations(
posted_date,
applicable_period_start,
applicable_period_end,
submitting_for_self,
registration_status,
org_type,
Expand All @@ -214,12 +210,10 @@ def create_registration(form, renewal=False):
state,
zip,
registration_year
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
RETURNING registration_id"""
values = (
datetime.now(),
None,
None,
True if form['on-behalf-of'] == 'true' else False,
'Received',
form['type'],
Expand Down Expand Up @@ -702,65 +696,6 @@ def delete_registration_contact(reg_id, cont_id):
conn.close()


def create_submitter(form, reg_data):
cur = None
conn = None
try:
conn = psycopg.connect(
host=APCD_DB['host'],
dbname=APCD_DB['database'],
user=APCD_DB['user'],
password=APCD_DB['password'],
port=APCD_DB['port'],
sslmode='require'
)
cur = conn.cursor()
operation = """INSERT INTO submitters(
registration_id,
org_name,
file_me,
file_pv,
file_mc,
file_pc,
file_dc,
submitting_for_self,
submitter_code,
payor_code,
encryption_key,
created_at,
status
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
RETURNING submitter_id"""
values = (
reg_data[0],
reg_data[13],
reg_data[6],
reg_data[5],
reg_data[4],
reg_data[7],
reg_data[8],
reg_data[9],
form['submit_code'],
_set_int(form['payor_code']),
form['encryption_key'],
datetime.now(),
'new'
)
cur.execute(operation, values)
conn.commit()
return cur.fetchone()[0]

except Exception as error:
logger.error(error)
return error

finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()


def create_other_exception(form, sub_data):
cur = None
conn = None
Expand Down Expand Up @@ -872,6 +807,7 @@ def create_threshold_exception(form, iteration, sub_data):
if conn is not None:
conn.close()


def get_cdl_exceptions(file_type):
cur = None
conn = None
Expand Down Expand Up @@ -908,80 +844,6 @@ def get_cdl_exceptions(file_type):
if conn is not None:
conn.close()

def get_submissions(user):
cur = None
conn = None
try:
conn = psycopg.connect(
host=APCD_DB['host'],
dbname=APCD_DB['database'],
user=APCD_DB['user'],
password=APCD_DB['password'],
port=APCD_DB['port'],
sslmode='require'
)

query = """SELECT * FROM submissions
WHERE submitter_id
IN (
SELECT submitter_users.submitter_id FROM submitter_users
WHERE user_id = %s )
"""

cur = conn.cursor()
cur.execute(query, (user,))
return cur.fetchall()

except Exception as error:
logger.error(error)

finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()

def get_submission_logs(submission_id):

cur = None
conn = None
try:
conn = psycopg.connect(
host=APCD_DB['host'],
dbname=APCD_DB['database'],
user=APCD_DB['user'],
password=APCD_DB['password'],
port=APCD_DB['port'],
sslmode='require'
)


query = """SELECT
submission_logs.log_id,
submission_logs.submission_id,
submission_logs.file_type,
submission_logs.validation_suite,
submission_logs.json_log,
submission_logs.outcome,
standard_codes.item_value
FROM submission_logs
LEFT JOIN standard_codes
ON UPPER(submission_logs.file_type) = UPPER(standard_codes.item_code) AND list_name='submission_file_type'
WHERE submission_id= (%s)
"""

cur = conn.cursor()
cur.execute(query, (submission_id,))
return cur.fetchall()

except Exception as error:
logger.error(error)

finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()

def get_user_submissions_and_logs(user):
cur = None
Expand Down
28 changes: 14 additions & 14 deletions apcd-cms/src/apps/utils/registrations_data_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ def _set_registration(reg, reg_ents, reg_conts):
'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,
'biz_name': reg[5],
'type': org_types[reg[4]] if (reg[4] and reg[4] in org_types.keys()) else None,
'location': '{city}, {state}'.format
(
city=reg[9],
state=reg[10]
city=reg[7],
state=reg[8]
),
'reg_status': reg[5].title(),
'reg_status': reg[3].title(),
'reg_id': reg[0],
'year': reg[12],
'year': reg[10],
'view_modal_content': _set_modal_content(reg, reg_ents, reg_conts, org_types)
}
def _set_entities(reg_ent):
Expand Down Expand Up @@ -67,14 +67,14 @@ def format_phone_number(num):
}
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],
'year': reg[12],
'biz_name': reg[5],
'type': org_types[reg[4]] if (reg[4] and reg[4] in org_types.keys()) else None,
'city': reg[7],
'state': reg[8],
'address': reg[6],
'zip': reg[9],
'for_self': reg[2],
'year': reg[10],
'entities': [_set_entities(ent) for ent in reg_ent],
'contacts': [_set_contacts(cont) for cont in reg_cont],
'org_types': org_types,
Expand Down

0 comments on commit 6fc7b8b

Please sign in to comment.