# Patient Activity Legacy Parity Contract — Phase 10.10

## Scope

Phase 10.10 closes the selected-branch Patient Activity contracts that map directly to the executive Visits workspace:

| Legacy dispatcher | Legacy function | Executive meaning | Current implementation |
|---|---|---|---|
| `gmov_s` | `get_monthly_outpatient_visits_s` | Monthly outpatient visits | `VisitsRepository::monthlyOutpatientVisits` |
| `perv_s` | `get_emergency_visits_s` | Monthly emergency visits | `VisitsRepository::monthlyEmergencyVisits` |
| `padm_s` | `get_patients_admissions_s` | Monthly admissions | `VisitsRepository::monthlyAdmissions` |
| `vfr` | `get_visit_followup_ratio` | New versus follow-up mix | `VisitsRepository::followupMix` |

The multi-branch composite legacy functions `gmov`, `padm`, and `perv` remain `PARTIAL`. Phase 10.10 does not falsely claim that the selected-branch executive page reproduces the old three-branch composite result in one chart.

## OPD legacy rule (`gmov_s`)

- Source: `RCP_VISIT` + `RCP_SERVICE_RESERVATION`.
- `CLASSCODE = 2`.
- Join on hospital, patient, and visit identifiers.
- Exclude `SERVSTATUS IN ('C','F')`.
- `SCHED_SERIAL IS NOT NULL`.
- Exclude emergency activity using the legacy discriminator:
  - `NVL(OUTPTA_EMERGENCY_TYPE,0) <> 1`
  - `CLINIC_ID NOT IN (16,297,298)`.
- Group by month of `EXPECTEDDONEDATE`.

## ER legacy rule (`perv_s`)

Same base joins and schedule/status rules as OPD, with the emergency discriminator:

- `NVL(OUTPTA_EMERGENCY_TYPE,0) = 1`
- **OR** `CLINIC_ID IN (16,297,298)`.

## Admissions legacy rule (`padm_s`)

- Source: `RCP_ENTRYEXIT` + `RCP_VISIT`.
- Join `HOSP_ID/BRANCHID`, patient, and visit identifiers.
- `RCP_VISIT.HOSP_ID = 1` inside the selected branch database context.
- `NVL(BABY_NORMAL_BED,1) = 1`.
- Group by month of `VISIT_START_DATE`.

## New vs Follow-up legacy rule (`vfr`)

- Source: `RCP_SERVICE_RESERVATION` + `RCP_VISIT`.
- Join by patient and visit identifiers, matching the old function.
- Selected branch `HOSP_ID IN (1)`.
- Exclude cancelled/final status `('C','F')`.
- `SCHED_SERIAL IS NOT NULL`.
- `RES_TYPE = 1` => Follow-up; otherwise New.

## Supported modes

### Year comparison

- Current year.
- Comparison year.
- 12 monthly buckets for OPD, ER, and Admissions.

### Custom date range

- `from_date` and `to_date` must be valid dates in the same year.
- Current period includes the whole end date.
- Monthly comparison series uses the same month/day window shifted to the selected comparison year.
- New vs Follow-up uses the selected current range because the legacy `vfr` contract is a category mix, not a two-series monthly chart.

## Exact parity acceptance

Phase 10.10 runs four functions in two modes:

- 4 legacy functions × 2 modes = **8 runtime parity checks**.
- Count differences must be exactly zero.
- Monthly current and comparison values are checked month-by-month.
- `vfr` checks exact New and Follow-up counts.
- No write SQL is permitted.

## Executive UI contract

The Visits page follows Executive Leadership UI Standard v1.0:

- primary body text at least 16 px;
- Arabic body text 17 px where appropriate;
- current period, comparison period, report mode, and active branch visible immediately;
- no raw Oracle/SQL/stack trace shown to executive users;
- three primary charts have explicit render, empty, and unavailable states;
- browser rendering must prove 3/3 chart execution.
