# LabCore — Laboratory Integration Engine

LabCore is the shared cloud-side engine that connects clinic laboratory
analyzers (Abaxis VetScan, NX600, IDEXX VetLab Station, …) to the ERP. It
owns the database, UI, REST API, sync logic and VetClinic linkage. Per-vendor
quirks live in tiny **vendor modules** that plug in through a driver registry.
The clinic-side listener is a separate static Go binary, the **LabBridge
Agent**, that relays analyzer messages to the cloud.

## Three modules + one agent

```
   CLINIC SITE                                    CLOUD ERP (this app)
┌────────────────────────────┐           ┌─────────────────────────────┐
│ Abaxis VS2  ─serial──┐      │           │  LabCore  (this module)     │
│ Abaxis HM5  ─TCP─────┤      │   HTTPS   │  ├─ AbaxisLab driver        │
│ IDEXX VLS   ─TCP─────┤      │ ─────────▶│  ├─ NX600Lab driver         │
│                      ▼      │           │  └─ (your vendor here)      │
│   ┌──────────────────────┐  │           │   MySQL: lab_* tables       │
│   │  LabBridge Agent (Go)│  │           │   VetClinic (optional sync) │
│   │  Windows Service     │  │           └─────────────────────────────┘
│   │  + SQLite queue      │  │
│   └──────────────────────┘  │
└────────────────────────────┘
```

| Component | What it is | Where it lives |
|---|---|---|
| **LabCore** | The engine: tables, UI, agent API, driver registry, VetClinic bridge | [Modules/LabCore/](.) |
| **AbaxisLab** | Abaxis VetScan vendor (ASTM driver + analyte catalog + simulator) | [Modules/AbaxisLab/](../AbaxisLab/) |
| **NX600Lab** | NX600 vendor (existing module, now a LabCore vendor too) | [Modules/NX600Lab/](../NX600Lab/) |
| **LabBridge Agent** | Standalone clinic-side service (Go) | [labbridge-agent/](../../labbridge-agent/) |

Each vendor module installs independently — an Abaxis-only clinic never
needs the IDEXX module, and vice-versa. The agent is vendor-agnostic — one
build handles every analyzer it's pointed at.

## Quick start (5 steps)

1. **Install LabCore + a vendor module.** See [docs/labcore/01-installation.md](../../docs/labcore/01-installation.md).
2. **Create a Bridge Agent in the UI** (Lab → Agents → Add). Copy the API token shown.
3. **Register your analyzer** (Lab → Devices → Add) — pick the vendor, set the listener TCP port or COM port.
4. **Install the LabBridge Agent at the clinic.** Build the Go binary, drop your `config.yaml` with the token, install as a Windows Service. See [docs/labcore/02-agent-installation.md](../../docs/labcore/02-agent-installation.md).
5. **Point the analyzer at the agent.** The agent's TCP listener (or COM port) is what the analyzer talks to. End-to-end walkthrough: [docs/labcore/03-device-integration.md](../../docs/labcore/03-device-integration.md).

Results flow back to **Lab → Results** with canonical analyte names,
reference ranges and abnormal flags. If VetClinic sync is on, they also
appear on the pet's profile.

## Full documentation

Everything below is under [docs/labcore/](../../docs/labcore/):

- [01 — Cloud module installation](../../docs/labcore/01-installation.md)
- [02 — LabBridge Agent installation](../../docs/labcore/02-agent-installation.md)
- [03 — Device integration walkthrough](../../docs/labcore/03-device-integration.md)
- [04 — UI guide](../../docs/labcore/04-ui-guide.md)
- [05 — Agent-facing REST API reference](../../docs/labcore/05-api-reference.md)
- [06 — VetClinic sync](../../docs/labcore/06-vetclinic-sync.md)
- [07 — Troubleshooting](../../docs/labcore/07-troubleshooting.md)
- [08 — Developer guide (adding a vendor)](../../docs/labcore/08-developer-guide.md)

## Module layout

```
Modules/LabCore/
  Config/config.php
  Database/Migrations/       11 lab_* tables + permissions
  Entities/
    Contracts/LabDeviceDriver.php   driver interface
    Services/
      DriverRegistry.php            vendor modules register here
      ResultIngestionService.php    raw → driver.parse → normalize → store
      Astm/AstmRecordParser.php     E1394 / LIS2-A2 content parser
    Lab{Agent,Device,Worklist,TestSession,TestResult,
        AnalyteMap,CommunicationLog,DeviceConnection,
        DeviceError,Setting}.php
  Http/Controllers/
    Api/AgentController.php          /api/lab/* — agent-facing
    InstallController.php
    Lab{Dashboard,Agent,Device,Worklist,Session,Log,Settings}Controller.php
  Providers/
    LabCoreServiceProvider.php
    RouteServiceProvider.php
  Resources/views/             dashboard, agents, devices, worklist,
                               sessions, logs, settings, partials/_nav
  Routes/{web,api}.php
```
