# Replace Java dcm4che2 `dcmqr` with dcmtk CLI

- [ ] 1. **Replace Java dcmqr in `mkiso.php`** — **see `todo/mkiso-replace-java-with-dcmtk.detail.md` § "mkiso.php"**
  - Start `storescp` as background receiver, run single `movescu` per accession (no modality loop)
  - Verify ISO generation, download, and cleanup still work

- [ ] 2. **Replace Java dcmqr in `mkiso2.php`** — **see `todo/mkiso-replace-java-with-dcmtk.detail.md` § "mkiso2.php"**
  - ⚠️ **LOW PRIORITY** — `mkiso2.php` is NOT called by the HIS `pacs_downloadiso` module. It is a standalone DICOM relay script, possibly run manually or by cron. See `docs/pacs_downloadiso-usage.md` for integration analysis.
  - Same C-MOVE replacement as mkiso.php
  - Also replace `/usr/bin/dcmsend` (missing binary) with `/data/dcmtk-bin/storescu +sd +r`
  - Verify DICOM relay to `172.16.0.120:104` works

- [ ] 3. **Replace Java dcmqr in `mkiso_multiple.php`** — **see `todo/mkiso-replace-java-with-dcmtk.detail.md` § "mkiso_multiple.php"**
  - Start `storescp` once, run `movescu` for each accession in the list
  - DB lookup logic stays unchanged
  - Verify multi-accession ISO download works with patient-name filenames

- [ ] 4. **Environment setup**
  - Ensure `/data/dcmtk-bin/` is readable and executable by the web server user
  - ⚠️ **Concurrent requests confirmed** — multiple HIS users can trigger downloads simultaneously via `pacs_downloadiso` module. Must use unique port per request.
  - If multiple concurrent requests are possible, use a unique port per request (e.g., `$port = 10104 + getmypid() % 100`)
  - No changes needed in the HIS `pacs_downloadiso` module — it calls scripts on the PACS host by URL only

- [ ] 5. **Testing**
  - Test with real accession numbers on the production server
  - Verify all DICOM files retrieved (spot-check file count and content)
  - Verify ISO downloads work end-to-end (download + mount + open in viewer)
  - Test through the HIS `pacs_downloadiso` UI (Preview → Download ISO) to verify end-to-end integration still works
  - Test both single and multi-accession download flows
  - Verify mkiso2.php relay to `172.16.0.120:104` (if migrated)
  - Test error cases: invalid accession number, PACS unreachable, timeout
  - Check storescp process is always cleaned up (no zombie processes)
  - Verify concurrent downloads from multiple HIS users don't conflict
  - Test Print ISO (CD Publisher) still works (not part of dcmtk migration, regression check only)

- [ ] 6. **Remove Java dependency** (after dcmtk verified in production)
  - Remove `/usr/local/dcm4che/dcm4che2/` if no other tools need it
  - Remove JDK 1.8.0_144 if no other Java apps on server
  - Remove `JAVA_HOME` environment variable
