Skip to content

Commit 6fc7b8b

Browse files
edmondsgarrettGarrett Edmonds
and
Garrett Edmonds
authored
task/WP-557: Cleaning up unused database fields + create submitter code (#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]>
1 parent 7f7a916 commit 6fc7b8b

File tree

3 files changed

+19
-170
lines changed

3 files changed

+19
-170
lines changed

apcd-cms/src/apps/admin_regis_table/views.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.http import HttpResponse, HttpResponseRedirect
22
from django.views.generic.base import TemplateView
33
from django.template import loader
4-
from apps.utils.apcd_database import get_registrations, get_registration_contacts, get_registration_entities, create_submitter, update_registration, update_registration_contact, update_registration_entity
4+
from apps.utils.apcd_database import get_registrations, get_registration_contacts, get_registration_entities, update_registration, update_registration_contact, update_registration_entity
55
from apps.utils.apcd_groups import is_apcd_admin
66
from apps.utils.utils import table_filter
77
from apps.utils.registrations_data_formatting import _set_registration
@@ -30,18 +30,7 @@ def _err_msg(resp):
3030
if isinstance(resp, Exception):
3131
return str(resp)
3232
return None
33-
34-
def _new_submitter(form, reg_data=reg_data):
35-
errors = []
36-
37-
sub_resp = create_submitter(form, reg_data)
38-
template = loader.get_template('create_submitter_success.html')
39-
if _err_msg(sub_resp) or type(sub_resp) != int:
40-
errors.append(_err_msg(sub_resp))
41-
template = loader.get_template('create_submitter_error.html')
42-
43-
return template
44-
33+
4534
def _edit_registration(form, reg_entities=reg_entities, reg_contacts=reg_contacts):
4635
errors = []
4736
reg_resp = update_registration(form, reg_id)
@@ -61,9 +50,7 @@ def _edit_registration(form, reg_entities=reg_entities, reg_contacts=reg_contact
6150
template = loader.get_template('edit_registration_error.html')
6251
return template
6352

64-
if 'create-submitter-form' in form:
65-
template = _new_submitter(form)
66-
elif 'edit-registration-form' in form:
53+
if 'edit-registration-form' in form:
6754
template = _edit_registration(form)
6855
return HttpResponse(template.render({}, request))
6956

apcd-cms/src/apps/utils/apcd_database.py

+2-140
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ def get_registrations(reg_id=None, submitter_code=None):
157157
query = f"""SELECT DISTINCT
158158
registrations.registration_id,
159159
registrations.posted_date,
160-
registrations.applicable_period_start,
161-
registrations.applicable_period_end,
162160
registrations.submitting_for_self,
163161
registrations.registration_status,
164162
registrations.org_type,
@@ -203,8 +201,6 @@ def create_registration(form, renewal=False):
203201
cur = conn.cursor()
204202
operation = """INSERT INTO registrations(
205203
posted_date,
206-
applicable_period_start,
207-
applicable_period_end,
208204
submitting_for_self,
209205
registration_status,
210206
org_type,
@@ -214,12 +210,10 @@ def create_registration(form, renewal=False):
214210
state,
215211
zip,
216212
registration_year
217-
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
213+
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
218214
RETURNING registration_id"""
219215
values = (
220216
datetime.now(),
221-
None,
222-
None,
223217
True if form['on-behalf-of'] == 'true' else False,
224218
'Received',
225219
form['type'],
@@ -702,65 +696,6 @@ def delete_registration_contact(reg_id, cont_id):
702696
conn.close()
703697

704698

705-
def create_submitter(form, reg_data):
706-
cur = None
707-
conn = None
708-
try:
709-
conn = psycopg.connect(
710-
host=APCD_DB['host'],
711-
dbname=APCD_DB['database'],
712-
user=APCD_DB['user'],
713-
password=APCD_DB['password'],
714-
port=APCD_DB['port'],
715-
sslmode='require'
716-
)
717-
cur = conn.cursor()
718-
operation = """INSERT INTO submitters(
719-
registration_id,
720-
org_name,
721-
file_me,
722-
file_pv,
723-
file_mc,
724-
file_pc,
725-
file_dc,
726-
submitting_for_self,
727-
submitter_code,
728-
payor_code,
729-
encryption_key,
730-
created_at,
731-
status
732-
) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
733-
RETURNING submitter_id"""
734-
values = (
735-
reg_data[0],
736-
reg_data[13],
737-
reg_data[6],
738-
reg_data[5],
739-
reg_data[4],
740-
reg_data[7],
741-
reg_data[8],
742-
reg_data[9],
743-
form['submit_code'],
744-
_set_int(form['payor_code']),
745-
form['encryption_key'],
746-
datetime.now(),
747-
'new'
748-
)
749-
cur.execute(operation, values)
750-
conn.commit()
751-
return cur.fetchone()[0]
752-
753-
except Exception as error:
754-
logger.error(error)
755-
return error
756-
757-
finally:
758-
if cur is not None:
759-
cur.close()
760-
if conn is not None:
761-
conn.close()
762-
763-
764699
def create_other_exception(form, sub_data):
765700
cur = None
766701
conn = None
@@ -872,6 +807,7 @@ def create_threshold_exception(form, iteration, sub_data):
872807
if conn is not None:
873808
conn.close()
874809

810+
875811
def get_cdl_exceptions(file_type):
876812
cur = None
877813
conn = None
@@ -908,80 +844,6 @@ def get_cdl_exceptions(file_type):
908844
if conn is not None:
909845
conn.close()
910846

911-
def get_submissions(user):
912-
cur = None
913-
conn = None
914-
try:
915-
conn = psycopg.connect(
916-
host=APCD_DB['host'],
917-
dbname=APCD_DB['database'],
918-
user=APCD_DB['user'],
919-
password=APCD_DB['password'],
920-
port=APCD_DB['port'],
921-
sslmode='require'
922-
)
923-
924-
query = """SELECT * FROM submissions
925-
WHERE submitter_id
926-
IN (
927-
SELECT submitter_users.submitter_id FROM submitter_users
928-
WHERE user_id = %s )
929-
"""
930-
931-
cur = conn.cursor()
932-
cur.execute(query, (user,))
933-
return cur.fetchall()
934-
935-
except Exception as error:
936-
logger.error(error)
937-
938-
finally:
939-
if cur is not None:
940-
cur.close()
941-
if conn is not None:
942-
conn.close()
943-
944-
def get_submission_logs(submission_id):
945-
946-
cur = None
947-
conn = None
948-
try:
949-
conn = psycopg.connect(
950-
host=APCD_DB['host'],
951-
dbname=APCD_DB['database'],
952-
user=APCD_DB['user'],
953-
password=APCD_DB['password'],
954-
port=APCD_DB['port'],
955-
sslmode='require'
956-
)
957-
958-
959-
query = """SELECT
960-
submission_logs.log_id,
961-
submission_logs.submission_id,
962-
submission_logs.file_type,
963-
submission_logs.validation_suite,
964-
submission_logs.json_log,
965-
submission_logs.outcome,
966-
standard_codes.item_value
967-
FROM submission_logs
968-
LEFT JOIN standard_codes
969-
ON UPPER(submission_logs.file_type) = UPPER(standard_codes.item_code) AND list_name='submission_file_type'
970-
WHERE submission_id= (%s)
971-
"""
972-
973-
cur = conn.cursor()
974-
cur.execute(query, (submission_id,))
975-
return cur.fetchall()
976-
977-
except Exception as error:
978-
logger.error(error)
979-
980-
finally:
981-
if cur is not None:
982-
cur.close()
983-
if conn is not None:
984-
conn.close()
985847

986848
def get_user_submissions_and_logs(user):
987849
cur = None

apcd-cms/src/apps/utils/registrations_data_formatting.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ def _set_registration(reg, reg_ents, reg_conts):
55
'pbm': 'Pharmacy Benefit Manager (PBM)'
66
}
77
return {
8-
'biz_name': reg[7],
9-
'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None,
8+
'biz_name': reg[5],
9+
'type': org_types[reg[4]] if (reg[4] and reg[4] in org_types.keys()) else None,
1010
'location': '{city}, {state}'.format
1111
(
12-
city=reg[9],
13-
state=reg[10]
12+
city=reg[7],
13+
state=reg[8]
1414
),
15-
'reg_status': reg[5].title(),
15+
'reg_status': reg[3].title(),
1616
'reg_id': reg[0],
17-
'year': reg[12],
17+
'year': reg[10],
1818
'view_modal_content': _set_modal_content(reg, reg_ents, reg_conts, org_types)
1919
}
2020
def _set_entities(reg_ent):
@@ -67,14 +67,14 @@ def format_phone_number(num):
6767
}
6868
def _set_modal_content(reg, reg_ent, reg_cont, org_types):
6969
return {
70-
'biz_name': reg[7],
71-
'type': org_types[reg[6]] if (reg[6] and reg[6] in org_types.keys()) else None,
72-
'city': reg[9],
73-
'state': reg[10],
74-
'address': reg[8],
75-
'zip': reg[11],
76-
'for_self': reg[4],
77-
'year': reg[12],
70+
'biz_name': reg[5],
71+
'type': org_types[reg[4]] if (reg[4] and reg[4] in org_types.keys()) else None,
72+
'city': reg[7],
73+
'state': reg[8],
74+
'address': reg[6],
75+
'zip': reg[9],
76+
'for_self': reg[2],
77+
'year': reg[10],
7878
'entities': [_set_entities(ent) for ent in reg_ent],
7979
'contacts': [_set_contacts(cont) for cont in reg_cont],
8080
'org_types': org_types,

0 commit comments

Comments
 (0)