Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data-tool/flows/corps_tombstone_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ def load_placeholder_filings(conn: Connection, tombstone_data: dict, business_id
jurisdiction_id = load_data(conn, 'jurisdictions', jurisdiction)
versioning_mapper['jurisdictions_version'].append(jurisdiction_id)

if court_order:= data['court_order']:
court_order['business_id'] = business_id
court_order['filing_id'] = filing_id
court_order_id = load_data(conn, 'court_orders', court_order)
versioning_mapper['court_orders_version'].append(court_order_id)

# load amalgamation snapshot linked to the current filing
if amalgamation_data := data['amalgamations']:
load_amalgamation_snapshot(conn, amalgamation_data, business_id, filing_id, versioning_mapper)
Expand Down
8 changes: 8 additions & 0 deletions data-tool/flows/tombstone/tombstone_base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
'expro_legal_name': None,
}

COURT_ORDER = {
'business_id': None,
'file_number': None,
'order_date': None, # date
'effect_of_order': None,
'order_details': None,
}


# ======== filing ========
FILING_JSON = {
Expand Down
23 changes: 22 additions & 1 deletion data-tool/flows/tombstone/tombstone_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_unprocessed_corps_subquery(flow_name, environment):
# [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)
# Other usage:
# [0] is used for other purposes, e.g. tweak query to select specific corps
subquery = subqueries[3]
subquery = subqueries[0]
return subquery['cte'], subquery['where']

def get_unprocessed_corps_query(flow_name, config, batch_size, *, include_account_ids: bool = False):
Expand Down Expand Up @@ -695,6 +695,26 @@ def get_jurisdictions_query(corp_num):
"""
return query

def get_court_order_query(corp_num):
query = f"""
select
-- event
e.event_id as e_event_id,
e.corp_num as e_corp_num,
f.arrangement_ind as f_arrangement_ind,
f.court_order_num as f_court_order_num,
lt.notation as lt_notation
from event e
left outer join filing f on e.event_id = f.event_id
left outer join ledger_text lt on lt.event_id = f.event_id
where 1 = 1
and e.corp_num = '{corp_num}'
and f.court_order_num is not NULL
order by e.event_id
;
"""
return query


def get_filings_query(corp_num):
query = f"""
Expand Down Expand Up @@ -950,6 +970,7 @@ def get_corp_snapshot_filings_queries(config, corp_num):
'resolutions': get_resolutions_query(corp_num),
'jurisdictions': get_jurisdictions_query(corp_num),
'filings': get_filings_query(corp_num),
'court_order':get_court_order_query(corp_num),
'amalgamations': get_amalgamation_query(corp_num),
'business_comments': get_business_comments_query(corp_num),
'filing_comments': get_filing_comments_query(corp_num),
Expand Down
55 changes: 53 additions & 2 deletions data-tool/flows/tombstone/tombstone_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import pandas as pd
import pytz
from sqlalchemy import Connection, bindparam, text
from tombstone.tombstone_base_data import (ALIAS, AMALGAMATION, FILING,
from tombstone.tombstone_base_data import (ALIAS, AMALGAMATION,
COURT_ORDER, FILING,
FILING_JSON, IN_DISSOLUTION,
JURISDICTION, OFFICE, OFFICES_HELD,
PARTY, PARTY_ROLE, RESOLUTION,
Expand Down Expand Up @@ -369,6 +370,24 @@ def format_resolutions_data(data: dict, config=None) -> list[dict]:
return formatted_resolutions


def format_court_order_data(data: dict, event_id: Decimal) -> Optional[dict]:
court_order_data = data['court_order']

matched_court_order = [
item for item in court_order_data if item.get('e_event_id') == event_id
]

if not matched_court_order:
return None

formatted_court_order = copy.deepcopy(COURT_ORDER)
formatted_court_order['file_number'] = matched_court_order[0]['f_court_order_num']
formatted_court_order['effect_of_order'] = matched_court_order[0]['f_arrangement_ind']
formatted_court_order['order_date'] = None # Note: order_date is not available in the current data, so set it to None
formatted_court_order['order_details'] = matched_court_order[0]['lt_notation']

return formatted_court_order

def format_jurisdictions_data(data: dict, event_id: Decimal) -> dict:
jurisdictions_data = data['jurisdictions']

Expand Down Expand Up @@ -463,6 +482,7 @@ def format_filings_data(data: dict, config=None) -> dict:
jurisdiction = None
amalgamation = None
consent_continuation_out = None
court_order = None

user_id = get_username(x)

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

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

court_order = format_court_order_data(data, x['e_event_id'])

colin_event_ids = {'colin_event_id': x['e_event_id']}
filing = {
'filings': filing_body,
'jurisdiction': jurisdiction,
'amalgamations': amalgamation,
'comments': comments,
'colin_event_ids': colin_event_ids,
'consent_continuation_out': consent_continuation_out
'consent_continuation_out': consent_continuation_out,
'court_order': court_order
}

formatted_filings.append(filing)
Expand Down Expand Up @@ -876,6 +899,31 @@ def get_business_update_value(key: str, effective_date: str, trigger_date: str,
return value


def update_court_order(meta_data: dict, data: dict, filing_data: dict) -> None:
court_order_data = data['court_order']

matched_court_order = [
item for item in court_order_data if item.get('e_event_id') == filing_data['e_event_id']
]

if not matched_court_order:
return None

court_order_num = matched_court_order[0]['f_court_order_num']

if not court_order_num:
return

meta_data['courtOrder'] = meta_data.get('courtOrder', {})
meta_data['courtOrder']['fileNumber'] = court_order_num

if effect_of_order := matched_court_order[0]['f_arrangement_ind']:
meta_data['courtOrder']['effectOfOrder'] = effect_of_order

if order_details := matched_court_order[0]['lt_notation']:
meta_data['courtOrder']['orderDetails'] = order_details


def build_filing_json_meta_data(raw_filing_type: str,
filing_type: str,
filing_subtype: str,
Expand Down Expand Up @@ -1025,6 +1073,9 @@ def build_filing_json_meta_data(raw_filing_type: str,
'withdrawnDate': withdrawn_ts.isoformat()
}

# populate court order info in meta_data if available
update_court_order(meta_data, data, filing_data)

# TODO: populate meta_data for correction to display correct filing name

return filing_json, meta_data
Expand Down