PHP code example of virusphp / bridging-satusehat

1. Go to this page and download the library: Download virusphp/bridging-satusehat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

virusphp / bridging-satusehat example snippets



// configurasi config (Support laravel 7 ke atas)
config/satusehat.php
return [
	'api' => [
		'endpoint_auth'  => env('API_SATUSEHAT_AUTH','ENDPOINT-KAMU'),
		'endpoint_base'  => env('API_SATUSEHAT_BASE','ENDPOINT-KAMU'),
		'endpoint_kfa'  => env('API_SATUSEHAT_KFA','ENDPOINT-KAMU'),
		'endpoint_kfa_v2'  => env('API_SATUSEHAT_KFA_V2','ENDPOINT-KAMU'),
		'endpoint_kyc'  => env('API_SATUSEHAT_KYC','ENDPOINT-KAMU'),
		'endpoint_consent'  => env('API_SATUSEHAT_CONSENT','ENDPOINT-KAMU'),
		'client_id' => env('CLIENT_ID_SATUSEHAT', 'SECRET-KAMU'),
		'client_secret' => env('CLIENT_SECRET_SATUSEHAT', 'SECRET-KAMU'),
	]
]



// Example Controller bridging to SATUSEHAT  (Laravel 7 ke atas)
use Virusphp\BridgingSatusehat\Bridge\BridgeBase;

Class SomeController
{
	protected $bridging;

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

	// Example To use get Patient
	// Name of Method example
	public function getPatient($nik)
	{
		$endpoint = 'Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|'. $nik;
		return $this->bridging->getRequest($endpoint);
	}
}



// Example Controller bridging to KYC  (PHP 8 & LARAVEL 8 Keatas)
use Virusphp\BridgingSatusehat\Bridge\BridgeKyc;
use Virusphp\BridgingSatusehat\Foundation\Handler\KYCgenerator;

Class KYCController
{
	use KYCgenerator;

	protected $bridgingKYC;

	public function __construct()
	{
		$this->bridgingKYC = new BridgeKyc();
	}

	// Example To use KYC
	// Name of Method example
	public function generateKYC()
	{
		$keyPair = $this->generateRSAKeyPair();
        $publicKey = $keyPair['publicKey'];
        $privateKey = $keyPair['privateKey'];

		$data['agent_name'] = "Admin";
        $data['agent_nik'] = "3375030xxxxxxxx";
        $data['public_key'] = $publicKey;

		$jsonData = json_encode($data);

		$pubPEM = "-----BEGIN PUBLIC KEY-----
			// SEUAIKAN KEY PUBLIC DARI SATUSEHAT KYC
			-----END PUBLIC KEY-----"

        $encryptedPayload = $this->encryptMessage($jsonData, $pubPEM);

		$endpoint = "generate-url";

		$response = $this->satusehat->postRequest($endpoint, $encryptedPayload);

        $result = $this->decryptMessage($response, $privateKey);

        return $result;
	}
}

cmd
php artisan vendor:publish --provider="Virusphp\BridgingSatusehat\SatusehatServiceProvider" --tag=config