Skip to content

Commit

Permalink
make 2 request icare and non icare and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
virusphp committed Sep 9, 2023
1 parent 04d374c commit e24f79f
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 38 deletions.
81 changes: 48 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ php artisan vendor:publish --provider="Vclaim\Bridging\BridgingBpjsServiceProvid
## Usage

```env
//Confirasi .env BPJS
#Confirasi .env BPJS
CONS_ID=xxxxx
SECRET_KEY=xxxX
// Config untuk Vclaim BPJS
API_BPJS_VCLAIM=https://apijkn-dev.bpjs-kesehatan.go.id/vclaim-rest-dev/
#Config untuk Vclaim BPJS
API_BPJS_VCLAIM=https://apijkn.bpjs-kesehatan.go.id/vclaim-rest-dev/
USER_KEY_VCLAIM=xxxx
// Config untuk Antrol BPJS
API_BPJS_ANTROL=https://apijkn-dev.bpjs-kesehatan.go.id/antreanrs_dev/
#Config untuk Vclaim BPJS
API_BPJS_ICARE=https://apijkn.bpjs-kesehatan.go.id/ihs_dev/
#Config untuk Antrol BPJS
API_BPJS_ANTROL=https://apijkn.bpjs-kesehatan.go.id/antreanrs_dev/
USER_KEY_ANTROL=xxxx
//Configurasi .env untuk sirs kemkes
##Configurasi .env untuk sirs kemkes
USER_ID=xxxx
PASS_ID=xxxx
API_KEMKES=http://sirs.kemkes.go.id/fo/index.php/
Expand Down Expand Up @@ -87,6 +90,39 @@ Class SomeController
}
```

```php
<?php
// Example Controller bridging to Vclaim BPJS (Laravel 7 ke atas)
use Bpjs\Bridging\Icare\BridgeIcare;
use Illuminate\Http\Request;

Class SomeController
{
protected $bridging;

public function __construct()
{
$this->bridging = new BridgeIcare();
}

// Example To use get Referensi diagnosa
// Name of Method example
public function getHistory(Request $reqeust)
{
$data = $this->handleRequest($reqeust);
$endpoint = 'api/rs/validate';
return $this->bridging->postRequest($endpoint, $data);
}

protected function handleRequest($request)
{
$data['param'] = $request->nomor_kartu;
$data['kodedokter'] = $request->kode_dokter;
return json_encode($data);
}
}
```

```php
<?php
// Example Controller bridging to SIRS Kemkes (Laravel 7 ke atas)
Expand All @@ -111,9 +147,9 @@ Class SomeController
}
```

## Channel
## CHANEL YOUTUBE

KLIK UNTUK SUPORT
KLIK TONTON UNTUK SUPORT (LIKE DAN KOMEN)

[![Watch the video](https://yt3.ggpht.com/ytc/AMLnZu8mCU3GUNwlmATLo2gLb0K_jaWjahlc_qmbRxEl=s88-c-k-c0x00ffffff-no-rj)](https://www.youtube.com/watch?v=Gq8-YOnsR-k&t=257s)

Expand All @@ -123,10 +159,13 @@ https://saweria.co/setsuga

# 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

Expand Down Expand Up @@ -183,27 +222,3 @@ https://saweria.co/setsuga
### 2021-09-19

- v0.6-beta Refactor and new fitur bridging kemkes

### 2021-09-15

- v0.5-beta Refactor and update documentation

### 2021-09-15

- v0.2-beta Refactor code and add documentation readme

### 2021-09-14

- v0.1-beta Upgraded codebase to be compatible to PHP 8.

### 2021-09-14

- Added v0.1-beta to packagist/composer virusphp/service-bridging

### 2021-09-14

- Using the Guzzle and Lz-string repositories (guzzlehttp/guzzle) and (nullpunkt/lz-string-php)

### 2021-09-14

- Overhaul and refactor generate signature service BPJS by virusphp
1 change: 1 addition & 0 deletions src/Bpjs/BridgingBpjsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function boot()

$this->publishes([
__DIR__.'../../../config/vclaim.php' => config_path('vclaim.php'),
__DIR__.'../../../config/icare.php' => config_path('icare.php'),
__DIR__.'../../../config/antrol.php' => config_path('antrol.php'),
__DIR__.'../../../config/kemkes.php' => config_path('kemkes.php'),
], 'config');
Expand Down
34 changes: 34 additions & 0 deletions src/Bpjs/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ public function request($endpoint, $headers, $method = "", $payload = "")
curl_setopt_array($ch, $optf);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
// dd($info);
curl_close($ch);

return $result;
}

public function requestIcare($endpoint, $headers, $method = "", $payload = "")
{
$headers = $this->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/json';
} 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;
Expand Down
64 changes: 64 additions & 0 deletions src/Bpjs/Icare/BridgeIcare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Bpjs\Bridging\Icare;

// use Bpjs\Bridging\Bridge;
use Bpjs\Bridging\CurlFactory;

class BridgeIcare extends CurlFactory
{
protected $config;
protected $response;
protected $header;
protected $headers;

public function __construct()
{
// parent::__construct();
$this->config = new ConfigIcare;
$this->response = new ResponseIcare;
$this->header = $this->config->setHeader();
}

public function getRequest($endpoint)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header);
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp']));
return $result;
}

