get_rows($sql); if ($resp["status"] != 0) { echo "ERR : " . $resp["message"]; exit(); } $rows = $resp["data"]; $covid_px_ids = "-1"; foreach ($rows as $r) { $covid_px_ids .= "," . $r["Nar_TestMappingNat_TestID"]; } return $covid_px_ids; } function update_submit() { $prm = $this->get_param(); $id = $prm["Nar_TxID"]; $postJson = $prm["PostJson"]; $responseJson = $prm["ResponseJson"]; $sql = "update nar_tx set Nar_TxIsSubmitted = 'Y' where Nar_TxID = ?"; $qry = $this->db->query($sql,[$id]); if (!$qry) { $this->reply(["status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query() ]); exit; } $data = ["Nar_TxDetailNar_TxID" => $id , "Nar_TxPostJson" => $postJson, "Nar_TxResponseJson" => $responseJson ]; $qry = $this->db->insert("nar_tx_detail",$data); if (!$qry) { $this->reply(["status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query() ]); exit; } $this->reply(["status" => "OK"]); } function get_nar_result() { $tzOffset = "+07:00"; $sql = "select distinct Nar_TxID Id, Nar_TxRequesterOrganizationID requesterOrganizationID, Nar_TxPerformerOrganizationID performerOrganizationID, T_OrderHeaderLabNumberExt labNumber, Nar_TxT_SampleBarcode sampleNumber, concat(T_OrderHeaderLabNumberExt,'-LAB') reportNumber, Nar_TxIhsNumber ihsNumber, DATE_FORMAT(T_OrderHeaderDate, '%Y-%m-%dT%T{$tzOffset}') orderDate, DATE_FORMAT(Nar_TxCollectedDate, '%Y-%m-%dT%T{$tzOffset}') collectedTime, DATE_FORMAT(Nar_TxReceivedDate, '%Y-%m-%dT%T{$tzOffset}') receivedTime, DATE_FORMAT(Nar_TxCollectedDate, '%Y-%m-%dT%T{$tzOffset}') effectiveDate, DATE_FORMAT(Nar_TxIssueDate, '%Y-%m-%dT%T{$tzOffset}') issueDate, Nar_TestCode, Nar_TestDisplay, Nar_TestDescription, Nar_SpecimenCode, Nar_SpecimenDescription, Nar_TestResultCode, Nar_TestResultDisplay, Nar_ReasonCode, Nar_TxT_OrderDetailID from nar_tx join t_orderheader on Nar_TxIsConfirm = 'Y' and Nar_TxIsSubmitted = 'N' and Nar_TxT_OrderHeaderID = T_OrderHeaderID join nar_test on Nar_TxNar_TestID = Nar_TestID join nar_specimen on Nar_TxNar_SpecimenID = Nar_SpecimenID join nar_test_result on Nar_TxNar_TestResultID = Nar_TestResultID join nar_reason on Nar_TxNar_ReasonID = Nar_ReasonID "; $resp = $this->get_rows($sql); if ($resp["status"] == -1) { $this->reply(["status" => "ERR", "message" => $resp["message"]]); exit; } $result = []; $tx_ids = "-1"; foreach($resp["data"] as $r) { $tx_ids .= $r["Id"]; $r["servicePxCode"] = [ "code" => $r["Nar_TestCode"], "display" => $r["Nar_TestDisplay"], "name" => $r["Nar_TestDescription"] ]; $r["specimenCode"] = [ "code" => $r["Nar_SpecimenCode"], "display" => $r["Nar_SpecimenDescription"] ]; $r["observationCode"] = [ "code" => $r["Nar_TestCode"], "display" => $r["Nar_TestDisplay"] ]; $r["resultCode"] = [ "code" => $r["Nar_TestResultCode"], "display" => $r["Nar_TestResultDisplay"] ]; unset($r["Nar_TestCode"]); unset($r["Nar_TestDisplay"]); unset($r["Nar_TestDescription"]); unset($r["Nar_SpecimenCode"]); unset($r["Nar_SpecimenDescription"]); unset($r["Nar_TestResultCode"]); unset($r["Nar_TestResultDisplay"]); $r["observationNumber"] = $r["labNumber"] . "." . $r["Nar_TxT_OrderDetailID"]; unset($r["Nar_TxT_OrderDetailID"]); $result[] = $r; } //questionaire $sql = "select * from nar_tx_questionnaire join nar_questionnaire_item on Nar_TxQuestionnaireNar_TxID in ($tx_ids) and Nar_TxQuestionnaireNar_QuestionnaireItemID = Nar_QuestionnaireItemID and Nar_TxQuestionnaireIsActive = 'Y' and Nar_QuestionnaireItemIsActive = 'Y' join nar_questionnaire on Nar_QuestionnaireItemNar_QuestionnaireID = Nar_QuestionnaireID and Nar_QuestionnaireIsActive = 'Y' join nar_questionnaire_answer on Nar_TxQuestionnaireNar_QuestionnaireAnswerID = Nar_QuestionnaireAnswerID and Nar_QuestionnaireAnswerIsActive = 'Y' "; $resp = $this->get_rows($sql); if ($resp["status"] == -1) { $this->reply(["status" => "ERR", "message" => $resp["message"]]); exit; } $questionnaires = $resp["data"]; foreach($result as $idx => $r) { $id = $r["Id"]; $qs = array_filter($questionnaires,function ($qi) use($id) { return $id == $qi["Nar_TxQuestionnaireNat_TxID"]; }); $rq = []; $jq = []; $jq_idx = 0; $jq_item_idx = 0; $prev_nar_questionnaire = ""; $prev_item = ""; foreach($qs as $q) { if ($prev_nar_questionnaire != $q["Nar_QuestionnaireNarID"]) { $jq[] = ["questionnaire" => $q["Nar_QuestionnaireNarID"], "item" => [] ]; $jq_idx = count($jq) - 1; $jq_item_idx = count($jq[$jq_idx]["item"]) - 1; } if ($prev_item != $q["Nar_QuestionnaireItemID"]) { $jq["item"][] = []; $jq_item_idx = count($jq[$jq_idx]["item"]); } $jq[$jq_idx]["item"][$jq_item_idx] = [ "linkID" => $q["Nar_QuestionnaireItemLinkID"], "text" => $q["Nar_QuestionnaireItemText"], "definition" => $q["Nar_QuestionnaireItemDefinition"], "answer" => [] ]; $jq[$jq_idx][$jq_item_idx]["answer"][] = [ "code" => $q["Nar_QuestionnaireAnswerCode"], "system" => $q["Nar_QuestionnaireAnswerSystem"], "display" => $q["Nar_QuestionnaireAnswerDisplay"], ]; } $result[$idx]["questionaire"] = $jq; } $this->reply(["status" => "OK", "data" => $result]); } function update_reflex_sample() { $param = $this->get_param(); $sql = "update nar_tx join t_orderheader on Nar_TxIsReflex = 'Y' and Nar_TxT_OrderHeaderID = ? and Nar_TxT_SampleTypeID = ? and T_OrderHeaderID = ? set Nar_TxCollectedDate = ?,Nar_TxReceivedDate = T_OrderHeaderCreated, Nar_TxT_SampleBarcode = ? "; $db_msg = ""; foreach ($param["payload"] as $r) { $orderID = $r["T_OrderHeaderID"]; $sampleTypeID = $r["T_SampleTypeID"]; $receiveDateTime = $r["T_OrderSampleReceiveDateTime"]; $barcodeNumber= $r["T_OrderSampleBarcode"]; $qry = $this->db->query($sql, [ $orderID, $sampleTypeID, $orderID, $receiveDateTime, $barcodeNumber ]); if (!$qry) { $db_msg .= "$orderID | $sampleTypeID | $receiveDateTime : " . $this->db->error()["message"] . "\n"; } } if ($db_msg != "") { $this->reply([ "status" => "ERR", "message" => $db_msg, ]); } $this->reply(["status" => "OK"]); } function get_reflex_sample() { $sql = "select distinct M_BranchIpAddress, T_OrderHeaderID, ReflexT_OrderHeaderID from ( select distinct M_BranchIpAddress, incomingRefDetailNewT_OrderHeaderID T_OrderHeaderID, incomingRefDetailT_OrderHeaderID ReflexT_OrderHeaderID from nar_tx join incoming_ref_detail on Nar_TxIsConfirm = 'N' and Nar_TxIsReflex = 'Y' and incomingRefDetailNewT_OrderHeaderID = Nar_TxT_OrderHeaderID join incoming_ref on incomingRefDetailIncomingRefID = incomingRefID join m_branch on incomingRefM_BranchID = M_BranchID union select distinct M_BranchIpAddress, incomingRefChildNewT_OrderHeaderID T_OrderHeaderID, incomingRefChildT_OrderHeaderID ReflexT_OrderHeaderID from nar_tx join incoming_ref_child on Nar_TxIsConfirm = 'N' and Nar_TxIsReflex = 'Y' and incomingRefChildNewT_OrderHeaderID = Nar_TxT_OrderHeaderID join incoming_ref on incomingRefChildIncomingRefID = incomingRefID join m_branch on incomingRefM_BranchID = M_BranchID ) xx order by M_BranchIpAddress"; $resp = $this->get_rows($sql); if ($resp["status"] != 0) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $rows = $resp["data"]; $result = []; $branchData = []; foreach ($rows as $r) { $ip = $r["M_BranchIpAddress"]; $orderID = $r["T_OrderHeaderID"]; $reflexOrderID = $r["ReflexT_OrderHeaderID"]; if (!isset($branchData[$ip])) { $branchData[$ip] = []; } $branchData[$ip][] = [ "T_OrderHeaderID" => $orderID, "ReflexT_OrderHeaderID" => $reflexOrderID, ]; } foreach ($branchData as $k => $v) { $result[] = [ "ip" => $k, "rows" => $v, ]; } $this->reply([ "status" => "OK", "data" => $result, ]); } function get_order_id($date = "", $debug=0, $limit = 100) { if ($date == "") { $date = date("Y-m-d"); } $covid_px_ids = $this->get_covid_test(); $sql = "select distinct T_OrderHeaderID from t_orderheader join t_orderdetail on T_OrderHeaderIsActive = 'Y' and T_OrderHeaderID not in ( select Nar_TxT_OrderHeaderID from nar_tx ) and T_OrderDetailIsActive = 'Y' and date(T_OrderHeaderDate) = ? and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_TestID in ($covid_px_ids) limit 0,$limit"; $resp = $this->get_rows($sql, [$date]); if ($resp["status"] != 0) { echo "ERR : " . $resp["message"]; exit(); } $rows = $resp["data"]; $order_ids = "-1"; $total_order = 0; foreach ($rows as $r) { $order_ids .= "," . $r["T_OrderHeaderID"]; $total_order++; } if($debug == 1) { print_r($order_ids); echo "\ncount : $total_order\n"; } return $order_ids; } function update_result() { $sql = "update nar_tx join t_orderdetail on Nar_TxT_OrderDetailID = T_OrderDetailID and T_OrderDetailValidation = 'Y' set Nar_TxT_OrderDetailResult = T_OrderDetailResult, Nar_TxIssueDate = T_OrderDetailValDate where Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx join nar_test_result_mapping on Nar_TxIsConfirm = 'N' and Nar_TxIsResult = 'N' and Nar_TestResultMappingIsActive = 'Y' and Nar_TestResultMappingNar_TestID = Nar_TxNar_TestID and Nar_TxT_OrderDetailResult = Nar_TestResultMappingBizOneResult set Nar_TxNar_TestResultID = Nar_TestResultMappingNar_TestResultID , Nar_TxIsResult = 'Y' "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx join t_ordersample on Nar_TxIsReflex = 'N' and Nar_TxIsConfirm = 'N' and T_OrderSampleT_OrderHeaderID = Nar_TxT_OrderHeaderID and Nar_TxT_SampleTypeID = T_OrderSampleT_SampleTypeID set Nar_TxCollectedDate = concat(T_OrderSampleSamplingDate, ' ', T_OrderSampleSamplingTime) ,Nar_TxReceivedDate = concat(T_OrderSampleReceiveDate,' ',T_OrderSampleReceiveTime) ,Nar_TxT_SampleBarcode = T_OrderSampleBarcode "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx join t_orderdetail on Nar_TxIsReflex = 'N' and Nar_TxIsConfirm = 'N' and Nar_TxT_OrderDetailID = T_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID join t_ordersample on T_OrderSampleT_OrderHeaderID = Nar_TxT_OrderHeaderID and T_OrderSampleT_SampleTypeID = fn_sampletype_from_local(T_TestNat_TestID) set Nar_TxCollectedDate = concat(T_OrderSampleSamplingDate, ' ', T_OrderSampleSamplingTime) ,Nar_TxReceivedDate = concat(T_OrderSampleReceiveDate,' ',T_OrderSampleReceiveTime) ,Nar_TxT_SampleBarcode = T_OrderSampleBarcode "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx join t_sampletype on Nar_TxIsReflex = 'Y' and Nar_TxIsConfirm = 'N' and Nar_TxT_SampleTypeID = T_SampleTypeID join t_orderheader on Nar_TxT_OrderHeaderID = T_OrderHeaderID join rujukan_bahan on Nar_TxT_OrderHeaderID = rujukanBahanT_OrderHeaderID and T_SampleTypeT_BahanID = rujukanBahanT_BahanID set Nar_TxCollectedDate = rujukanBahanReceiveDate, Nar_TxReceivedDate = T_OrderHeaderCreated"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $this->reply(["status" => "OK"]); } function update_patient() { $this->update_patient_name(); $param = $this->get_param(); $sql = "update nar_tx set Nar_TxIhsNumber = ?, Nar_TxIhsNumberRetry=Nar_TxIhsNumberRetry+1, Nar_TxIhsName = ?, Nar_TxIsIhsNumber = 'Y' where Nar_TxIsConfirm ='N' and Nar_TxM_PatientID = ? and Nar_TxIhsNumberRetry < 6"; $sql_no_ihs = "update nar_tx set Nar_TxIhsRetry= Nar_TxIhsNumberRetry+1 where Nar_TxIsConfirm ='N' and Nar_TxIsIhsNumber = 'N' and Nar_TxM_PatientID = ? and Nar_TxIhsNumberRetry < 6"; foreach ($param["payload"] as $p) { $patientID = $p["Nar_TxM_PatientID"]; $IhsNumber = $p["IhsNumber"]; $IhsName = $p["IhsName"]; if ($IhsNumber != "") { $qry = $this->db->query($sql, [ $IhsNumber, $IhsName, $patientID, ]); } else { $qry = $this->db->query($sql_no_ihs, [$patientID]); } if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } } $this->reply(["status" => "OK", "message" => ""]); } function update_patient_name($reply=0) { $sql = "update nar_tx set Nar_TxPatientFullName = json_unquote( json_extract(fn_get_patient_atribute(Nar_TxM_PatientID), '$.patient_fullname')) where Nar_TxPatientFullName is null"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } if($reply == 1) { $this->reply(["status"=>"OK"]); } } function update_organization() { list($branchID, $branchCode) = $this->get_branch(); $sql = "select Nar_BranchOrganizationID from nar_branch where Nar_BranchIsActive = 'Y' and Nar_BranchM_BranchID = ?"; $resp = $this->get_row($sql, [$branchID]); if ($resp["status"] == -1) { $this->reply(["status" => "ERR", "message" => $resp["message"]]); exit(); } if ($resp["status"] == 0) { $this->reply([ "status" => "ERR", "message" => "Nar Branch belum di set.", ]); exit(); } $performerID = $resp["data"]["Nar_BranchOrganizationID"]; $sql = "update nar_tx set Nar_TxPerformerOrganizationID = ? where Nar_TxPerformerOrganizationID is null and Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql, [$performerID]); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx set Nar_TxRequesterOrganizationID = ? where Nar_TxRequesterOrganizationID is null and Nar_TxIsReflex = 'N'"; $qry = $this->db->query($sql, [$performerID]); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } //update requester isReflexOrder $sql = "update nar_tx join incoming_ref_detail on Nar_TxIsOrganization = 'N' and Nar_TxRequesterOrganizationID is null and incomingRefDetailNewT_OrderHeaderID = Nar_TxT_OrderHeaderID join incoming_ref on incomingRefDetailIncomingRefID = incomingRefID join nar_branch on incomingRefM_BranchID = Nar_BranchM_BranchID set Nar_TxRequesterOrganizationID = Nar_BranchOrganizationID "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx join incoming_ref_child on Nar_TxIsOrganization = 'N' and Nar_TxRequesterOrganizationID is null and incomingRefChildNewT_OrderHeaderID = Nar_TxT_OrderHeaderID join incoming_ref on incomingRefChildIncomingRefID = incomingRefID join nar_branch on incomingRefM_BranchID = Nar_BranchM_BranchID set Nar_TxRequesterOrganizationID = Nar_BranchOrganizationID "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx set Nar_TxIsOrganization = 'Y' where Nar_TxIsOrganization = 'N' and Nar_TxPerformerOrganizationID is not null and Nar_TxRequesterOrganizationID is not null"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $this->reply(["status" => "OK", "message" => ""]); } function get_patient($limit = 50) { $sql = "select Nar_TxM_PatientID, json_unquote( json_extract(fn_get_patient_atribute(Nar_TxM_PatientID), '$.patient_fullname')) PatientFullName, M_IdTypeName, M_PatientIDNumber from nar_tx join m_patient on Nar_TxIsSubmitted = 'N' and Nar_TxIsIhsNumber = 'N' and Nar_TxM_PatientID = M_PatientID and Nar_TxIhsNumberRetry < 6 join m_idtype on M_PatientM_IdTypeID = M_IdTypeID and M_IdTypeID = 1 limit 0,$limit "; $resp = $this->get_rows($sql); if ($resp["status"] == -1) { $this->reply(["status" => "ERR", "message" => $resp["message"]]); } $this->reply(["status" => "OK", "rows" => $resp["data"]]); } function update_order($date = "", $debug = 0, $limit = 100) { $order_ids = $this->get_order_id($date, $limit); if ($debug == 1) { echo "ids : $order_ids\n"; $sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_SampleTypeID, if(T_OrderHeaderAddOnLabNumberOrigin is null,'N','Y') , T_OrderDetailID, T_OrderHeaderM_PatientID, Nar_SpecimenID,Nar_TestID from t_orderheader join t_orderheaderaddon on T_OrderHeaderID in ( $order_ids ) and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y' join t_test on T_TestID = T_OrderDetailT_TestID join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID join nar_test_mapping on T_TestNat_TestID = Nar_TestMappingNat_TestID and Nar_TestMappingIsActive = 'Y' join nar_test on Nar_TestMappingNar_TestID = Nar_TestID left join nar_specimen_mapping on T_TestT_SampleTypeID = Nar_SpecimenMappingT_SampleTypeID and Nar_SpecimenMappingIsActive = 'Y' left join nar_specimen on Nar_SpecimenMappingNar_SpecimenID = Nar_SpecimenID"; $qry = $this->db->query($sql); if(!$qry) { echo "ERR : " . $this->db->error()["message"]; exit; } echo $this->db->last_query(); "echo result :\n"; print_r($qry->result_array()); } $sql = "insert into nar_tx( Nar_TxT_OrderHeaderID,Nar_TxOccuranceDate,Nar_TxT_SampleTypeID, Nar_TxIsReflex, Nar_TxT_OrderDetailID, Nar_TxM_PatientID, Nar_TxNar_SpecimenID,Nar_TxNar_TestID ) select T_OrderHeaderID,T_OrderHeaderDate,T_SampleTypeID, if(T_OrderHeaderAddOnLabNumberOrigin is null,'N','Y') , T_OrderDetailID, T_OrderHeaderM_PatientID, Nar_SpecimenID,Nar_TestID from t_orderheader join t_orderheaderaddon on T_OrderHeaderID in ( $order_ids ) and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y' join t_test on T_TestID = T_OrderDetailT_TestID join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID join nar_test_mapping on T_TestNat_TestID = Nar_TestMappingNat_TestID and Nar_TestMappingIsActive = 'Y' join nar_test on Nar_TestMappingNar_TestID = Nar_TestID left join nar_specimen_mapping on T_TestT_SampleTypeID = Nar_SpecimenMappingT_SampleTypeID and Nar_SpecimenMappingIsActive = 'Y' left join nar_specimen on Nar_SpecimenMappingNar_SpecimenID = Nar_SpecimenID on duplicate key update Nar_TxT_OrderHeaderID = T_OrderHeaderID "; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx set Nar_TxIsTest = 'Y' where Nar_TxNar_TestID > 0 and Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx set Nar_TxIsSpecimen = 'Y' where Nar_TxNar_SpecimenID > 0 and Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $this->update_organization(); $this->reply(["status" => "OK"]); } function update_specimen() { $sql = "update nar_tx join nar_specimen_mapping on Nar_TxT_SampleTypeID = Nar_SpecimenMappingT_SampleTypeID and Nar_SpecimenMappingIsActive = 'Y' set Nar_TxNar_SpecimenID= Nar_SpecimenMappingNar_SpecimenID where Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $sql = "update nar_tx set Nar_TxIsSpecimen = 'Y' where Nar_TxNar_SpecimenID > 0 and Nar_TxIsConfirm = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->reply([ "status" => "ERR", "message" => $this->db->error()["message"] . "|" . $this->db->last_query(), ]); exit(); } $this->reply(["status" => "OK"]); } function get_order() { // get covid test //get order having covid test $order_ids = "-1"; $sql = "select T_OrderHeaderID,T_OrderHeaderDate, if(T_OrderHeaderAddOnLabNumberOrigin is null,'N','Y') isReflexOrder, T_OrderHeaderLabNumberExt,T_OrderHeaderM_PatientID, fn_get_patient_atribute(T_OrderHeaderM_PatientID) PatientName, '' as IhsNumber , Nar_TestCode, Nar_TestDisplay, Nar_TestDescription, Nar_SpecimenCode, ifnull(Nar_SpecimenDescription,concat(T_SampleTypeName,' belum di mapping ke Nar Specimen')) Nar_SpecimenDescription from t_orderheader join t_orderheaderaddon on T_OrderHeaderID in ( $order_ids ) and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID join t_test on T_TestID = T_OrderDetailT_TestID join t_sampletype on T_TestT_SampleTypeID = T_TestT_SampleTypeID join nar_test_mapping on T_TestNat_TestID = Nar_TestMappingNat_TestID and Nar_TestMappingIsActive = 'Y' join nar_test on Nar_TestMappingNar_TestID = Nar_TestID left join nar_specimen_mapping on T_TestT_SampleTypeID = Nar_SpecimenMappingT_SampleTypeID and Nar_SpecimenMappingIsActive = 'Y' left join nar_specimen on Nar_SpecimenMappingNar_SpecimenID = Nar_SpecimenID order by T_OrderHeaderID desc limit 0,10"; $resp = $this->get_rows($sql); if ($resp["status"] != 0) { echo "ERR : " . $resp["message"]; exit(); } $rows = $resp["data"]; foreach ($rows as $idx => $r) { $pat = $r["PatientName"]; unset($rows[$idx]["PatientName"]); unset($rows[$idx]["T_OrderHeaderID"]); unset($rows[$idx]["T_OrderHeaderM_PatientID"]); $j_pat = json_decode($pat, true); $rows[$idx]["Patient"] = $j_pat["patient_fullname"]; } $this->print_table_style(); $this->print_table($rows, array_keys($rows[0])); } function index() { } public function print_table_style() { echo " "; } public function print_table($rows, $keys) { echo "
| $k | "; } echo "
| " . $r[$k] . " | "; } echo "