Files
BE_CPONE/docs_api_wynacom.md
Hanan Askarim 94170e9de2 add glukosa
2026-06-22 14:44:52 +07:00

491 lines
8.8 KiB
Markdown

# Dokumentasi API Wynacom
Base URL dev:
```text
https://devcpone.aplikasi.web.id/one-api/tools/wynacom
```
Semua response API menggunakan format standar:
```json
{
"status": "OK",
"data": {}
}
```
Jika gagal:
```json
{
"status": "ERR",
"message": "Pesan error"
}
```
## Alur Integrasi
1. Wynacom memanggil `generate_token`.
2. Wynacom menyimpan `access_token` dari response.
3. Wynacom memanggil `sampling_timestamp` dengan header `Authorization: Bearer {access_token}`.
4. Jika token expired/tidak aktif, Wynacom memanggil `generate_token` lagi.
Token disimpan di tabel `api_wynacom_token`. Jika masih ada token aktif dan belum expired, `generate_token` akan mengembalikan token aktif tersebut, bukan membuat token baru.
## Generate Token
Endpoint:
```http
POST /generate_token
```
Request body:
```json
{}
```
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/generate_token" \
-H "Content-Type: application/json" \
-d '{}'
```
Contoh PHP `curl_init()`:
```php
<?php
$baseUrl = 'https://devcpone.aplikasi.web.id/one-api/tools/wynacom';
$ch = curl_init($baseUrl . '/generate_token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array()));
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$tokenResponse = json_decode($response, true);
if (!isset($tokenResponse['status']) || $tokenResponse['status'] !== 'OK') {
die('Generate token failed: ' . $response);
}
$accessToken = $tokenResponse['data']['access_token'];
```
Contoh response:
```json
{
"status": "OK",
"data": {
"access_token": "TOKEN_VALUE",
"token_type": "Bearer",
"expired_at": "2026-06-21 10:00:00",
"expired_days": 3,
"expires_in": 259200
}
}
```
Catatan:
- `expired_days` mengikuti setting `token_expired_days`.
- Jika token aktif masih ada, response mengembalikan token aktif dan `expires_in` sisa detik sampai expired.
## Check Token
Endpoint:
```http
POST /check_token
```
Header:
```http
Authorization: Bearer {access_token}
```
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/check_token" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN_VALUE" \
-d '{}'
```
Contoh response valid:
```json
{
"status": "OK",
"data": {
"valid": true,
"token_id": 1,
"expired_at": "2026-06-21 10:00:00"
}
}
```
Contoh response token tidak valid/expired:
```json
{
"status": "ERR",
"message": "Token tidak valid atau sudah expired"
}
```
Jika token tidak dikirim:
```json
{
"status": "ERR",
"message": "Token wajib diisi"
}
```
## Get Token Setting
Endpoint:
```http
POST /token_setting
```
Request body:
```json
{}
```
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/token_setting" \
-H "Content-Type: application/json" \
-d '{}'
```
Contoh response:
```json
{
"status": "OK",
"data": {
"token_expired_days": 3,
"expires_in": 259200
}
}
```
## Save Token Setting
Endpoint:
```http
POST /save_token_setting
```
Request body:
```json
{
"token_expired_days": 10
}
```
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/save_token_setting" \
-H "Content-Type: application/json" \
-d '{"token_expired_days":10}'
```
Validasi:
- Minimal `1` hari.
- Maksimal `365` hari.
- Setting berlaku untuk token baru. Token aktif yang sudah ada tetap berlaku sampai expired/nonaktif.
## Sampling Timestamp
Endpoint:
```http
POST /sampling_timestamp
```
Header:
```http
Authorization: Bearer {access_token}
```
Request body:
```json
{
"T_OrderHeaderLabNumber": "R2606110001"
}
```
Alias parameter yang juga diterima:
- `orderNumber`
- `nolab`
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/sampling_timestamp" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN_VALUE" \
-d '{"T_OrderHeaderLabNumber":"R2606110001"}'
```
Contoh PHP `curl_init()` lengkap dari generate token sampai ambil data sampling:
```php
<?php
$baseUrl = 'https://devcpone.aplikasi.web.id/one-api/tools/wynacom';
function postJson($url, $payload, $headers = array())
{
$defaultHeaders = array('Content-Type: application/json');
$headers = array_merge($defaultHeaders, $headers);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception('Curl error: ' . $error);
}
curl_close($ch);
$decoded = json_decode($response, true);
if (!is_array($decoded)) {
throw new Exception('Invalid JSON response: ' . $response);
}
return $decoded;
}
// 1. Generate token
$tokenResponse = postJson($baseUrl . '/generate_token', array());
if ($tokenResponse['status'] !== 'OK') {
throw new Exception('Generate token failed: ' . $tokenResponse['message']);
}
$accessToken = $tokenResponse['data']['access_token'];
// 2. Ambil data sampling timestamp
$samplingResponse = postJson(
$baseUrl . '/sampling_timestamp',
array(
'T_OrderHeaderLabNumber' => 'R2606110001'
),
array(
'Authorization: Bearer ' . $accessToken
)
);
if ($samplingResponse['status'] !== 'OK') {
throw new Exception('Get sampling failed: ' . $samplingResponse['message']);
}
print_r($samplingResponse['data']);
```
Contoh response:
```json
{
"status": "OK",
"data": [
{
"sample_station_name": "Sample Station Phlebotomy",
"location_name": "R. SAMPLING",
"cpone_test_code": "10530100",
"cpone_test_name": "Ureum",
"lis_test_code": "00000112",
"sampling_check_in_datetime": "2026-06-11 08:34:26",
"sampling_check_in_userid": "123",
"sampling_check_out_datetime": "2026-06-11 08:40:00",
"sampling_check_out_userid": "123"
}
]
}
```
Data `sampling_timestamp` adalah gabungan `UNION ALL` dari:
- nonlab: `t_samplingso`
- lab: `t_ordersample`
Kolom `sample_station_name` diambil lewat relasi:
```text
t_sampletype -> t_bahan -> t_samplestation
```
Kolom kode:
- `cpone_test_code`: 8 digit depan dari `T_TestSasCode`.
- `lis_test_code`: `nat_testmap.Nat_TestMapCode`.
Untuk lab, jika test adalah anak panel, data dinaikkan ke parent:
```text
child_test.T_TestParentT_TestID != 0 -> pakai parent test
```
Contoh: anak Hematologi Lengkap akan digabung sebagai parent Hematologi Lengkap.
## Glucose Result
Endpoint:
```http
POST /glucose
```
Header:
```http
Authorization: Bearer {access_token}
```
Request body:
```json
{
"T_OrderHeaderLabNumber": "R2606110001"
}
```
Contoh curl:
```bash
curl -X POST "https://devcpone.aplikasi.web.id/one-api/tools/wynacom/glucose" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN_VALUE" \
-d '{"T_OrderHeaderLabNumber":"R2606110001"}'
```
Contoh PHP `curl_init()`:
```php
<?php
$baseUrl = 'https://devcpone.aplikasi.web.id/one-api/tools/wynacom';
$accessToken = 'TOKEN_VALUE';
$ch = curl_init($baseUrl . '/glucose');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'T_OrderHeaderLabNumber' => 'R2606110001'
)));
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$glucoseResponse = json_decode($response, true);
print_r($glucoseResponse);
```
Contoh response:
```json
{
"status": "OK",
"data": [
{
"cpone_test_code": "10530200",
"cpone_test_name": "Glukosa Darah 2 Jam PP",
"lis_test_code": "00000251",
"result_glucosa": "120"
}
]
}
```
Sumber data:
- `order_glucose.OrderGlucoseResult` sebagai `result_glucosa`
- `t_test.T_TestSasCode` sebagai `cpone_test_code`, dipotong 8 digit dari depan
- `t_test.T_TestName` sebagai `cpone_test_name`
- `nat_testmap.Nat_TestMapCode` sebagai `lis_test_code`
## Error Umum
Token tidak dikirim:
```json
{
"status": "ERR",
"message": "Token wajib diisi"
}
```
Token tidak valid atau expired:
```json
{
"status": "ERR",
"message": "Token tidak valid atau sudah expired"
}
```
Nomor order kosong:
```json
{
"status": "ERR",
"message": "Parameter T_OrderHeaderLabNumber wajib diisi"
}
```
Nomor order tidak ditemukan:
```json
{
"status": "ERR",
"message": "Order tidak ditemukan: R2606110001"
}
```