public function getRequestNew($endpoint)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header);
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp']));
return $result;
}

public function postRequest($endpoint, $data)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "POST", $data);
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp']));
return $result;
}

public function putRequest($endpoint, $data)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "PUT", $data);
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp']));
return $result;
}

public function deleteRequest($endpoint, $data)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "DELETE", $data);
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp']));
return $result;
}

public function deleteResponseNoDecrypt($endpoint, $data)
{
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "DELETE", $data);
return $result;
}

}
89 changes: 89 additions & 0 deletions src/Bpjs/Icare/ConfigIcare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Bpjs\Bridging\Icare;

use Bpjs\Bridging\ManageService;
use Bpjs\Bridging\GenerateBpjs;
use Dotenv\Dotenv;

class ConfigIcare extends ManageService
{
protected $urlEndpoint;
protected $consId;
protected $secretKey;
protected $userKey;
protected $header;
protected $timestamps;

public function __construct()
{
$dotenv = Dotenv::createUnsafeImmutable(getcwd());
$dotenv->safeLoad();

$this->urlEndpoint = getenv('API_BPJS_ICARE');
$this->consId = getenv('CONS_ID');
$this->secretKey = getenv('SECRET_KEY');
$this->userKey = getenv('USER_KEY_VCLAIM');
}

public function setUrl()
{
return $this->urlEndpoint;
}

public function setConsId()
{
return $this->consId;
}

public function setSecretKey()
{
return $this->secretKey;
}

public function setUserKey()
{
return $this->userKey;
}

public function setTimestamp()
{
return GenerateBpjs::bpjsTimestamp();
}

public function setsignature()
{
return GenerateBpjs::generateSignature($this->setConsId(), $this->setSecretKey());
}

public function setUrlEncode()
{
return array('Content-Type' => 'Application/x-www-form-urlencoded');
}

public function setUrlJson()
{
return array('Content-Type' => 'Application/Json');
}

public function setHeader()
{
return [
'Accept' => 'application/json',
'X-cons-id' => $this->setConsid(),
'X-timestamp' => $this->setTimestamp(),
'X-signature' => $this->setSignature(),
'user_key' => $this->setUserKey()
];
}

public function keyDecrypt($timestamp)
{
return $this->setConsid().$this->setSecretKey().$timestamp;
}

public function setHeaders($header)
{
return array_merge($header, $this->setUrlEncode());
}
}
32 changes: 32 additions & 0 deletions src/Bpjs/Icare/ResponseIcare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Bpjs\Bridging\Icare;

use LZCompressor\LZString;
use Bpjs\Bridging\GenerateBpjs;

class ResponseIcare
{
public function responseIcare($response, $key)
{
$result = json_decode($response);
if ($result->metaData->code == "200" && is_string($result->response)) {
return self::doMaping($result->metaData, $result->response, $key);
}
return json_encode($result);
}

public function doMaping($metaData, $response, $key)
{
$data = [
"metaData" => $metaData,
"response" => json_decode($this->decompressed(GenerateBpjs::stringDecrypt($key, $response)))
];
return json_encode($data);
}

protected function decompressed($dataString)
{
return LZString::decompressFromEncodedURIComponent($dataString);
}
}
Loading

0 comments on commit e24f79f

Please sign in to comment.