From cff76effc9bbcc6a9a2250fbbdc5f56791c3d600 Mon Sep 17 00:00:00 2001 From: virusphp Date: Fri, 2 Aug 2024 10:58:12 +0700 Subject: [PATCH] refactoring sirs kemkes with curl and update readme --- README.md | 94 ++++---------------- composer.json | 2 +- src/Bpjs/Vclaim/BridgeVclaim.php | 1 - src/kemkes/BridgingKemkes.php | 85 ------------------ src/kemkes/BridgingKemkesServiceProvider.php | 8 +- src/kemkes/CurlFactory.php | 49 ++++++++++ src/kemkes/GenerateKemkes.php | 11 --- src/kemkes/Kemkes.php | 54 ----------- src/kemkes/ManageService.php | 27 ++++++ src/kemkes/Sirs/BridgeSirs.php | 43 +++++++++ src/kemkes/Sirs/ConfigSirs.php | 60 +++++++++++++ src/kemkes/TempatTidurController.php | 14 ++- src/routes.php | 35 +++++--- 13 files changed, 234 insertions(+), 249 deletions(-) delete mode 100755 src/kemkes/BridgingKemkes.php create mode 100644 src/kemkes/CurlFactory.php delete mode 100755 src/kemkes/GenerateKemkes.php delete mode 100755 src/kemkes/Kemkes.php create mode 100644 src/kemkes/ManageService.php create mode 100644 src/kemkes/Sirs/BridgeSirs.php create mode 100644 src/kemkes/Sirs/ConfigSirs.php diff --git a/README.md b/README.md index cf55596..e162b32 100755 --- a/README.md +++ b/README.md @@ -47,10 +47,9 @@ USER_KEY_ANTROL=xxxx API_BPJS_APLICARE=https://new-api.bpjs-kesehatan.go.id/aplicaresws/rest/ - ##Configurasi .env untuk sirs kemkes -USER_ID=xxxx -PASS_ID=xxxx +USER_SIRS=xxxx +PASS_SIRS=xxxx API_KEMKES=http://sirs.kemkes.go.id/fo/index.php/ ``` @@ -155,24 +154,25 @@ Class SomeController ```php bridging = new BridgingKemkes(); - } + public function __construct() + { + $this->bridging = new BridgeSirs; + } - // Example To use get Referensi diagnosa + // Example To use get list Tempat tidur // Name of Method example - public function getFasyankes($kode) - { - $endpoint = 'Fasyankes'. $kode; - return $this->bridging->getRequest($endpoint); - } + public function getTempatTidur() + { + $url = 'Fasyankes'; + $tempattidur = $this->bridging->getRequest($url); + return $tempattidur; + } } ``` @@ -193,66 +193,6 @@ KLIK TONTON UNTUK SUPORT (LIKE DAN KOMEN) # Changelog -#### 2023-09-09 - -- v2.1.2 Add new fitur briding I-care - -#### 2022-11-26 - -- v2.1.1 Fixed bug duplication encode string - -#### 2022-10-15 - -- v2.0.9 Refactoring Guzzle to curl and replace all guzzle - -#### 2022-10-07 - -- v2.0.9 fixed delete method for sep, surat kontrol, and rujukan - -#### 2022-02-26 - -- v2.0.0 Release Mayor Refactoring all service (New Service Antrol) - -#### 2022-01-29 - 2022-02-07 - -- v1.3.7 add support use to native php - -#### 2022-01-25 - -- v1.3.4 bug response antrol not same vclaim and add response antrol - -#### 2022-01-25 - -- v1.3.2 and v.13.3 fix bug response and add support php version 8 - -#### 2022-01-12 - -- v1.3.1 fix bug response json to encode - -#### 2022-01-04 - -- v1.3 fix bug and single generate timestamp to open key - -#### 2021-12-31 - -- v1.2 fixed bug minor - -#### 2021-12-28 - -- v1.1 fixed bug minor - -### 2021-12-27 - -- v1.0 Add user_key to bridging versi 2 and fix bug - -### 2021-11-22 - -- v0.8-beta fix bug minor - -### 2021-09-19 - -- v0.7-beta fix bug minor both briding old and new version - -### 2021-09-19 +#### 2024-08-02 -- v0.6-beta Refactor and new fitur bridging kemkes +- v2.1.4 Add new fitur briding Sirs update diff --git a/composer.json b/composer.json index 97b2eaa..27c3e1d 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "autoload": { "psr-4": { "Bpjs\\Bridging\\": "src/Bpjs/", - "Kemkes\\Bridging\\": "src/kemkes" + "Kemkes\\Bridging\\": "src/Kemkes/" } }, "config": { diff --git a/src/Bpjs/Vclaim/BridgeVclaim.php b/src/Bpjs/Vclaim/BridgeVclaim.php index 0dd6e16..8681a0d 100644 --- a/src/Bpjs/Vclaim/BridgeVclaim.php +++ b/src/Bpjs/Vclaim/BridgeVclaim.php @@ -14,7 +14,6 @@ class BridgeVclaim extends CurlFactory public function __construct() { - // parent::__construct(); $this->config = new ConfigVclaim; $this->response = new ResponseVclaim; $this->header = $this->config->setHeader(); diff --git a/src/kemkes/BridgingKemkes.php b/src/kemkes/BridgingKemkes.php deleted file mode 100755 index aca504f..0000000 --- a/src/kemkes/BridgingKemkes.php +++ /dev/null @@ -1,85 +0,0 @@ -client = new Client([ - 'verify' => true, - 'cookie' => true, - ]); - } - - public function getRequest($endpoint) - { - try { - $url = $this->setServiceApi() . $endpoint; - $response = $this->client->get($url, ['headers' => $this->setHeader()]); - $result = $response->getBody()->getContents(); - return $result; - } catch (RequestException $e) { - $result = $e->getRequest(); - if ($e->hasResponse()) { - $result = $e->getResponse(); - } - } - } - - public function postRequest($endpoint, $data) - { - $data = file_get_contents("php://input"); - try { - $url = $this->setServiceApi() . $endpoint; - $response = $this->client->post($url, ['headers' => $this->setHeaders(), 'body' => $data]); - $result = $response->getBody()->getContents(); - return $result(); - } catch (RequestException $e) { - $result =$e->getRequest(); - if ($e->hasResponse()) { - $result = $e->getResponse(); - } - } - } - - public function putRequest($endpoint, $data) - { - try { - $url = $this->setServiceApi() . $endpoint; - $response = $this->client->post($url, ['headers' => $this->setHeaders(), 'body' => $data]); - $result = $response->getBody()->getContents(); - return $result(); - } catch (RequestException $e) { - $result =$e->getRequest(); - if ($e->hasResponse()) { - $result = $e->getResponse(); - } - } - } - - public function deleteRequest($endpoint, $data) - { - $data = file_get_contents("php://input"); - try { - $url = $this->setServiceApi() . $endpoint; - $response = $this->client->post($url, ['headers' => $this->setHeaders(), 'body' => $data]); - $result = $response->getBody()->getContents(); - return $result(); - } catch (RequestException $e) { - $result = Psr7\str($e->getRequest()); - if ($e->hasResponse()) { - $result = Psr7\str($e->getResponse()); - } - } - } - -} \ No newline at end of file diff --git a/src/kemkes/BridgingKemkesServiceProvider.php b/src/kemkes/BridgingKemkesServiceProvider.php index 610d441..cbebf97 100755 --- a/src/kemkes/BridgingKemkesServiceProvider.php +++ b/src/kemkes/BridgingKemkesServiceProvider.php @@ -23,10 +23,10 @@ public function register() */ public function boot() { - include __DIR__.'../../routes.php'; - - $this->publishes([ - __DIR__.'../../../../config/kemkes.php' => config_path('kemkes.php'), + include __DIR__ . '../../routes.php'; + + $this->publishes([ + __DIR__ . '../../../config/kemkes.php' => config_path('kemkes.php'), ], 'config'); } } diff --git a/src/kemkes/CurlFactory.php b/src/kemkes/CurlFactory.php new file mode 100644 index 0000000..20a8a84 --- /dev/null +++ b/src/kemkes/CurlFactory.php @@ -0,0 +1,49 @@ +setHeader($headers); + + $optf = [ + CURLOPT_VERBOSE => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_TIMEOUT => 5, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => $headers + ]; + + if (!empty($method)) { + $optf[CURLOPT_CUSTOMREQUEST] = $method; + $optf[CURLOPT_POSTFIELDS] = $payload; + $optf[CURLOPT_HTTPHEADER][] = 'Content-Type: Application/x-www-form-urlencoded'; + } else { + $optf[CURLOPT_HTTPHEADER][] = 'Content-Type: Application/json'; + } + + $ch = curl_init($endpoint); + curl_setopt_array($ch, $optf); + $result = curl_exec($ch); + $info = curl_getinfo($ch); + // dd($info); + curl_close($ch); + + return $result; + } + + protected function setHeader($headers) + { + $header = []; + $header[] = 'Accept: application/json'; + $header[] = 'X-rs-id:' . $headers['X-rs-id']; + $header[] = 'X-timestamp:' . $headers['X-timestamp']; + $header[] = 'X-pass:' . $headers['X-pass']; + return $header; + } +} diff --git a/src/kemkes/GenerateKemkes.php b/src/kemkes/GenerateKemkes.php deleted file mode 100755 index de445b0..0000000 --- a/src/kemkes/GenerateKemkes.php +++ /dev/null @@ -1,11 +0,0 @@ -load(); - } - - public function setUserId() - { - return getenv('USER_SIRS'); - } - - public function setPassid() - { - return getenv('PASS_SIRS'); - } - - public function setServiceApi() - { - return getenv('API_KEMKES'); - } - - public function setTimestamp() - { - return GenerateKemkes::kemkesTimestamp(); - } - - public function setUrlEncode() - { - return array('Content-Type' => 'Application/x-www-form-urlencoded'); - } - - public function setHeader() - { - return [ - 'x-rs-id' => $this->setUserId(), - 'x-Timestamp' => $this->setTimestamp(), - 'x-pass' => $this->setPassid() - ]; - } - - public function setHeaders() - { - return array_merge($this->setHeader(), $this->setUrlEncode()); - } -} \ No newline at end of file diff --git a/src/kemkes/ManageService.php b/src/kemkes/ManageService.php new file mode 100644 index 0000000..1cb5f78 --- /dev/null +++ b/src/kemkes/ManageService.php @@ -0,0 +1,27 @@ +config = new ConfigSirs; + $this->header = $this->config->setHeader(); + } + + public function getRequest($endpoint) + { + $result = $this->request($this->config->setUrl() . $endpoint, $this->header); + return $result; + } + + public function postRequest($endpoint, $data) + { + $result = $this->request($this->config->setUrl() . $endpoint, $this->header, "POST", $data); + return $result; + } + + public function putRequest($endpoint, $data) + { + $result = $this->request($this->config->setUrl() . $endpoint, $this->header, "PUT", $data); + return $result; + } + + public function deleteRequest($endpoint, $data) + { + $result = $this->request($this->config->setUrl() . $endpoint, $this->header, "DELETE", $data); + return $result; + } +} diff --git a/src/kemkes/Sirs/ConfigSirs.php b/src/kemkes/Sirs/ConfigSirs.php new file mode 100644 index 0000000..9d64b04 --- /dev/null +++ b/src/kemkes/Sirs/ConfigSirs.php @@ -0,0 +1,60 @@ +safeLoad(); + + $this->urlEndpoint = getenv('API_SIRS'); + $this->user = getenv('USER_SIRS'); + $this->pass = getenv('PASS_SIRS'); + } + + public function setUrl() + { + return $this->urlEndpoint; + } + + public function setUser() + { + return $this->user; + } + + public function setPass() + { + return $this->pass; + } + + public function setTimestamp() + { + return strval(time() - strtotime('1970-01-01 00:00:00')); + } + + public function setUrlJson() + { + return array('Content-Type' => 'Application/Json'); + } + + public function setHeader() + { + return [ + 'Accept' => 'application/json', + 'X-rs-id' => $this->setUser(), + 'X-timestamp' => $this->setTimestamp(), + 'X-pass' => $this->setPass(), + ]; + } +} diff --git a/src/kemkes/TempatTidurController.php b/src/kemkes/TempatTidurController.php index 06a08c9..9f16534 100755 --- a/src/kemkes/TempatTidurController.php +++ b/src/kemkes/TempatTidurController.php @@ -2,18 +2,28 @@ namespace Kemkes\Bridging; +use Kemkes\Bridging\Sirs\BridgeSirs; + class TempatTidurController { protected $bridging; public function __construct() { - $this->bridging = new BridgingKemkes; + $this->bridging = new BridgeSirs; } public function getTempatTidur() { $url = 'Fasyankes'; $tempattidur = $this->bridging->getRequest($url); + return $tempattidur; + } + + public function getReferensi() + { + $endpoint = "Referensi/tempat_tidur"; + $referensi = $this->bridging->getRequest($endpoint); + return $referensi; } -} \ No newline at end of file +} diff --git a/src/routes.php b/src/routes.php index c8b7567..970e09c 100755 --- a/src/routes.php +++ b/src/routes.php @@ -4,7 +4,7 @@ use Vclaim\Bridging\GenerateBpjs; use Vclaim\Bridging\PesertaController; use Bpjs\Bridging\ReferensiController; - +use Kemkes\Bridging\TempatTidurController; // Route::get('sample', function() { // $generate = new GenerateBpjs; @@ -204,24 +204,31 @@ // return $referensi; // }); -// Route::get('rujukan/list/peserta/{peserta}', function($rujukan) { -// $referensi = new ReferensiController(); -// $referensi = $referensi->cariRujukanListPcare($rujukan); -// return $referensi; -// }); +Route::get('rujukan/list/peserta/{peserta}', function ($rujukan) { + $referensi = new ReferensiController(); + $referensi = $referensi->cariRujukanListPcare($rujukan); + return $referensi; +}); -// // Route::get('fasyankesx', function() { -// // dd("KOK GAK SAMPE SINI"); -// // // $tempattidur = new TempatTidurController(); -// // // $tempattidur = $tempattidur->getTempatTidur(); -// // // return $tempattidur; -// // }); +Route::get('fasyankes', function () { + // dd("KOK GAK SAMPE SINI"); + $tempattidur = new TempatTidurController(); + $tempattidur = $tempattidur->getTempatTidur(); + return $tempattidur; +}); + +Route::get('fasyankes/referensi', function () { + // dd("KOK GAK SAMPE SINI"); + $tempattidur = new TempatTidurController(); + $tempattidur = $tempattidur->getReferensi(); + return $tempattidur; +}); -Route::get('helo', function() { +Route::get('helo', function () { echo "HELO HELO HELO"; }); -Route::get('histori/pelayanan/peserta/{nokartu}/{kodedokter}', function($nokartu, $kodedokter) { +Route::get('histori/pelayanan/peserta/{nokartu}/{kodedokter}', function ($nokartu, $kodedokter) { $referensi = new ReferensiController(); $referensi = $referensi->getHistoryPelayanan($nokartu, $kodedokter); return $referensi;