To integrate a POS system with OpenEMR where the POS searches by pubpid and retrieves patient data via an API, you’ll need to expose a custom REST API in OpenEMR that does the following:
Flow You Want
POS sends a request with pubpid to OpenEMR.
OpenEMR searches for the patient with that pubpid.
OpenEMR responds with patient demographic data.
POS displays the patient data.
Step-by-Step: Create Custom API in OpenEMR
Step 1: Identify the Table and Field
pubpid is stored in the patient_data table.
You’ll fetch data like: pid, fname, lname, DOB, sex, etc.
Step 2: Create Your Custom API Endpoint
File: /src/RestControllers/POSPatientController.php
<?php
namespace OpenEMR\RestControllers;
use OpenEMR\RestControllers\RESTBaseController;
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Common\Database\DB;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class POSPatientController extends RESTBaseController
{
public function getPatientByPubPid(Request $request, Response $response): Response
{
$params = $request->getQueryParams();
$pubpid = $params['pubpid'] ?? null;
if (!$pubpid) {
return $this->errorResponse($response, "Missing pubpid", 400);
}
$sql = "SELECT pid, pubpid, fname, lname, DOB, sex, phone_home, email FROM patient_data WHERE pubpid = ?";
$pdo = DB::getInstance()->getConnection();
$stmt = $pdo->prepare($sql);
$stmt->execute([$pubpid]);
$patient = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$patient) {
return $this->errorResponse($response, "Patient not found", 404);
}
return $this->encodeResult($response, $patient);
}
}
🛣️ Step 3: Register Route
📂 File: /src/RestRoutes.php
Add the route at the bottom:
use OpenEMR\RestControllers\POSPatientController;
$app->get('/pos/patient', [POSPatientController::class, 'getPatientByPubPid']);
🧪 Step 4: Call API from POS
Sample API Call:
GET https://your-domain.com/apis/pos/patient?pubpid=12345
Headers:
Authorization: Bearer
Accept: application/json
🔐 Step 5: Auth Setup (JWT or Basic)
Use OpenEMR API credentials (from Globals → Connectors → Enable APIs) and generate a JWT token or use Basic Auth.
Username: OpenEMR username
Password: OpenEMR password
Generate JWT via /apis/api/token
📦 Response Example:
{
"pid": "2",
"pubpid": "12345",
"fname": "John",
"lname": "Doe",
"DOB": "1990-05-01",
"sex": "Male",
"phone_home": "555-555-5555",
"email": "john@example.com"
}