> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Lab & Diagnostic Orders — Admin Guide

> This guide covers administrative configuration for the Lab & Diagnostic Orders feature, including order template management, reference lab directory setup, and…

## Overview

This guide covers administrative configuration for the Lab & Diagnostic Orders feature, including order template management, reference lab directory setup, and integration configuration.

***

## Order Template Management

**Route:** Clinical > Settings > Order Templates\
**Permission:** `cl.order_templates.manage`

### Creating a Template

1. Navigate to **Clinical > Settings > Order Templates**.
2. Click **Add Template**.
3. Fill in:
   * **Template Name**: Descriptive name (e.g., "Basic Metabolic Panel").
   * **Template Type**: `lab`, `imaging`, `procedure`, or `referral`.
   * **Description**: Purpose and use case.
   * **Order Items**: Add LOINC codes using the typeahead search. For each item, specify:
     * LOINC Code & Component (auto-populated from search)
     * Specimen Type (e.g., Serum, Plasma)
     * Priority (Routine, Urgent, Stat)
4. Toggle **Active** to make available to clinicians.
5. Click **Save**.

### Managing Templates

* **Edit**: Click Edit on any template row to modify.
* **Deactivate**: Toggle the Active switch to hide from clinician order forms without deleting.
* **Delete**: Click Delete to permanently remove (admin only).

***

## Reference Lab Directory

**Route:** Clinical > Settings > Lab Directory\
**Permission:** `cl.reference_labs.manage`

### Adding a Reference Lab

1. Navigate to **Clinical > Settings > Lab Directory**.
2. Click **Add Lab**.
3. Fill in:
   * **Lab Name** (required): Display name.
   * **CLIA Number**: Clinical Laboratory Improvement Amendments number.
   * **NPI**: National Provider Identifier.
   * **Phone / Fax / Contact Name**: Lab contact information.
   * **Address fields**: Street, city, state, ZIP.
   * **Integration Type**: `none` (manual), `hl7v2`, or `fhir`.
4. Click **Save**.

### Integration Configuration

For labs that send results electronically:

| Integration Type    | Protocol         | Configuration                                         |
| ------------------- | ---------------- | ----------------------------------------------------- |
| **Manual** (`none`) | N/A              | Results entered manually by staff                     |
| **HL7v2**           | ORU^R01          | Lab sends HL7v2 messages to the ingestion endpoint    |
| **FHIR**            | DiagnosticReport | Lab sends FHIR R4 resources to the ingestion endpoint |

The ingestion endpoint is: `POST /functions/v1/cl-lab-result-ingestion`

Labs must authenticate with an API key provided during setup. Contact your system administrator for endpoint credentials.

### Managing Labs

* **Edit**: Click Edit to update lab details or integration settings.
* **Deactivate**: Toggle the Active switch to prevent new orders from being routed.
* **Delete**: Click Delete to permanently remove (admin only).

***

## LOINC Code Reference

The system ships with pre-seeded LOINC codes for common behavioral health lab panels:

| Panel                       | Codes Included                                                      |
| --------------------------- | ------------------------------------------------------------------- |
| Basic Metabolic Panel (BMP) | Glucose, BUN, Creatinine, Sodium, Potassium, Chloride, CO2, Calcium |
| Complete Blood Count (CBC)  | WBC, RBC, Hemoglobin, Hematocrit, MCV, MCH, MCHC, Platelets         |
| Hepatic Function (LFT)      | ALT, AST, ALP, Total Bilirubin, Albumin, Total Protein              |
| Thyroid Panel               | TSH, Free T4                                                        |
| Drug Monitoring             | Lithium, Valproic Acid                                              |
| Urine Drug Screen           | Multi-substance panel                                               |

Additional LOINC codes can be added by system administrators directly to the `cl_loinc_codes` table.

***

## Permissions Reference

| Permission Key              | Description                        |
| --------------------------- | ---------------------------------- |
| `cl.orders.view`            | View lab orders and results        |
| `cl.orders.create`          | Create new lab orders              |
| `cl.orders.update`          | Update order status                |
| `cl.orders.cancel`          | Cancel pending orders              |
| `cl.results.view`           | View lab results                   |
| `cl.results.review`         | Review and sign off on results     |
| `cl.order_templates.view`   | View order templates               |
| `cl.order_templates.manage` | Create/edit/delete order templates |
| `cl.reference_labs.manage`  | Manage reference lab directory     |

All permissions are granted to the `org_admin` role by default. Use the Roles & Permissions settings to grant these to other roles as needed.

***

## Security & Compliance

* All lab data is protected by Row Level Security (RLS) with tenant isolation.
* Lab results containing PHI are never logged to console or external services.
* The result ingestion endpoint uses API key authentication with timing-safe comparison.
* Rate limiting is enforced per lab to prevent abuse.
* Audit trails track all order creation, status changes, and result reviews.
