Skip to content

Commit

Permalink
Merge pull request #10 from nealwp/error-dialog
Browse files Browse the repository at this point in the history
Error dialog
  • Loading branch information
nealwp authored Jan 23, 2024
2 parents 6d1bf22 + 5b3e074 commit 0fe70fd
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ lib/*
*.json
files
*.drawio*
*.docx
.venv
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
14 changes: 14 additions & 0 deletions src/exporter/bell_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def generate_bell_format_summary(data):
doc.add_paragraph(f'TYPE OF CLAIM:\t\t{data["claimant"].claim}')
doc.add_paragraph(f'DATE OF APPLICATION:\t{datetime.strftime(data["claimant"].pdof, "%m/%d/%Y")}')
doc.add_paragraph(f'ALLEGED ONSET DATE:\t{data["onset_date"]}')
doc.add_paragraph(f'DATE LATE INSURED:\t\t{data["claimant"].last_insured_date}')
doc.add_paragraph(f'DOB:\t\t\t\t{data["birthdate"]}')
doc.add_paragraph(f'AGE:\t\t\t\t{data["age"]}')
doc.add_paragraph(f'EDUCATION:\t\t\t{data["education"]}')
Expand Down Expand Up @@ -66,6 +67,19 @@ def generate_bell_format_summary(data):
p = doc.add_paragraph()
p.add_run(f'{comment.date}: {comment.text} ({exhibit}/{comment.exhibit_page})')

doc.add_paragraph('')
doc.add_paragraph('')

doc.add_paragraph('CONSULTATIVE EXAM:')

doc.add_paragraph('')
doc.add_paragraph('')

doc.add_paragraph('MEDICAL-VOCATIONAL GRIDRULE AND/OR RULING:')

doc.add_paragraph('')
doc.add_paragraph('')

for section in doc.sections:
section.left_margin = Inches(1)
section.right_margin = Inches(1)
Expand Down
4 changes: 4 additions & 0 deletions src/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def age(self) -> int:
return None

def age_at_onset(self) -> int:

if self.onset_date == "N/A":
return None

if self.birthdate and self.onset_date:
birthdate = datetime.strptime(self.birthdate, '%m/%d/%Y')
onset_date = datetime.strptime(self.onset_date, '%m/%d/%Y')
Expand Down
94 changes: 60 additions & 34 deletions src/pdf/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,32 @@ def scan_pdf_for_summary(pdf_path):


def parse_client_info(page_text):

lines = page_text.splitlines()
lines = [line for line in lines if line]
client_data = lines[:7]
client_info = {}
for e in client_data:
e = e.split(':')
client_info[e[0]] = e[1].lstrip()
lines = page_text.splitlines()

for line in lines:
if line.startswith("Alleged Onset:"):
client_info["Alleged Onset"] = line.split(":")[1].strip()
continue
if line.startswith("Application:"):
client_info["Application"] = line.split(":")[1].strip()
continue
if line.startswith("Claim Type:"):
client_info["Claim Type"] = line.split(":")[1].strip()
continue
if line.startswith("Claimant:"):
client_info["Claimant"] = line.split(":")[1].strip()
continue
if line.startswith("Last Change:"):
client_info["Last Change"] = line.split(":")[1].strip()
continue
if line.startswith("Last Insured:"):
client_info["Last Insured"] = line.split(":")[1].strip()
continue
if line.startswith("SSN:"):
client_info["SSN"] = line.split(":")[1].strip()
continue

return client_info


Expand All @@ -152,41 +170,49 @@ def parse_work_history(page_text):
'job_title': e.split(": ")[1],
'intensity': '',
'skill_level': '',
}
}
return work_history


def get_exhibits_from_pdf(doc):
try:
outlines = doc.get_outlines()
sys.setrecursionlimit(999999999)
index = 1
provider = ''
exhibits = {}
for (level, title, dest, a, se) in outlines:
if level == 2:
provider = title
id = provider.split(":")[0]
provider_name = provider.split(":")[1].replace("Doc. Dt.", "").replace("Tmt. Dt.", "").strip()
provider_dates = re.sub(r"\(\d* page.*", "", provider.split(":")[2]).strip()
from_date = provider_dates.split("-")[0]
try:
to_date = provider_dates.split("-")[1]
except IndexError:
to_date = from_date
ex = Exhibit(provider_name=provider_name, from_date=from_date, to_date=to_date, comments=[])
exhibits[id] = ex
if level == 3:
index += 1
except PDFNoOutlines:
exhibits = {}
sys.setrecursionlimit(1000)
print('PDF has no outlines to reference.')

exhibits = {}
outlines = doc.get_outlines()
sys.setrecursionlimit(999999999)
index = 1
for (level, title, dest, a, se) in outlines:
if level == 2:
id, provider_name, from_date, to_date = parse_title(title)
ex = Exhibit(provider_name=provider_name, from_date=from_date, to_date=to_date, comments=[])
exhibits[id] = ex
if level == 3:
index += 1
sys.setrecursionlimit(1000)
return exhibits


def parse_title(title):
split_title = title.split(":")
id = split_title[0]
provider_name = split_title[1].replace("Doc. Dt.", "").replace("Tmt. Dt.", "").strip()

# if no dates, return empty
if len(split_title) == 2:
provider_name = re.sub(r"\(\d* page.*", "", provider_name).strip()
return (id, provider_name, "", "")

provider_dates = re.sub(r"\(\d* page.*", "", split_title[2]).strip().split("-")

# if one date, return both as date
if len(provider_dates) == 1:
date = provider_dates[0]
return (id, provider_name, date, date)

from_date = provider_dates[0]
to_date = provider_dates[1]

return (id, provider_name, from_date, to_date)


def parse_page_comments(annots):

page_comments = []
Expand Down
14 changes: 14 additions & 0 deletions src/ui/errordialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tkinter import Toplevel, Label, LEFT, Button


class ErrorDialog(Toplevel):
def __init__(self, parent, error):
super().__init__(parent)
self.title("Error")
Label(self, text=error, anchor='w', justify=LEFT).pack(pady=5, padx=5)

Button(self, text='Close', command=self.destroy).pack(pady=10)

self.transient(parent)
self.grab_set()
self.geometry("+%d+%d" % (parent.winfo_rootx()+50, parent.winfo_rooty()+50))
17 changes: 12 additions & 5 deletions src/ui/summaryform.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from datetime import datetime
from tkinter import Toplevel, Button, Label, Entry, StringVar, Text, LabelFrame, Radiobutton
from tkinter import Toplevel, Button, Label, Entry, StringVar, Text, LabelFrame, Radiobutton, LEFT
from tkinter.ttk import Combobox

from traceback import format_exc
from src.helpers import get_save_path, get_file_path, get_age, get_age_at_onset
from src.pdf.scanner import scan_for_comments, scan_pdf_for_summary
from src.ui.workhistoryform import WorkHistoryForm
from src.ui.errordialog import ErrorDialog
from src.exporter import generate_summary


Expand Down Expand Up @@ -179,9 +180,15 @@ def _get_summary_data(self):
modal.grab_set()
modal.geometry("+%d+%d" % (self.winfo_rootx()+50, self.winfo_rooty()+50))
self.update()
self.medical_record = scan_pdf_for_summary(self.pdf_path)
self._fill_entry_fields()
modal.destroy()
try:
self.medical_record = scan_pdf_for_summary(self.pdf_path)
self._fill_entry_fields()
modal.destroy()
except Exception:
modal.destroy()
error = format_exc()
error_modal = ErrorDialog(self, error)
self.update()

def _fill_entry_fields(self):
mr = self.medical_record
Expand Down
27 changes: 27 additions & 0 deletions tests/helpers/example_page_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Claimant: John Person Doe
SSN: 000-00-0000
Last Change: 01/01/1970
Alleged Onset: N/A

Claim Type: T16
Application: 01/01/2023
Last Insured: N/A

A. Payment Documents/Decisions
Title
1A: Disability Determination Explanation - DDE
2A: Disability Determination Transmittal - 831
3A: T16 Cease/Continue Disability Determination and Transmittal - 832
4A: Disability Determination Explanation - DDE
5A: Disability Determination Explanation - DDE
6A: T16 Cease/Continue Disability Determination and Transmittal - 832
7A: Disability Determination Explanation - DDE

Decision Date
08/06/2018
08/06/2018
08/30/2022
08/30/2022
02/23/2023
05/17/2023
05/17/2023
41 changes: 41 additions & 0 deletions tests/helpers/example_page_1_alt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Claimant: Jane Person Doe
SSN: 000-00-0000
Last Change: 01/01/1970
Alleged Onset: 01/01/2009

A. Payment Documents/Decisions
Title
1A: Disability Determination Transmittal - 831
2A: Disability Determination Explanation - DDE
3A: Disability Determination Transmittal - 831
4A: Disability Determination Explanation - DDE

Claim Type: T16
Application: 02/26/2022
Last Insured: N/A

B. Jurisdictional Documents/Notices
Title
1B: T16 Notice of Disapproved Claim - L444
2B: Request for Reconsideration - 561
3B: T16 Disability Reconsideration Notice - L1130
4B: SSA-1696 - Claimant’s Appointment of a Representative - 1696
5B: Fee Agreement for Representation before SSA - FEEAGRMT
6B: SSA-1696 - Claimant’s Appointment of a Representative - 1696
7B: Fee Agreement for Representation before SSA - FEEAGRMT
8B: Request for Hearing by ALJ - 501
9B: Hearing Agreement Form - HRNGAGREEFRM
10B: Outgoing ODAR Correspondence - OUTODARC
11B: Outgoing ODAR Correspondence - OUTODARC
12B: Request for Hearing Acknowledgement Letter - HRGACK
13B: Hearing Agreement Form - HRNGAGREEFRM
14B: Hearing Notice - 507
15B: Acknowledge Notice of Hearing - 504

D. Non-Disability Development
Title
1D: Application for Supplemental Security Income Benefits - 8000
2D: Detailed Earnings Query - DEQY
3D: Summary Earnings Query - SEQY
4D: Certified Earnings Records - CERTERN
5D: New Hire, Quarter Wage, Unemployment Query (NDNH) - NDNH
76 changes: 68 additions & 8 deletions tests/test_pdfscanner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
from modules.pdfscanner import *
from src.pdf.scanner import parse_title, parse_client_info

file_path = r'.\\files\\2909274-cecilia_phillips-case_file_exhibited_bookmarked-8-10-2022- w notes.pdf'

def test_read_medical_record():
medical_record = MedicalRecord(file_path)
assert(medical_record)
def test_parse_title():
test_cases = [
{
"test": "6F: 6F - 1 of 13 Office Treatment Records - OFFCREC LIFESTREAM BEHAIVORAL CENTER Tmt. Dt.: 12/28/2016-08/30/2021 (23 pages)",
"expected": (
"6F",
"6F - 1 of 13 Office Treatment Records - OFFCREC LIFESTREAM BEHAIVORAL CENTER",
"12/28/2016",
"08/30/2021",
)
},
{
"test": "16F: 16F - 1 of 112 Emergency Department Records - EMERREC UF HEALTH GAINESVILLE Tmt. Dt.: 01/09/2023 (17 pages)",
"expected": (
"16F",
"16F - 1 of 112 Emergency Department Records - EMERREC UF HEALTH GAINESVILLE",
"01/09/2023",
"01/09/2023",
)
},
{
"test": "19F: 19F - 1 of 23 Medical Evidence of Record - MER VOCATIONAL REHABILITATION (12 pages)",
"expected": (
"19F",
"19F - 1 of 23 Medical Evidence of Record - MER VOCATIONAL REHABILITATION",
"",
"",
)
},
]

def test_get_exhibits_from_medical_record():
medical_record = MedicalRecord(file_path)
exhibits = medical_record.exhibits
for case in test_cases:
result = parse_title(case["test"])
assert result == case["expected"]


def test_parse_client_info():
expected = [
{
"Alleged Onset": "N/A",
"Application": "01/01/2023",
"Claim Type": "T16",
"Claimant": "John Person Doe",
"Last Change": "01/01/1970",
"Last Insured": "N/A",
"SSN": "000-00-0000",
},
{
"Alleged Onset": "01/01/2009",
"Application": "02/26/2022",
"Claim Type": "T16",
"Claimant": "Jane Person Doe",
"Last Change": "01/01/1970",
"Last Insured": "N/A",
"SSN": "000-00-0000",
}
]

inputs = [
"tests/helpers/example_page_1.txt",
"tests/helpers/example_page_1_alt.txt"
]

for i, file in enumerate(inputs):
fd = open(file, "r")
page_one = str(fd.read())
result = parse_client_info(page_one)
assert result == expected[i]

0 comments on commit 0fe70fd

Please sign in to comment.