Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68dc5d7

Browse files
34622 - Tombstone pipline: Court order mapping (#4771)
* 34622 - imitial implementation * 34622 - update meta data * 34622 - update version data * 34622 - update file * 34622 - update version data * 34622 - updates to flow * 34622 - revert parallel flow setting * 34622 - update * 34622 - update to map order details
1 parent 093f7bc commit 68dc5d7

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

data-tool/flows/corps_tombstone_flow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ def load_placeholder_filings(conn: Connection, tombstone_data: dict, business_id
286286
jurisdiction_id = load_data(conn, 'jurisdictions', jurisdiction)
287287
versioning_mapper['jurisdictions_version'].append(jurisdiction_id)
288288

289+
if court_order:= data['court_order']:
290+
court_order['business_id'] = business_id
291+
court_order['filing_id'] = filing_id
292+
court_order_id = load_data(conn, 'court_orders', court_order)
293+
versioning_mapper['court_orders_version'].append(court_order_id)
294+
289295
# load amalgamation snapshot linked to the current filing
290296
if amalgamation_data := data['amalgamations']:
291297
load_amalgamation_snapshot(conn, amalgamation_data, business_id, filing_id, versioning_mapper)

data-tool/flows/tombstone/tombstone_base_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@
173173
'expro_legal_name': None,
174174
}
175175

176+
COURT_ORDER = {
177+
'business_id': None,
178+
'file_number': None,
179+
'order_date': None, # date
180+
'effect_of_order': None,
181+
'order_details': None,
182+
}
183+
176184

177185
# ======== filing ========
178186
FILING_JSON = {

data-tool/flows/tombstone/tombstone_queries.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_unprocessed_corps_subquery(flow_name, environment):
8080
# [2]->[1]->[3] (may fetch fewer eligible corps in [2] at the beginning, if so, go to [1] and then go back to [2], repeatedly)
8181
# Other usage:
8282
# [0] is used for other purposes, e.g. tweak query to select specific corps
83-
subquery = subqueries[3]
83+
subquery = subqueries[0]
8484
return subquery['cte'], subquery['where']
8585

8686
def get_unprocessed_corps_query(flow_name, config, batch_size, *, include_account_ids: bool = False):
@@ -695,6 +695,26 @@ def get_jurisdictions_query(corp_num):
695695
"""
696696
return query
697697

698+
def get_court_order_query(corp_num):
699+
query = f"""
700+
select
701+
-- event
702+
e.event_id as e_event_id,
703+
e.corp_num as e_corp_num,
704+
f.arrangement_ind as f_arrangement_ind,
705+
f.court_order_num as f_court_order_num,
706+
lt.notation as lt_notation
707+
from event e
708+
left outer join filing f on e.event_id = f.event_id
709+
left outer join ledger_text lt on lt.event_id = f.event_id
710+
where 1 = 1
711+
and e.corp_num = '{corp_num}'
712+
and f.court_order_num is not NULL
713+
order by e.event_id
714+
;
715+
"""
716+
return query
717+
698718

699719
def get_filings_query(corp_num):
700720
query = f"""
@@ -950,6 +970,7 @@ def get_corp_snapshot_filings_queries(config, corp_num):
950970
'resolutions': get_resolutions_query(corp_num),
951971
'jurisdictions': get_jurisdictions_query(corp_num),
952972
'filings': get_filings_query(corp_num),
973+
'court_order':get_court_order_query(corp_num),
953974
'amalgamations': get_amalgamation_query(corp_num),
954975
'business_comments': get_business_comments_query(corp_num),
955976
'filing_comments': get_filing_comments_query(corp_num),

data-tool/flows/tombstone/tombstone_utils.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import pandas as pd
99
import pytz
1010
from sqlalchemy import Connection, bindparam, text
11-
from tombstone.tombstone_base_data import (ALIAS, AMALGAMATION, FILING,
11+
from tombstone.tombstone_base_data import (ALIAS, AMALGAMATION,
12+
COURT_ORDER, FILING,
1213
FILING_JSON, IN_DISSOLUTION,
1314
JURISDICTION, OFFICE, OFFICES_HELD,
1415
PARTY, PARTY_ROLE, RESOLUTION,
@@ -369,6 +370,24 @@ def format_resolutions_data(data: dict, config=None) -> list[dict]:
369370
return formatted_resolutions
370371

371372

373+
def format_court_order_data(data: dict, event_id: Decimal) -> Optional[dict]:
374+
court_order_data = data['court_order']
375+
376+
matched_court_order = [
377+
item for item in court_order_data if item.get('e_event_id') == event_id
378+
]
379+
380+
if not matched_court_order:
381+
return None
382+
383+
formatted_court_order = copy.deepcopy(COURT_ORDER)
384+
formatted_court_order['file_number'] = matched_court_order[0]['f_court_order_num']
385+
formatted_court_order['effect_of_order'] = matched_court_order[0]['f_arrangement_ind']
386+
formatted_court_order['order_date'] = None # Note: order_date is not available in the current data, so set it to None
387+
formatted_court_order['order_details'] = matched_court_order[0]['lt_notation']
388+
389+
return formatted_court_order
390+
372391
def format_jurisdictions_data(data: dict, event_id: Decimal) -> dict:
373392
jurisdictions_data = data['jurisdictions']
374393

@@ -463,6 +482,7 @@ def format_filings_data(data: dict, config=None) -> dict:
463482
jurisdiction = None
464483
amalgamation = None
465484
consent_continuation_out = None
485+
court_order = None
466486

467487
user_id = get_username(x)
468488

@@ -520,14 +540,17 @@ def format_filings_data(data: dict, config=None) -> dict:
520540

521541
comments = format_filing_comments_data(data, x['e_event_id'])
522542

543+
court_order = format_court_order_data(data, x['e_event_id'])
544+
523545
colin_event_ids = {'colin_event_id': x['e_event_id']}
524546
filing = {
525547
'filings': filing_body,
526548
'jurisdiction': jurisdiction,
527549
'amalgamations': amalgamation,
528550
'comments': comments,
529551
'colin_event_ids': colin_event_ids,
530-
'consent_continuation_out': consent_continuation_out
552+
'consent_continuation_out': consent_continuation_out,
553+
'court_order': court_order
531554
}
532555

533556
formatted_filings.append(filing)
@@ -876,6 +899,31 @@ def get_business_update_value(key: str, effective_date: str, trigger_date: str,
876899
return value
877900

878901

902+
def update_court_order(meta_data: dict, data: dict, filing_data: dict) -> None:
903+
court_order_data = data['court_order']
904+
905+
matched_court_order = [
906+
item for item in court_order_data if item.get('e_event_id') == filing_data['e_event_id']
907+
]
908+
909+
if not matched_court_order:
910+
return None
911+
912+
court_order_num = matched_court_order[0]['f_court_order_num']
913+
914+
if not court_order_num:
915+
return
916+
917+
meta_data['courtOrder'] = meta_data.get('courtOrder', {})
918+
meta_data['courtOrder']['fileNumber'] = court_order_num
919+
920+
if effect_of_order := matched_court_order[0]['f_arrangement_ind']:
921+
meta_data['courtOrder']['effectOfOrder'] = effect_of_order
922+
923+
if order_details := matched_court_order[0]['lt_notation']:
924+
meta_data['courtOrder']['orderDetails'] = order_details
925+
926+
879927
def build_filing_json_meta_data(raw_filing_type: str,
880928
filing_type: str,
881929
filing_subtype: str,
@@ -1025,6 +1073,9 @@ def build_filing_json_meta_data(raw_filing_type: str,
10251073
'withdrawnDate': withdrawn_ts.isoformat()
10261074
}
10271075

1076+
# populate court order info in meta_data if available
1077+
update_court_order(meta_data, data, filing_data)
1078+
10281079
# TODO: populate meta_data for correction to display correct filing name
10291080

10301081
return filing_json, meta_data

0 commit comments

Comments
 (0)