392 lines
14 KiB
PHP
392 lines
14 KiB
PHP
<?php
|
|
class Riwayat_fitri extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "ETL MCU RIWAYAT";
|
|
}
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function generate($mgmMcuID, $orderHeaderID)
|
|
{
|
|
$url = "http://localhost/one-api/etl/mgmmcu_nonlab/json/" . $orderHeaderID;
|
|
$get_content = file_get_contents($url);
|
|
$json = json_decode($get_content, true);
|
|
// print_r($json);
|
|
// exit;
|
|
$this->generate_kebiasaan_hidup($mgmMcuID, $orderHeaderID, $json);
|
|
$this->generate_konsumsi_obat($mgmMcuID, $orderHeaderID, $json);
|
|
$this->generate_imunisasi($mgmMcuID, $orderHeaderID, $json);
|
|
}
|
|
|
|
function update_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode)
|
|
{
|
|
$sql = "UPDATE one_etl.mgm_header SET
|
|
Mgm_HeaderIsActive = 'N'
|
|
WHERE Mgm_HeaderMgm_McuID = ? AND
|
|
Mgm_HeaderT_OrderHeaderID = ? AND Mgm_HeaderNat_TestCode = ?";
|
|
$qry = $this->db->query($sql, array(
|
|
$mgmMcuID,
|
|
$orderHeaderID,
|
|
$natTestCode
|
|
));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
function update_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode)
|
|
{
|
|
$sql_select_header = "SELECT Mgm_HeaderID
|
|
FROM one_etl.mgm_header
|
|
WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderT_OrderHeaderID = ?
|
|
AND Mgm_HeaderNat_TestCode = ? AND Mgm_HeaderIsActive = 'N'
|
|
ORDER BY Mgm_HeaderID DESC";
|
|
$qry_select_header = $this->db->query($sql_select_header, array(
|
|
$mgmMcuID,
|
|
$orderHeaderID,
|
|
$natTestCode
|
|
));
|
|
if ($qry_select_header) {
|
|
$rows = $qry_select_header->result_array();
|
|
} else {
|
|
$this->sys_error_db("select mgm_header", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if (count($rows) > 0) {
|
|
$mgmHeaderID = $rows[0]["Mgm_HeaderID"];
|
|
|
|
$sql_upate_riwayat = "UPDATE one_etl.mgm_riwayat
|
|
SET Mgm_RiwayatIsActive = 'N'
|
|
WHERE Mgm_RiwayatMgm_HeaderID = ?";
|
|
$qry_update_detail = $this->db->query($sql_upate_riwayat, array(
|
|
$mgmHeaderID
|
|
));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry_update_detail) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
function insert_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode)
|
|
{
|
|
$query = "SELECT COUNT(*) as exist FROM one_etl.mgm_header WHERE Mgm_HeaderIsActive = 'Y'
|
|
AND Mgm_HeaderMgm_McuID = '{$mgmMcuID}'
|
|
AND Mgm_HeaderT_OrderHeaderID = '{$orderHeaderID}'
|
|
AND Mgm_HeaderNat_TestCode = '{$natTestCode}'";
|
|
$exist_name = $this->db->query($query)->row()->exist;
|
|
if($exist_name == 0){
|
|
$sql = "INSERT INTO one_etl.mgm_header(
|
|
Mgm_HeaderMgm_McuID,
|
|
Mgm_HeaderT_OrderHeaderID,
|
|
Mgm_HeaderNat_TestCode,
|
|
Mgm_HeaderType,
|
|
Mgm_HeaderIsNormal,
|
|
Mgm_HeaderIsActive,
|
|
Mgm_HeaderCreated,
|
|
Mgm_HeaderLastUpdated) VALUES(?,?,?,'R','Y','Y',NOW(),NOW())";
|
|
$qry = $this->db->query($sql, array(
|
|
$mgmMcuID,
|
|
$orderHeaderID,
|
|
$natTestCode
|
|
));
|
|
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function insert_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode, $mcuRiwayatID, $mcuRiwayatGroupID)
|
|
{
|
|
$query = "SELECT COUNT(*) as exist FROM one_etl.mgm_header WHERE Mgm_HeaderIsActive = 'Y'
|
|
AND Mgm_HeaderMgm_McuID = '{$mgmMcuID}'
|
|
AND Mgm_HeaderT_OrderHeaderID = '{$orderHeaderID}'
|
|
AND Mgm_HeaderNat_TestCode = '{$natTestCode}'";
|
|
$exist_name = $this->db->query($query)->row()->exist;
|
|
if($exist_name == 0){
|
|
$sql = "INSERT INTO one_etl.mgm_header(
|
|
Mgm_HeaderMgm_McuID,
|
|
Mgm_HeaderT_OrderHeaderID,
|
|
Mgm_HeaderNat_TestCode,
|
|
Mgm_HeaderType,
|
|
Mgm_HeaderIsNormal,
|
|
Mgm_HeaderIsActive,
|
|
Mgm_HeaderCreated,
|
|
Mgm_HeaderLastUpdated) VALUES(?,?,?,'R','N','Y',NOW(),NOW())";
|
|
$qry = $this->db->query($sql, array(
|
|
$mgmMcuID,
|
|
$orderHeaderID,
|
|
$natTestCode
|
|
));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
|
|
$insert_mgm_header_id = $this->db->insert_id();
|
|
|
|
}else{
|
|
$query = "SELECT Mgm_HeaderID FROM one_etl.mgm_header WHERE Mgm_HeaderIsActive = 'Y'
|
|
AND Mgm_HeaderMgm_McuID = '{$mgmMcuID}'
|
|
AND Mgm_HeaderT_OrderHeaderID = '{$orderHeaderID}'
|
|
AND Mgm_HeaderNat_TestCode = '{$natTestCode}'";
|
|
$insert_mgm_header_id = $this->db->query($query)->row()->Mgm_HeaderID;
|
|
}
|
|
$query = "SELECT COUNT(*) as exist FROM one_etl.mgm_riwayat WHERE Mgm_RiwayatIsActive = 'Y'
|
|
AND Mgm_RiwayatMgm_HeaderID = '{$insert_mgm_header_id}'
|
|
AND Mgm_RiwayatMcu_RiwayatID = '{$mcuRiwayatID}'
|
|
AND Mgm_RiwayatMcu_RiwayatGroupID = '{$mcuRiwayatGroupID}'";
|
|
$exist_riwayat = $this->db->query($query)->row()->exist;
|
|
if($exist_riwayat == 0){
|
|
// insert di mgm_riwayat
|
|
$sql_riwayat = "INSERT INTO one_etl.mgm_riwayat(
|
|
Mgm_RiwayatMgm_HeaderID,
|
|
Mgm_RiwayatMcu_RiwayatID,
|
|
Mgm_RiwayatMcu_RiwayatGroupID,
|
|
Mgm_RiwayatCreated,
|
|
Mgm_RiwayatLastUpdated) VALUES(?,?,?,NOW(),NOW())";
|
|
$qry_riwayat = $this->db->query($sql_riwayat, array(
|
|
$insert_mgm_header_id,
|
|
$mcuRiwayatID,
|
|
$mcuRiwayatGroupID,
|
|
));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry_riwayat) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
function generate_kebiasaan_hidup($mgmMcuID, $orderHeaderID, $json)
|
|
{
|
|
$this->db->trans_begin();
|
|
|
|
$have_kebiasaan_hidup = false;
|
|
$mcuRiwayatID = 0;
|
|
$mcuRiwayatGroupID = 0;
|
|
$natTestCode = "";
|
|
|
|
$title = "RIWAYAT KEBIASAAN HIDUP";
|
|
// update mgm header
|
|
$this->update_mgm_header($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
// update mgm detail
|
|
$this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
foreach ($json as $key => $value) {
|
|
if ($value["title"] == "RIWAYAT KEBIASAAN HIDUP" && $value["chx"] == 1) {
|
|
$have_kebiasaan_hidup = true;
|
|
$segment = $value["segment_name"];
|
|
$riwayat = $value["label"];
|
|
$natTestCode = $value["title"];
|
|
$sql = "SELECT Mcu_RiwayatID,
|
|
Mcu_RiwayatName,
|
|
Mcu_RiwayatMcu_RiwayatGroupID
|
|
FROM one_etl.mcu_riwayat
|
|
WHERE Mcu_RiwayatIsActive = 'Y'
|
|
AND Mcu_RiwayatSegmentName = ?
|
|
AND Mcu_RiwayatName = ?";
|
|
$qry = $this->db->query($sql, array($segment,$riwayat));
|
|
// echo $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select mcu riwayat", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if (count($rows) > 0) {
|
|
$mcuRiwayatID = $rows[0]["Mcu_RiwayatID"];
|
|
$mcuRiwayatGroupID = $rows[0]["Mcu_RiwayatMcu_RiwayatGroupID"];
|
|
}
|
|
|
|
// update mgm header
|
|
// $this->update_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
// update mgm detail
|
|
// $this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
if ($mcuRiwayatID == 0) {
|
|
$this->insert_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
} else {
|
|
$this->insert_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode, $mcuRiwayatID, $mcuRiwayatGroupID);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$this->reply(["status" => "OK", 'message' => 'Proses generate kebiasaan hidup berhasil']);
|
|
}
|
|
function generate_konsumsi_obat($mgmMcuID, $orderHeaderID, $json)
|
|
{
|
|
$this->db->trans_begin();
|
|
|
|
$have_kebiasaan_hidup = false;
|
|
$mcuRiwayatID = 0;
|
|
$mcuRiwayatGroupID = 0;
|
|
$natTestCode = "";
|
|
|
|
$title = "RIWAYAT KONSUMSI OBAT TERATUR";
|
|
// update mgm header
|
|
$this->update_mgm_header($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
// update mgm detail
|
|
$this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
foreach ($json as $key => $value) {
|
|
if ($value["title"] == "RIWAYAT KONSUMSI OBAT TERATUR" && $value["chx"] == 1) {
|
|
$have_kebiasaan_hidup = true;
|
|
$segment = '';
|
|
$riwayat = $value["label"];
|
|
$natTestCode = $value["title"];
|
|
$sql = "SELECT Mcu_RiwayatID,
|
|
Mcu_RiwayatName,
|
|
Mcu_RiwayatMcu_RiwayatGroupID
|
|
FROM one_etl.mcu_riwayat
|
|
WHERE Mcu_RiwayatIsActive = 'Y'
|
|
AND Mcu_RiwayatName = ?";
|
|
$qry = $this->db->query($sql, array($segment,$riwayat));
|
|
// echo $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select mcu riwayat", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if (count($rows) > 0) {
|
|
$mcuRiwayatID = $rows[0]["Mcu_RiwayatID"];
|
|
$mcuRiwayatGroupID = $rows[0]["Mcu_RiwayatMcu_RiwayatGroupID"];
|
|
}
|
|
|
|
// update mgm header
|
|
// $this->update_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
// update mgm detail
|
|
// $this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
if ($mcuRiwayatID == 0) {
|
|
$this->insert_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
} else {
|
|
$this->insert_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode, $mcuRiwayatID, $mcuRiwayatGroupID);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$this->reply(["status" => "OK", 'message' => 'Proses generate kebiasaan hidup berhasil']);
|
|
}
|
|
function generate_imunisasi($mgmMcuID, $orderHeaderID, $json)
|
|
{
|
|
$this->db->trans_begin();
|
|
|
|
$have_kebiasaan_hidup = false;
|
|
$mcuRiwayatID = 0;
|
|
$mcuRiwayatGroupID = 0;
|
|
$natTestCode = "";
|
|
|
|
$title = "RIWAYAT IMUNISASI";
|
|
// update mgm header
|
|
$this->update_mgm_header($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
// update mgm detail
|
|
$this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $title);
|
|
|
|
foreach ($json as $key => $value) {
|
|
if ($value["title"] == "RIWAYAT IMUNISASI" && $value["chx"] == 1) {
|
|
$have_kebiasaan_hidup = true;
|
|
$segment = $value["segment_name"];
|
|
$riwayat = $value["label"];
|
|
$natTestCode = $value["title"];
|
|
$sql = "SELECT Mcu_RiwayatID,
|
|
Mcu_RiwayatName,
|
|
Mcu_RiwayatMcu_RiwayatGroupID
|
|
FROM one_etl.mcu_riwayat
|
|
WHERE Mcu_RiwayatIsActive = 'Y'
|
|
AND Mcu_RiwayatSegmentName = ?
|
|
AND Mcu_RiwayatName = ?";
|
|
$qry = $this->db->query($sql, array($segment,$riwayat));
|
|
// echo $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select mcu riwayat", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if (count($rows) > 0) {
|
|
$mcuRiwayatID = $rows[0]["Mcu_RiwayatID"];
|
|
$mcuRiwayatGroupID = $rows[0]["Mcu_RiwayatMcu_RiwayatGroupID"];
|
|
}
|
|
|
|
// update mgm header
|
|
// $this->update_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
// update mgm detail
|
|
// $this->update_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
|
|
if ($mcuRiwayatID == 0) {
|
|
$this->insert_mgm_header($mgmMcuID, $orderHeaderID, $natTestCode);
|
|
} else {
|
|
$this->insert_mgm_riwayat($mgmMcuID, $orderHeaderID, $natTestCode, $mcuRiwayatID, $mcuRiwayatGroupID);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$this->reply(["status" => "OK", 'message' => 'Proses generate kebiasaan hidup berhasil']);
|
|
}
|
|
}
|