414 lines
11 KiB
PHP
414 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* BPJS Class
|
|
* Description : Class untuk akses REST API BPJS Vclaim, dengan menggunakan class ini
|
|
* user dimudahkan untuk melakukan operasi pada aplikasi vclaim BPJS.
|
|
*
|
|
* Require : GuzzleHTTP, Monolog
|
|
* BPJS Vclaim Version : 1.1
|
|
* Version : 1.0
|
|
* Author : nuril.isbah@gmail.com
|
|
* Parameter : mixed
|
|
* Return : Array
|
|
*
|
|
* How to use this class :
|
|
* - Create new object
|
|
* $bpjs = new BPJS([
|
|
* 'BPJS_CONSID'=>'CONSID',
|
|
* 'BPJS_KEY'=>'SECRETKEY',
|
|
* 'BPJS_VCLAIM_URL'=>'URL SERVICE',
|
|
* ]);
|
|
*
|
|
* - Define katalog and parameter
|
|
* $request = ['katalog'=>'peserta','parameter'=['nokartu','xx000123456','2019-01-01']];
|
|
*
|
|
* - Get result
|
|
* $result = $bpjs->request($request,(DEBUG=BOOLEAN,OBJECT_ONLY=BOOLEAN));
|
|
*
|
|
**/
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Psr7;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
use Monolog\Logger;
|
|
use Monolog\Handler\StreamHandler;
|
|
use Monolog\Handler\FirePHPHandler;
|
|
|
|
Class BPJS {
|
|
|
|
private $consId;
|
|
|
|
private $secretkey;
|
|
|
|
private $serviceUrl;
|
|
|
|
private $header;
|
|
|
|
private $timeStamp;
|
|
|
|
private $requestURL;
|
|
|
|
private $contentType;
|
|
|
|
private $method;
|
|
|
|
public function __construct($cons_id,$secret_key,$service_url)
|
|
{
|
|
$this->consId = $cons_id;
|
|
|
|
$this->secretkey = $secret_key;
|
|
|
|
$this->serviceUrl = $service_url;
|
|
}
|
|
|
|
private function setHeader()
|
|
{
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
|
|
$this->timeStamp = strval(strtotime('now'));
|
|
|
|
$signature = hash_hmac('sha256', $this->consId."&".$this->timeStamp, $this->secretkey, true);
|
|
|
|
$encodedSignature = base64_encode($signature);
|
|
|
|
$context = [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
'Content-type' => $this->contentType,
|
|
'X-cons-id' => $this->consId,
|
|
'X-timestamp' => $this->timeStamp,
|
|
'X-signature' => $encodedSignature,
|
|
]
|
|
];
|
|
|
|
$this->header = $context['headers'];
|
|
}
|
|
|
|
|
|
private function setUrl($param)
|
|
{
|
|
if($param['katalog'] != null)
|
|
{
|
|
switch ($param['katalog']) {
|
|
case 'peserta':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Peserta/'.$param['parameter'][0].'/'.$param['parameter'][1].'/tglSEP/'.$param['parameter'][2];
|
|
break;
|
|
}
|
|
// Referensi
|
|
case 'poli':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/poli/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'faskes':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/faskes/'.$param['parameter'][0].'/'.$param['parameter'][1];
|
|
break;
|
|
}
|
|
case 'propinsi':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/propinsi';
|
|
break;
|
|
}
|
|
case 'kabupaten':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/kabupaten/propinsi/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'kecamatan':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/kecamatan/kabupaten/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'dpjp':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/dokter/pelayanan/'.$param['parameter'][0].'/tglPelayanan/'.$param['parameter'][1].'/Spesialis/'.$param['parameter'][2];
|
|
break;
|
|
}
|
|
case 'diagnosa':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/diagnosa/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
// SEP
|
|
case 'insert_sep':
|
|
{
|
|
$this->method = 'POST';
|
|
$this->contentType = 'application/x-www-form-urlencoded';
|
|
$this->requestURL = '/SEP/1.1/insert';
|
|
break;
|
|
}
|
|
case 'update_sep':
|
|
{
|
|
$this->method = 'PUT';
|
|
$this->contentType = 'application/x-www-form-urlencoded';
|
|
$this->requestURL = '/SEP/1.1/Update';
|
|
break;
|
|
}
|
|
case 'hapus_sep':
|
|
{
|
|
$this->method = 'DELETE';
|
|
$this->contentType = 'application/x-www-form-urlencoded';
|
|
$this->requestURL = '/SEP/Delete';
|
|
break;
|
|
}
|
|
case 'sep':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/SEP/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'suplesi':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/sep/JasaRaharja/Suplesi/'.$param['parameter'][0].'/tglPelayanan/'.$param['parameter'][1];
|
|
break;
|
|
}
|
|
case 'update_pulang':
|
|
{
|
|
$this->method = 'PUT';
|
|
$this->contentType = 'application/x-www-form-urlencoded';
|
|
$this->requestURL = '/Sep/updtglplg';
|
|
break;
|
|
}
|
|
// RUJUKAN
|
|
case 'rujukan_pcare':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'rujukan_RS':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/RS/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'rujukan_pcare_kartu1':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/Peserta/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'rujukan_RS_kartu1':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/RS/Peserta/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'rujukan_pcare_kartumulti':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/List/Peserta/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'rujukan_RS_kartumulti':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Rujukan/RS/List/Peserta/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'insert_rujukan':
|
|
{
|
|
$this->method = 'POST';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/Rujukan/insert';
|
|
break;
|
|
}
|
|
case 'update_rujukan':
|
|
{
|
|
$this->method = 'PUT';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/Rujukan/update';
|
|
break;
|
|
}
|
|
case 'delete_rujukan':
|
|
{
|
|
$this->method = 'DELETE';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/Rujukan/delete';
|
|
break;
|
|
}
|
|
// Referensi LPK
|
|
case 'tindakan':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/procedure/'.$param['parameter'][0];
|
|
break;
|
|
}
|
|
case 'kelasrawat':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/kelasrawat';
|
|
break;
|
|
}
|
|
case 'ruangrawat':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/ruangrawat';
|
|
break;
|
|
}
|
|
case 'dokter':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/dokter';
|
|
break;
|
|
}
|
|
case 'spesialistik':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/spesialistik';
|
|
break;
|
|
}
|
|
case 'carakeluar':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/carakeluar';
|
|
break;
|
|
}
|
|
case 'pascapulang':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/referensi/pascapulang';
|
|
break;
|
|
}
|
|
// LPK
|
|
case 'insert_lpk':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/LPK/insert';
|
|
break;
|
|
}
|
|
case 'update_lpk':
|
|
{
|
|
$this->method = 'PUT';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/LPK/update';
|
|
break;
|
|
}
|
|
case 'delete_lpk':
|
|
{
|
|
$this->method = 'DELETE';
|
|
$this->contentType = 'Application/x-www-form-urlencoded';
|
|
$this->requestURL = '/LPK/delete';
|
|
break;
|
|
}
|
|
case 'list_lpk':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/LPK/TglMasuk/'.$param['parameter'][0].'/JnsPelayanan/'.$param['parameter'][1];
|
|
break;
|
|
}
|
|
case 'monitor_kunjungan':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Monitoring/Kunjungan/Tanggal/'.$param['parameter'][0].'/JnsPelayanan/'.$param['parameter'][1];
|
|
break;
|
|
}
|
|
case 'monitor_klaim':
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = '/Monitoring/Klaim/Tanggal/'.$param['parameter'][0].'/JnsPelayanan/'.$param['parameter'][1].'/Status/'.$param['parameter'][2];
|
|
break;
|
|
}
|
|
// DEFAULT
|
|
default:
|
|
{
|
|
$this->method = 'GET';
|
|
$this->contentType = 'application/json; charset=utf-8';
|
|
$this->requestURL = null;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function request($args, $debug = FALSE, $object_only = FALSE)
|
|
{
|
|
if($this->consId == null || $this->secretkey == null) {
|
|
return false;
|
|
}
|
|
|
|
$this->setUrl($args);
|
|
|
|
$this->setHeader();
|
|
|
|
if($debug == TRUE)
|
|
{
|
|
$this->log($this->method."\r\n".$this->serviceUrl.$this->requestURL."\r\n".http_build_query($this->header));
|
|
}
|
|
|
|
$client = new GuzzleHttp\Client();
|
|
|
|
$url_request = $this->serviceUrl.$this->requestURL;
|
|
|
|
try {
|
|
|
|
$request = new Request($this->method, $url_request, $this->header, $args['body']);
|
|
|
|
$obj_request = $client->send($request);
|
|
|
|
$json_request = ($obj_request->getStatusCode() == 200) ? $obj_request->getBody()->getContents() : [];
|
|
|
|
if($object_only == TRUE) {
|
|
return $json_request;
|
|
}
|
|
else {
|
|
return (array) json_decode($json_request);
|
|
}
|
|
}
|
|
catch(RequestException $e){
|
|
return Psr7\str($e->getRequest());
|
|
if ($e->hasResponse()) {
|
|
return Psr7\str($e->getResponse());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private function log($string)
|
|
{
|
|
$logger = new Logger('BPJS');
|
|
$daily_log = date('d-m-Y').'.log';
|
|
$logger->pushHandler(new StreamHandler(_DOCROOT_.'logs/bpjs_logs/'.$daily_log, Logger::INFO));
|
|
$logger->pushHandler(new FirePHPHandler());
|
|
|
|
$logger->addInfo($string);
|
|
}
|
|
} |