Skip to content

Commit 453c6a7

Browse files
authored
Merge pull request #186 from AAdewunmi/chore/add-PDF-evidence-export-integration-test
Chore/add pdf evidence export integration test
2 parents 9ff91c5 + 97009df commit 453c6a7

13 files changed

Lines changed: 912 additions & 271 deletions

README.md

Lines changed: 91 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,57 @@
77
[![PostgreSQL](https://img.shields.io/badge/postgresql-16-336791.svg)](https://www.postgresql.org/)
88
[![Docker](https://img.shields.io/badge/docker-enabled-2496ED.svg)](https://www.docker.com/)
99
[![Docker Compose](https://img.shields.io/badge/docker%20compose-supported-2496ED.svg)](https://docs.docker.com/compose/)
10-
[![Licence](https://img.shields.io/github/license/AAdewunmi/Claims-Fraud-Risk-Scoring-Project)](https://github.com/AAdewunmi/Claims-Fraud-Risk-Scoring-Project/blob/main/LICENSE)
10+
[![License](https://img.shields.io/github/license/AAdewunmi/Claims-Fraud-Risk-Scoring-Project)](https://github.com/AAdewunmi/Claims-Fraud-Risk-Scoring-Project/blob/main/LICENSE)
1111
[![Coverage Status](https://codecov.io/gh/AAdewunmi/Claims-Fraud-Risk-Scoring-Project/branch/main/graph/badge.svg)](https://codecov.io/gh/AAdewunmi/Claims-Fraud-Risk-Scoring-Project)
1212

1313
# PolicyLens
1414

15-
Insurance claims workflow platform with API-first domain logic, role-specific web surfaces, and auditable fraud-risk triage.
15+
Production-ready insurance claims workflow platform with an API-first domain model, role-specific operational surfaces, ML-assisted completeness scoring, and auditable evidence export.
1616

17-
## Status
17+
## Project Status
1818

19-
**Production app build in progress**
20-
Snapshot date: **February 28, 2026**
19+
Completed.
2120

22-
- Core product workflows are implemented and running in Docker.
23-
- CI quality gates are active (Black, Ruff, pytest, coverage threshold).
24-
- Multi-surface routing is live for admin, reviewer, and customer roles.
25-
- Production deployment profile and operational hardening are the active build track.
21+
As of March 6, 2026, PolicyLens includes the full Sprint 1-7 scope:
2622

27-
## What is live today
23+
- End-to-end claims workflow APIs (create, retrieve, documents, notes, decisions).
24+
- SLA-aware operational queue with deterministic filtering and ordering.
25+
- Multi-surface routing for admin, reviewer, and customer user journeys.
26+
- Health/readiness endpoint for runtime and infrastructure checks.
27+
- Idempotency protection for write endpoints.
28+
- ML scoring with persisted metadata and reason codes.
29+
- Audit evidence export in JSON and PDF.
30+
- Production-shaped Docker stack with Gunicorn + Nginx profiles.
31+
- CI gates for Black, Ruff, pytest, and coverage threshold enforcement.
2832

29-
### Core domain and API
33+
## Core Capabilities
3034

31-
- Claim intake for claim and policy-change types.
32-
- Document upload, internal notes, and review decisions.
33-
- Append-only audit events and JSON evidence export.
34-
- Queue API with status, priority, and SLA filtering.
35-
- ML scoring endpoint with persisted score metadata and reason codes.
36-
- Idempotency support for write endpoints.
37-
- Health check endpoint at `/api/health/`.
35+
### API and domain workflow
3836

39-
### Web surfaces
37+
- Claim intake for `CLAIM` and `POLICY_CHANGE` types.
38+
- Document upload, internal note capture, and reviewer decisioning.
39+
- Append-only audit events attached to workflow actions.
40+
- Queue endpoint with `status`, `priority`, and SLA filter options.
41+
- Idempotency-key support for safe client retries on write endpoints.
4042

41-
- Public landing page with role entry points.
42-
- Surface-specific login routes:
43-
- `/login/admin/`
44-
- `/login/reviewer/`
45-
- `/login/customer/`
46-
- Role-gated console home routes:
47-
- `/console/admin/`
48-
- `/console/reviewer/`
49-
- `/console/customer/`
50-
- Ops surface:
51-
- `/ops/queue/` with pagination and filter-preserving links
52-
- `/ops/claims/{id}/` claim detail page
53-
- HTMX actions for notes, documents, decisions, and ML scoring
54-
- Customer surface:
55-
- `/customer/` paginated claim list
56-
- `/customer/claims/{id}/` detail view
57-
- `/customer/claims/{id}/documents/upload/`
43+
### Ops and customer surfaces
5844

59-
### Quality baseline
45+
- Public landing page and role entry routes.
46+
- Role-gated console routes for admin/reviewer/customer.
47+
- Reviewer ops queue and claim detail with HTMX actions.
48+
- Customer claim list/detail views with pagination.
6049

61-
- Latest local run: **166 tests passed**, coverage **94.43%**.
62-
- CI enforces coverage floor at **80%**.
63-
- Test suite includes API, UI surface, authz, pagination, idempotency, SLA, and ML contract checks.
50+
### Evidence and ML
6451

65-
## Sprint delivery summary
52+
- JSON evidence bundle export for claim audits.
53+
- PDF evidence bundle export for portability/compliance workflows.
54+
- ML completeness scoring endpoint with:
55+
- score
56+
- label
57+
- reason codes
58+
- model version metadata
6659

67-
- **Sprint 1:** Project setup, Docker + Postgres, baseline API and test harness.
68-
- **Sprint 2:** Claim workflow APIs, notes/documents/decisions, seed data path.
69-
- **Sprint 3:** Queue ordering, audit events, audit export JSON, idempotency layer.
70-
- **Sprint 4:** ML feature contract, training/scoring flow, persisted score metadata.
71-
- **Sprint 5:** Multi-surface web app, console routing, ops and customer surface coverage.
72-
- **Sprint 6 (current):** Production hardening and deployment readiness.
73-
74-
## API surface map
60+
## API Surface
7561

7662
- `GET /api/health/`
7763
- `POST /api/claims/`
@@ -83,17 +69,26 @@ Snapshot date: **February 28, 2026**
8369
- `POST /api/claims/{id}/ml-score/`
8470
- `GET /api/claims/{id}/audit-events/`
8571
- `GET /api/claims/{id}/audit-export/`
72+
- `GET /api/claims/{id}/audit-export/?format=pdf`
8673
- `GET /api/queue/claims/?status=&priority=&sla=breached|due_soon|ok`
8774

8875
## Architecture
8976

90-
- Django + DRF application (`policylens/`) with PostgreSQL persistence.
91-
- Service-layer workflow logic in `policylens/apps/claims/services.py`.
92-
- Role and surface authorization helpers in `policylens/apps/core/authz.py`.
93-
- Shared pagination contract in `policylens/apps/core/pagination.py`.
94-
- Server-rendered templates with HTMX partial updates for low-friction ops actions.
77+
- Backend: Django + Django REST Framework
78+
- Database: PostgreSQL
79+
- Frontend: Django Templates + HTMX (server-rendered interactions)
80+
- ML: scikit-learn inference and persisted scoring metadata
81+
- Runtime: Docker Compose, Gunicorn, Nginx
82+
83+
Key modules:
84+
85+
- `policylens/apps/claims/` domain logic, APIs, queue, export, ML
86+
- `policylens/apps/core/` authz, idempotency, pagination utilities
87+
- `policylens/apps/ops/` reviewer workflows and HTMX endpoints
88+
- `policylens/apps/customer/` customer workflow surface
89+
- `policylens/apps/api/` top-level API wiring and health endpoint
9590

96-
## Local development
91+
## Local Development
9792

9893
### Prerequisites
9994

@@ -103,18 +98,18 @@ Snapshot date: **February 28, 2026**
10398

10499
1. Copy environment file:
105100
- `cp .env.example .env`
106-
2. Build and start services:
101+
2. Start the app stack:
107102
- `docker compose up --build`
108-
3. Seed deterministic sample records:
103+
3. Seed baseline records and users:
109104
- `docker compose exec web python manage.py seed_sample_data`
110-
4. Seed demo users and pagination-focused demo claims:
105+
4. Optional: add expanded demo users/data:
111106
- `docker compose exec web python manage.py create_demo_users`
112-
5. Open app surfaces:
107+
5. Open:
113108
- `http://localhost:8000/`
114109
- `http://localhost:8000/api/health/`
115110
- `http://localhost:8000/ops/queue/`
116111

117-
### Seeded users
112+
### Seeded credentials
118113

119114
From `seed_sample_data`:
120115

@@ -127,32 +122,50 @@ From `create_demo_users`:
127122
- `demo_reviewer / pass-12345-strong`
128123
- `demo_customer / pass-12345-strong`
129124

130-
## Validation commands
125+
## Production-shaped profiles
126+
127+
HTTP smoke profile:
128+
129+
- `docker compose -f docker/docker-compose.prod.yml up --build -d`
130+
- App entrypoint: `http://localhost:8080/`
131+
132+
Secure profile:
133+
134+
- `docker compose -f docker/docker-compose.prod.secure.yml up --build -d`
135+
- App entrypoint: `http://localhost/`
136+
137+
See:
138+
139+
- `docs/DEPLOYMENT.md`
140+
- `docs/RUNBOOK.md`
141+
142+
## Quality and Validation
143+
144+
Local validation commands:
131145

132146
- `docker compose exec web python -m black . --check`
133147
- `docker compose exec web python -m ruff check .`
134-
- `docker compose exec web pytest -q --cov=policylens --cov-config=.coveragerc --cov-report=term-missing --cov-report=xml --cov-fail-under=80`
148+
- `docker compose exec web pytest -q --cov=policylens --cov-config=.coveragerc --cov-report=term-missing --cov-report=xml --cov-fail-under=85`
135149

136-
## Production hardening backlog
150+
Latest local full suite run:
137151

138-
Current priority items for deployment readiness:
152+
- `201 passed in 103.68s` (March 6, 2026)
139153

140-
- Add production runtime profile (Gunicorn + reverse proxy).
141-
- Add production compose/deploy artifacts and environment split.
142-
- Tighten security settings by environment (hosts, cookies, headers, static/media strategy).
143-
- Introduce scheduled/background execution for SLA sweep and bulk scoring.
144-
- Extend evidence export format options (for example PDF).
154+
CI gates enforce:
145155

146-
## Repository layout
156+
- formatting (`black --check`)
157+
- lint (`ruff check`)
158+
- migrations + collectstatic sanity
159+
- pagination-first test execution
160+
- full test suite with coverage threshold
147161

148-
- `policylens/apps/claims/` claims domain, API, queue, export, ML
149-
- `policylens/apps/ops/` ops views, templates, HTMX endpoints
150-
- `policylens/apps/customer/` customer portal views and templates
151-
- `policylens/apps/accounts/` surface login and access flows
152-
- `policylens/apps/console/` role console surfaces
153-
- `policylens/apps/core/` authz, idempotency, pagination utilities
154-
- `tests/` integration and contract tests
155-
- `docs/` project documentation
162+
## Documentation
163+
164+
- `docs/DEPLOYMENT.md` production configuration and environment guidance
165+
- `docs/RUNBOOK.md` operational runbook for prod-shaped stacks
166+
- `docs/DEMO.md` manual demo checklist
167+
- `docs/DEMO_SCRIPT.md` automated demo script usage
168+
- `docs/Syllabus.md` complete sprint-by-sprint delivery map
156169

157170
## License
158171

docs/DEMO.md

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,98 @@
1-
# PolicyLens demo
1+
# PolicyLens demo (completed project)
22

3-
This demo validates Sprint 6 multi-surface behavior with deterministic routing,
4-
role boundaries, and pagination.
3+
This checklist validates the complete Sprint 7 experience across API, surfaces, pagination, and evidence export.
54

65
## Prerequisites
76

8-
The project should already be running via Docker Compose.
7+
- Docker Desktop running
8+
- Repo-root `.env` present (`cp .env.example .env` if needed)
99

10-
## Login entry points
10+
## Start and seed
1111

12-
Use the surface entry points:
12+
```bash
13+
docker compose up --build -d
14+
docker compose exec web python manage.py migrate --noinput
15+
docker compose exec web python manage.py seed_sample_data
16+
docker compose exec web python manage.py create_demo_users
17+
```
1318

14-
- Admin login: `/login/admin/`
15-
- Reviewer login: `/login/reviewer/`
16-
- Customer login: `/login/customer/`
19+
## Baseline quality checks
1720

18-
## Console-only runbook
21+
```bash
22+
docker compose exec web python -m black . --check
23+
docker compose exec web python -m ruff check .
24+
docker compose exec web pytest -q
25+
```
1926

20-
Run:
27+
Expected:
28+
29+
- formatter/lint checks pass
30+
- full test suite passes
31+
32+
## Health and routing
2133

22-
- `docker compose exec web python manage.py check`
23-
- `docker compose exec web python manage.py migrate`
24-
- `docker compose exec web python -m black . --check`
25-
- `docker compose exec web python -m ruff check .`
26-
- `docker compose exec web pytest -q`
27-
- `docker compose exec web python manage.py seed_sample_data`
28-
- `docker compose exec web pytest -q tests/test_surface_smoke.py`
34+
```bash
35+
curl -i http://localhost:8000/api/health/
36+
```
2937

3038
Expected:
3139

32-
- `check`, `migrate`, `black --check`, and `ruff check` complete without errors.
33-
- `pytest -q` passes.
34-
- `seed_sample_data` prints:
35-
`Seeded roles (reviewer, admin), users (reviewer1/admin1), holders, policies, claims.`
36-
- `tests/test_surface_smoke.py` passes and validates `?page=1` and `?page=2` return `200`
37-
for the relevant reviewer and customer surfaces.
40+
- `200 OK`
41+
- JSON payload includes service status and DB readiness check
42+
43+
## Surface entry points
44+
45+
- `http://localhost:8000/login/admin/`
46+
- `http://localhost:8000/login/reviewer/`
47+
- `http://localhost:8000/login/customer/`
48+
49+
## Pagination proof points
50+
51+
- Reviewer queue page 1: `http://localhost:8000/ops/queue/?page=1`
52+
- Reviewer queue page 2: `http://localhost:8000/ops/queue/?page=2`
53+
- Customer list page 1: `http://localhost:8000/customer/?page=1`
54+
- Customer list page 2: `http://localhost:8000/customer/?page=2`
55+
56+
## API checks
57+
58+
### Idempotent claim creation
3859

39-
## Seeded local credentials
60+
Use `sample-claim.json` and `sample-claim-changed.json` from repo root.
4061

41-
From `seed_sample_data`:
62+
```bash
63+
curl --netrc-file .curl-auth -i -X POST http://localhost:8000/api/claims/ \
64+
-H "Content-Type: application/json" \
65+
-H "Idempotency-Key: demo-key-001" \
66+
-d @sample-claim.json
67+
68+
curl --netrc-file .curl-auth -i -X POST http://localhost:8000/api/claims/ \
69+
-H "Content-Type: application/json" \
70+
-H "Idempotency-Key: demo-key-001" \
71+
-d @sample-claim.json
72+
73+
curl --netrc-file .curl-auth -i -X POST http://localhost:8000/api/claims/ \
74+
-H "Content-Type: application/json" \
75+
-H "Idempotency-Key: demo-key-001" \
76+
-d @sample-claim-changed.json
77+
```
78+
79+
Expected status flow: `201`, `201`, `409`.
80+
81+
### Queue and ML
82+
83+
```bash
84+
curl --netrc-file .curl-auth -i "http://localhost:8000/api/queue/claims/?priority=HIGH"
85+
curl --netrc-file .curl-auth -i -X POST "http://localhost:8000/api/claims/1/ml-score/"
86+
```
87+
88+
### Evidence export
89+
90+
```bash
91+
curl --netrc-file .curl-auth -i "http://localhost:8000/api/claims/1/audit-export/"
92+
curl --netrc-file .curl-auth -i "http://localhost:8000/api/claims/1/audit-export/?format=pdf"
93+
```
94+
95+
Expected:
4296

43-
- `reviewer1 / password123`
44-
- `admin1 / password123`
97+
- JSON export returns attachment filename ending `.json`
98+
- PDF export returns `Content-Type: application/pdf` and attachment filename ending `.pdf`

0 commit comments

Comments
 (0)