# Reception consultation reports

`/Reception/report0` uses under 12 / 12 and above. `/Reception/report1` uses under 5 / 5 and above.

## Update locations

- `app/Http/Controllers/Consultation0Controller.php` and `Consultation1Controller.php`: page key and fixed age cutoff only.
- `app/Http/Controllers/ReceptionConsultationReportController.php`: clinic mapping, date validation, page configuration, calculation snapshots and download handling.
- `app/Services/ReceptionConsultationReportService.php`: the counting rules adapted from the HTY-C1 report. Both report pages use this service. Existing similarly named consultation services are not used by these two endpoints.
- `resources/views/Reception/consultation_report.blade.php` and `public/js/Reception_report/consultation-report.js`: shared screen and request handling.
- `resources/views/Reception/consultation_export_monthly.blade.php` and `consultation_export_daily.blade.php`: Excel layouts.
- `app/Exports/ReceptionConsultationReportExport.php`: common Excel export class.

The legacy response keys containing `u12`/`o12` are retained for the reference table/export mappings. They mean below/at-or-above the configured cutoff, including on the five-year page. Do not add numeric comparisons against 12 in the counting code.

## Data selection and dates

Both follow-ups and the linked patient master are loaded from the selected clinic connection. Report option values intentionally preserve the old menu: 0=A, 1=B, 2=C1, 4=SPT, 5=SDG, 6=TL, 7=TBZY. These are different from the M&E export's positional option values.

Visit Date is filtered inclusively. Reports include preCode=1/null and visits without a matching master, as the HTY-C1 reference does. Registration age/DOB and risk values come from the selected clinic's synced `patients` record, serving the role of HTY-C1's `pt_configs` relation. The report uses current master risk rather than reconstructing risk history at the visit date.

Current Age uses one explicit Asia/Yangon calendar date for the whole calculation. The master field selection deliberately matches HTY-C1's existing selection, including its omission of Reg Date. Missing-master visits keep the reference's fallback classification. Treat changes to those conventions as counting-rule changes and compare against expected data.

## Export consistency

Calculate stores an eight-hour result snapshot in the application cache, keyed by UUID and associated with the user and report page. Monthly and daily exports use that exact snapshot. Filter edits clear the snapshot in the browser; expired results require Calculate again. The reports never truncate or write `DailyConsultationreport`.

Daily category counters preserve the deployed HTY-C1 reference semantics, including cervical cancer's child age cells versus its adult-only daily category counter. If that reference inconsistency is corrected later, update the shared calculator and its expected counts deliberately rather than changing one page alone.

## Regression checks

From the project directory:

```sh
php8.5 tests/regression/reception_consultation_reports.php
node tests/regression/reception_consultation_reports_ui.js
```

The PHP check replaces all relevant database connections with independent in-memory SQLite databases and uses an array cache inside its own CLI process. It generates synthetic visits, exercises both controllers and four Excel exports, and does not read or alter production patient/report tables. The JavaScript check mocks the form and network requests.

The deployment comparison additionally checked all 148 result fields against the HTY-C1 service on equivalent synthetic inputs. PHP checks include 4y11m/5y/11y11m/12y boundaries, Myanmar midnight, all seven clinic choices, preCode eligibility, missing master/DOB, legacy/short diagnosis data, empty ranges, invalid dates and isolated snapshots.
