432 lines
12 KiB
PHP
432 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* INCBG Class
|
|
* Description : Class untuk akses REST API INACBG E-Klaim, dengan menggunakan class ini
|
|
* user dimudahkan untuk melakukan operasi pada aplikasi E-Klaim.
|
|
*
|
|
* Require : GuzzleHTTP, Monolog
|
|
* INCBG E-Klaim Version : 5.3.8.201904220235
|
|
* Version : 1.0
|
|
* Author : nuril.isbah@gmail.com
|
|
*
|
|
* How to use this class :
|
|
* - Create new object
|
|
* $inacbg = new INACBG([
|
|
* 'INACBG_KEY'=>'SECRETKEY',
|
|
* 'INACBG_URL'=>'URL SERVICE',
|
|
* ]);
|
|
*
|
|
* - Get result
|
|
* $result = $inacbg->request($request);
|
|
*
|
|
**/
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Psr7;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
|
|
Class INACBG {
|
|
|
|
|
|
private $secretkey;
|
|
|
|
private $serviceUrl;
|
|
|
|
private $method;
|
|
|
|
public $formated_data;
|
|
|
|
public function __construct($key, $url)
|
|
{
|
|
|
|
$this->secretkey = $key;
|
|
|
|
$this->serviceUrl = $url;
|
|
}
|
|
|
|
private function encrypt($data, $key)
|
|
{
|
|
$key = hex2bin($key);
|
|
|
|
if(mb_strlen($key,'8bit') !== 32)
|
|
{
|
|
throw new Exception("Error Processing Request. Need a 256 bit key");
|
|
}
|
|
|
|
// $iv_size = openssl_chiper_iv_length("aes-256-cbc");
|
|
$iv_size = 16;
|
|
|
|
$iv = random_bytes($iv_size);
|
|
|
|
$encrypted = openssl_encrypt($data, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv);
|
|
|
|
$signature = mb_substr(hash_hmac("sha256", $encrypted, $key, true), 0, 10, '8bit');
|
|
|
|
$encoded = chunk_split(base64_encode($signature.$iv.$encrypted));
|
|
|
|
return $encoded;
|
|
}
|
|
|
|
private function decrypt($str, $key)
|
|
{
|
|
$key = hex2bin($key);
|
|
|
|
if(mb_strlen($key,'8bit') !== 32)
|
|
{
|
|
throw new Exception("Error Processing Request. Need a 256 bit key");
|
|
}
|
|
|
|
// $iv_size = openssl_chiper_iv_length("aes-256-cbc");
|
|
$iv_size = 16;
|
|
|
|
$decoded = base64_decode($str);
|
|
|
|
$signature = mb_substr($decoded, 0, 10, '8bit');
|
|
|
|
$iv = mb_substr($decoded,10,$iv_size,'8bit');
|
|
|
|
$encrypted = mb_substr($decoded,$iv_size+10,NULL,'8bit');
|
|
|
|
$calc_signature = mb_substr(hash_hmac("sha256", $encrypted, $key, true), 0, 10, '8bit');
|
|
|
|
if(!$this->compare($signature,$calc_signature))
|
|
{
|
|
return 'SIGNATURE_NOT_MATCH';
|
|
}
|
|
|
|
$decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
|
|
|
|
return $decrypted;
|
|
}
|
|
|
|
private function compare($signa1, $signa2)
|
|
{
|
|
if(strlen($signa1) !== strlen($signa2))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$result = 0;
|
|
for($i = 0; $i < strlen($signa1); $i++)
|
|
{
|
|
$result |= ord($signa1[$i]) ^ ord($signa2[$i]);
|
|
}
|
|
|
|
return $result == 0;
|
|
}
|
|
|
|
public function setMethod($method, $param)
|
|
{
|
|
$meta['metadata']['method'] = $method;
|
|
if($method == 'new_claim')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_kartu','nomor_sep','nomor_rm','nama_pasien','tgl_lahir','gender']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_kartu' => $param['nomor_kartu'],
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'nomor_rm' => $param['nomor_rm'],
|
|
'nama_pasien' => $param['nama_pasien'],
|
|
'tgl_lahir' => $param['tgl_lahir'],
|
|
'gender' => $param['gender']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'update_patient')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_kartu','nomor_rm','nama_pasien','tgl_lahir','gender']);
|
|
if($cek_param == true) {
|
|
$meta['metadata']['nomor_rm'] = $param['nomor_rm'];
|
|
$format = array_merge(
|
|
$meta,
|
|
['data'=> [
|
|
'nomor_kartu' => $param['nomor_kartu'],
|
|
'nomor_rm' => $param['nomor_rm'],
|
|
'nama_pasien' => $param['nama_pasien'],
|
|
'tgl_lahir' => $param['tgl_lahir'],
|
|
'gender' => $param['gender']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'delete_patient')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_rm','coder_nik']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_rm' => $param['nomor_rm'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'set_claim_data')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','nomor_kartu','tgl_masuk','tgl_pulang',
|
|
'jenis_rawat','kelas_rawat','adl_sub_acute','adl_chronic','icu_indikator','icu_los','ventilator_hour','upgrade_class_ind','upgrade_class_class','upgrade_class_los','add_payment_pct','birth_weight','discharge_status','diagnosa','procedure','prosedur_non_bedah','prosedur_bedah','konsultasi','tenaga_ahli','keperawatan','penunjang','radiologi','laboratorium','pelayanan_darah','rehabilitasi','kamar','rawat_intensif','obat','obat_kronis','obat_kemoterapi','alkes','bmhp','sewa_alat','tarif_poli_eks','nama_dokter','kode_tarif','payor_id','payor_cd','cob_cd','coder_nik']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'nomor_kartu' => $param['nomor_kartu'],
|
|
'tgl_masuk' => $param['tgl_masuk'],
|
|
'tgl_pulang' => $param['tgl_pulang'],
|
|
'jenis_rawat' => $param['jenis_rawat'],
|
|
'kelas_rawat' => $param['kelas_rawat'],
|
|
'adl_sub_acute' => $param['adl_sub_acute'],
|
|
'adl_chronic' => $param['adl_chronic'],
|
|
'icu_indikator' => $param['icu_indikator'],
|
|
'icu_los' => $param['icu_los'],
|
|
'ventilator_hour' => $param['ventilator_hour'],
|
|
'upgrade_class_ind' => $param['upgrade_class_ind'],
|
|
'upgrade_class_class' => $param['upgrade_class_class'],
|
|
'upgrade_class_los' => $param['upgrade_class_los'],
|
|
'add_payment_pct' => $param['add_payment_pct'],
|
|
'birth_weight' => $param['birth_weight'],
|
|
'discharge_status' => $param['discharge_status'],
|
|
'diagnosa' => $param['diagnosa'],
|
|
'procedure' => $param['procedure'],
|
|
'tarif_rs' => [
|
|
'prosedur_non_bedah' => $param['prosedur_non_bedah'],
|
|
'prosedur_bedah' => $param['prosedur_bedah'],
|
|
'konsultasi' => $param['konsultasi'],
|
|
'tenaga_ahli' => $param['tenaga_ahli'],
|
|
'keperawatan' => $param['keperawatan'],
|
|
'radiologi' => $param['radiologi'],
|
|
'laboratorium' => $param['laboratorium'],
|
|
'pelayanan_darah' => $param['pelayanan_darah'],
|
|
'rehabilitasi' => $param['rehabilitasi'],
|
|
'kamar' => $param['kamar'],
|
|
'rawat_intensif' => $param['rawat_intensif'],
|
|
'obat' => $param['obat'],
|
|
'obat_kronis' => $param['obat_kronis'],
|
|
'obat_kemoterapi' => $param['obat_kemoterapi'],
|
|
'alkes' => $param['alkes'],
|
|
'bmhp' => $param['bmhp'],
|
|
'sewa_alat' => $param['sewa_alat']
|
|
],
|
|
'tarif_poli_eks' => $param['tarif_poli_eks'],
|
|
'nama_dokter' => $param['nama_dokter'],
|
|
'kode_tarif' => $param['kode_tarif'],
|
|
'payor_id' => $param['payor_id'],
|
|
'payor_cd' => $param['payor_cd'],
|
|
'cob_cd' => $param['cob_cd'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'update_procedur')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','procedure','coder_nik']);
|
|
if($cek_param == true) {
|
|
$meta['metadata']['method'] = 'set_claim_data';
|
|
$meta['metadata']['nomor_sep'] = $param['nomor_sep'];
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'procedure' => $param['procedure'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'grouper_1')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep']);
|
|
if($cek_param == true) {
|
|
$meta['metadata']['method'] = 'grouper';
|
|
$meta['metadata']['stage'] = 1;
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'grouper_2')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','special_cmg']);
|
|
if($cek_param == true) {
|
|
$meta['metadata']['method'] = 'grouper';
|
|
$meta['metadata']['stage'] = 2;
|
|
$format = array_merge($meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'special_cmg' => $param['special_cmg']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'claim_final')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','coder_nik']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'reedit_claim')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'send_claim')
|
|
{
|
|
$cek_param = $this->validParam($param, ['start_dt','stop_dt','jenis_rawat','date_type']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'start_dt' => $param['start_dt'],
|
|
'stop_dt' => $param['stop_dt'],
|
|
'jenis_rawat' => $param['jenis_rawat'],
|
|
'date_type' => $param['date_type']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'send_claim_individual')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'get_claim_data')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'get_claim_status')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'delete_claim')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','coder_nik']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'claim_print')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','coder_nik']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'coder_nik' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
elseif($method == 'sitb_validate')
|
|
{
|
|
$cek_param = $this->validParam($param, ['nomor_sep','nomor_register_sitb']);
|
|
if($cek_param == true) {
|
|
$format = array_merge(
|
|
$meta,
|
|
['data' => [
|
|
'nomor_sep' => $param['nomor_sep'],
|
|
'nomor_register_sitb' => $param['coder_nik']
|
|
]]);
|
|
}
|
|
}
|
|
$this->formated_data = json_encode($format);
|
|
}
|
|
|
|
private function validParam($param,$arr_key)
|
|
{
|
|
foreach($arr_key as $key)
|
|
{
|
|
if(!array_key_exists($key, $param))
|
|
{
|
|
return "Parameter ".$key." not found";
|
|
break;
|
|
}
|
|
else {
|
|
if($param[$key] == '')
|
|
{
|
|
return "Invalid Parameter on ".$key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function request()
|
|
{
|
|
if($this->formated_data == '') { return false; }
|
|
|
|
$context = [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
'Content-type' => 'application/x-www-form-urlencoded'
|
|
]
|
|
];
|
|
|
|
$ws_query = $this->encrypt($this->formated_data, $this->secretkey);
|
|
|
|
$client = new GuzzleHttp\Client();
|
|
|
|
try {
|
|
|
|
$request = new Request('POST', $this->serviceUrl, $context, $ws_query);
|
|
|
|
$obj_request = $client->send($request);
|
|
|
|
$json_request = ($obj_request->getStatusCode() == 200) ? $obj_request->getBody()->getContents() : [];
|
|
|
|
$first = strpos($json_request, "\n")+1;
|
|
|
|
$last = strrpos($json_request, "\n")-1;
|
|
|
|
$response = substr($json_request, $first, strlen($json_request)-$first-$last);
|
|
|
|
$response = $this->decrypt($response, $this->secretkey);
|
|
|
|
return json_decode($response, true);
|
|
}
|
|
catch(RequestException $e){
|
|
return Psr7\str($e->getRequest());
|
|
if ($e->hasResponse()) {
|
|
return Psr7\str($e->getResponse());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |