File size: 12,179 Bytes
48e7216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ID: Passport"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check against sample extracted JSON"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "from utils.prep_validators_payload import process_extracted_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "custom_app_form = {\n",
    "    \"application_summary_full_name\": \"Jodie Pippa\",\n",
    "    \"application_summary_bank_name\": \"HSBC\",\n",
    "    \"application_summary_employer_name\": \"ABC Ltd\",\n",
    "    \"application_summary_complete_address\": \"123 Maple Street, London, UK, SW1A 1AA\",\n",
    "    \"full_name_err_msgs\": None,\n",
    "    \"bank_name_err_msgs\": None,\n",
    "    \"employer_name_err_msgs\": None,\n",
    "    \"complete_employee_address_err_msgs\": None,\n",
    "    \"is_incomplete\": False,\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'/tmp/tmp6w8qn6h6/sample_documents/sample_documents/3.pdf': {'/tmp/tmp6w8qn6h6/sample_documents/sample_documents/3.pdf_page_0.png': {'document_category': 'bank_statement', 'document_type': 'bank_statement', 'account_holder_name': 'Jodie Pippa', 'account_holder_address': '', 'bank_name': 'HSBC', 'account_number': '12345678', 'sort_code': '20-00-00', 'statement_start_date': '2025-01-01', 'statement_end_date': '2025-02-28', 'salary_credits': [{'date': '2025-01-06', 'amount': '2213.83', 'from': 'ABC Ltd', 'description': 'Salary - ABC Ltd (Pro-rated Jan)'}, {'date': '2025-02-06', 'amount': '2566.66', 'from': 'ABC Ltd', 'description': 'Salary - ABC Ltd (Full Feb Salary)'}]}}, '/tmp/tmp6w8qn6h6/sample_documents/sample_documents/5.pdf': {'/tmp/tmp6w8qn6h6/sample_documents/sample_documents/5.pdf_page_0.png': {'document_category': 'income_document', 'document_type': 'payslip', 'employee_name': 'Jodie Pippa', 'employer_name': 'ABC Ltd', 'employee_id': 'JP12345', 'employee_address': '123 Maple Street, London, UK, SW1A 1AA', 'employer_address': '456 Business Street, London, UK, SW1A 2BB', 'tax_code': '1257L', 'payslip_date': '2025-01-31', 'pay_period_start': '2025-01-06', 'pay_period_end': '2025-01-31', 'payment_frequency': 'monthly', 'basic_pay': '3333.33', 'net_pay': '2566.66', 'gross_pay': '3333.33', 'salary_components': [], 'ni_contribution': '266.67', 'tax_deduction': '333.33', 'other_deductions': [{'name': 'Pension Contribution', 'amount': '166.67'}]}}, '/tmp/tmp6w8qn6h6/sample_documents/sample_documents/2.pdf': {'/tmp/tmp6w8qn6h6/sample_documents/sample_documents/2.pdf_page_0.png': {'document_category': 'income_document', 'document_type': 'p60', 'employee_details': {'surname': 'Pippa', 'forenames_or_initials': 'Jodie', 'national_insurance_number': 'AB123456C', 'works_payroll_number': '5342'}, 'pay_and_income_tax_details': {'previous_employments': {'pay': 0.0, 'tax_deducted': 0.0}, 'current_employment': {'pay': 9545.45, 'tax_deducted': 0.0}, 'total_for_year': {'pay': 9545.45, 'tax_deducted': 0.0}, 'final_tax_code': '1257'}, 'national_insurance_contributions': [{'nic_letter': 'A', 'earnings': {'at_or_above_lel': 6396.0, 'above_lel_up_to_pt': 0.0, 'above_pt_up_to_uel': 3149.45}, 'employee_contributions_above_pt': 377.93}], 'statutory_payments': {'maternity_pay': 0.0, 'paternity_pay': 0.0, 'adoption_pay': 0.0, 'shared_parental_pay': 0.0}, 'other_details': {'student_loan_deductions': 0.0}, 'employer_details': {'employer_name_and_address': None, 'paye_reference': '123/AB456'}}}, '/tmp/tmp6w8qn6h6/sample_documents/sample_documents/1.pdf': {'/tmp/tmp6w8qn6h6/sample_documents/sample_documents/1.pdf_page_0.png': {'document_category': 'identity_verification_document', 'document_type': 'passport', 'full_name': 'UNITED-KINGDOM-FIVE JODIE PIPPA', 'surname': 'UNITED-KINGDOM-FIVE', 'given_names': 'JODIE PIPPA', 'passport_number': '107185703', 'nationality': 'BRITISH CITIZEN', 'date_of_birth': '1985-01-17', 'place_of_birth': 'LONDON', 'sex': 'F', 'date_of_issue': '2006-01-31', 'date_of_expiry': '2016-01-31', 'issuing_authority': 'UKPA', 'passport_type': 'P', 'country_code': 'GBR', 'mrz_line_1': 'P<GBRUNITED<KINGDOM<FIVE<<JODIE<PIPPA<<<<<<<', 'mrz_line_2': '1071857032GBR8501178F1601312<<<<<<<<<<<<<<02'}}}\n"
     ]
    }
   ],
   "source": [
    "with open(\"../analysis_results.json\", \"r\") as f:\n",
    "    full_data = json.load(f)\n",
    "\n",
    "print(full_data)\n",
    "# print(process_extracted_data(full_data, custom_app_form))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'payslips': [{'pay_period_start_date': datetime.date(2025, 1, 6), 'pay_period_end_date': datetime.date(2025, 1, 31), 'pay_period_days': None, 'pay_date': datetime.date(2025, 1, 31), 'full_name': 'Jodie Pippa', 'employer_name': 'ABC Ltd', 'is_basic_pay_net_pay_other_salary_components_present': True, 'is_tax_deducation_present': True, 'is_ni_deduction_present': True, 'complete_employee_address': '123 Maple Street, London, UK, SW1A 1AA', 'pay_dates_err_msgs': \"Pay date must be within the last 35 days & not in the future, Pay period's start date & end date must have a gap of at least 28 days\", 'full_name_err_msgs': None, 'employer_name_err_msgs': None, 'payslip_line_item_presence_err_msgs': None, 'complete_employee_address_err_msgs': None, 'validation_policy_status_df':                                               Policy        Value  Status  \\\n",
      "0            Applicant's full name should be present  Jodie Pippa    True   \n",
      "1  Full name must have a length of at least 2 & a...           11    True   \n",
      "2  Full name must consist of at least 2 words (fi...            2    True   \n",
      "3              Name should match with provided value  Jodie Pippa    True   \n",
      "4                      Employer name must be present      ABC Ltd    True   \n",
      "5       Employer name must match with provided value      ABC Ltd    True   \n",
      "\n",
      "                                             Message  \n",
      "0                   Applicant's full name is present  \n",
      "1  Full name has a length of at least 2 & at most 61  \n",
      "2  Full name consists of at least 2 words (first ...  \n",
      "3                   Name matches with provided value  \n",
      "4                           Employer name is present  \n",
      "5          Employer name matches with provided value  , 'is_red_flagged': True}], 'bank_statements': [{'statement_start_date': datetime.date(2025, 1, 1), 'statement_end_date': datetime.date(2025, 2, 28), 'first_salary_deposit_date_present': 6, 'bank_name': 'HSBC', 'full_name': 'Jodie Pippa', 'account_number': '12345678', 'sort_code': '20-00-00', 'account_statement_date_err_msgs': None, 'full_name_err_msgs': None, 'bank_name_err_msgs': None, 'account_number_err_msgs': None, 'sort_code_err_msgs': None, 'salary_deposit_err_msgs': None, 'is_red_flagged': False}], 'passports': [{'full_name': 'JODIE PIPPA', 'expiry_date': datetime.date(2016, 1, 31), 'full_name_err_msgs': None, 'expiry_date_err_msgs': 'Provided passport expires within 1 year', 'is_red_flagged': True}]}\n"
     ]
    }
   ],
   "source": [
    "print(process_extracted_data(full_data, custom_app_form))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Policy</th>\n",
       "      <th>Value</th>\n",
       "      <th>Status</th>\n",
       "      <th>Message</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Applicant's full name should be present</td>\n",
       "      <td>Jodie Pippa</td>\n",
       "      <td>True</td>\n",
       "      <td>Applicant's full name is present</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Full name must have a length of at least 2 &amp; a...</td>\n",
       "      <td>11</td>\n",
       "      <td>True</td>\n",
       "      <td>Full name has a length of at least 2 &amp; at most 61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Full name must consist of at least 2 words (fi...</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>Full name consists of at least 2 words (first ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Name should match with provided value</td>\n",
       "      <td>Jodie Pippa</td>\n",
       "      <td>True</td>\n",
       "      <td>Name matches with provided value</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Employer name must be present</td>\n",
       "      <td>ABC Ltd</td>\n",
       "      <td>True</td>\n",
       "      <td>Employer name is present</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Employer name must match with provided value</td>\n",
       "      <td>ABC Ltd</td>\n",
       "      <td>True</td>\n",
       "      <td>Employer name matches with provided value</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Policy        Value  Status  \\\n",
       "0            Applicant's full name should be present  Jodie Pippa    True   \n",
       "1  Full name must have a length of at least 2 & a...           11    True   \n",
       "2  Full name must consist of at least 2 words (fi...            2    True   \n",
       "3              Name should match with provided value  Jodie Pippa    True   \n",
       "4                      Employer name must be present      ABC Ltd    True   \n",
       "5       Employer name must match with provided value      ABC Ltd    True   \n",
       "\n",
       "                                             Message  \n",
       "0                   Applicant's full name is present  \n",
       "1  Full name has a length of at least 2 & at most 61  \n",
       "2  Full name consists of at least 2 words (first ...  \n",
       "3                   Name matches with provided value  \n",
       "4                           Employer name is present  \n",
       "5          Employer name matches with provided value  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = process_extracted_data(full_data, custom_app_form)\n",
    "a['payslips'][0]['validation_policy_status_df']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "hsbc_uk_demo_venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}