7 use OpenEMR\Common\Http\HttpClient
;
8 use OpenEMR\Common\System\System
;
9 use Psr\Http\Message\ResponseInterface
;
10 use Psr\Http\Message\StreamInterface
;
11 use GuzzleHttp\Psr7\Utils
;
12 use GuzzleHttp\Exception\ConnectException
;
13 use GuzzleHttp\Exception\ServerException
;
15 use function GuzzleHttp\Psr7\str
;
20 * @package OpenEMR\Cqm
23 class CqmClient
extends HttpClient
25 protected function getCommand(): string
30 $cmd = $this->servicePath
;
33 $cmd = "start /B $node $cmd";
37 $system = new System();
38 if (!$system->command_exists($node)) {
39 if ($system->command_exists('nodejs')) {
42 error_log("Connection failed. Node does not appear to be installed on the system.");
43 throw new Exception('Connection Failed.');
53 * Returns the CQM service's health.
56 * @throws \GuzzleHttp\Exception\GuzzleException
58 public function getHealth(): array
62 Utils
::copyToString($this->request('GET', '/health')->getBody()),
65 } catch (ConnectException
$exception) {
69 } catch (ServerException
$exception) {
77 * Returns CQM Service version and dependencies lookup.
80 * @throws \GuzzleHttp\Exception\GuzzleException
82 public function getVersion(): array
85 Utils
::copyToString($this->request('GET', '/version')->getBody()),
91 * Calculates a CQM measure given a QDM Patient, Measure and ValueSet
93 * @param StreamInterface $patients
94 * @param StreamInterface $measure
95 * @param StreamInterface $valueSets
96 * @return StreamInterface
97 * @throws \GuzzleHttp\Exception\GuzzleException
99 public function calculate(
100 StreamInterface
$patients,
101 StreamInterface
$measure,
102 StreamInterface
$valueSets,
103 StreamInterface
$options = null
105 $patients = (string)str_replace(["\r\n", "\n", "\r"], '', (string)$patients);
106 $measure = (string)str_replace(["\r\n", "\n", "\r"], '', (string)$measure);
107 $valueSets = (string)str_replace(["\r\n", "\n", "\r"], '', (string)$valueSets);
108 $options = (string)$options;
112 $this->request('POST', '/calculate', [
114 'patients' => $patients,
115 'measure' => $measure,
116 'valueSets' => $valueSets,
117 'options' => $options
122 } catch (ConnectException
$exception) {
123 return [$exception->getMessage()];
124 } catch (ServerException
$exception) {
125 return [$exception->getMessage()];
130 * Perform a graceful shutdown of cqm-service node (express) server
133 * @throws \GuzzleHttp\Exception\GuzzleException
135 public function shutdown(): array
138 Utils
::copyToString($this->request('GET', '/shutdown')->getBody()),