Add xray upload endpoints
This commit is contained in:
@@ -186,9 +186,9 @@ class Resultentry extends MY_Controller
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function getphotos($orderid, $sampletypeid)
|
||||
{
|
||||
$rows = [];
|
||||
function getphotos($orderid, $sampletypeid)
|
||||
{
|
||||
$rows = [];
|
||||
//print_r($_SERVER);
|
||||
$urlbase = 'http://' . $_SERVER['SERVER_NAME'] . "/one-media/one-image-nonlab/";
|
||||
$sql = "SELECT So_ImageUploadID as id,
|
||||
@@ -198,9 +198,30 @@ class Resultentry extends MY_Controller
|
||||
WHERE
|
||||
So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$rows = $this->db_onedev->query($sql)->result_array();
|
||||
return $rows;
|
||||
}
|
||||
$rows = $this->db_onedev->query($sql)->result_array();
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function get_nonlab_uploads($trx_id)
|
||||
{
|
||||
$rows = [];
|
||||
$urlbase = 'http://' . $_SERVER['SERVER_NAME'] . "/one-media/one-image-nonlab/";
|
||||
$sql = "SELECT
|
||||
T_NonlabDocumentID as id,
|
||||
T_NonlabDocumentFile as file,
|
||||
T_NonlabDocumentType as type,
|
||||
CONCAT('{$urlbase}', T_NonlabDocumentFile) as url
|
||||
FROM t_nonlabdocument
|
||||
WHERE
|
||||
T_NonlabDocumentSo_ResultEntryID = ?
|
||||
AND T_NonlabDocumentIsActive = 'Y'
|
||||
ORDER BY T_NonlabDocumentID DESC";
|
||||
$query = $this->db_onedev->query($sql, array($trx_id));
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
@@ -1571,14 +1592,265 @@ class Resultentry extends MY_Controller
|
||||
// "total" => 1,
|
||||
// "records" => $prm
|
||||
// );
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
function printcount()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
// $this->sys_ok($result);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
public function upload()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userid = intval($this->sys_user["M_UserID"]);
|
||||
$trx_id = intval($this->input->post('trx_id'));
|
||||
if ($trx_id <= 0 && isset($this->sys_input['trx_id'])) {
|
||||
$trx_id = intval($this->sys_input['trx_id']);
|
||||
}
|
||||
|
||||
if ($trx_id <= 0) {
|
||||
$this->sys_error("Parameter trx_id is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_FILES['file']) || empty($_FILES['file']['name'])) {
|
||||
$this->sys_error("File is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
sr.So_ResultEntryID,
|
||||
sr.So_ResultEntryT_OrderHeaderID,
|
||||
sr.So_ResultEntryT_OrderDetailID,
|
||||
oh.T_OrderHeaderDate,
|
||||
sso.T_SamplingSoID
|
||||
FROM so_resultentry sr
|
||||
JOIN t_orderdetail od
|
||||
ON od.T_OrderDetailID = sr.So_ResultEntryT_OrderDetailID
|
||||
AND od.T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_orderheader oh
|
||||
ON oh.T_OrderHeaderID = sr.So_ResultEntryT_OrderHeaderID
|
||||
AND oh.T_OrderHeaderIsActive = 'Y'
|
||||
LEFT JOIN t_samplingso sso
|
||||
ON sso.T_SamplingSoT_OrderHeaderID = sr.So_ResultEntryT_OrderHeaderID
|
||||
AND sso.T_SamplingSoT_TestID = od.T_OrderDetailT_TestID
|
||||
AND sso.T_SamplingSoIsActive = 'Y'
|
||||
WHERE
|
||||
sr.So_ResultEntryID = ?
|
||||
AND sr.So_ResultEntryIsActive = 'Y'
|
||||
LIMIT 1";
|
||||
$qry = $this->db_onedev->query($sql, array($trx_id));
|
||||
if ($qry === FALSE) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$row = $qry->row_array();
|
||||
if (!$row) {
|
||||
$this->sys_error("Data transaksi tidak ditemukan");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (intval($row['T_SamplingSoID']) <= 0) {
|
||||
$this->sys_error("T_SamplingSOID tidak ditemukan untuk transaksi ini");
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder_info = $this->build_nonlab_upload_folder($row['T_OrderHeaderDate']);
|
||||
$upload_path = $folder_info['absolute_path'];
|
||||
if (!$this->ensure_nonlab_upload_folder($upload_path)) {
|
||||
$this->sys_error("Gagal menyiapkan folder upload");
|
||||
exit;
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
|
||||
if (!in_array($extension, array('pdf', 'jpg', 'jpeg', 'png'))) {
|
||||
$this->sys_error("Format file harus pdf/jpg/jpeg/png");
|
||||
exit;
|
||||
}
|
||||
|
||||
$generated_name = $this->generate_nonlab_upload_name(32) . '.' . $extension;
|
||||
|
||||
$config = array();
|
||||
$config['upload_path'] = $upload_path;
|
||||
$config['allowed_types'] = 'pdf|jpg|jpeg|png';
|
||||
$config['max_size'] = '1024';
|
||||
$config['file_name'] = $generated_name;
|
||||
$config['overwrite'] = FALSE;
|
||||
$config['remove_spaces'] = TRUE;
|
||||
|
||||
$this->load->library('upload', $config);
|
||||
$this->upload->initialize($config);
|
||||
|
||||
if (!$this->upload->do_upload('file')) {
|
||||
$this->sys_error(strip_tags($this->upload->display_errors('', '')));
|
||||
exit;
|
||||
}
|
||||
|
||||
$upload_data = $this->upload->data();
|
||||
$stored_file = $folder_info['relative_path'] . '/' . $upload_data['file_name'];
|
||||
$file_type = ($extension === 'pdf') ? 'pdf' : 'image';
|
||||
|
||||
$insert = array(
|
||||
'T_NonlabDocumentT_OrderHeaderID' => intval($row['So_ResultEntryT_OrderHeaderID']),
|
||||
'T_NonlabDocumentSo_ResultEntryID' => intval($row['So_ResultEntryID']),
|
||||
'T_NonlabDocumentFile' => $stored_file,
|
||||
'T_NonlabDocumentType' => $file_type,
|
||||
'T_NonlabDocumentIsActive' => 'Y',
|
||||
'T_NonlabDocumentCreated' => date('Y-m-d H:i:s'),
|
||||
'T_NonlabDocumentCreatedUserID' => $userid,
|
||||
'T_NonlabDocumentLastUpdated' => date('Y-m-d H:i:s'),
|
||||
'T_NonlabDocumentLastUpdatedUserID' => $userid,
|
||||
'T_NonlabDocumentDeleted' => '0000-00-00 00:00:00',
|
||||
'T_NonlabDocumentDeletedUserID' => 0,
|
||||
);
|
||||
|
||||
$insert_ok = $this->db_onedev->insert('t_nonlabdocument', $insert);
|
||||
if (!$insert_ok) {
|
||||
@unlink($upload_data['full_path']);
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array(
|
||||
array(
|
||||
"id" => $this->db_onedev->insert_id(),
|
||||
"trx_id" => intval($row['So_ResultEntryID']),
|
||||
"samplingso_id" => intval($row['T_SamplingSoID']),
|
||||
"orderheader_id" => intval($row['So_ResultEntryT_OrderHeaderID']),
|
||||
"type" => $file_type,
|
||||
"file" => $stored_file,
|
||||
"url" => '/one-media/one-image-nonlab/' . $stored_file,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function deleteupload()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userid = intval($this->sys_user["M_UserID"]);
|
||||
$id = intval($this->input->post('id'));
|
||||
if ($id <= 0 && isset($this->sys_input['id'])) {
|
||||
$id = intval($this->sys_input['id']);
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
$this->sys_error("Parameter id is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
$check_sql = "SELECT
|
||||
T_NonlabDocumentID as id,
|
||||
T_NonlabDocumentSo_ResultEntryID as trx_id,
|
||||
T_NonlabDocumentFile as file
|
||||
FROM t_nonlabdocument
|
||||
WHERE
|
||||
T_NonlabDocumentID = ?
|
||||
AND T_NonlabDocumentIsActive = 'Y'
|
||||
LIMIT 1";
|
||||
$check_qry = $this->db_onedev->query($check_sql, array($id));
|
||||
if ($check_qry === FALSE) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$row = $check_qry->row_array();
|
||||
if (!$row) {
|
||||
$this->sys_error("File upload tidak ditemukan");
|
||||
exit;
|
||||
}
|
||||
|
||||
$update_sql = "UPDATE t_nonlabdocument SET
|
||||
T_NonlabDocumentIsActive = 'N',
|
||||
T_NonlabDocumentLastUpdated = NOW(),
|
||||
T_NonlabDocumentLastUpdatedUserID = ?,
|
||||
T_NonlabDocumentDeleted = NOW(),
|
||||
T_NonlabDocumentDeletedUserID = ?
|
||||
WHERE
|
||||
T_NonlabDocumentID = ?
|
||||
AND T_NonlabDocumentIsActive = 'Y'";
|
||||
$update_qry = $this->db_onedev->query($update_sql, array($userid, $userid, $id));
|
||||
if ($update_qry === FALSE) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array(
|
||||
array(
|
||||
"id" => intval($row['id']),
|
||||
"trx_id" => intval($row['trx_id']),
|
||||
"file" => $row['file'],
|
||||
"is_active" => 'N',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
private function generate_nonlab_upload_name($length = 32)
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$characters_length = strlen($characters);
|
||||
$random_string = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$random_string .= $characters[rand(0, $characters_length - 1)];
|
||||
}
|
||||
return $random_string;
|
||||
}
|
||||
|
||||
private function build_nonlab_upload_folder($order_header_date)
|
||||
{
|
||||
$timestamp = strtotime($order_header_date);
|
||||
if ($timestamp === FALSE) {
|
||||
$timestamp = time();
|
||||
}
|
||||
|
||||
$year = date('Y', $timestamp);
|
||||
$month = date('m', $timestamp);
|
||||
$relative_path = $year . '/' . $month;
|
||||
|
||||
return array(
|
||||
'relative_path' => $relative_path,
|
||||
'absolute_path' => '/home/one/project/one/one-media/one-image-nonlab/' . $relative_path . '/',
|
||||
);
|
||||
}
|
||||
|
||||
private function ensure_nonlab_upload_folder($path)
|
||||
{
|
||||
if (is_dir($path)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return mkdir($path, 0775, TRUE);
|
||||
}
|
||||
|
||||
function printcount()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
@@ -2714,10 +2986,12 @@ class Resultentry extends MY_Controller
|
||||
So_ResultEntryStatus as status,
|
||||
'' as language_name,
|
||||
IFNULL(M_DoctorID,0) as doctor_id,
|
||||
CONCAT(IFNULL(M_DoctorPrefix,''),' ',IFNULL(M_DoctorPrefix2,''), ' ', IFNULL(M_DoctorName,''), ' ',IFNULL(M_DoctorSufix,''),' ', IFNULL(M_DoctorSufix2,''), ' ') as doctor_fullname,
|
||||
'' as details,
|
||||
'' as photos
|
||||
FROM so_resultentry
|
||||
CONCAT(IFNULL(M_DoctorPrefix,''),' ',IFNULL(M_DoctorPrefix2,''), ' ', IFNULL(M_DoctorName,''), ' ',IFNULL(M_DoctorSufix,''),' ', IFNULL(M_DoctorSufix2,''), ' ') as doctor_fullname,
|
||||
'' as details,
|
||||
'' as photos,
|
||||
'' as uploads,
|
||||
'N' as has_upload
|
||||
FROM so_resultentry
|
||||
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
So_ResultEntryT_OrderHeaderID = {$trx_id} AND
|
||||
@@ -2825,9 +3099,11 @@ class Resultentry extends MY_Controller
|
||||
}
|
||||
|
||||
$rst_details[$ki]['details'] = $query_details->result_array();
|
||||
$rst_details[$ki]['langs'] = "";
|
||||
$rst_details[$ki]['photos'] = "";
|
||||
}
|
||||
$rst_details[$ki]['langs'] = "";
|
||||
$rst_details[$ki]['photos'] = "";
|
||||
$rst_details[$ki]['uploads'] = $this->get_nonlab_uploads($vi['trx_id']);
|
||||
$rst_details[$ki]['has_upload'] = count($rst_details[$ki]['uploads']) > 0 ? 'Y' : 'N';
|
||||
}
|
||||
|
||||
// Get deliveries
|
||||
$deliveries = $this->getdeliveries($trx_id, $typeresult);
|
||||
|
||||
Reference in New Issue
Block a user