|
8 | 8 | import pandas as pd |
9 | 9 | import pytz |
10 | 10 | 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, |
12 | 13 | FILING_JSON, IN_DISSOLUTION, |
13 | 14 | JURISDICTION, OFFICE, OFFICES_HELD, |
14 | 15 | PARTY, PARTY_ROLE, RESOLUTION, |
@@ -369,6 +370,24 @@ def format_resolutions_data(data: dict, config=None) -> list[dict]: |
369 | 370 | return formatted_resolutions |
370 | 371 |
|
371 | 372 |
|
| 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 | + |
372 | 391 | def format_jurisdictions_data(data: dict, event_id: Decimal) -> dict: |
373 | 392 | jurisdictions_data = data['jurisdictions'] |
374 | 393 |
|
@@ -463,6 +482,7 @@ def format_filings_data(data: dict, config=None) -> dict: |
463 | 482 | jurisdiction = None |
464 | 483 | amalgamation = None |
465 | 484 | consent_continuation_out = None |
| 485 | + court_order = None |
466 | 486 |
|
467 | 487 | user_id = get_username(x) |
468 | 488 |
|
@@ -520,14 +540,17 @@ def format_filings_data(data: dict, config=None) -> dict: |
520 | 540 |
|
521 | 541 | comments = format_filing_comments_data(data, x['e_event_id']) |
522 | 542 |
|
| 543 | + court_order = format_court_order_data(data, x['e_event_id']) |
| 544 | + |
523 | 545 | colin_event_ids = {'colin_event_id': x['e_event_id']} |
524 | 546 | filing = { |
525 | 547 | 'filings': filing_body, |
526 | 548 | 'jurisdiction': jurisdiction, |
527 | 549 | 'amalgamations': amalgamation, |
528 | 550 | 'comments': comments, |
529 | 551 | '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 |
531 | 554 | } |
532 | 555 |
|
533 | 556 | formatted_filings.append(filing) |
@@ -876,6 +899,31 @@ def get_business_update_value(key: str, effective_date: str, trigger_date: str, |
876 | 899 | return value |
877 | 900 |
|
878 | 901 |
|
| 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 | + |
879 | 927 | def build_filing_json_meta_data(raw_filing_type: str, |
880 | 928 | filing_type: str, |
881 | 929 | filing_subtype: str, |
@@ -1025,6 +1073,9 @@ def build_filing_json_meta_data(raw_filing_type: str, |
1025 | 1073 | 'withdrawnDate': withdrawn_ts.isoformat() |
1026 | 1074 | } |
1027 | 1075 |
|
| 1076 | + # populate court order info in meta_data if available |
| 1077 | + update_court_order(meta_data, data, filing_data) |
| 1078 | + |
1028 | 1079 | # TODO: populate meta_data for correction to display correct filing name |
1029 | 1080 |
|
1030 | 1081 | return filing_json, meta_data |
|
0 commit comments