Population Health Service — Testing Strategy
Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template · Testing Standards
1. Coverage Targets
| Layer | Target |
|---|---|
| Domain logic (cohort DSL parser, risk models, QM calculators) | ≥ 90% |
| Application use cases | ≥ 85% |
| Infrastructure adapters | ≥ 80% |
| Overall service | ≥ 80% |
2. Test Layers
2.1 Unit Tests
| Scenario | File |
|---|---|
| Cohort DSL parser: valid expression trees | cohort-expression.spec.ts |
| Cohort DSL parser: rejects invalid operators | cohort-expression.spec.ts |
| Quality metric: numerator/denominator/exclusion calculation | quality-metric-calculator.spec.ts |
| Quality metric: empty denominator returns null rate | quality-metric-calculator.spec.ts |
| Risk score: tier assignment from computed score | risk-score.spec.ts |
| Risk score: override invariants (reason required) | risk-score.spec.ts |
| Outreach FSM: valid transitions | outreach-item.spec.ts |
| Outreach FSM: invalid transitions throw domain error | outreach-item.spec.ts |
| De-identification: k-threshold validation | deident-config.spec.ts |
| De-identification: ε ≤ 1.0 enforcement | deident-config.spec.ts |
| HMIS period overlap: duplicate job detection | hmis-export-job.spec.ts |
2.2 Integration Tests (mandatory)
| Test | File |
|---|---|
| Tenant isolation — cohort query never returns rows from another tenant | tenant-isolation.integration.spec.ts |
| Outbox — domain events published after use-case commit | outbox.integration.spec.ts |
| Inbox — duplicate CloudEvent IDs are deduplicated | inbox.integration.spec.ts |
| Dashboard query returns aggregate metrics scoped to node | dashboard.integration.spec.ts |
| Cohort refresh job coalesces duplicate triggers | cohort-refresh.integration.spec.ts |
| HMIS export job retries and reaches terminal failure | hmis-export.integration.spec.ts |
| De-ident export blocked when k-threshold not met | deident-export.integration.spec.ts |
| Consent check blocks export when secondary use not approved | consent-enforcement.integration.spec.ts |
| RLS blocks cross-tenant row access at DB level | rls-enforcement.integration.spec.ts |
2.3 Contract Tests
| Test | File |
|---|---|
| OpenAPI contract — dashboard endpoint | dashboard.pact.spec.ts |
| OpenAPI contract — cohort CRUD | cohorts.pact.spec.ts |
Event schema — cohort.refreshed.v1 payload conformance | cohort-refreshed.schema.spec.ts |
Event schema — hmis_export.completed.v1 payload conformance | hmis-export-completed.schema.spec.ts |
| DHIS2 adapter — mock DHIS2 API contract | dhis2-rest.pact.spec.ts |
2.4 E2E Tests
| Scenario | File |
|---|---|
| Analyst creates cohort, triggers refresh, views membership count | cohort-lifecycle.e2e.spec.ts |
| MoPH admin triggers HMIS export; DHIS2 mock confirms receipt | hmis-export.e2e.spec.ts |
| Researcher requests de-identified export; receives download URL | deident-export.e2e.spec.ts |
| Clinician views disease registry, updates outreach item status | outreach-workflow.e2e.spec.ts |
3. Test Data / Seed Requirements
- Seed 3 tenants:
tenant-a(facility A, B),tenant-b(facility C),tenant-platform - Seed 10,000 synthetic patient rows per tenant with realistic age/gender/condition distributions
- Seed pre-computed cohorts and quality metric snapshots for dashboard tests
- DHIS2 mock server with configurable response (success / 502 failure)
4. Performance Tests
| Test | Threshold |
|---|---|
| Dashboard query at 100k patient population | p95 ≤ 2500 ms |
| Cohort refresh for 50k member cohort | Completes within 60 s |
| Quality metric snapshot for HEDIS full set | Completes within 120 s |
| De-identification pipeline for 50k rows | Completes within 10 min |