Skip to content

Commit

Permalink
Modifications in InternalApiTest and InternalFhirTest files to make i…
Browse files Browse the repository at this point in the history
…t work locally in a new module (openemr#6745)

* Modifications in InternalApiTest and InternalFhirTest files to make it work

Modifications :

InternalApiTest.php -

Added setIsLocalApi and setApiType  for the $restRequest,
Modified setRequestURI to setRequestPath for the $restRequest

InternalFhirTest.php -

Changed the URL endpoint from '/apis/api/facility' to '/apis/fhir/Patient' in the functions  testFetchApi and testAjaxApi,
Added setIsLocalApi and setApiType  for the $restRequest,
Modified setRequestURI to setRequestPath for the $restRequest,
Changed $routes list from $ROUTE_MAP to $FHIR_ROUTE_MAP to fetch the Fhir endpoints

* Update InternalApiTest.php removed white space

removed the white space that didn't allow the merge request
  • Loading branch information
sb-akash authored Aug 15, 2023
1 parent 7e64308 commit 2aae641
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tests/api/InternalApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function testFetchApi() {
$gbl::setNotRestCall();
$restRequest = new HttpRestRequest($gbl, $_SERVER);
$restRequest->setRequestMethod("GET");
$restRequest->setRequestURI("/api/facility");
$restRequest->setRequestPath("/api/facility");
$restRequest->setIsLocalApi(true);
$restRequest->setApiType("oemr");
// below will return as json
echo "<b>api via route handler call returning json:</b><br />";
echo HttpRestRouteHandler::dispatch($gbl::$ROUTE_MAP, $restRequest, 'direct-json');
Expand Down
13 changes: 8 additions & 5 deletions tests/api/InternalFhirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
function testAjaxApi() {
$.ajax({
type: 'GET',
url: '../../apis/api/facility',
url: '../../apis/fhir/Patient',
dataType: 'json',
headers: {
'apicsrftoken': <?php echo js_escape(CsrfUtils::collectCsrfToken('api')); ?>
Expand All @@ -45,7 +45,7 @@ function testAjaxApi() {
}

function testFetchApi() {
fetch('../../apis/api/facility', {
fetch('../../apis/fhir/Patient', {
credentials: 'same-origin',
method: 'GET',
headers: new Headers({
Expand Down Expand Up @@ -96,16 +96,19 @@ function testFetchApi() {
$gbl::setNotRestCall();
$restRequest = new HttpRestRequest($gbl, $_SERVER);
$restRequest->setRequestMethod("GET");
$restRequest->setRequestURI("/fhir/encounter");
$restRequest->setApiType("fhir");
$restRequest->setRequestPath("/fhir/Patient");
$restRequest->setIsLocalApi(true);
$getParams = $restRequest->getQueryParams();

// below will return as json
echo "<b>api via route handler call returning json:</b><br />";
echo HttpRestRouteHandler::dispatch($gbl::$ROUTE_MAP, $restRequest, 'direct-json');
echo HttpRestRouteHandler::dispatch($gbl::$FHIR_ROUTE_MAP, $restRequest, 'direct-json');
echo "<br /><br />";

// below will return as php array
echo "<b>api via route handler call returning php array:</b><br />";
echo print_r(HttpRestRouteHandler::dispatch($gbl::$ROUTE_MAP, $restRequest, 'direct'));
echo print_r(HttpRestRouteHandler::dispatch($gbl::$FHIR_ROUTE_MAP, $restRequest, 'direct'));
echo "<br /><br />";


Expand Down

0 comments on commit 2aae641

Please sign in to comment.