Files
2026-04-27 10:26:26 +07:00

1945 lines
64 KiB
PHP

<?php
/*
For refresh token
https://devpartner.id.meshbio.com/api-management
*/
class Dara_api extends MY_Controller
{
var $endpoint;
var $token_xloc;
var $init_token;
var $bearer_token;
var $pipeline;
function __construct()
{
parent::__construct();
//$this->endpoint = "https://devpartner.id.meshbio.com/";
//$this->endpoint = "https://testpartner.id.meshbio.com/";
$this->endpoint = "https://hs.id.meshbio.com/";
$this->check_token_table();
$sql = "select * from meshbio_token";
$qry = $this->db->query($sql);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => "Get Token Error " . $this->db->error()["message"],
]);
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode([
"status" => "ERR",
"message" => "Get Token Error No Initial Token",
]);
exit();
}
$this->token = $rows[0];
}
function bizone_pajanan($nolab, $meshbioScreenId)
{
$url = $this->endpoint . "api/v1/screenrecord-exposure-history/$meshbioScreenId";
$pajanan = $this->get_pajanan($nolab);
if (count($pajanan) == 0) {
echo json_encode(["status" => "OK", "message" => "Empty Exposure"]);
exit;
}
$param = [
"pipeline" => "pramita.update_exposure_history-v1.0",
"input" => $pajanan
];
$resp = $this->put($url, json_encode($param), $this->token["meshbioTokenAccess"]);
$jresp = json_decode($resp, true);
if (json_last_error() != JSON_ERROR_NONE) {
echo json_encode(["status" => "ERR", "ERR" => "Invalid JSON", "raw" => $resp]);
}
if ($jresp["success"]) {
echo json_encode(["status" => "OK", "raw" => $jresp, "bizone_param" => json_encode($param)]);
exit;
}
echo json_encode(["status" => "ERR", "raw" => $resp, "bizone_param" => json_encode($param)]);
}
function get_pajanan($nolab)
{
$arr = [
"faktor_ergonomi",
"faktor_biologi",
"faktor_fisik",
"faktor_kimia",
"faktor_psikologi",
];
$So_ResultEntryID = $this->get_so_result_entry_id($nolab);
if ($So_ResultEntryID == 0) {
return json_encode([]);
}
$result = [];
foreach ($arr as $s_url) {
$resp = $this->get_fisik_pajanan(
$s_url,
$So_ResultEntryID,
"k3"
);
$result[$s_url] = [];
foreach ($resp as $r) {
$dt = [];
foreach (array_keys($r) as $k) {
if (substr($k, -1) == "1") {
$dt["label"] = $r[$k];
} else if (substr($k, -1) == "2") {
$dt["status"] = $r[$k];
} else if (substr($k, -1) == "3") {
$dt["note"] = $r[$k];
}
}
$result[$s_url][] = $dt;
}
}
return $result;
}
function bizone_health_history($nolab, $meshbioScreenId)
{
$url = $this->endpoint . "api/v1/screenrecord-health-history/$meshbioScreenId";
$history = $this->get_riwayat($nolab);
$param = [
//"pipeline" => "pramita.update_health_history-v1.0",
"pipeline" => "pramita.update_health_history-v2.0",
"input" => $history
];
$resp = $this->put($url, json_encode($param), $this->token["meshbioTokenAccess"]);
$jresp = json_decode($resp, true);
if (json_last_error() != JSON_ERROR_NONE) {
echo json_encode(["status" => "ERR", "ERR" => "Invalid JSON", "raw" => $resp]);
}
if ($jresp["success"]) {
echo json_encode(["status" => "OK", "raw" => $jresp, "bizone_param" => json_encode($param)]);
exit;
}
echo json_encode(["status" => "ERR", "raw" => $resp, "bizone_param" => json_encode($param)]);
}
function get_etnicity($nolab, $debug = "")
{
$So_ResultEntryID = $this->get_so_result_entry_id($nolab);
if ($So_ResultEntryID == 0) {
if ($debug != "") {
echo "No So_ResultEntryID ";
}
return "";
}
$resp = $this->get_fisik("etnis", $So_ResultEntryID, "riwayat");
if (count($resp) > 0 && isset($resp[0]["x1"])) {
if ($debug != "") {
echo "Ethnicity : " . $resp[0]["x1"];
}
return $resp[0]["x1"];
}
}
//v2
function get_riwayat($nolab, $debug = "")
{
$arr = [
"keluhan_saat_ini_new",
"riwayat_obat",
"riwayat_penyakit",
"riwayat_hidup",
"riwayat_keluarga",
"riwayat_imunisasi",
];
$So_ResultEntryID = $this->get_so_result_entry_id($nolab);
if ($So_ResultEntryID == 0) {
if ($debug != "") {
echo "No So_ResultEntryID ";
}
return json_encode([]);
}
$result = [];
foreach ($arr as $s_url) {
$resp = $this->get_fisik($s_url, $So_ResultEntryID, "riwayat");
if ($s_url == "riwayat_imunisasi") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["g1"]), "value" => trim($r["g2"]), "note" => trim($r["g3"])];
}
}
} elseif ($s_url == "keluhan_saat_ini_new") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["a1"]), "value" => trim($r["a2"])];
}
}
} elseif ($s_url == "riwayat_phobia") {
if (count($resp) == 0) {
$result[$s_url] = [];
}
} elseif ($s_url == "riwayat_obat") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["f1"]), "value" => trim($r["f2"])];
}
}
} elseif ($s_url == "riwayat_penyakit") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
if ($debug != "") {
print_r($r);
}
if (true || $debug != "") {
$result[$s_url][] = ["label" => trim($r["c1"]), "value" => trim($r["c2"])];
} else {
$result[$s_url][] = trim($r["c1"]);
}
}
}
} elseif ($s_url == "riwayat_hidup") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["e1"]), "value" => trim($r["e2"])];
}
}
} elseif ($s_url == "riwayat_keluarga") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["d2"]), "value" => trim($r["d1"])];
}
}
}
}
if ($debug != "") {
print_r($result);
echo "\n";
echo json_encode($result, JSON_PRETTY_PRINT);
}
return $result;
}
function get_riwayat_v1($nolab, $debug = "")
{
$arr = [
"keluhan_saat_ini_new",
// "riwayat_phobia",
"riwayat_obat",
"riwayat_penyakit",
"riwayat_hidup",
"riwayat_keluarga",
"riwayat_imunisasi",
];
$So_ResultEntryID = $this->get_so_result_entry_id($nolab);
if ($So_ResultEntryID == 0) {
if ($debug != "") {
echo "No So_ResultEntryID ";
}
return json_encode([]);
}
$result = [];
foreach ($arr as $s_url) {
$resp = $this->get_fisik($s_url, $So_ResultEntryID, "riwayat");
if ($s_url == "riwayat_imunisasi") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["g1"]), "value" => trim($r["g2"]), "note" => trim($r["g3"])];
}
}
} elseif ($s_url == "keluhan_saat_ini_new") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["a1"]), "value" => trim($r["a2"])];
}
}
} elseif ($s_url == "riwayat_phobia") {
if (count($resp) == 0) {
$result[$s_url] = [];
}
} elseif ($s_url == "riwayat_obat") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = ["label" => trim($r["f1"]), "value" => trim($r["f2"])];
}
}
} elseif ($s_url == "riwayat_penyakit") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
if ($debug != "") {
print_r($r);
}
if (true || $debug != "") {
$result[$s_url][] = ["label" => trim($r["c1"]), "value" => trim($r["c2"])];
} else {
$result[$s_url][] = trim($r["c1"]);
}
}
}
} elseif ($s_url == "riwayat_hidup") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = [trim($r["e1"]) => trim($r["e2"])];
}
}
} elseif ($s_url == "riwayat_keluarga") {
if (count($resp) == 0) {
$result[$s_url] = [];
} else {
foreach ($resp as $r) {
$result[$s_url][] = [trim($r["d2"]) => trim($r["d1"])];
}
}
}
}
if ($debug != "") {
print_r($result);
}
return $result;
}
function get_fisik_pajanan(
$param,
$result_entry_id,
$type,
$lang_id = 1,
$debug = ""
) {
$url = "http://localhost/one-api/v1/report/fisik/$param/$result_entry_id/$lang_id/$type/k3";
$resp = $this->get_json_fisik($url);
// if ($debug != "") {
// echo "$url \n";
// print_r($resp);
// echo "\n";
// }
return json_decode($resp, true);
}
function get_fisik(
$param,
$result_entry_id,
$type,
$lang_id = 1,
$debug = ""
) {
$url = "http://localhost/one-api/v1/report/fisik/$param/$result_entry_id/$lang_id/$type";
//echo "$param : $url\n";
$resp = $this->get_json_fisik($url);
// if ($debug != "") {
// echo "url : $url\n";
// print_r($resp);
// echo "\n";
// }
return json_decode($resp, true);
}
function get_json_fisik($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function get_so_result_entry_id($nolab)
{
$sql = "select So_ResultEntryID
from so_resultentry
join t_orderheader on So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderLabNumber = ?
and So_ResultentryIsActive = 'Y'
and So_ResultEntrySo_TemplateName in ('FISIK UMUM',
'FISIK UMUM KONSUL', 'FISIK UMUM K3' )
join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_TestNat_GroupID = 4
order by So_ResultEntryID desc limit 0,1";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo "Error : " . $this->db->error()["message"];
return 0;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return 0;
}
return $rows[0]["So_ResultEntryID"];
}
function bizone_declaration($nolab, $meshbioScreenId)
{
$url = $this->endpoint . "api/v1/screenrecord-declarations/$meshbioScreenId";
$declaration = $this->get_declaration($nolab);
if (count($declaration) == 0) {
echo json_encode(["status" => "OK", "message" => "No Declaration"]);
exit;
//$declaration[] = "no declaration";
}
$param = [
"pipeline" => "pramita.update_declarations-v1.0",
"input" => [
"declarations" => $declaration
]
];
$resp = $this->put($url, json_encode($param), $this->token["meshbioTokenAccess"]);
$jresp = json_decode($resp, true);
if (json_last_error() != JSON_ERROR_NONE) {
echo json_encode(["status" => "ERR", "ERR" => "Invalid JSON", "raw" => $resp, "bizone_param" => $param]);
}
if ($jresp["success"]) {
echo json_encode(["status" => "OK", "raw" => $jresp, "bizone_param" => $param]);
exit;
}
echo json_encode(["status" => "ERR", "raw" => $resp, "bizone_param" => $param]);
}
function get_declaration($nolab)
{
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID,T_OrderReqs
from t_orderheader
join t_orderreq on T_OrderHeaderLabNumber = ?
and T_OrderHeaderID = T_OrderReqT_OrderHeaderID
and T_OrderReqNat_PositionID = 1 and T_OrderReqIsActive = 'Y'";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return [];
}
$reqs = json_decode($rows[0]["T_OrderReqs"], true);
if (count($reqs) == 0) {
return [];
}
$id_reqs = implode(",", $reqs);
$sql = "select * from nat_requirement where Nat_RequirementID in ($id_reqs)";
$qry = $this->db->query($sql);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
$result = [];
foreach ($rows as $r) {
$result[] = $r["Nat_RequirementName"];
}
return $result;
}
function delete_patient_photo($nolab)
{
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, M_PatientIdNumber, meshbioPatientIdentifier,
M_PatientID,M_PatientPhoto
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process"]);
exit;
}
$prm = [
"patientID" => $rows[0]["meshbioPatientIdentifier"],
"photo" => $rows[0]["M_PatientPhoto"],
];
$resp = $this->patient_photo_delete($prm);
echo $resp;
}
function patient_photo_delete($prm)
{
$input = $prm;
$patientID = $input["patientID"];
$url = $this->endpoint . "api/v1/patient/{$patientID}/avatar";
$resp = $this->delete_image($url, $this->token["meshbioTokenAccess"]);
print_r($prm);
echo "\n";
echo "URL: $url\n";
echo "RESP: $resp\n";
echo json_encode($resp);
}
function get_patient_photo($nolab, $debug = "")
{
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, M_PatientIdNumber, meshbioPatientIdentifier,
M_PatientID,M_PatientPhoto
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process"]);
exit;
}
$prm = [
"patientID" => $rows[0]["meshbioPatientIdentifier"],
"photo" => $rows[0]["M_PatientPhoto"],
];
$this->patient_photo_do($prm, $debug);
}
function patient_photo_do($prm, $debug = "")
{
$foto_folder = "/home/one/project/one";
$input = $prm;
$patientID = $input["patientID"];
$photo = $foto_folder . $input["photo"];
$url = $this->endpoint . "api/v1/patient/{$patientID}/avatar";
$data = file_get_contents($photo);
$resp = $this->post_image($url, $data, $this->token["meshbioTokenAccess"], $debug);
if ($debug != "") {
echo "Photo Size : " . strlen($data) . "\n";
}
if (strlen($data) == 0) {
echo json_encode(["status" => "ERR", "message" => "Photo length 0 byte"]);
return;
}
$json = json_decode($resp, true);
if (!$json) {
echo json_encode(["status" => "ERR", "message" => "Invalid JSON", "raw" => $json]);
exit();
}
if ($json["success"]) {
$aws_s3_url = $json["data"]["presigned_url"];
$resp = $this->put_image($aws_s3_url, $data);
$j_resp = json_encode($resp);
if (!$j_resp) {
echo json_encode(["status" => "ERR", "message" => "Invalid JSON", "raw" => $resp]);
} else {
echo json_encode(["status" => "OK", "raw" => $j_resp]);
}
exit;
}
echo json_encode(["status" => "ERR", "message" => "Meshbio S3 Photo Error", "raw" => $json]);
}
function check_order_meshbio($nolab)
{
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
Nat_TestID,
meshbioSessionIdentifier meshbioScreenId,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
and T_OrderHeaderLabNumber = ?
join t_orderdetail on
T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
left join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
left join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo "Err Qry : " . $this->db->error()["message"];
exit;
}
$rows = $qry->result_array();
print_r($rows);
}
function get_order_meshbio_bb($last_day = 3)
{
if ($last_day == 3 || $last_day == "3") {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
meshbioSessionIdentifier meshbioScreenId,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_orderdetail on
( T_OrderHeaderDate + interval ? day > now()
or
( T_OrderHeaderAddonIsComingDate is not null and T_OrderHeaderAddonIsComingDate + interval ? day > now() )
)
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day, $last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
$result[] = $r;
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_meshbio_v2($last_day = 3)
{
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
meshbioSessionIdentifier meshbioScreenId,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_confirm on T_OrderHeaderID = meshbio_confirmT_OrderHeaderID
and meshbio_confirmIsStatus = 'Y'
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
and meshbioSessionhl7status in ('C', 'R')
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => [], "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
$result[] = $r;
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_meshbio($last_day = 3)
{
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
meshbioSessionIdentifier meshbioScreenId,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
and meshbioSessionhl7status in ('C', 'R')
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => [], "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
$result[] = $r;
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_create_screen_bb($last_day = 3)
{
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioSessionIdentifier is null,'N','Y') registerSessionMeshbio,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_orderdetail on
( T_OrderHeaderDate + interval ? day > now()
or
( T_OrderHeaderAddonIsComingDate is not null and T_OrderHeaderAddonIsComingDate + interval ? day > now() )
)
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
left join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day, $last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => [], "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
if ($r["registerSessionMeshbio"] == "N") {
$result[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_create_screen_v2($last_day = 3)
{
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioSessionIdentifier is null,'N','Y') registerSessionMeshbio,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join meshbio_confirm on T_OrderHeaderID = meshbio_confirmT_OrderHeaderID
and meshbio_confirmIsStatus = 'Y'
left join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => [], "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
if ($r["registerSessionMeshbio"] == "N") {
$result[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_create_screen($last_day = 3)
{
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioSessionIdentifier is null,'N','Y') registerSessionMeshbio,
meshbioPatientIdentifier patientMeshbioId
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
left join meshbio_session on T_OrderHeaderID = meshbioSessionT_OrderHeaderID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => [], "query" => $this->db->last_query()]);
exit;
}
$result = [];
foreach ($rows as $r) {
if ($r["registerSessionMeshbio"] == "N") {
$result[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "query" => $this->db->last_query()]);
}
function get_order_create_patient_bb($last_day = 3)
{
/*
40122100, Health Analysis 1
40122200 : Health Analysis 2
40122300 : Health Analysis 3
*/
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioPatientIdentifier is null,'N','Y') registerPatientMeshbio,
ifnull(meshbioPatientIdentifier,'') patientMeshbioId,
T_OrderHeaderAddonVerificationDone,
T_OrderHeaderAddonValidationDone
from
t_orderheader
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_orderdetail on
( T_OrderHeaderDate + interval ? day > now()
or
( T_OrderHeaderAddonIsComingDate is not null and T_OrderHeaderAddonIsComingDate + interval ? day > now() )
)
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process"]);
exit;
}
$result = [];
$result_created = [];
$xdbg = [];
foreach ($rows as $r) {
$xdbg[] = $r;
if (
$r["registerPatientMeshbio"] == "N"
&& ($r["T_OrderHeaderAddonVerificationDone"] != "N" ||
$r["T_OrderHeaderAddonValidationDone"] != "N"
)
) {
$result[] = $r;
}
if ($r["registerPatientMeshbio"] == "Y") {
$result_created[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "meshbio_created" => $result_created, "xdbg" => $xdbg]);
}
// dengan confirm order
function get_order_create_patient_v2($last_day = 3)
{
/*
40122100, Health Analysis 1
40122200 : Health Analysis 2
40122300 : Health Analysis 3
*/
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioPatientIdentifier is null,'N','Y') registerPatientMeshbio,
ifnull(meshbioPatientIdentifier,'') patientMeshbioId,
T_OrderHeaderAddonVerificationDone,
T_OrderHeaderAddonValidationDone
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join meshbio_confirm on T_OrderHeaderID = meshbio_confirmT_OrderHeaderID
and meshbio_confirmIsStatus = 'Y'
left join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"], "data" => []]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => []]);
exit;
}
$result = [];
$result_created = [];
$xdbg = [];
foreach ($rows as $r) {
$xdbg[] = $r;
if (
$r["registerPatientMeshbio"] == "N"
&& ($r["T_OrderHeaderAddonVerificationDone"] != "N" ||
$r["T_OrderHeaderAddonValidationDone"] != "N"
)
) {
$result[] = $r;
}
if ($r["registerPatientMeshbio"] == "Y") {
$result_created[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "meshbio_created" => $result_created, "xdbg" => $xdbg]);
}
function get_order_create_patient($last_day = 3)
{
/*
40122100, Health Analysis 1
40122200 : Health Analysis 2
40122300 : Health Analysis 3
*/
if ($last_day == 3) {
$last_day = 60;
}
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$arr_nat_test_meshbio = ["'40122100'", "'40122200'", "'40122300'"];
$nat_test_meshbio = implode(",", $arr_nat_test_meshbio);
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,
if(meshbioPatientIdentifier is null,'N','Y') registerPatientMeshbio,
ifnull(meshbioPatientIdentifier,'') patientMeshbioId,
T_OrderHeaderAddonVerificationDone,
T_OrderHeaderAddonValidationDone
from
t_orderheader
join t_orderdetail on T_OrderHeaderDate + interval ? day > now()
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestCode in ($nat_test_meshbio)
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
group by T_OrderHeaderId";
$qry = $this->db->query($sql, [$last_day]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"], "data" => []]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "OK", "message" => "No Order Process", "data" => []]);
exit;
}
$result = [];
$result_created = [];
$xdbg = [];
foreach ($rows as $r) {
$xdbg[] = $r;
if (
$r["registerPatientMeshbio"] == "N"
&& ($r["T_OrderHeaderAddonVerificationDone"] != "N" ||
$r["T_OrderHeaderAddonValidationDone"] != "N"
)
) {
$result[] = $r;
}
if ($r["registerPatientMeshbio"] == "Y") {
$result_created[] = $r;
}
}
echo json_encode(["status" => "OK", "data" => $result, "meshbio_created" => $result_created, "xdbg" => $xdbg]);
}
function get_branch()
{
$sql = "select M_BranchCode,M_BranchName from m_branch
where M_BranchIsDefault = 'Y' and M_BranchIsActive='Y'";
$qry = $this->db->query($sql);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "ERR", "message" => "No Default Branch"]);
exit;
}
return [$rows[0]["M_BranchCode"], $rows[0]["M_BranchName"]];
}
function bizone_patient($nolab, $debug = "")
{
list($branchCode, $branchName) = $this->get_branch();
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, T_OrderHeaderDate,
M_PatientM_SexID, fn_get_patient_atribute(M_PatientID) patient,
M_PatientNoreg,M_MouName, M_CompanyName, M_CompanyNumber, M_PatientName,
M_PatientIdNumber, M_PatientM_IdTypeID, M_PatientDOB, M_MouM_OmzetTypeID
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join m_mou on T_OrderHeaderM_MouID = M_MouID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "ERR", "message" => "Nolab $nolab not found."]);
exit;
}
$patientName = $rows[0]["M_Patient"];
$patient = json_decode($rows[0]["patient"], true);
if ($patient) {
$patientName = $patient["patient_fullname"];
}
unset($rows[0]["patient"]);
$result = $rows[0];
$result["patient"] = $patientName;
$sexName = "Others";
if ($result["M_PatientM_SexID"] == 1) {
$sexName = "Male";
} else if ($result["M_PatientM_SexID"] == 1) {
$sexName = "Female";
}
$corporateCode = $result["M_CompanyNumber"];
if ($result["M_MouM_OmzetTypeID"] == 1) $corporateCode = "";
if ($result["M_MouM_OmzetTypeID"] == 2) $corporateCode = "";
$param = [
"idtype" => "NIK",
"sampleid" => $result["M_PatientIdNumber"],
"organization" => "Pramita",
"name" => $patientName,
"sex" => $sexName,
"dob" => $result["M_PatientDOB"],
"alternateid" => $result["M_PatientNoreg"],
"corporateCode" => $corporateCode,
];
$this->patient_create_do($param, $debug);
}
function patient_create_do($prm, $debug = "")
{
$pipeline = "meshbio.createpatient-v1.0";
$input = $prm;
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
//https://devpartner.id.meshbio.com/api/v1/patient
$url = $this->endpoint . "api/v1/patient";
$resp = $this->post($url, $j_param, $this->token["meshbioTokenAccess"]);
$org_resp = $resp;
$json = json_decode($resp, true);
if (!$json) {
echo json_encode([
"status" => "ERR", "message" => "Invalid JSON Response",
"raw" => $resp
]);
return;
} else {
if ($json["success"] != "") {
//update patient
$patient = $json["data"];
$sampleid = $input["sampleid"];
if ($sampleid != "") {
$arr = [
"meshbioPatientIdentifier" => $patient["id"],
"meshbioPatientNIK" => $sampleid,
"meshbioPatientBizonePID" => $input["alternateid"],
"meshbioPatientUrl" => $patient["url"],
];
} else {
$arr = [
"meshbioPatientIdentifier" => $patient["id"],
];
}
$resp = $this->insert_or_update("meshbio_patient", $arr, [
"meshbioPatientIdentifier",
]);
$resp["raw"] = $json;
echo json_encode($resp);
exit();
}
echo json_encode(["status" => "OK", "raw" => $json]);
}
}
function patient_create()
{
$pipeline = "meshbio.createpatient-v1.0";
$input = $this->get_param();
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
//https://devpartner.id.meshbio.com/api/v1/patient
$url = $this->endpoint . "api/v1/patient";
$resp = $this->post($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo $resp;
} else {
if ($json["success"] != "") {
//update patient
$patient = $json["data"];
$sampleid = $input["sampleid"];
if ($sampleid != "") {
$arr = [
"meshbioPatientIdentifier" => $patient["id"],
"meshbioPatientNIK" => $sampleid,
"meshbioPatientBizonePID" => $input["alternateid"],
"meshbioPatientUrl" => $patient["url"],
];
} else {
$arr = [
"meshbioPatientIdentifier" => $patient["id"],
];
}
$resp = $this->insert_or_update("meshbio_patient", $arr, [
"meshbioPatientIdentifier",
]);
echo json_encode($resp);
exit();
}
echo json_encode($json);
}
}
function bizone_screen($nolab, $debug = "")
{
list($branchCode, $branchName) = $this->get_branch();
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, T_OrderHeaderDate,
M_PatientIdNumber, M_PatientM_IdTypeID, meshbioPatientIdentifier,
fn_get_doctor_fullname(T_OrderHeaderPjM_DoctorID) doctorInCharge,
fn_get_doctor_fullname(T_SamplingSoM_DoctorID) doctorExaminator,
if(Mcu_ResumeT_OrderHeaderID is null, '', fn_get_doctor_fullname(Mcu_ResumeM_DoctorID)) doctorGp,
M_MouM_OmzetTypeID, M_CompanyNumber , M_MouName
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join m_mou on T_OrderHeaderM_MouID = M_MouID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
join t_samplingso on T_OrderHeaderID = T_SamplingSoT_OrderHeaderID and T_SamplingSoT_SampleStationID = 7
left join mcu_resume on T_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "ERR", "message" => "Nolab $nolab not registered to meshbio.\nPastikan dokter GP sudah valid."]);
exit;
}
$data = $rows[0];
$referal = "Others";
if ($data["M_MouM_OmzetTypeID"] == 1) $referal = "Self";
if ($data["M_MouM_OmzetTypeID"] == 2) $referal = "Clinician";
if ($data["M_MouM_OmzetTypeID"] == 3) $referal = "Corporate";
$doctor = "";
$doctorExaminator = $data["doctorExaminator"];
if ($data["doctorGp"] != "") {
$doctor = $data["doctorGp"];
}
$param = [
"T_OrderHeaderID" => $data["T_OrderHeaderID"],
"patientid" => $data["meshbioPatientIdentifier"],
"organization" => "Pramita",
"screentitle" => $data["T_OrderHeaderLabNumberExt"],
// "screentitle" => $data["T_OrderHeaderLabNumber"] . " / " . $data["T_OrderHeaderLabNumberExt"],
"branchCode" => $branchCode,
"package" => $data["M_MouName"],
"doctorincharge" => $doctor,
"physicalExamDoctor" => $doctorExaminator,
"screenReferralType" => $referal,
"corporateDetails" => [
"corporateCode" => $referal == "Self" ? "" : $data["M_CompanyNumber"],
"batchCode" => ""
]
];
if ($debug != "") {
echo "DEBUG : \n";
print_r($param);
exit;
}
$this->screen_create_do($param);
}
function bizone_screen_update($nolab, $debug = "")
{
list($branchCode, $branchName) = $this->get_branch();
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, T_OrderHeaderDate,
M_PatientIdNumber, M_PatientM_IdTypeID, meshbioSessionIdentifier,
fn_get_doctor_fullname(T_OrderHeaderPjM_DoctorID) doctorInCharge,
fn_get_doctor_fullname(T_SamplingSoM_DoctorID) doctorExaminator,
if(Mcu_ResumeT_OrderHeaderID is null, '', fn_get_doctor_fullname(Mcu_ResumeM_DoctorID)) doctorGp,
M_MouM_OmzetTypeID, M_CompanyNumber , M_MouName
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join meshbio_session on meshbioSessionT_OrderHeaderID = T_OrderHeaderID
join m_mou on T_OrderHeaderM_MouID = M_MouID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
join t_samplingso on T_OrderHeaderID = T_SamplingSoT_OrderHeaderID and T_SamplingSoT_SampleStationID = 7
left join mcu_resume on T_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(["status" => "ERR", "message" => "Nolab $nolab not registered to meshbio."]);
exit;
}
if ($debug != "") {
}
$data = $rows[0];
$referal = "Others";
if ($data["M_MouM_OmzetTypeID"] == 1) $referal = "Self";
if ($data["M_MouM_OmzetTypeID"] == 2) $referal = "Clinician";
if ($data["M_MouM_OmzetTypeID"] == 3) $referal = "Corporate";
$doctor = "";
if ($data["doctorGp"] != "") {
$doctor = $data["doctorGp"];
}
$doctorExaminator = $data["doctorExaminator"];
/* tanpa paket */
$param = [
"id" => $data["meshbioSessionIdentifier"],
"organization" => "Pramita",
//"screentitle" => $data["T_OrderHeaderLabNumber"] . " / " . $data["T_OrderHeaderLabNumberExt"],
"screentitle" => $data["T_OrderHeaderLabNumberExt"],
"branchCode" => $branchCode,
// "package" => $data["M_MouName"],
"doctorincharge" => $doctor,
"physicalExamDoctor" => $doctorExaminator,
"screenReferralType" => $referal,
"corporateDetails" => [
"corporateCode" => $referal == "Self" ? "" : $data["M_CompanyNumber"],
"batchCode" => ""
]
];
$this->screen_update_do($param);
}
function screen_update_do($input)
{
$xid = $input["id"];
unset($input["id"]);
$pipeline = "pramita.update_screenrecord-v1.0";
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
$url = $this->endpoint . "api/v1/screenrecord/$xid";
$resp = $this->put($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo json_encode(["status" => "ERR", "message" => "Invalid JSON", "raw" => $resp, "payload" => $param]);
} else {
if ($json["success"] != "") {
echo json_encode(["status" => "OK", "message" => "Screen Updated", "payload" => $param]);
exit();
}
echo json_encode(["status" => "ERR", "message" => "Meshbio not succeed", "raw" => $json, "payload" => $param]);
}
}
function screen_create_do($input)
{
$pipeline = "pramita.create_screenrecord-v1.0";
$orderHeaderID = $input["T_OrderHeaderID"];
unset($input["T_OrderHeaderID"]);
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
$url = $this->endpoint . "api/v1/screenrecord";
$resp = $this->post($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo json_encode([
"status" => "ERR",
"message" => "Invalid JSON", "raw" => $resp
]);
exit();
} else {
if ($json["success"] != "") {
//update patient
$result = $json["data"];
$arr = [
"meshbioSessionIdentifier" => $result["id"],
"meshbioSessionT_OrderHeaderID" => $orderHeaderID,
"meshbioSessionUrl" => $result["url"],
];
$resp = $this->insert_or_update("meshbio_session", $arr, [
"meshbioSessionIdentifier",
]);
$resp["raw"] = $json;
echo json_encode($resp);
exit();
} else {
//already exists
if ($json["info"]["error_code"] == "409014") {
$result = $json["data"];
$arr = [
"meshbioSessionIdentifier" => $result["id"],
"meshbioSessionT_OrderHeaderID" => $orderHeaderID,
"meshbioSessionUrl" => $result["url"],
];
$resp = $this->insert_or_update("meshbio_session", $arr, [
"meshbioSessionIdentifier",
]);
$resp["raw"] = $json;
echo json_encode($resp);
exit();
}
}
echo json_encode([
"status" => "ERR",
"message" => "Meshbio not succeed",
"raw" => $json
]);
}
/*
{
"pipeline": "meshbio.create_screenrecord-v1.0",
"input": {
"patientid": "6358dd99c3daa7799c504ed2",
"organization": "Pramita",
"screentitle": "001LB",
"clinicLocation": "LB",
"package": "PACKAGENAME NEW",
"doctorincharge": "Dr. Name",
"screenReferralType": "Clinician",
"corporateDetails": {
"corporateCode": "004",
"batchCode": ""
}
}
}
*/
}
function screen_create()
{
$pipeline = "pramita.create_screenrecord-v1.0";
$input = $this->get_param();
$orderHeaderID = $input["T_OrderHeaderID"];
unset($input["T_OrderHeaderID"]);
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
$url = $this->endpoint . "api/v1/screenrecord";
$resp = $this->post($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo $resp;
} else {
if ($json["success"] != "") {
//update patient
$result = $json["data"];
$arr = [
"meshbioSessionIdentifier" => $result["id"],
"meshbioSessionT_OrderHeaderID" => $orderHeaderID,
"meshbioSessionUrl" => $result["url"],
];
$resp = $this->insert_or_update("meshbio_session", $arr, [
"meshbioSessionIdentifier",
]);
echo json_encode($resp);
exit();
}
echo json_encode($json);
}
/*
{
"pipeline": "meshbio.create_screenrecord-v1.0",
"input": {
"patientid": "6358dd99c3daa7799c504ed2",
"organization": "Pramita",
"screentitle": "001LB",
"clinicLocation": "LB",
"package": "PACKAGENAME NEW",
"doctorincharge": "Dr. Name",
"screenReferralType": "Clinician",
"corporateDetails": {
"corporateCode": "004",
"batchCode": ""
}
}
}
*/
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function bizone_patient_update($nolab)
{
list($branchCode, $branchName) = $this->get_branch();
$sql = "select T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
T_OrderHeaderID, T_OrderHeaderDate,
M_PatientM_SexID, fn_get_patient_atribute(M_PatientID) patient,
M_PatientNoreg,M_MouName, M_CompanyName, M_CompanyNumber, M_PatientName,
M_PatientIdNumber, M_PatientM_IdTypeID, meshbioPatientIdentifier, M_PatientDOB
from t_orderheader
join m_patient on T_OrderHeaderLabNumber = ?
and T_OrderHeaderM_PatientID = M_PatientID
join meshbio_patient on M_PatientNoreg = meshbioPatientBizonePID
join m_mou on T_OrderHeaderM_MouID = M_MouID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID";
$qry = $this->db->query($sql, [$nolab]);
if (!$qry) {
echo json_encode(["status" => "ERR", "message" => $this->db->error()["message"]]);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode([
"status" => "ERR",
"message" => "Nolab $nolab not found."
]);
exit;
}
$patientName = $rows[0]["M_Patient"];
$patient = json_decode($rows[0]["patient"], true);
if ($patient) {
$patientName = $patient["patient_fullname"];
}
unset($rows[0]["patient"]);
$result = $rows[0];
$result["patient"] = $patientName;
$sexName = "Others";
if ($result["M_PatientM_SexID"] == 1) {
$sexName = "Male";
} else if ($result["M_PatientM_SexID"] == 2) {
$sexName = "Female";
}
$etnicity = trim($this->get_etnicity($nolab));
if ($etnicity == "") {
echo json_encode([
"status" => "ERR",
"message" => "Nolab $nolab, etnis belum di set."
]);
exit;
}
$param = [
"idtype" => "NIK",
"sampleid" => $result["M_PatientIdNumber"],
"name" => $patientName,
"sex" => $sexName,
"ethnicity" => $etnicity,
"patientID" => $result["meshbioPatientIdentifier"],
"dob" => $result["M_PatientDOB"],
"alternateid" => $result["M_PatientNoreg"],
"corporateCode" => $result["M_CompanyNumber"],
];
$this->patient_update_do($param);
}
function patient_update_do($prm)
{
$input = $prm;
$patientID = $input["patientID"];
unset($input["patientID"]);
$pipeline = "meshbio.updatepatient-v1.0";
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
$url = $this->endpoint . "api/v1/patient/{$patientID}";
$resp = $this->put($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo json_encode(["status" => "ERR", "message" => "Invalid Json", "raw" => $resp, "payload" => $param]);
exit();
}
echo json_encode(["status" => "OK", "raw" => $resp, "payload" => $param]);
}
function patient_update()
{
$input = $this->get_param();
$patientID = $input["patientID"];
unset($input["patientID"]);
$pipeline = "meshbio.updatepatient-v1.0";
$param = [
"pipeline" => $pipeline,
"input" => $input,
];
$j_param = json_encode($param);
$url = $this->endpoint . "api/v1/patient/{$patientID}";
$resp = $this->put($url, $j_param, $this->token["meshbioTokenAccess"]);
$json = json_decode($resp, true);
if (!$json) {
echo $resp;
exit();
}
echo json_encode($json);
}
function patient_find($patientID)
{
$url =
$this->endpoint .
"api/v1/patient/find-one?patientid={$patientID}";
$token = $this->token["meshbioTokenAccess"];
$resp = $this->get($url, $token);
$json = json_decode($resp, true);
echo json_encode($json);
}
function refresh_token()
{
$url = $this->endpoint . "auth/v1/refreshtoken";
$token = $this->token["meshbioTokenRefresh"];
$param = http_build_query(["refresh_token" => $token]);
$resp = $this->post_xmod($url, $param);
$jresp = json_decode($resp, true);
$json = $jresp["data"];
if ($json["refresh_token"] != "") {
$arr = [
"meshbioTokenID" => 1,
"meshbioTokenRefresh" => $json["refresh_token"],
"meshbioTokenAccess" => $json["access_token"],
"meshbioTokenType" => $json["token_type"],
"meshbioTokenExpiry" => $json["expires_in"],
"meshbioTokenIdToken" => $json["id_token"],
];
$resp = $this->insert_or_update("meshbio_token", $arr, ["meshbioTokenID"]);
echo json_encode($resp);
} else {
echo $resp;
}
}
public function get($url, $token)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Authorization: Bearer $token",
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo "URL : $url \n";
echo "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
return "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}
public function post_xmod($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}
public function put_image($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: image/jpeg",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
$resp_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($resp_code != "200") {
return "ERROR AWS [$url] : $resp_code \n";
}
curl_close($ch);
return ["status" => "OK", "code" => $resp_code];
}
public function put($url, $data, $token)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Content-Length: " . strlen($data),
"Authorization: Bearer $token",
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}
public function delete_image($url, $token)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
// "Content-Type: image/jpeg",
// "Content-Length: " . strlen($data),
"Authorization: Bearer $token",
]);
$result = curl_exec($ch);
$resp_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($resp_code != "200") {
return ["status" => "ERR", "code" => $resp_code];
}
return ["status" => "OK", "code" => $resp_code];
}
public function post_image($url, $data, $token, $debug = "")
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: image/jpeg",
"Content-Length: " . strlen($data),
"Authorization: Bearer $token",
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
}
if ($debug != "") {
$curl_info = curl_getinfo($ch);
echo "DEBUG Detail header:\n";
print_r($curl_info);
echo "\n";
echo "Raw Response:\n";
echo $result;
echo "\n";
}
curl_close($ch);
return $result;
}
public function post($url, $data, $token)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Content-Length: " . strlen($data),
"Authorization: Bearer $token",
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR DARA API [$url] : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}
function check_token_table()
{
$sql = "select count(*) from meshbio_token";
$qry = $this->db->query($sql);
if (!$qry) {
$sql = "create table meshbio_token(
meshbioTokenID int not null auto_increment primary key,
meshbioTokenAccess varchar(64),
meshbioTokenRefresh varchar(64),
meshbioTokenType varchar(64),
meshbioTokenExpiry int,
meshbioTokenIdToken Text,
meshbioTokenCreated datetime default current_timestamp(),
meshbioTokenLastUpdated datetime default current_timestamp()
on update current_timestamp()
)";
$qry = $this->db->query($sql);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" =>
"ERR Create Table mesbio_token : " .
$this->db->error()["message"],
]);
exit();
}
}
}
function insert_or_update($table, $dt, $keys)
{
$s_where = "";
$param = [];
foreach ($keys as $k) {
if ($s_where != "") {
$s_where .= " and ";
}
$s_where .= " $k = ?";
$param[] = $dt[$k];
}
$sql = "select count(*) as total
from $table
where $s_where ";
$qry = $this->db->query($sql, $param);
if (!$qry) {
return [
"status" => "ERR",
"message" =>
$this->db->error()["message"] .
"|" .
$this->db->last_query(),
];
}
$rows = $qry->result_array();
$status = "Insert";
if (count($rows) > 0) {
if ($rows[0]["total"] > 0) {
foreach ($keys as $k) {
$this->db->where($k, $dt[$k]);
}
$qry = $this->db->update($table, $dt);
if (!$qry) {
return [
"status" => "ERR",
"message" =>
"ERR Update : " .
$this->db->error()["message"] .
"|" .
$this->db->last_query(),
];
}
$status = "Update";
} else {
//insert
$qry = $this->db->insert($table, $dt);
if (!$qry) {
return [
"status" => "ERR",
"message" =>
"ERR Insert : " .
$this->db->error()["message"] .
"|" .
$this->db->last_query(),
];
}
}
} else {
//insert
$qry = $this->db->insert($table, $dt);
if (!$qry) {
return [
"status" => "ERR",
"message" =>
"ERR Insert : " .
$this->db->error()["message"] .
"|" .
$this->db->last_query(),
];
}
}
return ["status" => "OK", "message" => $status];
}
}
/*
create table meshbio_patient(
meshbioPatientID int not null auto_increment primary key,
meshbioPatientIdentifier varchar(32),
meshbioPatientNIK varchar(20),
meshbioPatientBizonePID varchar(30),
meshbioPatientUrl varchar(300),
meshbioPatientIsActive varchar(1) default 'Y',
meshbioPatientCreated datetime default current_timestamp(),
meshbioPatientLastUpdated datetime default current_timestamp() on update current_timestamp(),
key(meshbioPatientBizonePID),
key(meshbioPatientNIK),
key(meshbioPatientSampleID)
);
alter table meshbio_patient add meshbioPatientUrl varchar(300), add key(meshbioPatientUrl);
create table meshbio_token(
meshbioTokenID int not null auto_increment primary key,
meshbioTokenAccess varchar(64),
meshbioTokenRefresh varchar(64),
meshbioTokenType varchar(64),
meshbioTokenExpiry int,
meshbioTokenIdToken Text,
meshbioTokenCreated datetime default current_timestamp(),
meshbioTokenLastUpdated datetime default current_timestamp()
on update current_timestamp(),
);
create table meshbio_session(
meshbioSessionID int not null auto_increment primary key,
meshbioSessionT_OrderHeaderID int,
meshbioSessionIdentifier varchar(32),
meshbioSessionUrl varchar(100),
meshbioSessionCreated datetime default current_timestamp(),
meshbioSessionLastUpdated datetime default current_timestamp()
on update current_timestamp(),
key(meshbioSessionT_OrderHeaderID),
key(meshbioSessionIdentifier),
);
*/
/*
-d '{
"idtype": "NIK",
"sampleid": "1234567890123456",
"name": "Test Patient JOKO",
"sex": "Male",
"dob": "2010-08-08",
"ethnicity": "Malay",
"nationality": "Indonesian",
"allergy": "",
"mobile": "+6288888888",
"email": "testpatient@domain.com",
"organization": "Pramita",
"address": "",
"postal_code": ""
}'
{"access_token": "5e611ef3c6d14f82bce9793a80fc34e3", "refresh_token": "a927b3dc580148aeb6a18d4971d9460c", "token_type": "bearer", "expires
_in": 604800, "id_token": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vb2lkYy5tZXNoYmlvLmNvbS9vcGVuaWQiLCJzdWIiOiI5MTIiLCJhdWQiOiIxNDkxOTAiLC
JleHAiOjE2NjQyNTkzMTMsImlhdCI6MTY2NDI1ODcxMywiYXV0aF90aW1lIjoxNjY0MTU2NTczLCJhdF9oYXNoIjoiVGpZZVBrSjYzN19SYWY3RnUtQXdFQSJ9.QH5j0dmprrcLzKH
YfeMcEGV16KatjOo8-jYuW_YDtFs"}{"status":"OK","message":"Update"}⏎
*/