Hi I am trying to author tests for openEMR. I’ve got a local dev environment up and running on macOS Ventura.
I am very confused as to how to access the internal api of openEMR. I’ve located and opened the swagger page. However, I need authorization tokens to access the endpoints. I’ve read the API documentation, and I’m not understanding the process of gaining authorization. None of the command scripts work.
I tried this as I understood it to respond with the needed token?
The README.md on this suggests looking here for examples of what you are trying to accomplish. The tests folder seems to lay a decent foundation.
I am currently accessing the internal api via the command-runner interface which may be an option for you. Below is some example code from file named src/Common/Command/CreateCCDAExportCommand.php that could be run like
php ./bin/command-runner -c CreateCCDAExport
Only part of this utility is shown below, it is intended to highligh accessing the internal api.
class CreateCCDAExportCommand implements IOpenEMRCommand
{
public function printUsage(CommandContext $context)
{
echo "Command Usage: " . $context->getScriptName() . " -c CreateCCDAExportCommand" . "\n";
}
public function getDescription(CommandContext $context): string
{
return "Generates CCDA exports for all participants.";
}
/**
* Execute the command and spit any output to STDOUT and errors to STDERR
* @param CommandContext $context All the context information needed for the CLI Command to execute
*
* Loop across all participants
*
*/
public function execute(CommandContext $context)
{
error_reporting(E_ALL ^ E_DEPRECATED);
$uri = '/fhir/Patient';
$_SESSION['authUser'] = 'admin';
$_SESSION['authUserID'] = 1;
$_SESSION['authProvider'] = 'Default';
$_SERVER['HTTP_HOST'] = 'dev.openemr.stjamesinfirmary.org';
$_SESSION['site_id'] = 'default';
$_SERVER['REQUEST_URI'] = $uri;
$_SERVER['REQUEST_METHOD'] = 'GET';
global $ignoreAuth, $sqlconf, $GLOBALS, $_SERVER, $_SESSION;
$ignoreAuth = true;
$GLOBALS['OE_SITE_DIR'] = 'sites/default';
$GLOBALS['is_local_api'] = 1;
require_once("library/sqlconf.php");
$GLOBALS['dbase'] = $GLOBALS['sqlconf']['dbase'];
$GLOBALS['host'] = $GLOBALS['sqlconf']['host'];
$GLOBALS['pass'] = $GLOBALS['sqlconf']['pass'];
$GLOBALS['login'] = $GLOBALS['sqlconf']['login'];
@include_once('interface/globals.php');
$gbl = RestConfig::GetInstance();
$GLOBALS['system_error_logging'] = 'DEBUG';
$GLOBALS['oauth_scopes'] = Array(
'patient/Patient.read',
'patient/DocumentReference.read',
'patient/DocumentReference.$docref');
$gbl::setNotRestCall();
$restRequest = new HttpRestRequest($gbl, $_SERVER);
$restRequest->setRequestMethod("GET");
$restRequest->setApiType("fhir");
$restRequest->setRequestPath($uri);
$restRequest->setRequestURI($uri);
$restRequest->setIsLocalApi(true);
$restRequest->setApiBaseFullUrl('https://dev.openemr.stjamesinfirmary.org');
$getParams = $restRequest->getQueryParams();
$restRequest->setQueryParams($getParams);
$response = HttpRestRouteHandler::dispatch(
$gbl::$FHIR_ROUTE_MAP, $restRequest, 'direct');
$entries = $response->entry;
$restRequest->setQueryParams(Array());
foreach ($entries as $participant) {
print_r($participant);
}
}
}