feat: payment PDF extraction, import, and remittance tracking

- Add Upload Payment Documents section with Extract & Download (Excel)
  and Extract & Import (database) buttons
- PDF extractor (pdfplumber) parses MassHealth RA PDFs: two-pass
  strategy joins summary-page ICN/patient map with detail-page
  procedure data (CDT code, paid code, tooth, date, allowed amount)
- RA cover-page summary (Payee ID, RA #, Payment Amount, etc.)
  included as separate Excel sheet; numeric values written as numbers
- Backend PDF import route groups rows by Member #, finds/creates
  patient, creates Payment + ServiceLines with ICN per procedure
- Add icn, paidCode, allowedAmount fields to ServiceLine schema
- Payments table: status simplified to Paid in Full / Balance;
  adjustment auto-computed on mhPaidAmount/copayment change;
  Paid in Full and Revert buttons with confirmation dialogs
- Edit Payment modal: shows ICN, Paid Code, Allowed Amount per line
- PDF Import badge distinguishes from OCR imports in payments table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-07 12:53:50 -04:00
parent e204d30ff6
commit dd0df4a435
76 changed files with 1570 additions and 96 deletions

View File

@@ -10,6 +10,7 @@ from dotenv import load_dotenv
load_dotenv()
from complete_pipeline_adapter import process_images_to_rows,rows_to_csv_bytes
from pdf_extractor import extract_ra_pdf
app = FastAPI(
title="Payment OCR Services API",
@@ -35,7 +36,8 @@ app.add_middleware(
allow_headers=["*"],
)
ALLOWED_EXTS = {".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp"}
ALLOWED_EXTS = {".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp"}
ALLOWED_PDF_EXTS = {".pdf"}
# -------------------------------------------------
# Health + status
@@ -122,6 +124,38 @@ async def extract_csvtext(files: List[UploadFile] = File(...)):
async with lock:
active_jobs -= 1
@app.post("/extract/pdf/json")
async def extract_pdf_json(files: List[UploadFile] = File(...)):
bad = [f.filename for f in files if os.path.splitext(f.filename or "")[1].lower() not in ALLOWED_PDF_EXTS]
if bad:
raise HTTPException(status_code=415, detail=f"Only PDF files allowed. Got: {', '.join(bad)}")
async with lock:
global waiting_jobs
waiting_jobs += 1
async with semaphore:
async with lock:
waiting_jobs -= 1
global active_jobs
active_jobs += 1
try:
all_rows = []
all_headers = []
for f in files:
blob = await f.read()
result = extract_ra_pdf(blob, f.filename or "upload.pdf")
all_rows.extend(result["rows"])
all_headers.append(result["header"])
return JSONResponse(content={"rows": all_rows, "headers": all_headers})
except Exception as e:
raise HTTPException(status_code=500, detail=f"PDF extraction error: {e}")
finally:
async with lock:
active_jobs -= 1
@app.post("/extract/csv")
async def extract_csv(files: List[UploadFile] = File(...), filename: Optional[str] = None):
_validate_files(files)