From 9505d0f27ff9519d319a23f459f752cfb158090e Mon Sep 17 00:00:00 2001 From: Jun Li Date: Tue, 5 Nov 2024 17:11:01 -0500 Subject: [PATCH 1/2] Remove undisplayed mur disipotion categor --- ...305__add_ref_case_disposition_category.sql | 22 ++++ tests/integration/test_current_cases.py | 35 +++++- webservices/legal_docs/current_cases.py | 115 ++++++++---------- 3 files changed, 109 insertions(+), 63 deletions(-) create mode 100644 data/migrations/V0305__add_ref_case_disposition_category.sql diff --git a/data/migrations/V0305__add_ref_case_disposition_category.sql b/data/migrations/V0305__add_ref_case_disposition_category.sql new file mode 100644 index 000000000..9def9a122 --- /dev/null +++ b/data/migrations/V0305__add_ref_case_disposition_category.sql @@ -0,0 +1,22 @@ +/* +This is for issue #6041, Add a new table to ref case(MUR, ADR, AF) disposition category. +*/ + +CREATE TABLE IF NOT EXISTS fecmur.ref_case_disposition_category + ( + category_id integer NOT NULL, + category_name varchar(200) NOT NULL, + display_category_name varchar(200) NOT NULL, + doc_type varchar(8) NOT NULL, + published_flg boolean DEFAULT true, + upload_date timestamp without time zone DEFAULT now(), + CONSTRAINT ref_category_pkey PRIMARY KEY (category_id) +); + +ALTER TABLE IF EXISTS fecmur.ref_case_disposition_category OWNER to fec; + +GRANT SELECT ON TABLE fecmur.ref_case_disposition_category TO aomur_usr; + +GRANT ALL ON TABLE fecmur.ref_case_disposition_category TO fec; + +GRANT SELECT ON TABLE fecmur.ref_case_disposition_category TO fec_read; \ No newline at end of file diff --git a/tests/integration/test_current_cases.py b/tests/integration/test_current_cases.py index ac201ec7d..b30267e9a 100644 --- a/tests/integration/test_current_cases.py +++ b/tests/integration/test_current_cases.py @@ -429,6 +429,20 @@ def test_mur_with_disposition(self, get_bucket, get_credential): commission_id, agenda_date, vote_date, action, case_id, pg_date ) + category_id = 1 + category_name = "Conciliation-PPC" + display_category_name = "Conciliation-PPC" + published_flg = True + doc_type = "MUR" + + self.create_disposition_category( + category_id, + category_name, + display_category_name, + published_flg, + doc_type + ) + load_mur_citations() actual_mur = next(get_cases('MUR')) @@ -444,7 +458,7 @@ def test_mur_with_disposition(self, get_bucket, get_credential): 'dispositions': [ { 'disposition': 'Conciliation-PPC', - 'mur_disposition_category_id': '7', + 'mur_disposition_category_id': 1, 'respondent': 'Open Elections LLC', 'penalty': Decimal('50000.00'), 'citations': [ @@ -800,6 +814,25 @@ def create_event( pg_date, ) + def create_disposition_category( + self, + category_id, + category_name, + display_category_name, + published_flg, + doc_type, + ): + self.connection.execute( + "INSERT INTO fecmur.ref_case_disposition_category (category_id, category_name, " + "display_category_name, published_flg, doc_type) " + "VALUES (%s, %s, %s, %s, %s)", + category_id, + category_name, + display_category_name, + published_flg, + doc_type, + ) + def create_relatedobjects(self, master_key, detail_key, relation_id): self.connection.execute( "INSERT INTO fecmur.relatedobjects (master_key, detail_key, relation_id) " diff --git a/webservices/legal_docs/current_cases.py b/webservices/legal_docs/current_cases.py index e9864ca66..c14cbed03 100644 --- a/webservices/legal_docs/current_cases.py +++ b/webservices/legal_docs/current_cases.py @@ -274,56 +274,15 @@ "Dismissed - Failed to Approve": "Case Dismissed" } -MUR_ADR_DISPOSITION_CATEGORY_MAP = { - 'Approved by Commission': '1', - 'Approved In Part Recs.': '2', - 'Approved Recs.': '3', - 'Case Activated': '4', - 'Case Activation': '5', - 'Conciliation-PC': '6', - 'Conciliation-PPC': '7', - 'Dismiss and Remind': '8', - 'Dismissed': '9', - 'Dismissed - Agreement Rejected': '10', - 'Dismissed-Low Rated': '11', - 'Dismissed-Other': '12', - 'Dismissed-Stale': '13', - 'Dismiss pursuant to prosecutorial discretion': '14', - 'Dismiss pursuant to prosecutorial discretion, and caution': '15', - 'Enforcement - Disposition - Dismissed "Dismiss" - Dismiss and Caution': '16', - 'Failed to Approve Recs.': '17', - 'First General Counsel Report': '18', - 'Formal Discovery Authorized': '19', - 'Investigative Activity': '20', - 'Mailed to Respondent': '21', - 'Merged': '22', - 'No PCTB': '23', - 'No RTB': '24', - 'Offer from Respondent Received': '25', - 'Other': '26', - 'PC Brief': '27', - 'PC Conciliation Approved': '28', - 'PC/NFA': '29', - 'PCTB Finding': '30', - 'Pre-PCC Commenced': '31', - 'Received': '32', - 'Received from Audit Division': '33', - 'Received from Commission': '34', - 'Received from OGC': '35', - 'Received from RAD': '36', - 'Request for Extension of Time Approved': '37', - 'Request for Extension of Time Approved/Denied': '38', - 'Request for Extension of Time Received': '39', - 'Response Received': '40', - 'RTB Finding': '41', - 'RTB/NFA': '42', - 'Settlement Agreement': '43', - 'Suit Authorization': '44', - 'Take no action': '45', - 'Take No Further Action': '46', - 'To Respondent': '47', - 'Transferred to ADR': '48', -} +CASE_DISPOSITION_CATEGORY = """ + SELECT category_name, + category_id, + doc_type + from fecmur.ref_case_disposition_category + WHERE published_flg = true + AND doc_type = %s +""" + STATUTE_REGEX = re.compile(r"(?\d+([a-z](-1)?)?)") REGULATION_REGEX = re.compile(r"(?\d+)(\.(?P
\d+))?") @@ -661,23 +620,55 @@ def get_adr_case_status(case_id): def get_mur_dispositions(case_id): with db.engine.connect() as conn: rs = conn.execute(MUR_ADR_DISPOSITION_DATA.format(case_id)) + + # Get the allowed displayed MUR disposition category list from table fecmur.ref_case_disposition_category + category_list = [dict(row) for row in conn.execute(CASE_DISPOSITION_CATEGORY, "MUR")] + # print(category_list): + # [{'category': 'Conciliation-PPC', 'category_id': 1}, + # {'category': 'Conciliation-PC', 'category_id': 2}, + # {'category': 'Dismiss and Remind', 'category_id': 3}, + # {'category': 'Dismissed', 'category_id': 4}, + # {'category': 'Dismissed-Low Rated', 'category_id': 5}, + # {'category': 'Dismissed-Other', 'category_id': 6}, + # {'category': 'Dismissed-Stale', 'category_id': 7}, + # {'category': 'Dismiss pursuant to prosecutorial discretion', 'category_id': 8}, + # {'category': 'Dismiss pursuant to prosecutorial discretion, and caution', 'category_id': 9}, + # {'category': 'Enforcement - Disposition - Dismissed Dismiss - Dismiss and Caution', 'category_id': 10}, + # {'category': 'No PCTB', 'category_id': 11}, + # {'category': 'No RTB', 'category_id': 12}, + # {'category': 'PCTB Finding', 'category_id': 13}, + # {'category': 'PC/NFA', 'category_id': 14}, + # {'category': 'RTB Finding', 'category_id': 15}, + # {'category': 'RTB/NFA', 'category_id': 16}, + # {'category': 'Take no action', 'category_id': 17}, + # {'category': 'Take No Further Action', 'category_id': 18}] + disposition_data = [] for row in rs: - citations = [] - if ALL_STATUTORY_CITATIONS.get(str(case_id) + row["name"]): - citations += ALL_STATUTORY_CITATIONS.get(str(case_id) + row["name"]) - if ALL_REGULATORY_CITATIONS.get(str(case_id) + row["name"]): - citations += ALL_REGULATORY_CITATIONS.get(str(case_id) + row["name"]) - disposition_data.append({ - "citations": citations, - "disposition": row["event_name"], - "mur_disposition_category_id": MUR_ADR_DISPOSITION_CATEGORY_MAP[row["event_name"]], - "penalty": row["final_amount"], - "respondent": row["name"], }, - ) + category_id = get_display_case_disposition_category_id(category_list, row["event_name"], "MUR") + if category_id: + citations = [] + if ALL_STATUTORY_CITATIONS.get(str(case_id) + row["name"]): + citations += ALL_STATUTORY_CITATIONS.get(str(case_id) + row["name"]) + if ALL_REGULATORY_CITATIONS.get(str(case_id) + row["name"]): + citations += ALL_REGULATORY_CITATIONS.get(str(case_id) + row["name"]) + + disposition_data.append({ + "citations": citations, + "disposition": row["event_name"], + "mur_disposition_category_id": category_id, + "penalty": row["final_amount"], + "respondent": row["name"], }, + ) return disposition_data +def get_display_case_disposition_category_id(category_list, category_name, doc_type): + for one_row in category_list: + if one_row["category_name"] == category_name and one_row["doc_type"] == doc_type: + return one_row["category_id"] + + def parse_statutory_citations(statutory_citation, case_id, entity_id, doc_type=None): citations = [] if statutory_citation: From aefd9858cbda78b8036459b419cde0e13fc76099 Mon Sep 17 00:00:00 2001 From: Jun Li Date: Thu, 7 Nov 2024 10:38:48 -0500 Subject: [PATCH 2/2] Add category description --- webservices/args.py | 7 +-- webservices/docs.py | 69 +++++++------------------ webservices/legal_docs/current_cases.py | 21 +------- 3 files changed, 23 insertions(+), 74 deletions(-) diff --git a/webservices/args.py b/webservices/args.py index 7965e2443..28faf6f1b 100644 --- a/webservices/args.py +++ b/webservices/args.py @@ -387,11 +387,8 @@ def make_seek_args(field=fields.Int, description=None): 'mur_disposition_category_id': fields.List(IStr( validate=validate.OneOf([ '', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', - '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', - '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', - '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', - '41', '42', '43', '44', '45', '46', '47', '48'])), - description=docs.MUR_DISPOSITION_CATEGORY_DISCRIPTION + '11', '12', '13', '14', '15', '16', '17', '18'])), + description=docs.MUR_DISPOSITION_CATEGORY_DESCRIPTION ), 'af_name': fields.List(IStr, required=False, description=docs.AF_NAME), diff --git a/webservices/docs.py b/webservices/docs.py index fbc97aab2..7b721be5d 100644 --- a/webservices/docs.py +++ b/webservices/docs.py @@ -2246,56 +2246,27 @@ def add_ytd(var): - 2001 - Administrative Fine Case\n\ ''' -MUR_DISPOSITION_CATEGORY_DISCRIPTION = ''' + +MUR_DISPOSITION_CATEGORY_DESCRIPTION = ''' Select one or more MUR disposition category id to filter by corresponding MUR disposition category:\n\ - - 1 - Approved by Commission\n\ - - 2 - Approved In Part Recs.\n\ - - 3 - Approved Recs.\n\ - - 4 - Case Activated\n\ - - 5 - Case Activation\n\ - - 6 - Conciliation-PC\n\ - - 7 - Conciliation-PPC\n\ - - 8 - Dismiss and Remind\n\ - - 9 - Dismissed\n\ - - 10 - Dismissed - Agreement Rejected\n\ - - 11 - Dismissed-Low Rated\n\ - - 12 - Dismissed-Other\n\ - - 13 - Dismissed-Stale\n\ - - 14 - Dismiss pursuant to prosecutorial discretion\n\ - - 15 - Dismiss pursuant to prosecutorial discretion, and caution\n\ - - 16 - Enforcement - Disposition - Dismissed "Dismiss" - Dismiss and Caution\n\ - - 17 - Failed to Approve Recs.\n\ - - 18 - First General Counsel Report\n\ - - 19 - Formal Discovery Authorized\n\ - - 20 - Investigative Activity\n\ - - 21 - Mailed to Respondent\n\ - - 22 - Merged\n\ - - 23 - No PCTB\n\ - - 24 - No RTB\n\ - - 25 - Offer from Respondent Received\n\ - - 26 - Other\n\ - - 27 - PC Brief\n\ - - 28 - PC Conciliation Approved\n\ - - 29 - PC/NFA\n\ - - 30 - PCTB Finding\n\ - - 31 - Pre-PCC Commenced\n\ - - 32 - Received\n\ - - 33 - Received from Audit Division\n\ - - 34 - Received from Commission\n\ - - 35 - Received from OGC\n\ - - 36 - Received from RAD\n\ - - 37 - Request for Extension of Time Approved\n\ - - 38 - Request for Extension of Time Approved/Denied\n\ - - 39 - Request for Extension of Time Received\n\ - - 40 - Response Received\n\ - - 41 - RTB Finding\n\ - - 42 - RTB/NFA\n\ - - 43 - Settlement Agreement\n\ - - 44 - Suit Authorization\n\ - - 45 - Take no action\n\ - - 46 - Take No Further Action\n\ - - 47 - To Respondent\n\ - - 48 - Transferred to ADR\n\ + - 1 - Conciliation-PPC\n\ + - 2 - Conciliation-PC\n\ + - 3 - Dismiss and Remind\n\ + - 4 - Dismissed\n\ + - 5 - Dismissed-Low Rated\n\ + - 6 - Dismissed-Other\n\ + - 7 - Dismissed-Stale\n\ + - 8 - Dismiss pursuant to prosecutorial discretion\n\ + - 9 - Dismiss pursuant to prosecutorial discretion, and caution\n\ + - 10 - Enforcement - Disposition - Dismissed Dismiss - Dismiss and Caution\n\ + - 11 - No PCTB\n\ + - 12 - No RTB\n\ + - 13 - PCTB Finding\n\ + - 14 - PC/NFA\n\ + - 15 - RTB Finding\n\ + - 16 - RTB/NFA\n\ + - 17 - Take no action\n\ + - 18 - Take No Further Action\n\ ''' MUR_TYPE = ''' diff --git a/webservices/legal_docs/current_cases.py b/webservices/legal_docs/current_cases.py index c14cbed03..45c7df92d 100644 --- a/webservices/legal_docs/current_cases.py +++ b/webservices/legal_docs/current_cases.py @@ -623,26 +623,7 @@ def get_mur_dispositions(case_id): # Get the allowed displayed MUR disposition category list from table fecmur.ref_case_disposition_category category_list = [dict(row) for row in conn.execute(CASE_DISPOSITION_CATEGORY, "MUR")] - # print(category_list): - # [{'category': 'Conciliation-PPC', 'category_id': 1}, - # {'category': 'Conciliation-PC', 'category_id': 2}, - # {'category': 'Dismiss and Remind', 'category_id': 3}, - # {'category': 'Dismissed', 'category_id': 4}, - # {'category': 'Dismissed-Low Rated', 'category_id': 5}, - # {'category': 'Dismissed-Other', 'category_id': 6}, - # {'category': 'Dismissed-Stale', 'category_id': 7}, - # {'category': 'Dismiss pursuant to prosecutorial discretion', 'category_id': 8}, - # {'category': 'Dismiss pursuant to prosecutorial discretion, and caution', 'category_id': 9}, - # {'category': 'Enforcement - Disposition - Dismissed Dismiss - Dismiss and Caution', 'category_id': 10}, - # {'category': 'No PCTB', 'category_id': 11}, - # {'category': 'No RTB', 'category_id': 12}, - # {'category': 'PCTB Finding', 'category_id': 13}, - # {'category': 'PC/NFA', 'category_id': 14}, - # {'category': 'RTB Finding', 'category_id': 15}, - # {'category': 'RTB/NFA', 'category_id': 16}, - # {'category': 'Take no action', 'category_id': 17}, - # {'category': 'Take No Further Action', 'category_id': 18}] - + logger.debug("category_list =" + json.dumps(category_list, indent=3, cls=DateTimeEncoder)) disposition_data = [] for row in rs: category_id = get_display_case_disposition_category_id(category_list, row["event_name"], "MUR")