# H11.0-P8 — Legacy Batch A Source Contract

## Batch scope

This batch recovers and proves three related historical monthly activity functions:

- `padm` → `get_patients_admissions`
- `perv` → `get_emergency_visits`
- `popr` → `get_patients_operations`

The recovered historical dispatcher calls each function once and each function runs the
same Oracle SQL independently against three branch databases: NJCH, JCKH, and MNH.

Because JCKH is formally `DEFERRED_NOT_READY`, H11.0-P8 proves the exact READY scope
(NJCH + MNH) and keeps all three functions at `PARTIAL_DEFERRED_BRANCH`. It does not
falsely promote them to MATCHED.

## padm — Monthly patient admissions

Historical function: `get_patients_admissions`

Oracle sources:

- `RCP_ENTRYEXIT`
- `RCP_VISIT`
- `SEC_LOOKUP_DETAIL`

Exact rules:

- `RCP_VISIT.HOSP_ID = RCP_ENTRYEXIT.BRANCHID`
- `RCP_VISIT.PATIENTID = RCP_ENTRYEXIT.PATIENTID`
- `RCP_VISIT.VISIT_ID = RCP_ENTRYEXIT.VISIT_ID`
- `RCP_VISIT.HOSP_ID = 1` inside the active branch database
- `NVL(RCP_ENTRYEXIT.BABY_NORMAL_BED,1) = 1`
- year filter on `RCP_VISIT.VISIT_START_DATE`, or explicit date range
- monthly grouping using Oracle month number
- 12-month completion through `SEC_LOOKUP_DETAIL WHERE PARENT_ID = 1`

## perv — Monthly emergency visits

Historical function: `get_emergency_visits`

Oracle sources:

- `RCP_VISIT`
- `RCP_SERVICE_RESERVATION`
- `SEC_LOOKUP_DETAIL`

Exact rules:

- `RCP_VISIT.CLASSCODE = 2`
- joins by `HOSP_ID`, `PATIENTID`, and `VISIT_ID`
- `RCP_SERVICE_RESERVATION.SERVSTATUS NOT IN ('C','F')`
- `RCP_SERVICE_RESERVATION.SCHED_SERIAL IS NOT NULL`
- emergency discriminator:
  - `NVL(OUTPTA_EMERGENCY_TYPE,0) = 1`
  - or `CLINIC_ID IN (16,297,298)`
- year filter or explicit range on `EXPECTEDDONEDATE`
- monthly grouping and 12-month completion

## popr — Monthly patient operations

Historical function: `get_patients_operations`

Oracle sources:

- `RCP_SERVICE_RESERVATION`
- `OPER_OPERATION_SCHEDULE`
- `SEC_LOOKUP_DETAIL`

Exact rules:

- `RCP_SERVICE_RESERVATION.SER = OPER_OPERATION_SCHEDULE.SER`
- `RCP_SERVICE_RESERVATION.SERVSTATUS <> 'C'`
- year filter or explicit range on `EXPECTEDDONEDATE`
- monthly grouping and 12-month completion

## Live acceptance matrix

- Functions: 3
- READY branches: 2
- Modes: 2 (`year`, `range`)
- Dataset checks: 12
- Checks per dataset: 24 values (12 months × current/comparison series)
- Total exact value checks: 288
- Identity mismatches required: 0
- Maximum difference required: 0
- Oracle writes: NONE

## Promotion policy

A full PASS proves:

- `padm` → `PARTIAL_DEFERRED_BRANCH`
- `perv` → `PARTIAL_DEFERRED_BRANCH`
- `popr` → `PARTIAL_DEFERRED_BRANCH`

No MATCHED promotion is allowed while JCKH remains deferred because these historical
functions are inherently three-branch composite outputs.

Official Legacy progress therefore remains:

- Known: 31
- MATCHED: 23
- PARTIAL: 6
- MISSING: 2
- Progress: 74.2%

What does improve is proof depth: after PASS, 4 of the 6 partial functions have exact
READY-scope proof (`gmov`, `padm`, `perv`, `popr`), leaving only `plts` and `prts`.
