# CareFix Agent: installation for hospital IT

CareFix is Caresoft's support system for correcting data in your Caresoft HIS database. The CareFix Agent is a small Windows service that lets Caresoft support work on your database **without opening any port** on your network.

## What it does and does not do

- It only makes **outbound HTTPS** connections to the Caresoft CareFix server. Nothing connects in.
- It reads your HIS database with a **read-only** login (`carefix_ro`).
- It can change data **only** through one Caresoft procedure (`carefix.usp_CF_UpdateRow`), **only** for columns your DBA listed in `carefix.CF_ALLOWLIST`, and **only** after Caresoft staff have approved the change. High-risk changes also need your written consent.
- Every change is recorded in your own database, in `carefix.CF_CHANGE_LOG`.
- Passwords are stored encrypted, and only this computer can decrypt them.

## Requirements

- Windows Server 2016 or later (or Windows 10/11), on a machine that can reach your HIS SQL Server.
- Outbound HTTPS (port 443) to the CareFix server address that Caresoft gives you.
- The two SQL logins created by `02_hospital_setup.sql` (your DBA runs this first).
- No .NET installation is needed.

## Install

1. Create the folder `C:\CareFix\Agent` and copy `CareFix.Agent.exe` into it.
2. Open **Command Prompt as Administrator** in that folder and run:
   ```
   CareFix.Agent.exe configure
   ```
   Enter the CareFix server URL, your hospital code, the SQL Server details, the two SQL passwords, and the agent key from Caresoft.
3. Check the setup:
   ```
   CareFix.Agent.exe test
   ```
   All lines should say OK or "accepted".
4. Install and start the service:
   ```
   sc.exe create "CareFix Agent" binPath= "C:\CareFix\Agent\CareFix.Agent.exe" start= delayed-auto
   sc.exe description "CareFix Agent" "Caresoft CareFix support agent (outbound HTTPS only)"
   sc.exe failure "CareFix Agent" reset= 86400 actions= restart/60000/restart/60000/restart/60000
   sc.exe start "CareFix Agent"
   ```
5. Tell Caresoft support that the agent is running. They will see it as Online.

## Day to day

- Logs are in **Event Viewer > Windows Logs > Application**, source "CareFix Agent".
- To stop Caresoft's access at any time, stop the service: `sc.exe stop "CareFix Agent"`.
- To change a password or key, run `CareFix.Agent.exe configure` again, then restart the service.
- To update, stop the service, replace `CareFix.Agent.exe`, and start the service.
- To remove: `sc.exe stop "CareFix Agent"`, `sc.exe delete "CareFix Agent"`, then delete `C:\CareFix\Agent` and `C:\ProgramData\CareFix`.
