{"v":{"id":463,"url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/issues\/206","html_url":"https:\/\/www-s01.apinet.com\/codeforge\/apiintl\/hhmanager\/issues\/206","number":206,"user":{"id":1,"login":"charles","login_name":"","source_id":0,"full_name":"Charles Willgren","email":"charles@apinet.com","avatar_url":"https:\/\/www-s01.apinet.com\/codeforge\/avatars\/d3c894f7297c5a18eb3f6ac837c335b11a00aa9cc0961323771632b1e2d61bb2","html_url":"https:\/\/www-s01.apinet.com\/codeforge\/charles","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2025-12-08T10:03:41-06:00","restricted":false,"active":false,"prohibit_login":false,"location":"","pronouns":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"charles"},"original_author":"","original_author_id":0,"title":"Fax dashboard: examine fax data, attach each fax to a client, compare it with VESTA","body":"**Background.** The agencies receive service authorizations by fax. The forms are the state's Form 2101 and Form 2067. The fax pipeline (#205) reads each fax with OCR and keeps the values, encrypted, in `fax_jobs` \/ `fax_pages` \/ `fax_fields`. Now, an accepted fax goes nowhere. Nothing attaches it to a client, and nothing compares it with VESTA (#205, item 4).\n\nThis issue is the screen for that work. Staff use it to:\n\n1. Examine the data that the fax pipeline read.\n2. See the fax page beside the data, and correct the data.\n3. Attach each fax to a client.\n4. See the differences between the fax and VESTA.\n5. Find a client and see all faxes for that client.\n\nThe client detail also shows the last 5 faxes for that client.\n\nThis issue is written in ASD-STE100 (Simplified Technical English).\n\n## Terms\n\n| Term | Meaning |\n|---|---|\n| Fax | One received fax (`fax_jobs` row). It can hold more than one form. |\n| Form | One 2101 or 2067 in a fax. A form is a group of pages. |\n| Fax date | The date that we received the fax (`fax_jobs.received_at`). |\n| Form date | The date printed on the form. The dashboard shows it, but the date rule uses the fax date. |\n| VESTA date | The date that the VESTA data for the client last changed. See \"The VESTA date\". |\n| Match | The link from a form to one client (`hh_member`). |\n\n## Before you start\n\n1. **Find how the fax data gets to production.** The fax data comes from the secure server. Write down the route in `docs\/Fax.md`.\n   - The processed-bundle route (`report_type 'fax'` in `web\/ingest.php`) is retired. Do not add it again. Parsing occurs on production (CLAUDE.md, HH Data Pipeline).\n   - If the secure server must parse the faxes, that is a change to the house rule. Write the reason in `docs\/DesignRationale.md` before you build it.\n2. Read #205, step 6. This issue uses the same match rules and the same flag decisions.\n\n## 1. The dashboard\n\nExtend `\/fax-queue` into the dashboard. Do not make a second fax screen.\n\n1. Show one row for each form. Show these columns:\n   - Fax date and form date\n   - Form type (2101 or 2067)\n   - Client name, or the match state (see section 3)\n   - Review state: \"Not checked\", \"Checked\", \"Corrected\"\n   - Number of differences from VESTA\n2. Let staff filter the list by date range, form type, review state, match state and \"has differences\".\n3. Show the unrouted faxes (`fk_system = 0`) to each administrator, as `\/fax-queue` does now.\n\n## 2. Examine a fax\n\nUse the current review screen (`\/fax-review\/{pk}`) as the start.\n\n1. Show the page image on the left. Show the boxes that the template reads.\n2. Show the values that OCR read on the right. Show the confidence of each value.\n3. Let staff correct a value. Keep the OCR value and the corrected value (this is also the tuning data in #205, step 5).\n4. Let staff accept the form. Only an accepted form can raise a flag (#205, step 6).\n5. Show the differences from VESTA on the same screen (see section 4).\n\n## 3. Attach each form to a client\n\n1. **Match automatically.** Use the client no. and the Medicaid no. from the form. Use `VestaResolver`, as the report joins do.\n2. **Do not guess.** If a number finds two clients, do not attach the form. Show \"More than one client\". Do not use `LIMIT 1`.\n3. **New client.** If a number finds no client, show \"No client record yet\". This is a correct state: a new client can be on a fax before VESTA has a record.\n   - After each VESTA load, try the match again for each form in this state.\n   - If the match is now unambiguous, attach the form automatically.\n4. **Attach by hand.** Let staff find a client and attach the form. Let staff remove a wrong attachment.\n   - Keep a record of each attachment: who, when, automatic or by hand. Do not delete this record.\n   - An attachment by hand is a write: use a POST with the CSRF token.\n5. One fax can hold forms for different clients. Attach each form, not each fax.\n\n## 4. Compare the fax with VESTA\n\n1. Show a table for each form. Show these columns: field, fax value, VESTA value, result.\n2. Use these results: \"Same\", \"Different\", \"Not in VESTA\", \"Not on the fax\".\n3. Compare these fields:\n   - **2101:** contract, begin date, end date, units, service items, and New \/ Update \/ Terminate. Compare with `hh_auth`.\n   - **2067:** name, date of birth, address, phone, Medicaid no. Compare with the client record.\n4. Make the values the same format before you compare them (dates, units, phone numbers, case of letters).\n5. Put the comparison rules in a new pure file, `code\/fax_compare_rules.inc.php`. Test it with `scripts\/test-fax-compare-rules.php`. The rules file has no database access.\n6. If a form is not accepted, show the comparison with the label \"Not checked\".\n\n### The date rule\n\nA fax can be old. An old fax can hold data that is no longer correct. Thus, compare the fax date with the VESTA date before you show a difference.\n\n| Condition | Result | Text on the screen |\n|---|---|---|\n| Fax date is after the VESTA date | VESTA possibly does not have the fax data yet | \"VESTA not updated since this fax\" |\n| Fax date is on or before the VESTA date | The fax is possibly old | \"VESTA changed after this fax\" |\n\n1. Do not raise a flag for a fax that is older than the VESTA date.\n2. Use the fax date, not the form date.\n3. Use the VESTA date for the data that the form compares: the authorization date for a 2101, the client date for a 2067.\n4. Use one \"today\" for each pass. Read the clock one time, and give the date to the rules as a parameter (CLAUDE.md, Flags).\n\n### The VESTA date\n\n**VESTA does not give a \"last updated\" date for a record.** We examined the API guide (v2.2) and the column lists of each VESTA report (`hh_report_columns`), 2026-11-02:\n\n| Source | Date that it gives | What the date covers |\n|---|---|---|\n| Members report | `statusdate` | Status changes only |\n| Member Master List | `statusasof` | Status changes only |\n| Authorization report | none | \u2014 |\n| API `Member` record | `Status_Date` | Status changes only |\n| API `DownloadModifiedMembers` | no date on the record. The request takes `After`, and the result is the members \"updated after\" that date. | Unknown. VestaAPIPlan Q18 is open. The attendant probe (\u00a717.2) shows that a status change is a modification. |\n\nThe only `LastModificationTime` in the guide is on `Biller\/DownloadClaimActivityDetails`. We never call `Biller\/*`.\n\nThe status date does not cover all changes. A change to an address, a phone number, units or authorization dates does not change it. Thus, we must make the VESTA date ourselves:\n\n1. **Authorizations (2101).** At each load, calculate a hash of the compared fields of each authorization (contract, begin date, end date, units, service items). If the hash is new or changed, keep the **report date** of that load as the authorization's VESTA date. Do not use the load time: `hh_auth` is replaced on each run, so its `created_at` is the load time, not the time of the change.\n2. **Client data (2067).** Use the same method with the compared client fields. `hh_member_record.statusdate` is not sufficient.\n3. **API agencies.** `DownloadModifiedMembers` can make the client date more accurate (one day, if we call it each night with `After` = the last call). Use it only after Q18 has an answer. Authorizations are not in the member API, so method 1 also applies to API agencies.\n4. **Accuracy.** The VESTA date is the report date of the first load that saw the change. If VESTA changes on Monday and we load on Wednesday, the VESTA date is Wednesday. With daily loads, the error is 1 day or less. Show \"on or before\" on the screen when it is necessary.\n5. **Start.** The first load after this change has no previous hash. For each record at that load, keep \"not known\" as the VESTA date, not the load date. Do not raise a flag when the VESTA date is not known.\n\n## 5. Find a client and see the faxes\n\n1. Let staff search by client name, Medicaid no., or client no.\n2. Show all forms for that client, newest first.\n3. Also search the forms that have no match. Use the name and numbers read from the fax.\n   - These values are encrypted. Use a blind index (`db_hash_v2()`), or decrypt in a limited date range. The volume is approximately 20 faxes each day.\n\n## 6. Client detail: last 5 faxes\n\n1. Add a \"Faxes\" section to the client detail (`backend\/hhMemberDetail.php`).\n2. Show the last 5 forms for the client: fax date, form type, review state, number of differences.\n3. Add a link to the dashboard for all faxes for the client.\n4. Show the link to the fax image only if the reader has fax access.\n\n## Security rules\n\n1. **Access.** Use the same gate as `\/fax-queue` (`role\/Administrator`) at first. #205, step 7 replaces it with a staff-only fax right. The fax right must not be available to a client or attendant account (`account_type_may_hold()`).\n2. **Rows.** Show only faxes and clients for the current agency. Use `hh_member_scope()` for the client data.\n3. **Requests.** A `pk_*` in a request is not authorization. Find again what the reader can see.\n4. **Audit.** Each view of a fax image or of fax values is a PHI read. Call `audit_phi_view()`.\n5. **Storage.** Keep all values encrypted (`*_enc`). Do not keep plaintext PHI. The change hashes use `db_hash_v2()`.\n6. **Screen text.** Do not show codes, versions or internal state names on the screen (docs\/Forms.md \u00a72.4).\n\n## Work, in order\n\n1. Find the route from the secure server to production. Write `docs\/Fax.md`.\n2. **Start the change hashes now** (section \"The VESTA date\"). Each day without them is a day with no VESTA date.\n3. Add the form and match tables (a migration in `migrations\/`, then fold it into `docs\/schema.sql`).\n4. Automatic match, and the retry after each VESTA load.\n5. The comparison rules and their test.\n6. The dashboard: list, filters, examine, attach by hand.\n7. Search.\n8. Client detail: last 5 faxes.\n9. Update `docs\/Changelog.md` and `docs\/UserChangelog.md`.\n\nThe flags against VESTA stay in #205, step 6. They use the match and the comparison from this issue.\n\n## Decisions to make\n\n- [ ] How does the fax data get from the secure server to production?\n- [x] VESTA has no \"last updated\" date. We calculate it from change hashes on each load (2026-11-02).\n- [ ] For API agencies: use `DownloadModifiedMembers` for the client date? (Needs an answer to VestaAPIPlan Q18.)\n- [ ] Which 2067 fields do we compare?\n- [ ] Can staff attach a form to a client that is not in their agency? (Proposal: no.)\n- [ ] The grace period before a difference becomes a flag (open in #205).\n\n## Done when\n\n- [ ] Each form shows a client, \"No client record yet\", or \"More than one client\".\n- [ ] A form attaches automatically after VESTA adds the client.\n- [ ] Staff can attach a form by hand, and the record shows who did it.\n- [ ] Each authorization and client has a VESTA date, or \"not known\".\n- [ ] The comparison table uses the date rule, and its test passes.\n- [ ] Staff can find a client and see all of the forms for that client.\n- [ ] The client detail shows the last 5 forms.\n- [ ] Each fax view writes a PHI audit record.","ref":"","assets":[],"labels":[{"id":33,"name":"action","exclusive":false,"is_archived":false,"color":"d97706","description":"Action item tracked on the Connect dashboard","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/33"},{"id":34,"name":"area:clients","exclusive":false,"is_archived":false,"color":"1d76db","description":"Client records, member list, client reports","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/34"},{"id":3,"name":"design","exclusive":false,"is_archived":false,"color":"5319e7","description":"Design to agree before building","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/3"},{"id":1,"name":"feature","exclusive":false,"is_archived":false,"color":"0e8a16","description":"New user-facing capability","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/1"},{"id":18,"name":"size:weeks","exclusive":false,"is_archived":false,"color":"bfbfbf","description":"A week or more","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/18"}],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2026-11-02T15:25:32-06:00","updated_at":"2026-11-02T15:28:57-06:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":27,"name":"hhmanager","owner":"apiintl","full_name":"apiintl\/hhmanager"},"pin_order":0}}