Open EMR API integration from POS System

Hi,

Could someone point me the right direction on how to implement an integration from POS System to Open EMR.

Flow is from the POS → there is a search field for pubpid → connect to open emr via api → returned to POS with patient data display the data.

First how to create a api for this type of request?

Thanks
Casper

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:

:white_check_mark: 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.

:wrench: Step-by-Step: Create Custom API in OpenEMR

:jigsaw: 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.

:file_folder: Step 2: Create Your Custom API Endpoint

:open_file_folder: 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" }
1 Like

Hi @Qiaben thank you for this guide but on the Step 3: Register Route :open_file_folder: File: /src/RestRoutes.php the RestRoutes.php does not exist in Open EMR 7.0.2.

Thanks
Casper